changes to get qa building on Windows with msvc. had to move variable declarations to the top of functions (ie ANSI C89)
This commit is contained in:
parent
26b196a9f0
commit
cedaf41606
4 changed files with 154 additions and 109 deletions
|
|
@ -114,7 +114,7 @@ void PaQa_GenerateCrackDISABLED( float *buffer, int numSamples, int stride )
|
|||
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;
|
||||
|
|
@ -138,12 +138,15 @@ void PaQa_TerminateRecording( PaQaRecording *recording )
|
|||
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;
|
||||
|
|
@ -157,12 +160,15 @@ int PaQa_WriteRecording( PaQaRecording *recording, float *buffer, int numFrames,
|
|||
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;
|
||||
|
|
@ -175,12 +181,15 @@ int PaQa_WriteSilence( PaQaRecording *recording, int numFrames )
|
|||
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.
|
||||
|
|
@ -201,12 +210,12 @@ int PaQa_SaveRecordingToWaveFile( PaQaRecording *recording, const char *filename
|
|||
#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;
|
||||
|
|
@ -291,15 +300,16 @@ double PaQa_CorrelateSine( PaQaRecording *recording, double frequency, double fr
|
|||
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++;
|
||||
|
|
@ -340,12 +350,14 @@ void PaQa_FilterRecording( PaQaRecording *input, PaQaRecording *output, BiquadFi
|
|||
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;
|
||||
|
|
@ -412,11 +424,13 @@ double PaQa_MeasureRootMeanSquare( float *buffer, int numFrames )
|
|||
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;
|
||||
}
|
||||
|
|
@ -455,9 +469,8 @@ int PaQa_MeasureLatency( PaQaRecording *recording, PaQaTestTone *testTone, PaQaA
|
|||
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;
|
||||
|
|
@ -472,21 +485,23 @@ error:
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -496,7 +511,11 @@ void PaQa_FadeInRecording( PaQaRecording *recording, int startFrame, int count )
|
|||
*/
|
||||
int PaQa_DetectPop( PaQaRecording *recording, PaQaTestTone *testTone, PaQaAnalysisResult *analysisResult )
|
||||
{
|
||||
int result = 0;
|
||||
int i;
|
||||
double maxAmplitude;
|
||||
int maxPosition;
|
||||
|
||||
PaQaRecording notchOutput = { 0 };
|
||||
BiquadFilter notchFilter;
|
||||
|
||||
|
|
@ -508,7 +527,7 @@ int PaQa_DetectPop( PaQaRecording *recording, PaQaTestTone *testTone, PaQaAnalys
|
|||
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 );
|
||||
|
|
@ -530,8 +549,8 @@ int PaQa_DetectPop( PaQaRecording *recording, PaQaTestTone *testTone, PaQaAnalys
|
|||
//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];
|
||||
|
|
@ -566,12 +585,6 @@ int PaQa_DetectPhaseError( PaQaRecording *recording, PaQaTestTone *testTone, PaQ
|
|||
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;
|
||||
|
||||
|
|
@ -580,6 +593,12 @@ int PaQa_DetectPhaseError( PaQaRecording *recording, PaQaTestTone *testTone, PaQ
|
|||
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 )
|
||||
{
|
||||
|
|
@ -636,10 +655,11 @@ int PaQa_DetectPhaseError( PaQaRecording *recording, PaQaTestTone *testTone, PaQ
|
|||
/*==========================================================================================*/
|
||||
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) )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@
|
|||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "portaudio.h"
|
||||
|
||||
#include "qa_tools.h"
|
||||
|
|
@ -641,7 +643,11 @@ static int PaQa_SaveTestResultToWaveFile( UserOptions *userOptions, PaQaRecordin
|
|||
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 );
|
||||
}
|
||||
|
|
@ -759,12 +765,14 @@ static int PaQa_SingleLoopBackTest( UserOptions *userOptions, TestParameters *te
|
|||
|
||||
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 );
|
||||
|
||||
}
|
||||
|
|
@ -885,17 +893,12 @@ static int PaQa_AnalyzeLoopbackConnection( UserOptions *userOptions, PaDeviceInd
|
|||
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));
|
||||
|
|
@ -911,6 +914,9 @@ static int PaQa_AnalyzeLoopbackConnection( UserOptions *userOptions, PaDeviceInd
|
|||
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 );
|
||||
|
|
@ -932,11 +938,13 @@ static int PaQa_AnalyzeLoopbackConnection( UserOptions *userOptions, PaDeviceInd
|
|||
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;
|
||||
|
|
@ -951,10 +959,12 @@ static int PaQa_AnalyzeLoopbackConnection( UserOptions *userOptions, PaDeviceInd
|
|||
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;
|
||||
|
|
@ -974,11 +984,12 @@ static int PaQa_AnalyzeLoopbackConnection( UserOptions *userOptions, PaDeviceInd
|
|||
|
||||
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" );
|
||||
|
|
@ -1046,11 +1057,14 @@ int PaQa_CheckForLoopBack( UserOptions *userOptions, PaDeviceIndex inputDevice,
|
|||
{
|
||||
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 )
|
||||
{
|
||||
|
|
@ -1109,21 +1123,22 @@ int PaQa_CheckForLoopBack( UserOptions *userOptions, PaDeviceIndex inputDevice,
|
|||
|
||||
// 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,
|
||||
|
|
@ -1146,7 +1161,7 @@ int PaQa_CheckForLoopBack( UserOptions *userOptions, PaDeviceIndex inputDevice,
|
|||
if( PaQa_CheckForClippedLoopback( &loopbackContext ) )
|
||||
{
|
||||
// Clipped so don't use this loopback.
|
||||
loopbackConnected = 0;
|
||||
loopbackIsConnected = 0;
|
||||
}
|
||||
|
||||
err = PaQa_MeasureBackgroundNoise( &loopbackContext, &rms );
|
||||
|
|
@ -1154,17 +1169,17 @@ int PaQa_CheckForLoopBack( UserOptions *userOptions, PaDeviceIndex inputDevice,
|
|||
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 );
|
||||
|
|
@ -1248,7 +1263,7 @@ int TestSampleFormatConversion( void )
|
|||
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];
|
||||
|
|
@ -1341,10 +1356,12 @@ void usage( const char *name )
|
|||
/*******************************************************************/
|
||||
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));
|
||||
|
|
@ -1357,7 +1374,6 @@ int main( int argc, char **argv )
|
|||
userOptions.waveFilePath = ".";
|
||||
|
||||
// Process arguments. Skip name of executable.
|
||||
char *name = argv[0];
|
||||
i = 1;
|
||||
while( i<argc )
|
||||
{
|
||||
|
|
@ -1399,7 +1415,7 @@ int main( int argc, char **argv )
|
|||
break;
|
||||
|
||||
case 'h':
|
||||
usage( name );
|
||||
usage( executableName );
|
||||
exit(0);
|
||||
break;
|
||||
|
||||
|
|
@ -1418,7 +1434,7 @@ int main( int argc, char **argv )
|
|||
else
|
||||
{
|
||||
printf("Illegal option: %s\n", arg);
|
||||
usage( name );
|
||||
usage( executableName );
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
|
@ -1428,7 +1444,7 @@ int main( int argc, char **argv )
|
|||
|
||||
default:
|
||||
printf("Illegal option: %s\n", arg);
|
||||
usage( name );
|
||||
usage( executableName );
|
||||
exit(1);
|
||||
break;
|
||||
}
|
||||
|
|
@ -1436,7 +1452,7 @@ int main( int argc, char **argv )
|
|||
else
|
||||
{
|
||||
printf("Illegal argument: %s\n", arg);
|
||||
usage( name );
|
||||
usage( executableName );
|
||||
exit(1);
|
||||
|
||||
}
|
||||
|
|
@ -1455,8 +1471,12 @@ int main( int argc, char **argv )
|
|||
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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -100,8 +100,7 @@ void PaQa_ConvertToFloat( const void *input, int numSamples, PaSampleFormat inFo
|
|||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,18 +63,21 @@ static int TestSingleMonoTone( void )
|
|||
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 );
|
||||
|
|
@ -82,10 +85,10 @@ static int TestSingleMonoTone( void )
|
|||
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 );
|
||||
|
|
@ -117,6 +120,11 @@ static int TestMixedMonoTones( void )
|
|||
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++ )
|
||||
{
|
||||
|
|
@ -126,8 +134,7 @@ static int TestMixedMonoTones( void )
|
|||
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 );
|
||||
|
|
@ -144,7 +151,7 @@ static int TestMixedMonoTones( void )
|
|||
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 );
|
||||
|
|
@ -164,19 +171,19 @@ error:
|
|||
|
||||
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;
|
||||
|
|
@ -225,13 +232,13 @@ static void MakeRecordingWithPop( PaQaRecording *recording, PaQaTestTone *testTo
|
|||
#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)
|
||||
{
|
||||
|
|
@ -260,20 +267,19 @@ static void MakeRecordingWithPop( PaQaRecording *recording, PaQaTestTone *testTo
|
|||
*/
|
||||
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 );
|
||||
|
||||
|
|
@ -281,7 +287,6 @@ static int TestDetectSinglePhaseError( double sampleRate, int cycleSize, int lat
|
|||
|
||||
PaQa_AnalyseRecording( &recording, &testTone, &analysisResult );
|
||||
|
||||
int framesDropped = 0;
|
||||
if( framesAdded < 0 )
|
||||
{
|
||||
framesDropped = -framesAdded;
|
||||
|
|
@ -350,20 +355,18 @@ static int TestDetectPhaseErrors( void )
|
|||
*/
|
||||
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 );
|
||||
|
||||
|
|
@ -478,12 +481,13 @@ void PaQa_FillWithSine( PaQaRecording *recording, double sampleRate, double freq
|
|||
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 );
|
||||
|
|
@ -510,6 +514,8 @@ static int TestNotchFilter( void )
|
|||
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 );
|
||||
|
||||
|
|
@ -518,7 +524,7 @@ static int TestNotchFilter( void )
|
|||
//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.
|
||||
|
|
@ -530,7 +536,7 @@ static int TestNotchFilter( void )
|
|||
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.
|
||||
|
|
@ -540,7 +546,7 @@ static int TestNotchFilter( void )
|
|||
//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 );
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue