/*==========================================================================================*/
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;
}
/*==========================================================================================*/
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.
/*==========================================================================================*/
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 );
/*==========================================================================================*/
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;
/*==========================================================================================*/
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;
}
/*==========================================================================================*/
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];
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.
// 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++;
// 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;
// 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;
*/
int PaQa_DetectPop( PaQaRecording *recording, PaQaTestTone *testTone, PaQaAnalysisResult *analysisResult )
{
+ int i;
PaQaRecording notchOutput = { 0 };
BiquadFilter notchFilter;
// 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 );
/*==========================================================================================*/
int PaQa_DetectPhaseError( PaQaRecording *recording, PaQaTestTone *testTone, PaQaAnalysisResult *analysisResult )
{
+ int i;
double period = testTone->sampleRate / testTone->frequency;
int cycleSize = (int) (period + 0.5);
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 );
PaStreamCallbackFlags statusFlags,
void *userData )
{
+ int i;
float *in = (float *)inputBuffer;
float *out = (float *)outputBuffer;
int done = paContinue;
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,
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,
LoopbackContext *loopbackContext
)
{
+ int i;
float *in = (float *)g_BigBuffer;
float *out = (float *)g_BigBuffer;
PaError err;
}
// 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,
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,
/*******************************************************************/
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 );
/*******************************************************************/
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] );
}
*/
static int PaQa_SingleLoopBackTest( UserOptions *userOptions, TestParameters *testParams, double expectedAmplitude )
{
+ int i;
LoopbackContext loopbackContext;
PaError err = paNoError;
PaQaTestTone testTone;
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;
*/
static int PaQa_AnalyzeLoopbackConnection( UserOptions *userOptions, PaDeviceIndex inputDevice, PaDeviceIndex outputDevice, double expectedAmplitude )
{
+ int i;
+ int iSize;
int totalBadChannels = 0;
TestParameters testParams;
const PaDeviceInfo *inputDeviceInfo;
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",
// 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];
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];
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");
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] == '-' )
}
}
- //result = PaQa_TestAnalyzer();
+ result = PaQa_TestAnalyzer();
if( (result == 0) && (justMath == 0) )
{
static int TestMixedMonoTones( void )
{
+ int i;
int result = 0;
#define NUM_TONES (5)
PaQaSineGenerator generators[NUM_TONES];
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 );
}
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 );
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];
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);