void MLProcMatrix::process(const int frames) { const int inputs = min(kMLMatrixMaxIns, getNumInputs()); const int outputs = min(kMLMatrixMaxOuts, getNumOutputs()); if((inputs != mInputs) || (outputs != mOutputs)) { resize(); } if (mParamsChanged) { calcCoeffs(); } // TODO optimize, calc constants for (int j=1; j <= outputs; ++j) { MLSignal& y = getOutput(j); y.clear(); for (int i=1; i <= inputs; ++i) { const MLSignal& x = getInput(i); if (mGain[i][j] > 0.) { for (int n=0; n < frames; ++n) { y[n] += x[n]; } } } } }
// Compute of the DSP, adding the controls to the input/output passed void remote_dsp_aux::compute(int count, FAUSTFLOAT** input, FAUSTFLOAT** output){ if (fRunningFlag) { // If count > fBufferSize : the cycle is divided in numberOfCycles NetJack cycles, and a lastCycle one int numberOfCycles = count/fBufferSize; int lastCycle = count%fBufferSize; int i = 0; for (i = 0; i < numberOfCycles; i++) { setupBuffers(input, output, i*fBufferSize); ControlUI::encode_midi_control(fControlInputs[0], fInControl, fCounterIn); sendSlice(fBufferSize); recvSlice(fBufferSize); ControlUI::decode_midi_control(fControlOutputs[0], fOutControl, fCounterOut); } if (lastCycle > 0) { setupBuffers(input, output, i*fBufferSize); ControlUI::encode_midi_control(fControlInputs[0], fInControl, fCounterIn); fillBufferWithZerosOffset(getNumInputs(), lastCycle, fBufferSize-lastCycle, fAudioInputs); sendSlice(lastCycle); recvSlice(lastCycle); ControlUI::decode_midi_control(fControlOutputs[0], fOutControl, fCounterOut); } } else { fillBufferWithZerosOffset(getNumOutputs(), 0, count, output); } }
vector<SXMatrix> FX::evalSX(const vector<SXMatrix>& arg){ casadi_assert_message(isInit(),"Function has not been initialized"); // Copy the arguments into a new vector with the right sparsity casadi_assert_message(arg.size()<=getNumInputs(), "FX::evalSX: number of passed-in dependencies (" << arg.size() << ") should not exceed the number of inputs of the function (" << getNumInputs() << ")."); vector<SXMatrix> arg2 = arg; arg2.resize(getNumInputs()); for(int iind=0; iind<arg.size(); ++iind){ // If sparsities do not match, we need to map the nonzeros onto the new pattern if(!(arg2[iind].sparsity()==input(iind).sparsity())){ arg2[iind] = project(arg2[iind],input(iind).sparsity()); } } // Create result vector with correct sparsity for the result vector<SXMatrix> res(getNumOutputs()); for(int i=0; i<res.size(); ++i){ res[i] = SXMatrix(output(i).sparsity()); } // No sensitivities vector<vector<SXMatrix> > dummy; // Evaluate the algorithm (*this)->evalSX(arg2,res,dummy,dummy,dummy,dummy,false); // Return the result return res; }
RecordNode::RecordNode() : GenericProcessor("Record Node"), newDirectoryNeeded(true), timestamp(0) { isProcessing = false; isRecording = false; setFirstBlock = false; settings.numInputs = 2048; settings.numOutputs = 0; recordingNumber = -1; spikeElectrodeIndex = 0; experimentNumber = 0; hasRecorded = false; settingsNeeded = false; // 128 inputs, 0 outputs setPlayConfigDetails(getNumInputs(),getNumOutputs(),44100.0,128); m_recordThread = new RecordThread(engineArray); m_dataQueue = new DataQueue(WRITE_BLOCK_LENGTH, DATA_BUFFER_NBLOCKS); m_eventQueue = new EventMsgQueue(EVENT_BUFFER_NEVENTS); m_spikeQueue = new SpikeMsgQueue(SPIKE_BUFFER_NSPIKES); m_recordThread->setQueuePointers(m_dataQueue, m_eventQueue, m_spikeQueue); }
AudioResamplingNode::AudioResamplingNode() : GenericProcessor("Resampling Node"), sourceBufferSampleRate(40000.0), destBufferSampleRate(44100.0), ratio(1.0), lastRatio(1.0), destBuffer(0), tempBuffer(0), destBufferIsTempBuffer(true), isTransmitting(false), destBufferPos(0) { settings.numInputs = 2; settings.numOutputs = 2; setPlayConfigDetails(getNumInputs(), // number of inputs getNumOutputs(), // number of outputs 44100.0, // sampleRate 128); // blockSize filter = new Dsp::SmoothedFilterDesign <Dsp::RBJ::Design::LowPass, 1> (1024); if (destBufferIsTempBuffer) destBufferWidth = 1024; else destBufferWidth = 1000; destBufferTimebaseSecs = 1.0; destBuffer = new AudioSampleBuffer(16, destBufferWidth); tempBuffer = new AudioSampleBuffer(16, destBufferWidth); continuousDataBuffer = new int16[10000]; }
vector<vector<MX> > Function::callParallel(const vector<vector<MX> > &x, const Dictionary& paropt) { assertInit(); // Make sure not empty casadi_assert_message(x.size()>1, "Function: callParallel(vector<vector<MX> >): " "argument must be of length > 1. You supplied length " << x.size() << "."); // Return object vector<vector<MX> > ret(x.size()); // Check if we are bypassing the parallelizer Dictionary::const_iterator ii=paropt.find("parallelization"); if (ii!=paropt.end() && ii->second=="expand") { for (int i=0; i<x.size(); ++i) { ret[i] = call(x[i]); } return ret; } // Create parallelizer object and initialize it Parallelizer p(vector<Function>(x.size(), *this)); p.setOption(paropt); p.init(); // Concatenate the arguments vector<MX> p_in; p_in.reserve(x.size() * getNumInputs()); for (int i=0; i<x.size(); ++i) { p_in.insert(p_in.end(), x[i].begin(), x[i].end()); p_in.resize(p_in.size()+getNumInputs()-x[i].size()); } // Call the parallelizer vector<MX> p_out = p.call(p_in); casadi_assert(p_out.size() == x.size() * getNumOutputs()); // Collect the outputs vector<MX>::const_iterator it=p_out.begin(); for (int i=0; i<x.size(); ++i) { ret[i].insert(ret[i].end(), it, it+getNumOutputs()); it += getNumOutputs(); } return ret; }
void SimpleIndefDpleInternal::evaluate() { for (int i=0;i<getNumInputs();++i) { std::copy(input(i).begin(), input(i).end(), f_.input(i).begin()); } f_.evaluate(); for (int i=0;i<getNumOutputs();++i) { std::copy(f_.output(i).begin(), f_.output(i).end(), output(i).begin()); } }
void MLProcMatrix::disconnect(int a, int b) { const int inputs = min(kMLMatrixMaxIns, getNumInputs()); const int outputs = min(kMLMatrixMaxOuts, getNumOutputs()); if ((a <= inputs) && (b <= outputs)) { mGain[a][b] = 0.; } }
MLProc::err MLProcMatrix::resize() { MLProc::err e = OK; const int inputs = min(kMLMatrixMaxIns, getNumInputs()); const int outputs = min(kMLMatrixMaxOuts, getNumOutputs()); mInputs = inputs; mOutputs = outputs; return e; }
void DpleToDle::evaluate() { for (int i=0;i<getNumInputs();++i) { std::copy(input(i).begin(), input(i).end(), dplesolver_.input(i).begin()); } dplesolver_.evaluate(); for (int i=0;i<getNumOutputs();++i) { std::copy(dplesolver_.output(i).begin(), dplesolver_.output(i).end(), output(i).begin()); } }
void QpToImplicit::solveNonLinear() { // Equality nonlinear constraints solver_.input(NLP_SOLVER_LBG).set(0.); solver_.input(NLP_SOLVER_UBG).set(0.); // Simple constraints vector<double>& lbx = solver_.input(NLP_SOLVER_LBX).data(); vector<double>& ubx = solver_.input(NLP_SOLVER_UBX).data(); for (int k=0; k<u_c_.size(); ++k) { lbx[k] = u_c_[k] <= 0 ? -std::numeric_limits<double>::infinity() : 0; ubx[k] = u_c_[k] >= 0 ? std::numeric_limits<double>::infinity() : 0; } // Pass initial guess solver_.input(NLP_SOLVER_X0).set(output(iout_)); // Add auxiliary inputs vector<double>::iterator nlp_p = solver_.input(NLP_SOLVER_P).begin(); for (int i=0; i<getNumInputs(); ++i) { if (i!=iin_) { std::copy(input(i).begin(), input(i).end(), nlp_p); nlp_p += input(i).size(); } } // Solve the NLP solver_.evaluate(); stats_["solver_stats"] = solver_.getStats(); // Get the implicit variable output(iout_).set(solver_.output(NLP_SOLVER_X)); // Evaluate auxilary outputs, if necessary if (getNumOutputs()>0) { f_.setInput(output(iout_), iin_); for (int i=0; i<getNumInputs(); ++i) if (i!=iin_) f_.setInput(input(i), i); f_.evaluate(); for (int i=0; i<getNumOutputs(); ++i) { if (i!=iout_) f_.getOutput(output(i), i); } } }
void remote_dsp_aux::setupBuffers(FAUSTFLOAT** input, FAUSTFLOAT** output, int offset) { for(int j=0; j<getNumInputs(); j++) { fAudioInputs[j] = &input[j][offset]; } for(int j=0; j<getNumOutputs(); j++) { fAudioOutputs[j] = &output[j][offset]; } }
void ImplicitFunctionInternal::init(){ // Initialize the residual function if(!f_.isInit()) f_.init(); // Allocate inputs setNumInputs(f_.getNumInputs()-1); for(int i=0; i<getNumInputs(); ++i){ input(i) = f_.input(i+1); } // Allocate outputs setNumOutputs(f_.getNumOutputs()); output(0) = f_.input(0); for(int i=1; i<getNumOutputs(); ++i){ output(i) = f_.output(i); } // Call the base class initializer FXInternal::init(); // Number of equations N_ = output().size(); // Generate Jacobian if not provided if(J_.isNull()) J_ = f_.jacobian(0,0); J_.init(); casadi_assert_message(J_.output().size1()==J_.output().size2(),"ImplicitFunctionInternal::init: the jacobian must be square but got " << J_.output().dimString()); casadi_assert_message(!isSingular(J_.output().sparsity()),"ImplicitFunctionInternal::init: singularity - the jacobian is structurally rank-deficient. sprank(J)=" << sprank(J_.output()) << " (in stead of "<< J_.output().size1() << ")"); // Get the linear solver creator function if(linsol_.isNull() && hasSetOption("linear_solver")){ linearSolverCreator linear_solver_creator = getOption("linear_solver"); // Allocate an NLP solver linsol_ = linear_solver_creator(CRSSparsity()); // Pass options if(hasSetOption("linear_solver_options")){ const Dictionary& linear_solver_options = getOption("linear_solver_options"); linsol_.setOption(linear_solver_options); } } // Initialize the linear solver, if provided if(!linsol_.isNull()){ linsol_.setSparsity(J_.output().sparsity()); linsol_.init(); } // Allocate memory for directional derivatives ImplicitFunctionInternal::updateNumSens(false); }
void SimpleIndefDleInternal::evaluate() { std::cout << "eval" << std::endl; input(DLE_A).printDense(); for (int i=0;i<getNumInputs();++i) { std::copy(input(i).begin(), input(i).end(), f_.input(i).begin()); } f_.evaluate(); for (int i=0;i<getNumOutputs();++i) { std::copy(f_.output(i).begin(), f_.output(i).end(), output(i).begin()); } }
// get a single connection. bool MLProcMatrix::getConnection(int a, int b) { bool r = false; const int inputs = min(kMLMatrixMaxIns, getNumInputs()); const int outputs = min(kMLMatrixMaxOuts, getNumOutputs()); if ((a <= inputs) && (b <= outputs)) { r = (mGain[a][b] > 0.5f); } return r; }
mydsp_wrap() { // Creates paths buildUserInterface(this); // Creates JSON JSONUI builder(getNumInputs(), getNumOutputs()); metadata(&builder); buildUserInterface(&builder); fJSON = builder.JSON(); }
void remote_dsp_aux::sendSlice(int buffer_size) { if (fRunningFlag && jack_net_master_send_slice(fNetJack, getNumInputs(), fAudioInputs, 1, (void**)fControlInputs, buffer_size) < 0){ fillBufferWithZerosOffset(getNumOutputs(), 0, buffer_size, fAudioOutputs); if (fErrorCallback) { printf("Is sent OK ?\n"); fRunningFlag = (fErrorCallback(WRITE_ERROR, fErrorCallbackArg) == 0); } } }
// MLProc::prepareToProcess() is called after all connections in DSP graph are made. // This is where sample rates and block sizes propagate through the graph, and // are checked for consistency. // Setup internal buffers and data to prepare for processing any attached input signals. // MLProcs have no concept of enabled -- it's up to the enclosing container to disable // itself if things go wrong here. // MLProc::err MLProc::prepareToProcess() { MLProc::err e = OK; // debug() << "preparing " << getClassName() << " \"" << getName() << "\" : " ; int ins = getNumInputs(); int outs = getNumOutputs(); float rate = getContextSampleRate(); int blockSize = getContextVectorSize(); // debug() << ins << " ins, " << outs << " outs, rate " << rate << ", blockSize " << blockSize << "\n"; // All inputs must have a signal connected. // So connect unconnected inputs to null input signal. for (int i=0; i<ins; i++) { if (!mInputs[i]) { mInputs[i] = &getContext()->getNullInput(); } } // set size and rate of output signals // TODO it looks like this allocation may be redundant because outputs are allocated in compile() already!? for (int i=1; i<=outs; ++i) { MLSignal& out = getOutput(i); if (&out) { out.setRate(rate); MLSample* outData = out.setDims(blockSize, getOutputFrameSize(i)); if (!outData) { e = memErr; goto bail; } } else { debug() << "MLProc::prepareToProcess: null output " << i << " for " << getName() << "! \n"; } //debug() << " out " << i << ": " << (void *)(MLSignal*)(&out) << ", " << out.getSize() << " samples.\n"; } e = resize(); // recalc params for new sample rate mParamsChanged = true; bail: return e; }
void SimpleIndefDleInternal::init() { DleInternal::init(); casadi_assert_message(!pos_def_, "pos_def option set to True: Solver only handles the indefinite case."); n_ = A_.size1(); MX As = MX::sym("A", A_); MX Vs = MX::sym("V", V_); MX Vss = (Vs+Vs.T())/2; MX A_total = DMatrix::eye(n_*n_) - kron(As, As); MX Pf = solve(A_total, vec(Vss), getOption("linear_solver")); MX P = reshape(Pf, n_, n_); f_ = MXFunction(dleIn("a", As, "v", Vs), dleOut("p", MX(P(output().sparsity())))); f_.init(); casadi_assert(getNumOutputs()==f_.getNumOutputs()); for (int i=0;i<getNumInputs();++i) { casadi_assert_message(input(i).sparsity()==f_.input(i).sparsity(), "Sparsity mismatch for input " << i << ":" << input(i).dimString() << " <-> " << f_.input(i).dimString() << "."); } for (int i=0;i<getNumOutputs();++i) { casadi_assert_message(output(i).sparsity()==f_.output(i).sparsity(), "Sparsity mismatch for output " << i << ":" << output(i).dimString() << " <-> " << f_.output(i).dimString() << "."); } }
returnValue PIDcontroller::step( double currentTime, const Vector& _x, const Vector& _p, const VariablesGrid& _yRef ) { if ( getStatus( ) != BS_READY ) return ACADOERROR( RET_BLOCK_NOT_READY ); if ( _x.getDim( ) != getNumInputs( ) ) return ACADOERROR( RET_VECTOR_DIMENSION_MISMATCH ); /* 1) Use reference trajectory if it is defined */ // set default reference to zero Vector xRef( _x.getDim() ); if ( _yRef.getNumPoints( ) > 0 ) { if ( _yRef.getNumValues( ) != getNumInputs( ) ) return ACADOERROR( RET_VECTOR_DIMENSION_MISMATCH ); xRef = _yRef.getVector( 0 ); } else { xRef.setZero( ); } /* 2) Determine PID control action. */ if ( getNumOutputs( ) > 0 ) { if ( determineControlAction( xRef-_x,u ) != SUCCESSFUL_RETURN ) return ACADOERROR( RET_CONTROLLAW_STEP_FAILED ); } else u.init(); p = _p; /* 3) Call output transformator. */ if ( clipSignals( u,p ) != SUCCESSFUL_RETURN ) return ACADOERROR( RET_OUTPUTTRANSFORMATOR_STEP_FAILED ); return SUCCESSFUL_RETURN; }
void MLProc::clearProc() { const int op = getNumOutputs(); //debug() << "clearing " << getName() << " (" << getClassName() << ")\n"; // clear anything left in outputs for (int i=0; i<op; i++) { mOutputs[i]->clear(); } // let subclass clear filter histories etc. clear(); }
void CContinuousActionGradientPolicy::getGradientPre(ColumnVector *input, ColumnVector *outputErrors, CFeatureList *gradientFeatures) { CFeatureList *featureList = new CFeatureList(); CState *state = new CState(modelState); for (int i = 0; i < getNumInputs(); i ++) { state->setContinuousState(i, input->element(i)); } for (int i = 0; i < getNumOutputs(); i++) { getGradient(state, i, featureList); gradientFeatures->add(featureList, outputErrors->element(i)); } delete featureList; delete state; }
AudioNode::AudioNode() : GenericProcessor("Audio Node"), volume(0.00001f), audioEditor(0) { settings.numInputs = 128; settings.numOutputs = 2; // 64 inputs, 2 outputs (left and right channel) setPlayConfigDetails(getNumInputs(),getNumOutputs(),44100.0,128); leftChan.clear(); rightChan.clear(); nextAvailableChannel = 2; // keep first two channels empty }
void MLMultiContainer::compile() { const int copies = (int)mCopies.size(); for(int i=0; i<copies; i++) { getCopyAsContainer(i)->compile(); } // MLProcContainer's outputs are allocated in compile(). We do a minimal verison here. int outs = getNumOutputs(); for(int i=0; i<outs; ++i) { MLSignal& newSig = *allocBuffer(); setOutput(i + 1, newSig); } }
//============================================================================== void WrappedJucePlugin::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages) { const int blockSize = buffer.getNumSamples (); if (instance) { // Juce plugins put their input into (passed in) buffer, so we need to copy this out from the Jost inputBuffer for (int i = 0; i < getNumInputs(); i++) buffer.copyFrom(i, 0, *inputBuffer, i, 0, buffer.getNumSamples()); // Similar for midi input MidiBuffer dud; MidiBuffer* midiBuffer = &dud; if (midiBuffers.size() > 0) { midiBuffer = midiBuffers.getUnchecked (0); // add events from keyboards keyboardState.processNextMidiBuffer(*midiBuffer, 0, blockSize, true); // process midi automation midiAutomatorManager.handleMidiMessageBuffer(*midiBuffer); } // apply a midi filter on the input to the synth if one is set MidiFilter* synthInputFilter = getSynthInputChannelFilter(); if (synthInputFilter) { MidiManipulator manip; manip.setMidiFilter(synthInputFilter); manip.processEvents(*midiBuffer, blockSize); } // Call through to Juce plugin instance to get the VST to actually do its thing! instance->processBlock(buffer, *midiBuffer); // haven't worked out what jiggerying needs to be done to the midi output yet // Juce plugins put their output into (passed in) buffer, so we need to copy this out into the Jost outputBuffer for (int i = 0; i < getNumOutputs(); i++) outputBuffer->copyFrom(i, 0, buffer, i, 0, buffer.getNumSamples()); } }
void CContinuousActionGradientPolicy::getFunctionValuePre(ColumnVector *input, ColumnVector *output) { CState *state = new CState(modelState); CContinuousActionData *data = dynamic_cast<CContinuousActionData *>(contAction->getNewActionData()); for (int i = 0; i < getNumInputs(); i ++) { state->setContinuousState(i, input->element(i)); } getNextContinuousAction(state, data); for (int i = 0; i < getNumOutputs(); i ++) { output->element(i) = state->getContinuousState(i); } delete state; delete data; }
AudioNode::AudioNode() : GenericProcessor("Audio Node"), audioEditor(0), volume(0.00001f), noiseGateLevel(0.0f), bufferA(2,10000), bufferB(2,10000) { settings.numInputs = 2048; settings.numOutputs = 2; // 128 inputs, 2 outputs (left and right channel) setPlayConfigDetails(getNumInputs(), getNumOutputs(), 44100.0, 128); nextAvailableChannel = 2; // keep first two channels empty numSamplesExpected = 1024; samplesInOverflowBuffer = 0; samplesInBackupBuffer = 0; }
void SignalGenerator::updateSettings() { //std::cout << "Signal generator updating parameters" << std::endl; while (waveformType.size() < getNumOutputs()) { waveformType.add(SINE); frequency.add(defaultFrequency); amplitude.add(defaultAmplitude); phase.add(0); phasePerSample.add(double_Pi * 2.0 / (getSampleRate() / frequency.getLast())); currentPhase.add(0); } sampleRateRatio = getSampleRate() / 44100.0; std::cout << "Sample rate ratio: " << sampleRateRatio << std::endl; }
SourceNode::SourceNode(const String& name_) : GenericProcessor(name_), dataThread(0) { if (getName().equalsIgnoreCase("Intan Demo Board")) { setNumOutputs(16); setNumInputs(0); } else if (getName().equalsIgnoreCase("Custom FPGA")) { setNumOutputs(32); setNumInputs(0); } else if (getName().equalsIgnoreCase("File Reader")) { setNumOutputs(16); setNumInputs(0); } setPlayConfigDetails(getNumInputs(), getNumOutputs(), 44100.0, 128); //sendActionMessage("Intan Demo Board source created."); //sendMessage("Intan Demo Board source created."); }
remote_dsp_aux::remote_dsp_aux(remote_dsp_factory* factory){ fFactory = factory; fNetJack = NULL; fAudioInputs = new float*[getNumInputs()]; fAudioOutputs = new float*[getNumOutputs()]; fControlInputs = new float*[1]; fControlOutputs = new float*[1]; fCounterIn = 0; fCounterOut = 0; fErrorCallback = 0; fErrorCallbackArg = 0; fRunningFlag = true; printf("remote_dsp_aux::remote_dsp_aux = %p\n", this); }