int PaQa_InitializeRecording( PaQaRecording *recording, int maxFrames, int frameRate )
{
int numBytes = maxFrames * sizeof(float);
- recording->buffer = malloc(numBytes);
+ recording->buffer = (float*)malloc(numBytes);
QA_ASSERT_TRUE( "Allocate recording buffer.", (recording->buffer != NULL) );
recording->maxFrames = maxFrames; recording->sampleRate = frameRate;
recording->numFrames = 0;
int PaQa_WriteRecording( PaQaRecording *recording, float *buffer, int numFrames, int stride )
{
int i;
- int framesToWrite = numFrames;
+ int framesToWrite;
+ float *data = &recording->buffer[recording->numFrames];
+
+ framesToWrite = numFrames;
if ((framesToWrite + recording->numFrames) > recording->maxFrames)
{
framesToWrite = recording->maxFrames - recording->numFrames;
}
- float *data = &recording->buffer[recording->numFrames];
+
for( i=0; i<framesToWrite; i++ )
{
*data++ = *buffer;
int PaQa_WriteSilence( PaQaRecording *recording, int numFrames )
{
int i;
- int framesToRecord = numFrames;
+ int framesToRecord;
+ float *data = &recording->buffer[recording->numFrames];
+
+ framesToRecord = numFrames;
if ((framesToRecord + recording->numFrames) > recording->maxFrames)
{
framesToRecord = recording->maxFrames - recording->numFrames;
}
- float *data = &recording->buffer[recording->numFrames];
+
for( i=0; i<framesToRecord; i++ )
{
*data++ = 0.0f;
int PaQa_RecordFreeze( PaQaRecording *recording, int numFrames )
{
int i;
- int framesToRecord = numFrames;
+ int framesToRecord;
+ float *data = &recording->buffer[recording->numFrames];
+
+ framesToRecord = numFrames;
if ((framesToRecord + recording->numFrames) > recording->maxFrames)
{
framesToRecord = recording->maxFrames - recording->numFrames;
}
- float *data = &recording->buffer[recording->numFrames];
+
for( i=0; i<framesToRecord; i++ )
{
// Copy old value forward as if the signal had frozen.
#define NUM_SAMPLES (200)
short data[NUM_SAMPLES];
const int samplesPerFrame = 1;
+ int numLeft = recording->numFrames;
+ float *buffer = &recording->buffer[0];
+
result = Audio_WAV_OpenWriter( &writer, filename, recording->sampleRate, samplesPerFrame );
if( result < 0 ) goto error;
- int numLeft = recording->numFrames;
- float *buffer = &recording->buffer[0];
-
while( numLeft > 0 )
{
int i;
int startFrame, int numFrames, double *phasePtr )
{
double magnitude = 0.0;
- QA_ASSERT_TRUE( "startFrame out of bounds", (startFrame < recording->numFrames) );
- QA_ASSERT_TRUE( "numFrames out of bounds", ((startFrame+numFrames) <= recording->numFrames) );
-
- int numLeft = numFrames;
+ int numLeft = numFrames;
double phase = 0.0;
double phaseIncrement = 2.0 * MATH_PI * frequency / frameRate;
double sinAccumulator = 0.0;
double cosAccumulator = 0.0;
float *data = &recording->buffer[startFrame];
+
+ QA_ASSERT_TRUE( "startFrame out of bounds", (startFrame < recording->numFrames) );
+ QA_ASSERT_TRUE( "numFrames out of bounds", ((startFrame+numFrames) <= recording->numFrames) );
+
while( numLeft > 0 )
{
double sample = (double) *data++;
double PaQa_FindFirstMatch( PaQaRecording *recording, float *buffer, int numFrames, double tolerance )
{
int ic,is;
- QA_ASSERT_TRUE( "numFrames out of bounds", (numFrames < recording->numFrames) );
// How many buffers will fit in the recording?
int maxCorrelations = recording->numFrames - numFrames;
double maxSum = 0.0;
int peakIndex = -1;
double location = -1.0;
+
+ QA_ASSERT_TRUE( "numFrames out of bounds", (numFrames < recording->numFrames) );
+
for( ic=0; ic<maxCorrelations; ic++ )
{
double sum = 0.0;
double PaQa_CompareAmplitudes( PaQaRecording *recording, int startAt, float *buffer, int numFrames )
{
QA_ASSERT_TRUE( "startAt+numFrames out of bounds", ((startAt+numFrames) < recording->numFrames) );
- double recordedArea = PaQa_MeasureArea( &recording->buffer[startAt], numFrames, 1 );
- double bufferArea = PaQa_MeasureArea( buffer, numFrames, 1 );
- if( bufferArea == 0.0 ) return 100000000.0;
- return recordedArea / bufferArea;
+ {
+ double recordedArea = PaQa_MeasureArea( &recording->buffer[startAt], numFrames, 1 );
+ double bufferArea = PaQa_MeasureArea( buffer, numFrames, 1 );
+ if( bufferArea == 0.0 ) return 100000000.0;
+ return recordedArea / bufferArea;
+ }
error:
return -1.0;
}
PaQa_SetupSineGenerator( &generator, testTone->frequency, testTone->amplitude, testTone->sampleRate );
PaQa_EraseBuffer( buffer, cycleSize, testTone->samplesPerFrame );
PaQa_MixSine( &generator, buffer, cycleSize, testTone->samplesPerFrame );
-
- double tolerance = 0.1;
- analysisResult->latency = PaQa_FindFirstMatch( recording, buffer, cycleSize, tolerance );
+
+ analysisResult->latency = PaQa_FindFirstMatch( recording, buffer, cycleSize, /* tolerance= */ 0.1 );
QA_ASSERT_TRUE( "Could not find the start of the signal.", (analysisResult->latency >= 0) );
analysisResult->amplitudeRatio = PaQa_CompareAmplitudes( recording, analysisResult->latency, buffer, cycleSize );
return 0;
void PaQa_FadeInRecording( PaQaRecording *recording, int startFrame, int count )
{
int is;
- assert( startFrame >= 0 );
- assert( count > 0 );
double phase = 0.5 * MATH_PI;
// Advance a quarter wave
double phaseIncrement = 0.25 * 2.0 * MATH_PI / count;
+ assert( startFrame >= 0 );
+ assert( count > 0 );
+
for( is=0; is<count; is++ )
{
double c = cos( phase );
- phase += phaseIncrement;
double w = c * c;
float x = recording->buffer[ is + startFrame ];
float y = x * w;
//printf("FADE %d : w=%f, x=%f, y=%f\n", is, w, x, y );
recording->buffer[ is + startFrame ] = y;
+
+ phase += phaseIncrement;
}
}
*/
int PaQa_DetectPop( PaQaRecording *recording, PaQaTestTone *testTone, PaQaAnalysisResult *analysisResult )
{
+ int result = 0;
int i;
+ double maxAmplitude;
+ int maxPosition;
+
PaQaRecording notchOutput = { 0 };
BiquadFilter notchFilter;
analysisResult->popPosition = -1;
analysisResult->popAmplitude = 0.0;
- int result = PaQa_InitializeRecording( ¬chOutput, recording->numFrames, frameRate );
+ result = PaQa_InitializeRecording( ¬chOutput, recording->numFrames, frameRate );
QA_ASSERT_EQUALS( "PaQa_InitializeRecording failed", 0, result );
result = PaQa_InitializeRecording( &hipassOutput, recording->numFrames, frameRate );
//QA_ASSERT_EQUALS( "PaQa_SaveRecordingToWaveFile failed", 0, result );
// Scan remaining signal looking for peak.
- double maxAmplitude = 0.0;
- int maxPosition = -1;
+ maxAmplitude = 0.0;
+ maxPosition = -1;
for( i=0; i<hipassOutput.numFrames; i++ )
{
float x = hipassOutput.buffer[i];
double period = testTone->sampleRate / testTone->frequency;
int cycleSize = (int) (period + 0.5);
- // Scan recording starting with first cycle, looking for phase errors.
- analysisResult->numDroppedFrames = 0.0;
- analysisResult->numAddedFrames = 0.0;
- analysisResult->droppedFramesPosition = -1.0;
- analysisResult->addedFramesPosition = -1.0;
-
double maxAddedFrames = 0.0;
double maxDroppedFrames = 0.0;
int loopCount = 0;
int skip = cycleSize;
int windowSize = cycleSize;
+
+ // Scan recording starting with first cycle, looking for phase errors.
+ analysisResult->numDroppedFrames = 0.0;
+ analysisResult->numAddedFrames = 0.0;
+ analysisResult->droppedFramesPosition = -1.0;
+ analysisResult->addedFramesPosition = -1.0;
for( i=analysisResult->latency; i<(recording->numFrames - windowSize); i += skip )
{
/*==========================================================================================*/
int PaQa_AnalyseRecording( PaQaRecording *recording, PaQaTestTone *testTone, PaQaAnalysisResult *analysisResult )
{
+ int result = 0;
+
memset( analysisResult, 0, sizeof(PaQaAnalysisResult) );
-
- int result = PaQa_MeasureLatency( recording, testTone, analysisResult );
- QA_ASSERT_EQUALS( "latency measurement", 0, result );
+ result = PaQa_MeasureLatency( recording, testTone, analysisResult );
+ QA_ASSERT_EQUALS( "latency measurement", 0, result );
if( (analysisResult->latency >= 0) && (analysisResult->amplitudeRatio > 0.1) )
{
#include <stdlib.h>
#include <memory.h>
#include <math.h>
+#include <string.h>
+
#include "portaudio.h"
#include "qa_tools.h"
if( userOptions->saveBadWaves )
{
char filename[256];
+#ifdef WIN32
+ _snprintf( filename, sizeof(filename), "%s\\paloopback_%d.wav", userOptions->waveFilePath, userOptions->waveFileCount++ );
+#else
snprintf( filename, sizeof(filename), "%s/paloopback_%d.wav", userOptions->waveFilePath, userOptions->waveFileCount++ );
+#endif
printf( "\"%s\", ", filename );
return PaQa_SaveRecordingToWaveFile( recording, filename );
}
if( i==0 )
{
+ double latencyMSec;
+
printf( "%4d-%4d | ",
loopbackContext.minFramesPerBuffer,
loopbackContext.maxFramesPerBuffer
);
- double latencyMSec = 1000.0 * analysisResult.latency / testParams->sampleRate;
+ latencyMSec = 1000.0 * analysisResult.latency / testParams->sampleRate;
printf("%7.2f | ", latencyMSec );
}
int iRate;
int iSize;
int iFormat;
- int totalBadChannels = 0;
int savedValue;
TestParameters testParams;
- const PaDeviceInfo *inputDeviceInfo;
- const PaDeviceInfo *outputDeviceInfo;
- inputDeviceInfo = Pa_GetDeviceInfo( inputDevice );
- outputDeviceInfo = Pa_GetDeviceInfo( outputDevice );
-
- printf( "=============== Analysing Loopback %d to %d ====================\n", outputDevice, inputDevice );
- printf( " Devices: %s => %s\n", outputDeviceInfo->name, inputDeviceInfo->name);
-
+ const PaDeviceInfo *inputDeviceInfo = Pa_GetDeviceInfo( inputDevice );
+ const PaDeviceInfo *outputDeviceInfo = Pa_GetDeviceInfo( outputDevice );
+ int totalBadChannels = 0;
+
// test half duplex first because it is more likely to work.
int flagSettings[] = { PAQA_FLAG_TWO_STREAMS, 0 };
int numFlagSettings = (sizeof(flagSettings)/sizeof(int));
const char *sampleFormatNames[] = { "paUInt8", "paInt8", "paInt16", "paInt32" };
int numSampleFormats = (sizeof(sampleFormats)/sizeof(PaSampleFormat));
+ printf( "=============== Analysing Loopback %d to %d ====================\n", outputDevice, inputDevice );
+ printf( " Devices: %s => %s\n", outputDeviceInfo->name, inputDeviceInfo->name);
+
PaQa_SetDefaultTestParameters( &testParams, inputDevice, outputDevice );
PaQa_OverrideTestParameters( &testParams, userOptions );
savedValue = testParams.sampleRate;
for( iRate=0; iRate<numRates; iRate++ )
{
+ int numBadChannels;
+
// SAMPLE RATE
testParams.sampleRate = sampleRates[iRate];
testParams.maxFrames = (int) (PAQA_TEST_DURATION * testParams.sampleRate);
- int numBadChannels = PaQa_SingleLoopBackTest( userOptions, &testParams );
+ numBadChannels = PaQa_SingleLoopBackTest( userOptions, &testParams );
totalBadChannels += numBadChannels;
}
testParams.sampleRate = savedValue;
savedValue = testParams.framesPerBuffer;
for( iSize=0; iSize<numBufferSizes; iSize++ )
{
+ int numBadChannels;
+
// BUFFER SIZE
testParams.framesPerBuffer = framesPerBuffers[iSize];
- int numBadChannels = PaQa_SingleLoopBackTest( userOptions, &testParams );
+ numBadChannels = PaQa_SingleLoopBackTest( userOptions, &testParams );
totalBadChannels += numBadChannels;
}
testParams.framesPerBuffer = savedValue;
for( iFormat=0; iFormat<numSampleFormats; iFormat++ )
{
+ int numBadChannels;
PaSampleFormat format = sampleFormats[ iFormat ];
testParams.inputParameters.sampleFormat = format;
testParams.outputParameters.sampleFormat = format;
printf("Sample format = %d = %s\n", (int) format, sampleFormatNames[iFormat] );
- int numBadChannels = PaQa_SingleLoopBackTest( userOptions, &testParams );
+ numBadChannels = PaQa_SingleLoopBackTest( userOptions, &testParams );
totalBadChannels += numBadChannels;
}
printf( "\n" );
{
TestParameters testParams;
LoopbackContext loopbackContext;
- const PaDeviceInfo *inputDeviceInfo;
- const PaDeviceInfo *outputDeviceInfo;
+ const PaDeviceInfo *inputDeviceInfo;
+ const PaDeviceInfo *outputDeviceInfo;
PaError err = paNoError;
double minAmplitude;
-
+ int loopbackIsConnected;
+ int startFrame, numFrames;
+ double magLeft, magRight;
+
inputDeviceInfo = Pa_GetDeviceInfo( inputDevice );
if( inputDeviceInfo == NULL )
{
// Analyse recording to see if we captured the output.
// Start in the middle assuming past latency.
- int startFrame = testParams.maxFrames/2;
- int numFrames = testParams.maxFrames/2;
- double magLeft = PaQa_CorrelateSine( &loopbackContext.recordings[0],
- loopbackContext.generators[0].frequency,
- testParams.sampleRate,
- startFrame, numFrames, NULL );
- double magRight = PaQa_CorrelateSine( &loopbackContext.recordings[1],
- loopbackContext.generators[1].frequency,
- testParams.sampleRate,
- startFrame, numFrames, NULL );
+ startFrame = testParams.maxFrames/2;
+ numFrames = testParams.maxFrames/2;
+ magLeft = PaQa_CorrelateSine( &loopbackContext.recordings[0],
+ loopbackContext.generators[0].frequency,
+ testParams.sampleRate,
+ startFrame, numFrames, NULL );
+ magRight = PaQa_CorrelateSine( &loopbackContext.recordings[1],
+ loopbackContext.generators[1].frequency,
+ testParams.sampleRate,
+ startFrame, numFrames, NULL );
printf(" Amplitudes: left = %f, right = %f\n", magLeft, magRight );
- int loopbackConnected = ((magLeft > minAmplitude) && (magRight > minAmplitude));
// Check for backwards cable.
- if( !loopbackConnected )
+ loopbackIsConnected = ((magLeft > minAmplitude) && (magRight > minAmplitude));
+
+ if( !loopbackIsConnected )
{
double magLeftReverse = PaQa_CorrelateSine( &loopbackContext.recordings[0],
loopbackContext.generators[1].frequency,
if( PaQa_CheckForClippedLoopback( &loopbackContext ) )
{
// Clipped so don't use this loopback.
- loopbackConnected = 0;
+ loopbackIsConnected = 0;
}
err = PaQa_MeasureBackgroundNoise( &loopbackContext, &rms );
if( err )
{
printf("ERROR - Could not measure background noise on this input!\n");
- loopbackConnected = 0;
+ loopbackIsConnected = 0;
}
else if( rms > MAX_BACKGROUND_NOISE_RMS )
{
printf("ERROR - There is too much background noise on this input!\n");
- loopbackConnected = 0;
+ loopbackIsConnected = 0;
}
}
PaQa_TeardownLoopbackContext( &loopbackContext );
- return loopbackConnected;
+ return loopbackIsConnected;
error:
PaQa_TeardownLoopbackContext( &loopbackContext );
const char charInput[] = { 127, 64, -64, -128 };
const unsigned char ucharInput[] = { 255, 128+64, 64, 0 };
const short shortInput[] = { 32767, 32768/2, -32768/2, -32768 };
- const int intInput[] = { 2147483647, 2147483647/2, -2147483648/2, -2147483648 };
+ const int intInput[] = { 2147483647, 2147483647/2, -1073741824 /*-2147483648/2 doesn't work in msvc*/, -2147483648 };
float floatOutput[4];
short shortOutput[4];
/*******************************************************************/
int main( int argc, char **argv )
{
+ int i;
UserOptions userOptions;
- int i;
int result = 0;
int justMath = 0;
+ char *executableName = argv[0];
+
printf("PortAudio LoopBack Test built " __DATE__ " at " __TIME__ "\n");
memset(&userOptions, 0, sizeof(userOptions));
userOptions.waveFilePath = ".";
// Process arguments. Skip name of executable.
- char *name = argv[0];
i = 1;
while( i<argc )
{
break;
case 'h':
- usage( name );
+ usage( executableName );
exit(0);
break;
else
{
printf("Illegal option: %s\n", arg);
- usage( name );
+ usage( executableName );
exit(1);
}
default:
printf("Illegal option: %s\n", arg);
- usage( name );
+ usage( executableName );
exit(1);
break;
}
else
{
printf("Illegal argument: %s\n", arg);
- usage( name );
+ usage( executableName );
exit(1);
}
Pa_GetVersion(), Pa_GetVersionText() );
printf( "=============== PortAudio Devices ========================\n" );
PaQa_ListAudioDevices();
+ if( Pa_GetDeviceCount() == 0 )
+ printf( "no devices found.\n" );
+
printf( "=============== Detect Loopback ==========================\n" );
ScanForLoopback(&userOptions);
+
Pa_Terminate();
}
int *data = (int *)input;
for( i=0; i<numSamples; i++ )
{
- int value = *data++;
- value = value >> 8;
+ int value = (*data++) >> 8;
float fval = (float) (value / ((double) 0x00800000));
*output++ = fval;
}
double sampleRate = 44100.0;
int maxFrames = ((int)sampleRate) * 1;
int samplesPerFrame = 1;
-
+ int stride = 1;
+ int done = 0;
+
double freq = 234.5;
double amp = 0.5;
+ double mag1, mag2;
+
// Setup a sine oscillator.
PaQa_SetupSineGenerator( &generator, freq, amp, sampleRate );
result = PaQa_InitializeRecording( &recording, maxFrames, (int) sampleRate );
QA_ASSERT_EQUALS( "PaQa_InitializeRecording failed", 0, result );
-
- int stride = 1;
- int done = 0;
+
+ done = 0;
while (!done)
{
PaQa_EraseBuffer( buffer, FRAMES_PER_BLOCK, samplesPerFrame );
done = PaQa_WriteRecording( &recording, buffer, FRAMES_PER_BLOCK, samplesPerFrame );
}
- double mag1 = PaQa_CorrelateSine( &recording, freq, sampleRate, 0, recording.numFrames, NULL );
+ mag1 = PaQa_CorrelateSine( &recording, freq, sampleRate, 0, recording.numFrames, NULL );
QA_ASSERT_CLOSE( "exact frequency match", amp, mag1, 0.01 );
- double mag2 = PaQa_CorrelateSine( &recording, freq * 1.23, sampleRate, 0, recording.numFrames, NULL );
+ mag2 = PaQa_CorrelateSine( &recording, freq * 1.23, sampleRate, 0, recording.numFrames, NULL );
QA_ASSERT_CLOSE( "wrong frequency", 0.0, mag2, 0.01 );
PaQa_TerminateRecording( &recording );
double baseFreq = 234.5;
double amp = 0.1;
+ double mag2;
+
+ int stride = samplesPerFrame;
+ int done = 0;
+
// Setup a sine oscillator.
for( i=0; i<NUM_TONES; i++ )
{
result = PaQa_InitializeRecording( &recording, maxFrames, (int) sampleRate );
QA_ASSERT_EQUALS( "PaQa_InitializeRecording failed", 0, result );
- int stride = samplesPerFrame;
- int done = 0;
+ done = 0;
while (!done)
{
PaQa_EraseBuffer( buffer, FRAMES_PER_BLOCK, samplesPerFrame );
QA_ASSERT_CLOSE( "exact frequency match", amp, mag, 0.01 );
}
- double mag2 = PaQa_CorrelateSine( &recording, baseFreq * 0.87, sampleRate, 0, recording.numFrames, NULL );
+ mag2 = PaQa_CorrelateSine( &recording, baseFreq * 0.87, sampleRate, 0, recording.numFrames, NULL );
QA_ASSERT_CLOSE( "wrong frequency", 0.0, mag2, 0.01 );
PaQa_TerminateRecording( &recording );
static void MakeRecordingWithAddedFrames( PaQaRecording *recording, PaQaTestTone *testTone, int glitchPosition, int framesToAdd )
{
-
PaQaSineGenerator generator;
#define BUFFER_SIZE 512
float buffer[BUFFER_SIZE];
- // Setup a sine oscillator.
- PaQa_SetupSineGenerator( &generator, testTone->frequency, testTone->amplitude, testTone->sampleRate );
+ int frameCounter = testTone->startDelay;
int stride = 1;
// Record some initial silence.
int done = PaQa_WriteSilence( recording, testTone->startDelay );
- int frameCounter = testTone->startDelay;
+ // Setup a sine oscillator.
+ PaQa_SetupSineGenerator( &generator, testTone->frequency, testTone->amplitude, testTone->sampleRate );
+
while (!done)
{
int framesThisLoop = BUFFER_SIZE;
#define BUFFER_SIZE 512
float buffer[BUFFER_SIZE];
- // Setup a sine oscillator.
- PaQa_SetupSineGenerator( &generator, testTone->frequency, testTone->amplitude, testTone->sampleRate );
-
int stride = 1;
// Record some initial silence.
int done = PaQa_WriteSilence( recording, testTone->startDelay );
+ // Setup a sine oscillator.
+ PaQa_SetupSineGenerator( &generator, testTone->frequency, testTone->amplitude, testTone->sampleRate );
+
// Generate recording with good phase.
while (!done)
{
*/
static int TestDetectSinglePhaseError( double sampleRate, int cycleSize, int latencyFrames, int glitchPosition, int framesAdded )
{
-
int result = 0;
PaQaRecording recording;
PaQaTestTone testTone;
PaQaAnalysisResult analysisResult = { 0.0 };
-
+ int framesDropped = 0;
+ int maxFrames = ((int)sampleRate) * 2;
+
testTone.samplesPerFrame = 1;
testTone.sampleRate = sampleRate;
testTone.frequency = sampleRate / cycleSize;
testTone.amplitude = 0.5;
testTone.startDelay = latencyFrames;
- int maxFrames = ((int)testTone.sampleRate) * 2;
-
result = PaQa_InitializeRecording( &recording, maxFrames, (int) sampleRate );
QA_ASSERT_EQUALS( "PaQa_InitializeRecording failed", 0, result );
PaQa_AnalyseRecording( &recording, &testTone, &analysisResult );
- int framesDropped = 0;
if( framesAdded < 0 )
{
framesDropped = -framesAdded;
*/
static int TestDetectSinglePop( double sampleRate, int cycleSize, int latencyFrames, int popPosition, int popWidth, double popAmplitude )
{
-
int result = 0;
PaQaRecording recording;
PaQaTestTone testTone;
PaQaAnalysisResult analysisResult = { 0.0 };
-
+ int maxFrames = ((int)sampleRate) * 2;
+
testTone.samplesPerFrame = 1;
testTone.sampleRate = sampleRate;
testTone.frequency = sampleRate / cycleSize;
testTone.amplitude = 0.5;
testTone.startDelay = latencyFrames;
- int maxFrames = ((int)testTone.sampleRate) * 2;
-
result = PaQa_InitializeRecording( &recording, maxFrames, (int) sampleRate );
QA_ASSERT_EQUALS( "PaQa_InitializeRecording failed", 0, result );
PaQaSineGenerator generator;
float buffer[FRAMES_PER_BLOCK];
int samplesPerFrame = 1;
-
+ int stride = 1;
+ int done = 0;
+
// Setup a sine oscillator.
PaQa_SetupSineGenerator( &generator, freq, amp, sampleRate );
- int stride = 1;
- int done = 0;
+ done = 0;
while (!done)
{
PaQa_EraseBuffer( buffer, FRAMES_PER_BLOCK, samplesPerFrame );
double freq = 234.5;
double amp = 0.5;
+ double mag1, mag2, mag3;
+
result = PaQa_InitializeRecording( &original, maxFrames, (int) sampleRate );
QA_ASSERT_EQUALS( "PaQa_InitializeRecording failed", 0, result );
//result = PaQa_SaveRecordingToWaveFile( &original, "original.wav" );
//QA_ASSERT_EQUALS( "PaQa_SaveRecordingToWaveFile failed", 0, result );
- double mag1 = PaQa_CorrelateSine( &original, freq, sampleRate, 0, original.numFrames, NULL );
+ mag1 = PaQa_CorrelateSine( &original, freq, sampleRate, 0, original.numFrames, NULL );
QA_ASSERT_CLOSE( "exact frequency match", amp, mag1, 0.01 );
// Filter with exact frequency.
result = PaQa_SaveRecordingToWaveFile( &filtered, "filtered1.wav" );
QA_ASSERT_EQUALS( "PaQa_SaveRecordingToWaveFile failed", 0, result );
- double mag2 = PaQa_CorrelateSine( &filtered, freq, sampleRate, 0, filtered.numFrames, NULL );
+ mag2 = PaQa_CorrelateSine( &filtered, freq, sampleRate, 0, filtered.numFrames, NULL );
QA_ASSERT_CLOSE( "should eliminate tone", 0.0, mag2, 0.01 );
// Filter with mismatched frequency.
//result = PaQa_SaveRecordingToWaveFile( &filtered, "badfiltered.wav" );
//QA_ASSERT_EQUALS( "PaQa_SaveRecordingToWaveFile failed", 0, result );
- double mag3 = PaQa_CorrelateSine( &filtered, freq, sampleRate, 0, filtered.numFrames, NULL );
+ mag3 = PaQa_CorrelateSine( &filtered, freq, sampleRate, 0, filtered.numFrames, NULL );
QA_ASSERT_CLOSE( "should eliminate tone", amp*0.26, mag3, 0.01 );