void EngineFilter::process(CSAMPLE* pInOut, const int iBufferSize) { int i; for(i = 0; i < iBufferSize; i += 2) { pInOut[i] = (CSAMPLE) processSample(fbuf1, (double) pInOut[i]); pInOut[i + 1] = (CSAMPLE) processSample(fbuf2, (double) pInOut[i + 1]); } }
void processAudio(AudioBuffer &buffer){ float gain = getParameterValue(PARAMETER_A); gain = gain*gain*2.0; float iterations = getParameterValue(PARAMETER_B); float r = getParameterValue(PARAMETER_C)*(maxR-minR) + minR; iterations = iterations*iterations*maxI; int size = buffer.getSize(); FloatArray left = buffer.getSamples(LEFT_CHANNEL); FloatArray right = buffer.getSamples(RIGHT_CHANNEL); float wet = getParameterValue(PARAMETER_D); for(int i=0; i<size; i++){ left[i] = processSample(gain*left[i], iterations, r) * wet + left[i]*(1-wet); right[i] = processSample(gain*right[i], iterations, r) * wet + right[i]*(1-wet); } }
//-------------------------------------------------------------- void testApp::draw(){ unsigned long start = ofGetElapsedTimeMillis(); bool isButtonPressed = (ard.getDigital(2) == ARD_HIGH); if (!wasButtonPressed && isButtonPressed) { cout << "aaa\n"; waitForAction(); beginCapture(); } if (isCapturing) { int x = ard.getAnalog(0); int y = ard.getAnalog(1); int z = ard.getAnalog(2); processSample(x, y, z); } wasButtonPressed = isButtonPressed; unsigned long elapsedTime = ofGetElapsedTimeMillis() - start; if (elapsedTime < samplingInterval) { delay(samplingInterval - elapsedTime); } }
void processAudio(AudioBuffer &buffer){ prepare(); int size = buffer.getSize(); for (int ch = 0; ch<buffer.getChannels(); ++ch) { float* buf = buffer.getSamples(ch); for(int i = 0; i < size; ++i) buf[i] = processSample(buf[i]); } }
void CDMRDMORX::samples(const q15_t* samples, const uint16_t* rssi, uint8_t length) { bool dcd = false; for (uint8_t i = 0U; i < length; i++) dcd = processSample(samples[i], rssi[i]); io.setDecode(dcd); }
void Train(const vector<TrainingSample> &samples, float learnRate) { for (const auto &sample : samples) { processSample(sample); } float normScale = 1.0f / samples.size(); for (auto& layer : layers) { if (layer.type != NeuronType::INPUT) { for_each(layer.neurons, [=] (sptr<Neuron> neuron) { neuron->UpdateWeights(normScale, learnRate); }); } } }
int dtObstacleAvoidanceQuery::sampleVelocityGrid(const float* pos, const float rad, const float vmax, const float* vel, const float* dvel, float* nvel, const dtObstacleAvoidanceParams* params, dtObstacleAvoidanceDebugData* debug) { prepare(pos, dvel); memcpy(&m_params, params, sizeof(dtObstacleAvoidanceParams)); m_invHorizTime = 1.0f / m_params.horizTime; m_vmax = vmax; m_invVmax = vmax > 0 ? 1.0f / vmax : FLT_MAX; dtVset(nvel, 0,0,0); if (debug) debug->reset(); const float cvx = dvel[0] * m_params.velBias; const float cvz = dvel[2] * m_params.velBias; const float cs = vmax * 2 * (1 - m_params.velBias) / (float)(m_params.gridSize-1); const float half = (m_params.gridSize-1)*cs*0.5f; float minPenalty = FLT_MAX; int ns = 0; for (int y = 0; y < m_params.gridSize; ++y) { for (int x = 0; x < m_params.gridSize; ++x) { float vcand[3]; vcand[0] = cvx + x*cs - half; vcand[1] = 0; vcand[2] = cvz + y*cs - half; if (dtSqr(vcand[0])+dtSqr(vcand[2]) > dtSqr(vmax+cs/2)) continue; const float penalty = processSample(vcand, cs, pos,rad,vel,dvel, minPenalty, debug); ns++; if (penalty < minPenalty) { minPenalty = penalty; dtVcopy(nvel, vcand); } } } return ns; }
void UniformResamplingRecursiveMISBPTRenderer::processTile(uint32_t threadID, uint32_t tileID, const Vec4u& viewport) const { auto spp = getSppCount(); TileProcessingRenderer::processTilePixels(viewport, [&](uint32_t x, uint32_t y) { auto pixelID = getPixelIndex(x, y); // Add a new sample to the pixel for(auto i = 0u; i <= getFramebuffer().getChannelCount(); ++i) { accumulate(i, pixelID, Vec4f(0, 0, 0, 1)); } // Process each sample for(auto sampleID = 0u; sampleID < spp; ++sampleID) { processSample(threadID, tileID, pixelID, sampleID, x, y); } }); // Compute contributions for 1-length eye paths (connection to sensor) connectLightVerticesToSensor(threadID, tileID, viewport); }
UtlBoolean MprSimpleDtmfDetector::doProcessFrame(MpBufPtr inBufs[], MpBufPtr outBufs[], int inBufsSize, int outBufsSize, UtlBoolean isEnabled, int samplesPerFrame, int samplesPerSecond) { // Don't process frame if disabled if (!isEnabled) { return TRUE; } // Check input buffer assert(inBufsSize == 1); if(!inBufs[0].isValid()) { return TRUE; } // Get samples from buffer const MpAudioSample* input = ((MpAudioBufPtr)inBufs[0])->getSamplesPtr(); int numSamples = ((MpAudioBufPtr)inBufs[0])->getSamplesNumber(); for (int i = 0; i < numSamples; i++) { UtlBoolean bCheckResult = processSample(input[i]); if (bCheckResult) { if (shouldSendNotification()) { notify(MP_RES_DTMF_INBAND_NOTIFICATION, m_currentDtmfDigit); } } } return TRUE; }
void dtObstacleAvoidanceQuery::sampleVelocityGrid(const float* pos, const float rad, const float vmax, const float* vel, const float* dvel, float* nvel, const int gsize, dtObstacleAvoidanceDebugData* debug) { prepare(pos, dvel); dtVset(nvel, 0,0,0); if (debug) debug->reset(); const float cvx = dvel[0] * m_velBias; const float cvz = dvel[2] * m_velBias; const float cs = vmax * 2 * (1 - m_velBias) / (float)(gsize-1); const float half = (gsize-1)*cs*0.5f; float minPenalty = FLT_MAX; for (int y = 0; y < gsize; ++y) { for (int x = 0; x < gsize; ++x) { float vcand[3]; vcand[0] = cvx + x*cs - half; vcand[1] = 0; vcand[2] = cvz + y*cs - half; if (dtSqr(vcand[0])+dtSqr(vcand[2]) > dtSqr(vmax+cs/2)) continue; const float penalty = processSample(vcand, cs, pos,rad,vmax,vel,dvel, debug); if (penalty < minPenalty) { minPenalty = penalty; dtVcopy(nvel, vcand); } } } }
void HexGrid::addPoint(Point p) { if (m_width < 0) { m_sample.push_back(p); if (m_sample.size() >= m_maxSample) processSample(); return; } Hexagon *h = findHexagon(p); h->increment(); if (!h->dense()) { if (dense(h)) { h->setDense(); m_miny = std::min(m_miny, h->y() - 1); if (h->possibleRoot()) m_pos_roots.insert(h); markNeighborBelow(h); } } }
int dtObstacleAvoidanceQuery::sampleVelocityAdaptive(const float* pos, const float rad, const float vmax, const float* vel, const float* dvel, float* nvel, const dtObstacleAvoidanceParams* params, dtObstacleAvoidanceDebugData* debug) { prepare(pos, dvel); memcpy(&m_params, params, sizeof(dtObstacleAvoidanceParams)); m_invHorizTime = 1.0f / m_params.horizTime; m_vmax = vmax; m_invVmax = vmax > 0 ? 1.0f / vmax : FLT_MAX; dtVset(nvel, 0,0,0); if (debug) debug->reset(); // Build sampling pattern aligned to desired velocity. float pat[(DT_MAX_PATTERN_DIVS*DT_MAX_PATTERN_RINGS+1)*2]; int npat = 0; const int ndivs = (int)m_params.adaptiveDivs; const int nrings= (int)m_params.adaptiveRings; const int depth = (int)m_params.adaptiveDepth; const int nd = dtClamp(ndivs, 1, DT_MAX_PATTERN_DIVS); const int nr = dtClamp(nrings, 1, DT_MAX_PATTERN_RINGS); //const int nd2 = nd / 2; const float da = (1.0f/nd) * DT_PI*2; const float ca = cosf(da); const float sa = sinf(da); // desired direction float ddir[6]; dtVcopy(ddir, dvel); dtNormalize2D(ddir); dtRorate2D (ddir+3, ddir, da*0.5f); // rotated by da/2 // Always add sample at zero pat[npat*2+0] = 0; pat[npat*2+1] = 0; npat++; for (int j = 0; j < nr; ++j) { const float r = (float)(nr-j)/(float)nr; pat[npat*2+0] = ddir[(j%1)*3] * r; pat[npat*2+1] = ddir[(j%1)*3+2] * r; float* last1 = pat + npat*2; float* last2 = last1; npat++; for (int i = 1; i < nd-1; i+=2) { // get next point on the "right" (rotate CW) pat[npat*2+0] = last1[0]*ca + last1[1]*sa; pat[npat*2+1] = -last1[0]*sa + last1[1]*ca; // get next point on the "left" (rotate CCW) pat[npat*2+2] = last2[0]*ca - last2[1]*sa; pat[npat*2+3] = last2[0]*sa + last2[1]*ca; last1 = pat + npat*2; last2 = last1 + 2; npat += 2; } if ((nd&1) == 0) { pat[npat*2+2] = last2[0]*ca - last2[1]*sa; pat[npat*2+3] = last2[0]*sa + last2[1]*ca; npat++; } } // Start sampling. float cr = vmax * (1.0f - m_params.velBias); float res[3]; dtVset(res, dvel[0] * m_params.velBias, 0, dvel[2] * m_params.velBias); int ns = 0; for (int k = 0; k < depth; ++k) { float minPenalty = FLT_MAX; float bvel[3]; dtVset(bvel, 0,0,0); for (int i = 0; i < npat; ++i) { float vcand[3]; vcand[0] = res[0] + pat[i*2+0]*cr; vcand[1] = 0; vcand[2] = res[2] + pat[i*2+1]*cr; if (dtSqr(vcand[0])+dtSqr(vcand[2]) > dtSqr(vmax+0.001f)) continue; const float penalty = processSample(vcand,cr/10, pos,rad,vel,dvel, minPenalty, debug); ns++; if (penalty < minPenalty) { minPenalty = penalty; dtVcopy(bvel, vcand); } } dtVcopy(res, bvel); cr *= 0.5f; } dtVcopy(nvel, res); return ns; }
void dtObstacleAvoidanceQuery::sampleVelocityAdaptive(const float* pos, const float rad, const float vmax, const float* vel, const float* dvel, float* nvel, const int ndivs, const int nrings, const int depth, dtObstacleAvoidanceDebugData* debug) { prepare(pos, dvel); dtVset(nvel, 0,0,0); if (debug) debug->reset(); // Build sampling pattern aligned to desired velocity. static const int MAX_PATTERN_DIVS = 32; static const int MAX_PATTERN_RINGS = 4; float pat[(MAX_PATTERN_DIVS*MAX_PATTERN_RINGS+1)*2]; int npat = 0; const int nd = dtClamp(ndivs, 1, MAX_PATTERN_DIVS); const int nr = dtClamp(nrings, 1, MAX_PATTERN_RINGS); const float da = (1.0f/nd) * DT_PI*2; const float dang = atan2f(dvel[2], dvel[0]); // Always add sample at zero pat[npat*2+0] = 0; pat[npat*2+1] = 0; npat++; for (int j = 0; j < nr; ++j) { const float rad = (float)(nr-j)/(float)nr; float a = dang + (j&1)*0.5f*da; for (int i = 0; i < nd; ++i) { pat[npat*2+0] = cosf(a)*rad; pat[npat*2+1] = sinf(a)*rad; npat++; a += da; } } // Start sampling. float cr = vmax * (1.0f-m_velBias); float res[3]; dtVset(res, dvel[0] * m_velBias, 0, dvel[2] * m_velBias); for (int k = 0; k < depth; ++k) { float minPenalty = FLT_MAX; float bvel[3]; dtVset(bvel, 0,0,0); for (int i = 0; i < npat; ++i) { float vcand[3]; vcand[0] = res[0] + pat[i*2+0]*cr; vcand[1] = 0; vcand[2] = res[2] + pat[i*2+1]*cr; if (dtSqr(vcand[0])+dtSqr(vcand[2]) > dtSqr(vmax+0.001f)) continue; const float penalty = processSample(vcand,cr/10, pos,rad,vmax,vel,dvel, debug); if (penalty < minPenalty) { minPenalty = penalty; dtVcopy(bvel, vcand); } } dtVcopy(res, bvel); cr *= 0.5f; } dtVcopy(nvel, res); }
int dtObstacleAvoidanceQuery::sampleVelocityAdaptive(const float* pos, const float rad, const float vmax, const float* vel, const float* dvel, float* nvel, const dtObstacleAvoidanceParams* params, dtObstacleAvoidanceDebugData* debug) { prepare(pos, dvel); memcpy(&m_params, params, sizeof(dtObstacleAvoidanceParams)); m_invHorizTime = 1.0f / m_params.horizTime; m_vmax = vmax; m_invVmax = 1.0f / vmax; dtVset(nvel, 0,0,0); if (debug) debug->reset(); // Build sampling pattern aligned to desired velocity. float pat[(DT_MAX_PATTERN_DIVS*DT_MAX_PATTERN_RINGS+1)*2]; int npat = 0; const int ndivs = (int)m_params.adaptiveDivs; const int nrings= (int)m_params.adaptiveRings; const int depth = (int)m_params.adaptiveDepth; const int nd = dtClamp(ndivs, 1, DT_MAX_PATTERN_DIVS); const int nr = dtClamp(nrings, 1, DT_MAX_PATTERN_RINGS); const float da = (1.0f/nd) * DT_PI*2; const float dang = atan2f(dvel[2], dvel[0]); // Always add sample at zero pat[npat*2+0] = 0; pat[npat*2+1] = 0; npat++; for (int j = 0; j < nr; ++j) { const float r = (float)(nr-j)/(float)nr; float a = dang + (j&1)*0.5f*da; for (int i = 0; i < nd; ++i) { pat[npat*2+0] = cosf(a)*r; pat[npat*2+1] = sinf(a)*r; npat++; a += da; } } // Start sampling. float cr = vmax * (1.0f - m_params.velBias); float res[3]; dtVset(res, dvel[0] * m_params.velBias, 0, dvel[2] * m_params.velBias); int ns = 0; for (int k = 0; k < depth; ++k) { float minPenalty = FLT_MAX; float bvel[3]; dtVset(bvel, 0,0,0); for (int i = 0; i < npat; ++i) { float vcand[3]; vcand[0] = res[0] + pat[i*2+0]*cr; vcand[1] = 0; vcand[2] = res[2] + pat[i*2+1]*cr; if (dtSqr(vcand[0])+dtSqr(vcand[2]) > dtSqr(vmax+0.001f)) continue; const float penalty = processSample(vcand,cr/10, pos,rad,vel,dvel, debug); ns++; if (penalty < minPenalty) { minPenalty = penalty; dtVcopy(bvel, vcand); } } dtVcopy(res, bvel); cr *= 0.5f; } dtVcopy(nvel, res); return ns; }
void PhaserEffect::processChannel(const ChannelHandle& handle, PhaserGroupState* pState, const CSAMPLE* pInput, CSAMPLE* pOutput, const mixxx::EngineParameters& bufferParameters, const EffectEnableState enableState, const GroupFeatureState& groupFeatures, const EffectChainMixMode mixMode) { Q_UNUSED(handle); Q_UNUSED(mixMode); if (enableState == EffectEnableState::Enabling) { pState->clear(); } CSAMPLE depth = 0; if (enableState != EffectEnableState::Disabling) { depth = m_pDepthParameter->value(); } double periodParameter = m_pLFOPeriodParameter->value(); double periodSamples; if (groupFeatures.has_beat_length_sec) { // periodParameter is a number of beats periodParameter = std::max(roundToFraction(periodParameter, 2.0), 1/4.0); if (m_pTripletParameter->toBool()) { periodParameter /= 3.0; } periodSamples = periodParameter * groupFeatures.beat_length_sec * bufferParameters.sampleRate(); } else { // periodParameter is a number of seconds periodSamples = std::max(periodParameter, 1/4.0) * bufferParameters.sampleRate(); } // freqSkip is used to calculate the phase independently for each channel, // so do not multiply periodSamples by the number of channels. CSAMPLE freqSkip = 1.0 / periodSamples * 2.0 * M_PI; CSAMPLE feedback = m_pFeedbackParameter->value(); CSAMPLE range = m_pRangeParameter->value(); int stages = 2 * m_pStagesParameter->value(); CSAMPLE* oldInLeft = pState->oldInLeft; CSAMPLE* oldOutLeft = pState->oldOutLeft; CSAMPLE* oldInRight = pState->oldInRight; CSAMPLE* oldOutRight = pState->oldOutRight; // Using two sets of coefficients for left and right channel CSAMPLE filterCoefLeft = 0; CSAMPLE filterCoefRight = 0; CSAMPLE left = 0, right = 0; CSAMPLE_GAIN oldDepth = pState->oldDepth; const CSAMPLE_GAIN depthDelta = (depth - oldDepth) / bufferParameters.framesPerBuffer(); const CSAMPLE_GAIN depthStart = oldDepth + depthDelta; int stereoCheck = m_pStereoParameter->value(); int counter = 0; for (unsigned int i = 0; i < bufferParameters.samplesPerBuffer(); i += bufferParameters.channelCount()) { left = pInput[i] + tanh(left * feedback); right = pInput[i + 1] + tanh(right * feedback); // For stereo enabled, the channels are out of phase pState->leftPhase = fmodf(pState->leftPhase + freqSkip, 2.0 * M_PI); pState->rightPhase = fmodf(pState->rightPhase + freqSkip + M_PI * stereoCheck, 2.0 * M_PI); // Updating filter coefficients once every 'updateCoef' samples to avoid // extra computing if ((counter++) % updateCoef == 0) { CSAMPLE delayLeft = 0.5 + 0.5 * sin(pState->leftPhase); CSAMPLE delayRight = 0.5 + 0.5 * sin(pState->rightPhase); // Coefficient computing based on the following: // https://ccrma.stanford.edu/~jos/pasp/Classic_Virtual_Analog_Phase.html CSAMPLE wLeft = range * delayLeft; CSAMPLE wRight = range * delayRight; CSAMPLE tanwLeft = tanh(wLeft / 2); CSAMPLE tanwRight = tanh(wRight / 2); filterCoefLeft = (1.0 - tanwLeft) / (1.0 + tanwLeft); filterCoefRight = (1.0 - tanwRight) / (1.0 + tanwRight); } left = processSample(left, oldInLeft, oldOutLeft, filterCoefLeft, stages); right = processSample(right, oldInRight, oldOutRight, filterCoefRight, stages); const CSAMPLE_GAIN depth = depthStart + depthDelta * (i / bufferParameters.channelCount()); // Computing output combining the original and processed sample pOutput[i] = pInput[i] * (1.0 - 0.5 * depth) + left * depth * 0.5; pOutput[i + 1] = pInput[i + 1] * (1.0 - 0.5 * depth) + right * depth * 0.5; } pState->oldDepth = depth; }
void processTile(uint32_t threadID, uint32_t tileID, const Vec4u& viewport) const override { processTileSamples(viewport, [this, threadID](uint32_t x, uint32_t y, uint32_t pixelID, uint32_t sampleID) { processSample(threadID, pixelID, sampleID, x, y); }); }
bool SensorsProcessor:: parseString(const QString *str) { // check if and which sensor we have (S10 - gyro, S11 - acc, S12 - mag) auto s = str->left(3); if (s != "-S1") return false; // extract the type of data QStringRef sensor_type_str(str, 3, 1); auto sensor_type = sensor_type_str.toInt(); // retrieve the data auto data = str->right(str->length() - 5); // parse the response into corresponding structs // one response per sensor IMUEvent *se = new IMUEvent; QStringList axesVals = data.split(" "); int axisIdx = 0; foreach(const QString axisEntry, axesVals) { switch(sensor_type) { case 0: se->g[axisIdx]= decodeSensorVal(axisEntry); break; case 1: se->a[axisIdx]= decodeSensorVal(axisEntry); break; case 2: se->m[axisIdx]= decodeSensorVal(axisEntry); break; } if (++axisIdx > 2) break; } processSample(se); delete se; /* // check which sensor we have (S10 - gyro, S11 - acc, S12 - mag) short seIdx = str->contains("-S10", Qt::CaseInsensitive)?0:(str->contains("-S11", Qt::CaseInsensitive)?1:2); // extract the content of the robot stream QStringList rawData = str->split(QRegularExpression("-S1\\d\\s"), QString::SkipEmptyParts); foreach(const QString &sensorEntry, rawData){ QStringList axesVals = sensorEntry.split(" "); axisIdx = 0; foreach(const QString axisEntry, axesVals){ switch(sensor_type){ case 0: se->g[axisIdx]= decodeSensorVal(axisEntry); break; case 1: se->a[axisIdx]= decodeSensorVal(axisEntry); break; case 2: se->m[axisIdx]= decodeSensorVal(axisEntry); break; } if((axisIdx++)==2) break; } } // ... and send the packed struct to update RPY processSample(se); delete se; */ return true; }
float ToneFilter::processSample(float newX){ return processSample(newX, 0); }