/* Demo 2 */ void GenerateAndTest2(FLOATING frequency) { int index; FLOATING magnitudeSquared; FLOATING magnitude; FLOATING real; FLOATING imag; printf("Freq=%7.1f ", frequency); Generate(frequency); /* Process the samples. */ for (index = 0; index < N; index++) { ProcessSample(testData[index]); } /* Do the "standard Goertzel" processing. */ GetRealImag(&real, &imag); magnitudeSquared = real*real + imag*imag; printf("rel mag^2=%16.5f ", magnitudeSquared); magnitude = sqrt(magnitudeSquared); printf("rel mag=%12.5f\n", magnitude); ResetGoertzel(); }
void UtilCaptureImpl::DeviceImpl::ThreadFunc(void) { EnterCriticalSection(&cs); queues.resize(streams.size()); LeaveCriticalSection(&cs); while (!stop) { std::deque<pxcU32> updates; UpdateSample(updates); for (std::deque<pxcU32>::iterator update=updates.begin();update!=updates.end();update++) { SampleContext context; PopContext(*update,context); SignalContext(context,ProcessSample(*update,context.storage)); } } }
float Goertzel::detect() { float magnitude; /* Process the samples. */ for (int index = 0; index < _N; index++) { ProcessSample(testData[index]); } /* Do the "standard Goertzel" processing. */ magnitude = sqrt(Q1*Q1 + Q2*Q2 - coeff*Q1*Q2); ResetGoertzel(); return magnitude; }
// return the magnitudes of the 8 DTMF frequencies void DTMF::detect(float dtmf_mag[],int adc_centre) { int index; /* Process the samples. */ for (index = 0; index < N; index++) { ProcessSample(testData[index],adc_centre); } // Calculate the magnitude of each tone. for(int i=0;i < 8;i++) { // This is the equivalent of sqrt(real*real + imag*imag) dtmf_mag[i] = sqrt(Q1[i]*Q1[i] + Q2[i]*Q2[i] - coeff[i]*Q1[i]*Q2[i]); } ResetDTMF(); return; }
// returns true if voice ended double ProcessSample() { double sampleValue=0; // update amplitude currentAmplitude+=amplitudeCoeff*(amplitude-currentAmplitude); if(amplitude==0 && currentAmplitude<.0001) { // value below threshold => the voice ended // if not the last voice in the list if(!(voices[activeVoicesCount-1]==*this)) { // swap with last voice in the list *this=voices[activeVoicesCount-1]; voices[activeVoicesCount-1].CancelNote(); // decrease voices count activeVoicesCount--; // process swaped voice instead of this one return ProcessSample(); } else { // cancel current note CancelNote(); // decrease voices count activeVoicesCount--; return 0; } } // compute sample value sampleValue=currentAmplitude*(bar1Level*sin(currentPhase*.5)+bar2Level*sin(currentPhase)+bar3Level*sin(currentPhase*1.5)+bar4Level*sin(currentPhase*2)+bar5Level*sin(currentPhase*3)); // update phase currentPhase+=omega; return sampleValue; }
HRESULT Scheduler::ProcessSamplesInQueue(LONG *plNextSleep) { HRESULT hr = S_OK; LONG lWait = 0; IMFSample *pSample = NULL; // Process samples until the queue is empty or until the wait time > 0. // Note: Dequeue returns S_FALSE when the queue is empty. while (m_ScheduledSamples.Dequeue(&pSample) == S_OK) { // Process the next sample in the queue. If the sample is not ready // for presentation. the value returned in lWait is > 0, which // means the scheduler should sleep for that amount of time. hr = ProcessSample(pSample, &lWait); SAFE_RELEASE(pSample); if (FAILED(hr)) { break; } if (lWait > 0) { break; } } // If the wait time is zero, it means we stopped because the queue is // empty (or an error occurred). Set the wait time to infinite; this will // make the scheduler thread sleep until it gets another thread message. if (lWait == 0) { lWait = INFINITE; } *plNextSleep = lWait; return hr; }
/* Test the given data */ static FLOATING Test(int i, const SAMPLE *input) { int index; FLOATING magnitudeSquared; FLOATING magnitude; FLOATING real; FLOATING imag; /* Process the samples. */ for (index = 0; index < NS[i]; index++) { ProcessSample(input[index]); // instead of processing the testData, process the actual sound file so long as the constants agree (no need to generate) } /* Do the "standard Goertzel" processing. */ real = (Q1 - Q2 * cosine); imag = (Q2 * sine); magnitudeSquared = real*real + imag*imag; magnitude = sqrt(magnitudeSquared); return magnitude; ResetGoertzel(); }
/* Demo 1 */ void GenerateAndTest(FLOATING frequency) { int index; FLOATING magnitudeSquared; FLOATING magnitude; FLOATING real; FLOATING imag; printf("For test frequency %f:\n", frequency); Generate(frequency); /* Process the samples */ for (index = 0; index < N; index++) { ProcessSample(testData[index]); } /* Do the "basic Goertzel" processing. */ GetRealImag(&real, &imag); printf("real = %f imag = %f\n", real, imag); magnitudeSquared = real*real + imag*imag; printf("Relative magnitude squared = %f\n", magnitudeSquared); magnitude = sqrt(magnitudeSquared); printf("Relative magnitude = %f\n", magnitude); /* Do the "optimized Goertzel" processing */ magnitudeSquared = GetMagnitudeSquared(); printf("Relative magnitude squared = %f\n", magnitudeSquared); magnitude = sqrt(magnitudeSquared); printf("Relative magnitude = %f\n\n", magnitude); ResetGoertzel(); }
// ========================================================================= void _wndUserRNG_TakeSampleIfMoved(HWND hWnd) { BOOL changed = FALSE; USERRNG_DATA* WindowData; if (IsWindowEnabled(hWnd)) { WindowData = wndUserRNG_GetWindowData(hWnd); // Handle the situation in which no mouse co-ordinates have yet been taken if ( (WindowData->LastPnt.x > -1) && (WindowData->LastPnt.y > -1) ) { // If there are no points, we have a new one if (WindowData->PointCount == 0) { changed = TRUE; } else { // If the mouse cursor has moved a significant difference, use the new // co-ordinates // Both the X *and* Y mouse co-ordinates must have changed, to prevent // the user from generating non-random data by simply moving the mouse in // just a horizontal (or vertical) motion, in which case the X (or Y) // position would change, but the Y (or X) position would remain // relativly the same. This would only generate 1/2 as much random data // The effects of the following code are trivial to see; simply waggle // the mouse back and forth horizontally; instead of seeing a new dark // line appearing (indicating that the sample has been taken), the // inverse coloured line appears, indicating the mouse pointer if ( ( (WindowData->LastPnt.x > (WindowData->LinesListHead->Point.x+USERRNG_MIN_DIFF)) || (WindowData->LastPnt.x < (WindowData->LinesListHead->Point.x-USERRNG_MIN_DIFF)) ) && ( (WindowData->LastPnt.y > (WindowData->LinesListHead->Point.y+USERRNG_MIN_DIFF)) || (WindowData->LastPnt.y < (WindowData->LinesListHead->Point.y-USERRNG_MIN_DIFF)) ) ) { changed = TRUE; } } } if (!(changed)) { // User hasn't moved cursor - delete oldest line until we catch up with // the cursor if ( (WindowData->LinesListTail != WindowData->LinesListHead) && (WindowData->LinesListTail != NULL) ) { _wndUserRNG_DrawLine( hWnd, R2_MERGENOTPEN, WindowData->LinesListTail->Point, WindowData->LinesListTail->Next->Point ); RemoveLastPoint(WindowData); } } else { // AT THIS POINT, WE USE LastMouseX AND LastMouseY AS THE CO-ORDS TO USE // Store the position StoreNewPoint(WindowData, WindowData->LastPnt); // User moved cursor - don't delete any more lines unless the max number // of lines which may be displayed is exceeded if ( ((WindowData->PointCount+1) > WindowData->TrailLines) && (WindowData->PointCount > 1) ) { _wndUserRNG_DrawLine( hWnd, R2_MERGENOTPEN, WindowData->LinesListTail->Point, WindowData->LinesListTail->Next->Point ); RemoveLastPoint(WindowData); } // Draw newest line if ( (WindowData->TrailLines > 0) && (WindowData->PointCount > 1) ) { _wndUserRNG_DrawLine( hWnd, R2_COPYPEN, WindowData->LinesListHead->Prev->Point, WindowData->LinesListHead->Point ); } ProcessSample(hWnd, WindowData->LastPnt); } } }
/** UsedSweeperActiveState * \ingroup intFastMaint * * \desc The MAC Address USED Table sweep is in progress. * * \param[in] sw is the switch on which to operate * * \param[in] currentTime is the current value of the aging timer. * * \return None. * *****************************************************************************/ static void UsedSweeperActiveState(fm_int sw, fm_uint64 currentTime) { fm_switch * switchPtr; fm10000_switch *switchExt; fm_sweepStats stats; fm_int upperBound; fm_int numWords; switchPtr = GET_SWITCH_PTR(sw); switchExt = switchPtr->extension; FM_CLEAR(stats); upperBound = switchExt->usedTableSweeperIndex + USED_TABLE_SAMPLE_SIZE; if (upperBound > USED_TABLE_SIZE) { upperBound = USED_TABLE_SIZE; } numWords = USED_TABLE_SAMPLE_UNIT; while (switchExt->usedTableSweeperIndex < upperBound) { if ((switchExt->usedTableSweeperIndex + numWords) > upperBound) { numWords = upperBound - switchExt->usedTableSweeperIndex; } ProcessSample(sw, switchExt->usedTableSweeperIndex, numWords, currentTime, switchExt->usedTableAgingTime, switchExt->usedTableExpiryTime, &stats); switchExt->usedTableSweeperIndex += numWords; } /* end while (switchExt->usedTableSweeperIndex < upperBound) */ switchExt->usedTableNumExpired += stats.expired; if (switchExt->usedTableSweeperIndex >= USED_TABLE_SIZE) { if (stats.young || stats.old || stats.expired) { FM_LOG_DEBUG(FM_LOG_CAT_EVENT_FAST_MAINT, "sw=%d young=%d old=%d expired=%d elapsed=%llu\n", sw, stats.young, stats.old, stats.expired, currentTime - switchExt->usedTableLastSweepTime); } if (switchExt->usedTableNumExpired) { fm_maWorkTypeData data; fm_status err; FM_CLEAR(data); err = fmEnqueueMAPurge(sw, FM_UPD_FLUSH_EXPIRED, data, NULL, NULL); if (err != FM_OK) { FM_LOG_ERROR(FM_LOG_CAT_EVENT_FAST_MAINT, "fmEnqueueMAPurge failed: %s\n", fmErrorMsg(err)); } } /* Enter READY state to wait for next pass. */ switchExt->usedTableSweeperState = FM_USED_SWEEPER_READY; FM_LOG_DEBUG(FM_LOG_CAT_EVENT_FAST_MAINT, "sw=%d state=READY\n", sw); } } /* end UsedSweeperActiveState */