Fix C99 error with modern for loops.
This commit is contained in:
parent
8a905a2a19
commit
981c2eac70
3 changed files with 52 additions and 33 deletions
|
|
@ -56,8 +56,9 @@ double PaQa_GetNthFrequency( double baseFrequency, int index )
|
|||
/*==========================================================================================*/
|
||||
void PaQa_EraseBuffer( float *buffer, int numFrames, int samplesPerFrame )
|
||||
{
|
||||
int i;
|
||||
int numSamples = numFrames * samplesPerFrame;
|
||||
for( int i=0; i<numSamples; i++ )
|
||||
for( i=0; i<numSamples; i++ )
|
||||
{
|
||||
*buffer++ = 0.0;
|
||||
}
|
||||
|
|
@ -75,7 +76,8 @@ void PaQa_SetupSineGenerator( PaQaSineGenerator *generator, double frequency, do
|
|||
/*==========================================================================================*/
|
||||
void PaQa_MixSine( PaQaSineGenerator *generator, float *buffer, int numSamples, int stride )
|
||||
{
|
||||
for( int i=0; i<numSamples; i++ )
|
||||
int i;
|
||||
for( i=0; i<numSamples; i++ )
|
||||
{
|
||||
float value = sinf( (float) generator->phase ) * generator->amplitude;
|
||||
*buffer += value; // Mix with existing value.
|
||||
|
|
@ -92,8 +94,9 @@ void PaQa_MixSine( PaQaSineGenerator *generator, float *buffer, int numSamples,
|
|||
/*==========================================================================================*/
|
||||
void PaQa_GenerateCrackDISABLED( float *buffer, int numSamples, int stride )
|
||||
{
|
||||
int i;
|
||||
int offset = numSamples/2;
|
||||
for( int i=0; i<numSamples; i++ )
|
||||
for( i=0; i<numSamples; i++ )
|
||||
{
|
||||
float phase = (MATH_TWO_PI * 0.5 * (i - offset)) / numSamples;
|
||||
float cosp = cosf( phase );
|
||||
|
|
@ -133,13 +136,14 @@ void PaQa_TerminateRecording( PaQaRecording *recording )
|
|||
/*==========================================================================================*/
|
||||
int PaQa_WriteRecording( PaQaRecording *recording, float *buffer, int numFrames, int stride )
|
||||
{
|
||||
int i;
|
||||
int framesToWrite = numFrames;
|
||||
if ((framesToWrite + recording->numFrames) > recording->maxFrames)
|
||||
{
|
||||
framesToWrite = recording->maxFrames - recording->numFrames;
|
||||
}
|
||||
float *data = &recording->buffer[recording->numFrames];
|
||||
for( int i=0; i<framesToWrite; i++ )
|
||||
for( i=0; i<framesToWrite; i++ )
|
||||
{
|
||||
*data++ = *buffer;
|
||||
buffer += stride;
|
||||
|
|
@ -151,13 +155,14 @@ int PaQa_WriteRecording( PaQaRecording *recording, float *buffer, int numFrames,
|
|||
/*==========================================================================================*/
|
||||
int PaQa_WriteSilence( PaQaRecording *recording, int numFrames )
|
||||
{
|
||||
int i;
|
||||
int framesToRecord = numFrames;
|
||||
if ((framesToRecord + recording->numFrames) > recording->maxFrames)
|
||||
{
|
||||
framesToRecord = recording->maxFrames - recording->numFrames;
|
||||
}
|
||||
float *data = &recording->buffer[recording->numFrames];
|
||||
for( int i=0; i<framesToRecord; i++ )
|
||||
for( i=0; i<framesToRecord; i++ )
|
||||
{
|
||||
*data++ = 0.0f;
|
||||
}
|
||||
|
|
@ -168,13 +173,14 @@ int PaQa_WriteSilence( PaQaRecording *recording, int numFrames )
|
|||
/*==========================================================================================*/
|
||||
int PaQa_RecordFreeze( PaQaRecording *recording, int numFrames )
|
||||
{
|
||||
int i;
|
||||
int framesToRecord = numFrames;
|
||||
if ((framesToRecord + recording->numFrames) > recording->maxFrames)
|
||||
{
|
||||
framesToRecord = recording->maxFrames - recording->numFrames;
|
||||
}
|
||||
float *data = &recording->buffer[recording->numFrames];
|
||||
for( int i=0; i<framesToRecord; i++ )
|
||||
for( i=0; i<framesToRecord; i++ )
|
||||
{
|
||||
// Copy old value forward as if the signal had frozen.
|
||||
data[i] = data[i-1];
|
||||
|
|
@ -202,9 +208,10 @@ int PaQa_SaveRecordingToWaveFile( PaQaRecording *recording, const char *filename
|
|||
|
||||
while( numLeft > 0 )
|
||||
{
|
||||
int i;
|
||||
int numToSave = (numLeft > NUM_SAMPLES) ? NUM_SAMPLES : numLeft;
|
||||
// Convert double samples to shorts.
|
||||
for( int i=0; i<numToSave; i++ )
|
||||
for( i=0; i<numToSave; i++ )
|
||||
{
|
||||
double fval = *buffer++;
|
||||
// Convert float to int and clip to short range.
|
||||
|
|
@ -283,18 +290,19 @@ void PaQa_FilterRecording( PaQaRecording *input, PaQaRecording *output, BiquadFi
|
|||
// peaks then drops to half the peak.
|
||||
double PaQa_FindFirstMatch( PaQaRecording *recording, float *buffer, int numFrames, double tolerance )
|
||||
{
|
||||
int i;
|
||||
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;
|
||||
for( int ic=0; ic<maxCorrelations; ic++ )
|
||||
for( ic=0; ic<maxCorrelations; ic++ )
|
||||
{
|
||||
double sum = 0.0;
|
||||
// Correlate buffer against the recording.
|
||||
float *recorded = &recording->buffer[ ic ];
|
||||
for( int is=0; is<numFrames; is++ )
|
||||
for( is=0; is<numFrames; is++ )
|
||||
{
|
||||
float s1 = buffer[is];
|
||||
float s2 = *recorded++;
|
||||
|
|
@ -321,8 +329,9 @@ error:
|
|||
// Measure the area under the curve by summing absolute value of each value.
|
||||
double PaQa_MeasureArea( float *buffer, int numFrames, int stride )
|
||||
{
|
||||
int i;
|
||||
double area = 0.0;
|
||||
for( int is=0; is<numFrames; is++ )
|
||||
for( is=0; is<numFrames; is++ )
|
||||
{
|
||||
area += fabs( *buffer );
|
||||
buffer += stride;
|
||||
|
|
@ -395,13 +404,14 @@ error:
|
|||
// Apply cosine squared window.
|
||||
void PaQa_FadeInRecording( PaQaRecording *recording, int startFrame, int count )
|
||||
{
|
||||
int i;
|
||||
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;
|
||||
|
||||
for( int is=0; is<count; is++ )
|
||||
for( is=0; is<count; is++ )
|
||||
{
|
||||
double c = cos( phase );
|
||||
phase += phaseIncrement;
|
||||
|
|
@ -419,6 +429,7 @@ void PaQa_FadeInRecording( PaQaRecording *recording, int startFrame, int count )
|
|||
*/
|
||||
int PaQa_DetectPop( PaQaRecording *recording, PaQaTestTone *testTone, PaQaAnalysisResult *analysisResult )
|
||||
{
|
||||
int i;
|
||||
PaQaRecording notchOutput = { 0 };
|
||||
BiquadFilter notchFilter;
|
||||
|
||||
|
|
@ -454,7 +465,7 @@ int PaQa_DetectPop( PaQaRecording *recording, PaQaTestTone *testTone, PaQaAnalys
|
|||
// Scan remaining signal looking for peak.
|
||||
double maxAmplitude = 0.0;
|
||||
int maxPosition = -1;
|
||||
for( int i=0; i<hipassOutput.numFrames; i++ )
|
||||
for( i=0; i<hipassOutput.numFrames; i++ )
|
||||
{
|
||||
float x = hipassOutput.buffer[i];
|
||||
float mag = fabs( x );
|
||||
|
|
@ -484,6 +495,7 @@ error:
|
|||
/*==========================================================================================*/
|
||||
int PaQa_DetectPhaseError( PaQaRecording *recording, PaQaTestTone *testTone, PaQaAnalysisResult *analysisResult )
|
||||
{
|
||||
int i;
|
||||
double period = testTone->sampleRate / testTone->frequency;
|
||||
int cycleSize = (int) (period + 0.5);
|
||||
|
||||
|
|
@ -502,7 +514,7 @@ int PaQa_DetectPhaseError( PaQaRecording *recording, PaQaTestTone *testTone, PaQ
|
|||
int skip = cycleSize;
|
||||
int windowSize = cycleSize;
|
||||
|
||||
for( int i=analysisResult->latency; i<(recording->numFrames - windowSize); i += skip )
|
||||
for( i=analysisResult->latency; i<(recording->numFrames - windowSize); i += skip )
|
||||
{
|
||||
double expectedPhase = previousPhase + (skip * MATH_TWO_PI / period);
|
||||
double expectedPhaseIncrement = PaQa_ComputePhaseDifference( expectedPhase, previousPhase );
|
||||
|
|
|
|||
|
|
@ -123,6 +123,7 @@ static int RecordAndPlaySinesCallback( const void *inputBuffer, void *outputBuff
|
|||
PaStreamCallbackFlags statusFlags,
|
||||
void *userData )
|
||||
{
|
||||
int i;
|
||||
float *in = (float *)inputBuffer;
|
||||
float *out = (float *)outputBuffer;
|
||||
int done = paContinue;
|
||||
|
|
@ -136,7 +137,7 @@ static int RecordAndPlaySinesCallback( const void *inputBuffer, void *outputBuff
|
|||
if( in != NULL)
|
||||
{
|
||||
// Read each channel from the buffer.
|
||||
for( int i=0; i<loopbackContext->test->inputParameters.channelCount; i++ )
|
||||
for( i=0; i<loopbackContext->test->inputParameters.channelCount; i++ )
|
||||
{
|
||||
done |= PaQa_WriteRecording( &loopbackContext->recordings[i],
|
||||
in + i,
|
||||
|
|
@ -150,7 +151,7 @@ static int RecordAndPlaySinesCallback( const void *inputBuffer, void *outputBuff
|
|||
PaQa_EraseBuffer( out, framesPerBuffer, loopbackContext->test->outputParameters.channelCount );
|
||||
|
||||
|
||||
for( int i=0; i<loopbackContext->test->outputParameters.channelCount; i++ )
|
||||
for( i=0; i<loopbackContext->test->outputParameters.channelCount; i++ )
|
||||
{
|
||||
PaQa_MixSine( &loopbackContext->generators[i],
|
||||
out + i,
|
||||
|
|
@ -282,6 +283,7 @@ static int RecordAndPlayBlockingIO( PaStream *inStream,
|
|||
LoopbackContext *loopbackContext
|
||||
)
|
||||
{
|
||||
int i;
|
||||
float *in = (float *)g_BigBuffer;
|
||||
float *out = (float *)g_BigBuffer;
|
||||
PaError err;
|
||||
|
|
@ -305,7 +307,7 @@ static int RecordAndPlayBlockingIO( PaStream *inStream,
|
|||
}
|
||||
|
||||
// Save in a recording.
|
||||
for( int i=0; i<loopbackContext->test->inputParameters.channelCount; i++ )
|
||||
for( i=0; i<loopbackContext->test->inputParameters.channelCount; i++ )
|
||||
{
|
||||
done |= PaQa_WriteRecording( &loopbackContext->recordings[i],
|
||||
in + i,
|
||||
|
|
@ -317,7 +319,7 @@ static int RecordAndPlayBlockingIO( PaStream *inStream,
|
|||
available = Pa_GetStreamWriteAvailable( outStream );
|
||||
if( available > (2*framesPerBuffer) ) available = (2*framesPerBuffer);
|
||||
PaQa_EraseBuffer( out, available, loopbackContext->test->outputParameters.channelCount );
|
||||
for( int i=0; i<loopbackContext->test->outputParameters.channelCount; i++ )
|
||||
for( i=0; i<loopbackContext->test->outputParameters.channelCount; i++ )
|
||||
{
|
||||
PaQa_MixSine( &loopbackContext->generators[i],
|
||||
out + i,
|
||||
|
|
@ -522,15 +524,16 @@ static int PaQa_SaveTestResultToWaveFile( UserOptions *userOptions, PaQaRecordin
|
|||
/*******************************************************************/
|
||||
static int PaQa_SetupLoopbackContext( LoopbackContext *loopbackContextPtr, TestParameters *testParams )
|
||||
{
|
||||
int i;
|
||||
// Setup loopback context.
|
||||
memset( loopbackContextPtr, 0, sizeof(LoopbackContext) );
|
||||
loopbackContextPtr->test = testParams;
|
||||
for( int i=0; i<testParams->samplesPerFrame; i++ )
|
||||
for( i=0; i<testParams->samplesPerFrame; i++ )
|
||||
{
|
||||
int err = PaQa_InitializeRecording( &loopbackContextPtr->recordings[i], testParams->maxFrames, testParams->sampleRate );
|
||||
QA_ASSERT_EQUALS( "PaQa_InitializeRecording failed", paNoError, err );
|
||||
}
|
||||
for( int i=0; i<testParams->samplesPerFrame; i++ )
|
||||
for( i=0; i<testParams->samplesPerFrame; i++ )
|
||||
{
|
||||
PaQa_SetupSineGenerator( &loopbackContextPtr->generators[i], PaQa_GetNthFrequency( testParams->baseFrequency, i ),
|
||||
testParams->amplitude, testParams->sampleRate );
|
||||
|
|
@ -543,8 +546,8 @@ error:
|
|||
/*******************************************************************/
|
||||
static void PaQa_TeardownLoopbackContext( LoopbackContext *loopbackContextPtr )
|
||||
{
|
||||
|
||||
for( int i=0; i<loopbackContextPtr->test->samplesPerFrame; i++ )
|
||||
int i;
|
||||
for( i=0; i<loopbackContextPtr->test->samplesPerFrame; i++ )
|
||||
{
|
||||
PaQa_TerminateRecording( &loopbackContextPtr->recordings[i] );
|
||||
}
|
||||
|
|
@ -594,6 +597,7 @@ static void PaQa_PrintFullErrorReport( PaQaAnalysisResult *analysisResultPtr, in
|
|||
*/
|
||||
static int PaQa_SingleLoopBackTest( UserOptions *userOptions, TestParameters *testParams, double expectedAmplitude )
|
||||
{
|
||||
int i;
|
||||
LoopbackContext loopbackContext;
|
||||
PaError err = paNoError;
|
||||
PaQaTestTone testTone;
|
||||
|
|
@ -615,7 +619,7 @@ static int PaQa_SingleLoopBackTest( UserOptions *userOptions, TestParameters *te
|
|||
QA_ASSERT_TRUE("loopback did not run", (loopbackContext.callbackCount > 1) );
|
||||
|
||||
// Analyse recording to to detect glitches.
|
||||
for( int i=0; i<testParams->samplesPerFrame; i++ )
|
||||
for( i=0; i<testParams->samplesPerFrame; i++ )
|
||||
{
|
||||
double freq = PaQa_GetNthFrequency( testParams->baseFrequency, i );
|
||||
testTone.frequency = freq;
|
||||
|
|
@ -700,6 +704,8 @@ static void PaQa_SetDefaultTestParameters( TestParameters *testParamsPtr, PaDevi
|
|||
*/
|
||||
static int PaQa_AnalyzeLoopbackConnection( UserOptions *userOptions, PaDeviceIndex inputDevice, PaDeviceIndex outputDevice, double expectedAmplitude )
|
||||
{
|
||||
int i;
|
||||
int iSize;
|
||||
int totalBadChannels = 0;
|
||||
TestParameters testParams;
|
||||
const PaDeviceInfo *inputDeviceInfo;
|
||||
|
|
@ -735,7 +741,7 @@ static int PaQa_AnalyzeLoopbackConnection( UserOptions *userOptions, PaDeviceInd
|
|||
testParams.maxFrames = (int) (0.5 * testParams.sampleRate);
|
||||
|
||||
// Loop though combinations of audio parameters.
|
||||
for( int iFlags=0; iFlags<numFlagSettings; iFlags++ )
|
||||
for( iFlags=0; iFlags<numFlagSettings; iFlags++ )
|
||||
{
|
||||
testParams.flags = flagSettings[iFlags];
|
||||
printf( "************ Mode = %s ************\n",
|
||||
|
|
@ -744,7 +750,7 @@ static int PaQa_AnalyzeLoopbackConnection( UserOptions *userOptions, PaDeviceInd
|
|||
|
||||
// Loop though combinations of audio parameters.
|
||||
testParams.framesPerBuffer = 128;
|
||||
for( int iRate=0; iRate<numRates; iRate++ )
|
||||
for( iRate=0; iRate<numRates; iRate++ )
|
||||
{
|
||||
// SAMPLE RATE
|
||||
testParams.sampleRate = sampleRates[iRate];
|
||||
|
|
@ -757,7 +763,7 @@ static int PaQa_AnalyzeLoopbackConnection( UserOptions *userOptions, PaDeviceInd
|
|||
|
||||
testParams.sampleRate = 44100;
|
||||
testParams.maxFrames = (int) (1.2 * testParams.sampleRate);
|
||||
for( int iSize=0; iSize<numBufferSizes; iSize++ )
|
||||
for( iSize=0; iSize<numBufferSizes; iSize++ )
|
||||
{
|
||||
// BUFFER SIZE
|
||||
testParams.framesPerBuffer = framesPerBuffers[iSize];
|
||||
|
|
@ -940,7 +946,7 @@ void usage( const char *name )
|
|||
int main( int argc, char **argv )
|
||||
{
|
||||
UserOptions userOptions;
|
||||
|
||||
int i;
|
||||
int result = 0;
|
||||
int justMath = 0;
|
||||
printf("PortAudio LoopBack Test built " __DATE__ " at " __TIME__ "\n");
|
||||
|
|
@ -952,7 +958,7 @@ int main( int argc, char **argv )
|
|||
userOptions.waveFilePath = ".";
|
||||
|
||||
char *name = argv[0];
|
||||
for( int i=1; i<argc; i++ )
|
||||
for( i=1; i<argc; i++ )
|
||||
{
|
||||
char *arg = argv[i];
|
||||
if( arg[0] == '-' )
|
||||
|
|
@ -1008,7 +1014,7 @@ int main( int argc, char **argv )
|
|||
}
|
||||
}
|
||||
|
||||
//result = PaQa_TestAnalyzer();
|
||||
result = PaQa_TestAnalyzer();
|
||||
|
||||
if( (result == 0) && (justMath == 0) )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -104,6 +104,7 @@ error:
|
|||
|
||||
static int TestMixedMonoTones( void )
|
||||
{
|
||||
int i;
|
||||
int result = 0;
|
||||
#define NUM_TONES (5)
|
||||
PaQaSineGenerator generators[NUM_TONES];
|
||||
|
|
@ -117,7 +118,7 @@ static int TestMixedMonoTones( void )
|
|||
double amp = 0.1;
|
||||
|
||||
// Setup a sine oscillator.
|
||||
for( int i=0; i<NUM_TONES; i++ )
|
||||
for( i=0; i<NUM_TONES; i++ )
|
||||
{
|
||||
PaQa_SetupSineGenerator( &generators[i], PaQa_GetNthFrequency( baseFreq, i ), amp, sampleRate );
|
||||
}
|
||||
|
|
@ -130,14 +131,14 @@ static int TestMixedMonoTones( void )
|
|||
while (!done)
|
||||
{
|
||||
PaQa_EraseBuffer( buffer, FRAMES_PER_BLOCK, samplesPerFrame );
|
||||
for( int i=0; i<NUM_TONES; i++ )
|
||||
for( i=0; i<NUM_TONES; i++ )
|
||||
{
|
||||
PaQa_MixSine( &generators[i], buffer, FRAMES_PER_BLOCK, stride );
|
||||
}
|
||||
done = PaQa_WriteRecording( &recording, buffer, FRAMES_PER_BLOCK, samplesPerFrame );
|
||||
}
|
||||
|
||||
for( int i=0; i<NUM_TONES; i++ )
|
||||
for( i=0; i<NUM_TONES; i++ )
|
||||
{
|
||||
double mag = PaQa_CorrelateSine( &recording, PaQa_GetNthFrequency( baseFreq, i), sampleRate, 0, recording.numFrames, NULL );
|
||||
QA_ASSERT_CLOSE( "exact frequency match", amp, mag, 0.01 );
|
||||
|
|
@ -219,7 +220,7 @@ static void MakeRecordingWithAddedFrames( PaQaRecording *recording, PaQaTestTone
|
|||
|
||||
static void MakeRecordingWithPop( PaQaRecording *recording, PaQaTestTone *testTone, int popPosition, int popWidth, double popAmplitude )
|
||||
{
|
||||
|
||||
int i;
|
||||
PaQaSineGenerator generator;
|
||||
#define BUFFER_SIZE 512
|
||||
float buffer[BUFFER_SIZE];
|
||||
|
|
@ -245,7 +246,7 @@ static void MakeRecordingWithPop( PaQaRecording *recording, PaQaTestTone *testTo
|
|||
popWidth = (recording->numFrames - popPosition) - 1;
|
||||
}
|
||||
|
||||
for( int i=0; i<popWidth; i++ )
|
||||
for( i=0; i<popWidth; i++ )
|
||||
{
|
||||
float good = recording->buffer[i+popPosition];
|
||||
float bad = (good > 0.0) ? (good - popAmplitude) : (good + popAmplitude);
|
||||
|
|
|
|||
Loading…
Reference in a new issue