Clean up whitespace in qa/ in preparation for .editorconfig. (#418)
* Clean up whitespace in qa/ in preparation for .editorconfig. Convert tabs to 4 spaces. Indent by 4 spaces. Strip trailing whitespace. Ensure EOL at EOF.
This commit is contained in:
parent
f58b69dc36
commit
0b832f5ff1
15 changed files with 2570 additions and 2569 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -26,13 +26,13 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* The text above constitutes the entire PortAudio license; however,
|
||||
* The text above constitutes the entire PortAudio license; however,
|
||||
* the PortAudio community also makes the following non-binding requests:
|
||||
*
|
||||
* Any person wishing to distribute modifications to the Software is
|
||||
* requested to send the modifications to the original developer so that
|
||||
* they can be incorporated into the canonical version. It is also
|
||||
* requested that these non-binding requests be included along with the
|
||||
* they can be incorporated into the canonical version. It is also
|
||||
* requested that these non-binding requests be included along with the
|
||||
* license above.
|
||||
*/
|
||||
|
||||
|
|
@ -46,44 +46,44 @@
|
|||
|
||||
typedef struct PaQaSineGenerator_s
|
||||
{
|
||||
double phase;
|
||||
double phaseIncrement;
|
||||
double frequency;
|
||||
double amplitude;
|
||||
double phase;
|
||||
double phaseIncrement;
|
||||
double frequency;
|
||||
double amplitude;
|
||||
} PaQaSineGenerator;
|
||||
|
||||
/** Container for a monophonic audio sample in memory. */
|
||||
/** Container for a monophonic audio sample in memory. */
|
||||
typedef struct PaQaRecording_s
|
||||
{
|
||||
/** Maximum number of frames that can fit in the allocated buffer. */
|
||||
int maxFrames;
|
||||
float *buffer;
|
||||
/** Actual number of valid frames in the buffer. */
|
||||
int numFrames;
|
||||
int sampleRate;
|
||||
/** Maximum number of frames that can fit in the allocated buffer. */
|
||||
int maxFrames;
|
||||
float *buffer;
|
||||
/** Actual number of valid frames in the buffer. */
|
||||
int numFrames;
|
||||
int sampleRate;
|
||||
} PaQaRecording;
|
||||
|
||||
typedef struct PaQaTestTone_s
|
||||
{
|
||||
int samplesPerFrame;
|
||||
int startDelay;
|
||||
double sampleRate;
|
||||
double frequency;
|
||||
double amplitude;
|
||||
int samplesPerFrame;
|
||||
int startDelay;
|
||||
double sampleRate;
|
||||
double frequency;
|
||||
double amplitude;
|
||||
} PaQaTestTone;
|
||||
|
||||
typedef struct PaQaAnalysisResult_s
|
||||
{
|
||||
int valid;
|
||||
/** Latency in samples from output to input. */
|
||||
double latency;
|
||||
double amplitudeRatio;
|
||||
double popAmplitude;
|
||||
double popPosition;
|
||||
double numDroppedFrames;
|
||||
double droppedFramesPosition;
|
||||
double numAddedFrames;
|
||||
double addedFramesPosition;
|
||||
int valid;
|
||||
/** Latency in samples from output to input. */
|
||||
double latency;
|
||||
double amplitudeRatio;
|
||||
double popAmplitude;
|
||||
double popPosition;
|
||||
double numDroppedFrames;
|
||||
double droppedFramesPosition;
|
||||
double numAddedFrames;
|
||||
double addedFramesPosition;
|
||||
} PaQaAnalysisResult;
|
||||
|
||||
|
||||
|
|
@ -101,7 +101,7 @@ void PaQa_EraseBuffer( float *buffer, int numFrames, int samplesPerFrame );
|
|||
void PaQa_MixSine( PaQaSineGenerator *generator, float *buffer, int numSamples, int stride );
|
||||
|
||||
void PaQa_WriteSine( float *buffer, int numSamples, int stride,
|
||||
double frequency, double amplitude );
|
||||
double frequency, double amplitude );
|
||||
|
||||
/**
|
||||
* Generate a signal with a sharp edge in the middle that can be recognized despite some phase shift.
|
||||
|
|
@ -133,12 +133,12 @@ void PaQa_SetupSineGenerator( PaQaSineGenerator *generator, double frequency, do
|
|||
* Allocate memory for containing a mono audio signal. Set up recording for writing.
|
||||
*/
|
||||
int PaQa_InitializeRecording( PaQaRecording *recording, int maxSamples, int sampleRate );
|
||||
|
||||
|
||||
/**
|
||||
* Free memory allocated by PaQa_InitializeRecording.
|
||||
*/
|
||||
void PaQa_TerminateRecording( PaQaRecording *recording );
|
||||
|
||||
|
||||
/**
|
||||
* Apply a biquad filter to the audio from the input recording and write it to the output recording.
|
||||
*/
|
||||
|
|
@ -146,29 +146,29 @@ void PaQa_FilterRecording( PaQaRecording *input, PaQaRecording *output, BiquadFi
|
|||
|
||||
|
||||
int PaQa_SaveRecordingToWaveFile( PaQaRecording *recording, const char *filename );
|
||||
|
||||
|
||||
/**
|
||||
* @param stride is the spacing of samples to skip in the input buffer. To use every samples pass 1. To use every other sample pass 2.
|
||||
*/
|
||||
int PaQa_WriteRecording( PaQaRecording *recording, float *buffer, int numSamples, int stride );
|
||||
|
||||
|
||||
/** Write zeros into a recording. */
|
||||
int PaQa_WriteSilence( PaQaRecording *recording, int numSamples );
|
||||
|
||||
|
||||
int PaQa_RecordFreeze( PaQaRecording *recording, int numSamples );
|
||||
|
||||
double PaQa_CorrelateSine( PaQaRecording *recording, double frequency, double frameRate,
|
||||
int startFrame, int numSamples, double *phasePtr );
|
||||
int startFrame, int numSamples, double *phasePtr );
|
||||
|
||||
double PaQa_FindFirstMatch( PaQaRecording *recording, float *buffer, int numSamples, double tolerance );
|
||||
|
||||
/**
|
||||
/**
|
||||
* Estimate the original amplitude of a clipped sine wave by measuring
|
||||
* its average slope at the zero crossings.
|
||||
*/
|
||||
double PaQa_MeasureSineAmplitudeBySlope( PaQaRecording *recording,
|
||||
double frequency, double frameRate,
|
||||
int startFrame, int numFrames );
|
||||
double frequency, double frameRate,
|
||||
int startFrame, int numFrames );
|
||||
|
||||
double PaQa_MeasureRootMeanSquare( float *buffer, int numFrames );
|
||||
|
||||
|
|
|
|||
|
|
@ -4,9 +4,10 @@
|
|||
#include "biquad_filter.h"
|
||||
|
||||
/**
|
||||
* Unit_BiquadFilter implements a second order IIR filter.
|
||||
Here is the equation that we use for this filter:
|
||||
y(n) = a0*x(n) + a1*x(n-1) + a2*x(n-2) - b1*y(n-1) - b2*y(n-2)
|
||||
* Unit_BiquadFilter implements a second order IIR filter.
|
||||
*
|
||||
* Here is the equation that we use for this filter:
|
||||
* y(n) = a0*x(n) + a1*x(n-1) + a2*x(n-2) - b1*y(n-1) - b2*y(n-2)
|
||||
*
|
||||
* @author (C) 2002 Phil Burk, SoftSynth.com, All Rights Reserved
|
||||
*/
|
||||
|
|
@ -17,17 +18,17 @@
|
|||
*/
|
||||
static void BiquadFilter_CalculateCommon( BiquadFilter *filter, double ratio, double Q )
|
||||
{
|
||||
double omega;
|
||||
|
||||
memset( filter, 0, sizeof(BiquadFilter) );
|
||||
double omega;
|
||||
|
||||
memset( filter, 0, sizeof(BiquadFilter) );
|
||||
|
||||
/* Don't let frequency get too close to Nyquist or filter will blow up. */
|
||||
if( ratio >= 0.499 ) ratio = 0.499;
|
||||
omega = 2.0 * (double)FILTER_PI * ratio;
|
||||
if( ratio >= 0.499 ) ratio = 0.499;
|
||||
omega = 2.0 * (double)FILTER_PI * ratio;
|
||||
|
||||
filter->cos_omega = (double) cos( omega );
|
||||
filter->sin_omega = (double) sin( omega );
|
||||
filter->alpha = filter->sin_omega / (2.0 * Q);
|
||||
filter->cos_omega = (double) cos( omega );
|
||||
filter->sin_omega = (double) sin( omega );
|
||||
filter->alpha = filter->sin_omega / (2.0 * Q);
|
||||
}
|
||||
|
||||
/*********************************************************************************
|
||||
|
|
@ -35,21 +36,21 @@ static void BiquadFilter_CalculateCommon( BiquadFilter *filter, double ratio, do
|
|||
*/
|
||||
void BiquadFilter_SetupHighPass( BiquadFilter *filter, double ratio, double Q )
|
||||
{
|
||||
double scalar, opc;
|
||||
|
||||
if( ratio < BIQUAD_MIN_RATIO ) ratio = BIQUAD_MIN_RATIO;
|
||||
if( Q < BIQUAD_MIN_Q ) Q = BIQUAD_MIN_Q;
|
||||
|
||||
BiquadFilter_CalculateCommon( filter, ratio, Q );
|
||||
|
||||
scalar = 1.0 / (1.0 + filter->alpha);
|
||||
opc = (1.0 + filter->cos_omega);
|
||||
|
||||
filter->a0 = opc * 0.5 * scalar;
|
||||
filter->a1 = - opc * scalar;
|
||||
double scalar, opc;
|
||||
|
||||
if( ratio < BIQUAD_MIN_RATIO ) ratio = BIQUAD_MIN_RATIO;
|
||||
if( Q < BIQUAD_MIN_Q ) Q = BIQUAD_MIN_Q;
|
||||
|
||||
BiquadFilter_CalculateCommon( filter, ratio, Q );
|
||||
|
||||
scalar = 1.0 / (1.0 + filter->alpha);
|
||||
opc = (1.0 + filter->cos_omega);
|
||||
|
||||
filter->a0 = opc * 0.5 * scalar;
|
||||
filter->a1 = - opc * scalar;
|
||||
filter->a2 = filter->a0;
|
||||
filter->b1 = -2.0 * filter->cos_omega * scalar;
|
||||
filter->b2 = (1.0 - filter->alpha) * scalar;
|
||||
filter->b1 = -2.0 * filter->cos_omega * scalar;
|
||||
filter->b2 = (1.0 - filter->alpha) * scalar;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -58,21 +59,21 @@ void BiquadFilter_SetupHighPass( BiquadFilter *filter, double ratio, double Q )
|
|||
*/
|
||||
void BiquadFilter_SetupNotch( BiquadFilter *filter, double ratio, double Q )
|
||||
{
|
||||
double scalar, opc;
|
||||
|
||||
if( ratio < BIQUAD_MIN_RATIO ) ratio = BIQUAD_MIN_RATIO;
|
||||
if( Q < BIQUAD_MIN_Q ) Q = BIQUAD_MIN_Q;
|
||||
|
||||
BiquadFilter_CalculateCommon( filter, ratio, Q );
|
||||
|
||||
scalar = 1.0 / (1.0 + filter->alpha);
|
||||
opc = (1.0 + filter->cos_omega);
|
||||
|
||||
filter->a0 = scalar;
|
||||
filter->a1 = -2.0 * filter->cos_omega * scalar;
|
||||
double scalar, opc;
|
||||
|
||||
if( ratio < BIQUAD_MIN_RATIO ) ratio = BIQUAD_MIN_RATIO;
|
||||
if( Q < BIQUAD_MIN_Q ) Q = BIQUAD_MIN_Q;
|
||||
|
||||
BiquadFilter_CalculateCommon( filter, ratio, Q );
|
||||
|
||||
scalar = 1.0 / (1.0 + filter->alpha);
|
||||
opc = (1.0 + filter->cos_omega);
|
||||
|
||||
filter->a0 = scalar;
|
||||
filter->a1 = -2.0 * filter->cos_omega * scalar;
|
||||
filter->a2 = filter->a0;
|
||||
filter->b1 = filter->a1;
|
||||
filter->b2 = (1.0 - filter->alpha) * scalar;
|
||||
filter->b1 = filter->a1;
|
||||
filter->b2 = (1.0 - filter->alpha) * scalar;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
|
|
@ -80,43 +81,43 @@ void BiquadFilter_SetupNotch( BiquadFilter *filter, double ratio, double Q )
|
|||
*/
|
||||
void BiquadFilter_Filter( BiquadFilter *filter, float *inputs, float *outputs, int numSamples )
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
double xn, yn;
|
||||
// Pull values from structure to speed up the calculation.
|
||||
double a0 = filter->a0;
|
||||
double a1 = filter->a1;
|
||||
double a2 = filter->a2;
|
||||
double b1 = filter->b1;
|
||||
double b2 = filter->b2;
|
||||
double xn1 = filter->xn1;
|
||||
double xn2 = filter->xn2;
|
||||
double yn1 = filter->yn1;
|
||||
double yn2 = filter->yn2;
|
||||
// Pull values from structure to speed up the calculation.
|
||||
double a0 = filter->a0;
|
||||
double a1 = filter->a1;
|
||||
double a2 = filter->a2;
|
||||
double b1 = filter->b1;
|
||||
double b2 = filter->b2;
|
||||
double xn1 = filter->xn1;
|
||||
double xn2 = filter->xn2;
|
||||
double yn1 = filter->yn1;
|
||||
double yn2 = filter->yn2;
|
||||
|
||||
for( i=0; i<numSamples; i++)
|
||||
{
|
||||
// Generate outputs by filtering inputs.
|
||||
xn = inputs[i];
|
||||
yn = (a0 * xn) + (a1 * xn1) + (a2 * xn2) - (b1 * yn1) - (b2 * yn2);
|
||||
outputs[i] = yn;
|
||||
for( i=0; i<numSamples; i++)
|
||||
{
|
||||
// Generate outputs by filtering inputs.
|
||||
xn = inputs[i];
|
||||
yn = (a0 * xn) + (a1 * xn1) + (a2 * xn2) - (b1 * yn1) - (b2 * yn2);
|
||||
outputs[i] = yn;
|
||||
|
||||
// Delay input and output values.
|
||||
// Delay input and output values.
|
||||
xn2 = xn1;
|
||||
xn1 = xn;
|
||||
yn2 = yn1;
|
||||
yn1 = yn;
|
||||
|
||||
if( (i & 7) == 0 )
|
||||
{
|
||||
// Apply a small bipolar impulse to filter to prevent arithmetic underflow.
|
||||
// Underflows can cause the FPU to interrupt the CPU.
|
||||
yn1 += (double) 1.0E-26;
|
||||
yn2 -= (double) 1.0E-26;
|
||||
}
|
||||
}
|
||||
|
||||
filter->xn1 = xn1;
|
||||
filter->xn2 = xn2;
|
||||
filter->yn1 = yn1;
|
||||
filter->yn2 = yn2;
|
||||
|
||||
if( (i & 7) == 0 )
|
||||
{
|
||||
// Apply a small bipolar impulse to filter to prevent arithmetic underflow.
|
||||
// Underflows can cause the FPU to interrupt the CPU.
|
||||
yn1 += (double) 1.0E-26;
|
||||
yn2 -= (double) 1.0E-26;
|
||||
}
|
||||
}
|
||||
|
||||
filter->xn1 = xn1;
|
||||
filter->xn2 = xn2;
|
||||
filter->yn1 = yn1;
|
||||
filter->yn2 = yn2;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
|
||||
/**
|
||||
* Unit_BiquadFilter implements a second order IIR filter.
|
||||
* Unit_BiquadFilter implements a second order IIR filter.
|
||||
*
|
||||
* @author (C) 2002 Phil Burk, SoftSynth.com, All Rights Reserved
|
||||
*/
|
||||
|
|
@ -14,20 +14,20 @@
|
|||
typedef struct BiquadFilter_s
|
||||
{
|
||||
double xn1; // storage for delayed signals
|
||||
double xn2;
|
||||
double yn1;
|
||||
double yn2;
|
||||
double xn2;
|
||||
double yn1;
|
||||
double yn2;
|
||||
|
||||
double a0; // coefficients
|
||||
double a1;
|
||||
double a2;
|
||||
double a0; // coefficients
|
||||
double a1;
|
||||
double a2;
|
||||
|
||||
double b1;
|
||||
double b2;
|
||||
double b1;
|
||||
double b2;
|
||||
|
||||
double cos_omega;
|
||||
double sin_omega;
|
||||
double alpha;
|
||||
double cos_omega;
|
||||
double sin_omega;
|
||||
double alpha;
|
||||
} BiquadFilter;
|
||||
|
||||
void BiquadFilter_SetupHighPass( BiquadFilter *filter, double ratio, double Q );
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -26,13 +26,13 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* The text above constitutes the entire PortAudio license; however,
|
||||
* The text above constitutes the entire PortAudio license; however,
|
||||
* the PortAudio community also makes the following non-binding requests:
|
||||
*
|
||||
* Any person wishing to distribute modifications to the Software is
|
||||
* requested to send the modifications to the original developer so that
|
||||
* they can be incorporated into the canonical version. It is also
|
||||
* requested that these non-binding requests be included along with the
|
||||
* they can be incorporated into the canonical version. It is also
|
||||
* requested that these non-binding requests be included along with the
|
||||
* license above.
|
||||
*/
|
||||
|
||||
|
|
@ -43,129 +43,129 @@
|
|||
void PaQa_ListAudioDevices(void)
|
||||
{
|
||||
int i, numDevices;
|
||||
const PaDeviceInfo *deviceInfo;
|
||||
numDevices = Pa_GetDeviceCount();
|
||||
const PaDeviceInfo *deviceInfo;
|
||||
numDevices = Pa_GetDeviceCount();
|
||||
for( i=0; i<numDevices; i++ )
|
||||
{
|
||||
deviceInfo = Pa_GetDeviceInfo( i );
|
||||
printf( "#%d: ", i );
|
||||
printf( "%2d in", deviceInfo->maxInputChannels );
|
||||
printf( ", %2d out", deviceInfo->maxOutputChannels );
|
||||
printf( ", %s", deviceInfo->name );
|
||||
printf( ", %s", deviceInfo->name );
|
||||
printf( ", on %s\n", Pa_GetHostApiInfo( deviceInfo->hostApi )->name );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************/
|
||||
void PaQa_ConvertToFloat( const void *input, int numSamples, PaSampleFormat inFormat, float *output )
|
||||
{
|
||||
int i;
|
||||
switch( inFormat )
|
||||
{
|
||||
case paUInt8:
|
||||
{
|
||||
unsigned char *data = (unsigned char *)input;
|
||||
for( i=0; i<numSamples; i++ )
|
||||
{
|
||||
int value = *data++;
|
||||
value -= 128;
|
||||
*output++ = value / 128.0f;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case paInt8:
|
||||
{
|
||||
char *data = (char *)input;
|
||||
for( i=0; i<numSamples; i++ )
|
||||
{
|
||||
int value = *data++;
|
||||
*output++ = value / 128.0f;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case paInt16:
|
||||
{
|
||||
short *data = (short *)input;
|
||||
for( i=0; i<numSamples; i++ )
|
||||
{
|
||||
*output++ = *data++ / 32768.0f;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case paInt32:
|
||||
{
|
||||
int *data = (int *)input;
|
||||
for( i=0; i<numSamples; i++ )
|
||||
{
|
||||
int value = (*data++) >> 8;
|
||||
float fval = (float) (value / ((double) 0x00800000));
|
||||
*output++ = fval;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
int i;
|
||||
switch( inFormat )
|
||||
{
|
||||
case paUInt8:
|
||||
{
|
||||
unsigned char *data = (unsigned char *)input;
|
||||
for( i=0; i<numSamples; i++ )
|
||||
{
|
||||
int value = *data++;
|
||||
value -= 128;
|
||||
*output++ = value / 128.0f;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case paInt8:
|
||||
{
|
||||
char *data = (char *)input;
|
||||
for( i=0; i<numSamples; i++ )
|
||||
{
|
||||
int value = *data++;
|
||||
*output++ = value / 128.0f;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case paInt16:
|
||||
{
|
||||
short *data = (short *)input;
|
||||
for( i=0; i<numSamples; i++ )
|
||||
{
|
||||
*output++ = *data++ / 32768.0f;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case paInt32:
|
||||
{
|
||||
int *data = (int *)input;
|
||||
for( i=0; i<numSamples; i++ )
|
||||
{
|
||||
int value = (*data++) >> 8;
|
||||
float fval = (float) (value / ((double) 0x00800000));
|
||||
*output++ = fval;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*******************************************************************/
|
||||
void PaQa_ConvertFromFloat( const float *input, int numSamples, PaSampleFormat outFormat, void *output )
|
||||
{
|
||||
int i;
|
||||
switch( outFormat )
|
||||
{
|
||||
case paUInt8:
|
||||
{
|
||||
unsigned char *data = (unsigned char *)output;
|
||||
for( i=0; i<numSamples; i++ )
|
||||
{
|
||||
float value = *input++;
|
||||
int byte = ((int) (value * 127)) + 128;
|
||||
*data++ = (unsigned char) byte;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case paInt8:
|
||||
{
|
||||
char *data = (char *)output;
|
||||
for( i=0; i<numSamples; i++ )
|
||||
{
|
||||
float value = *input++;
|
||||
int byte = (int) (value * 127);
|
||||
*data++ = (char) byte;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case paInt16:
|
||||
{
|
||||
short *data = (short *)output;
|
||||
for( i=0; i<numSamples; i++ )
|
||||
{
|
||||
float value = *input++;
|
||||
// Use asymmetric conversion to avoid clipping.
|
||||
short sval = value * 32767.0;
|
||||
*data++ = sval;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case paInt32:
|
||||
{
|
||||
int *data = (int *)output;
|
||||
for( i=0; i<numSamples; i++ )
|
||||
{
|
||||
float value = *input++;
|
||||
// Use asymmetric conversion to avoid clipping.
|
||||
int ival = value * ((double) 0x007FFFF0);
|
||||
ival = ival << 8;
|
||||
*data++ = ival;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
int i;
|
||||
switch( outFormat )
|
||||
{
|
||||
case paUInt8:
|
||||
{
|
||||
unsigned char *data = (unsigned char *)output;
|
||||
for( i=0; i<numSamples; i++ )
|
||||
{
|
||||
float value = *input++;
|
||||
int byte = ((int) (value * 127)) + 128;
|
||||
*data++ = (unsigned char) byte;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case paInt8:
|
||||
{
|
||||
char *data = (char *)output;
|
||||
for( i=0; i<numSamples; i++ )
|
||||
{
|
||||
float value = *input++;
|
||||
int byte = (int) (value * 127);
|
||||
*data++ = (char) byte;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case paInt16:
|
||||
{
|
||||
short *data = (short *)output;
|
||||
for( i=0; i<numSamples; i++ )
|
||||
{
|
||||
float value = *input++;
|
||||
// Use asymmetric conversion to avoid clipping.
|
||||
short sval = value * 32767.0;
|
||||
*data++ = sval;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case paInt32:
|
||||
{
|
||||
int *data = (int *)output;
|
||||
for( i=0; i<numSamples; i++ )
|
||||
{
|
||||
float value = *input++;
|
||||
// Use asymmetric conversion to avoid clipping.
|
||||
int ival = value * ((double) 0x007FFFF0);
|
||||
ival = ival << 8;
|
||||
*data++ = ival;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,13 +26,13 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* The text above constitutes the entire PortAudio license; however,
|
||||
* The text above constitutes the entire PortAudio license; however,
|
||||
* the PortAudio community also makes the following non-binding requests:
|
||||
*
|
||||
* Any person wishing to distribute modifications to the Software is
|
||||
* requested to send the modifications to the original developer so that
|
||||
* they can be incorporated into the canonical version. It is also
|
||||
* requested that these non-binding requests be included along with the
|
||||
* they can be incorporated into the canonical version. It is also
|
||||
* requested that these non-binding requests be included along with the
|
||||
* license above.
|
||||
*/
|
||||
|
||||
|
|
|
|||
|
|
@ -26,13 +26,13 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* The text above constitutes the entire PortAudio license; however,
|
||||
* The text above constitutes the entire PortAudio license; however,
|
||||
* the PortAudio community also makes the following non-binding requests:
|
||||
*
|
||||
* Any person wishing to distribute modifications to the Software is
|
||||
* requested to send the modifications to the original developer so that
|
||||
* they can be incorporated into the canonical version. It is also
|
||||
* requested that these non-binding requests be included along with the
|
||||
* they can be incorporated into the canonical version. It is also
|
||||
* requested that these non-binding requests be included along with the
|
||||
* license above.
|
||||
*/
|
||||
|
||||
|
|
@ -43,32 +43,32 @@ extern int g_testsPassed;
|
|||
extern int g_testsFailed;
|
||||
|
||||
#define QA_ASSERT_TRUE( message, flag ) \
|
||||
if( !(flag) ) \
|
||||
{ \
|
||||
printf( "%s:%d - ERROR - %s\n", __FILE__, __LINE__, message ); \
|
||||
g_testsFailed++; \
|
||||
goto error; \
|
||||
} \
|
||||
else g_testsPassed++;
|
||||
if( !(flag) ) \
|
||||
{ \
|
||||
printf( "%s:%d - ERROR - %s\n", __FILE__, __LINE__, message ); \
|
||||
g_testsFailed++; \
|
||||
goto error; \
|
||||
} \
|
||||
else g_testsPassed++;
|
||||
|
||||
|
||||
#define QA_ASSERT_EQUALS( message, expected, actual ) \
|
||||
if( ((expected) != (actual)) ) \
|
||||
{ \
|
||||
printf( "%s:%d - ERROR - %s, expected %d, got %d\n", __FILE__, __LINE__, message, expected, actual ); \
|
||||
g_testsFailed++; \
|
||||
goto error; \
|
||||
} \
|
||||
else g_testsPassed++;
|
||||
if( ((expected) != (actual)) ) \
|
||||
{ \
|
||||
printf( "%s:%d - ERROR - %s, expected %d, got %d\n", __FILE__, __LINE__, message, expected, actual ); \
|
||||
g_testsFailed++; \
|
||||
goto error; \
|
||||
} \
|
||||
else g_testsPassed++;
|
||||
|
||||
#define QA_ASSERT_CLOSE( message, expected, actual, tolerance ) \
|
||||
if (fabs((expected)-(actual))>(tolerance)) \
|
||||
{ \
|
||||
printf( "%s:%d - ERROR - %s, expected %f, got %f, tol=%f\n", __FILE__, __LINE__, message, ((double)(expected)), ((double)(actual)), ((double)(tolerance)) ); \
|
||||
g_testsFailed++; \
|
||||
goto error; \
|
||||
} \
|
||||
else g_testsPassed++;
|
||||
if (fabs((expected)-(actual))>(tolerance)) \
|
||||
{ \
|
||||
printf( "%s:%d - ERROR - %s, expected %f, got %f, tol=%f\n", __FILE__, __LINE__, message, ((double)(expected)), ((double)(actual)), ((double)(tolerance)) ); \
|
||||
g_testsFailed++; \
|
||||
goto error; \
|
||||
} \
|
||||
else g_testsPassed++;
|
||||
|
||||
#define QA_ASSERT_CLOSE_INT( message, expected, actual, tolerance ) \
|
||||
if (abs((expected)-(actual))>(tolerance)) \
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -26,13 +26,13 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* The text above constitutes the entire PortAudio license; however,
|
||||
* The text above constitutes the entire PortAudio license; however,
|
||||
* the PortAudio community also makes the following non-binding requests:
|
||||
*
|
||||
* Any person wishing to distribute modifications to the Software is
|
||||
* requested to send the modifications to the original developer so that
|
||||
* they can be incorporated into the canonical version. It is also
|
||||
* requested that these non-binding requests be included along with the
|
||||
* they can be incorporated into the canonical version. It is also
|
||||
* requested that these non-binding requests be included along with the
|
||||
* license above.
|
||||
*/
|
||||
|
||||
|
|
|
|||
|
|
@ -25,13 +25,13 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* The text above constitutes the entire PortAudio license; however,
|
||||
* The text above constitutes the entire PortAudio license; however,
|
||||
* the PortAudio community also makes the following non-binding requests:
|
||||
*
|
||||
* Any person wishing to distribute modifications to the Software is
|
||||
* requested to send the modifications to the original developer so that
|
||||
* they can be incorporated into the canonical version. It is also
|
||||
* requested that these non-binding requests be included along with the
|
||||
* they can be incorporated into the canonical version. It is also
|
||||
* requested that these non-binding requests be included along with the
|
||||
* license above.
|
||||
*/
|
||||
|
||||
|
|
@ -47,32 +47,32 @@
|
|||
/* Write long word data to a little endian format byte array. */
|
||||
static void WriteLongLE( unsigned char **addrPtr, unsigned long data )
|
||||
{
|
||||
unsigned char *addr = *addrPtr;
|
||||
*addr++ = (unsigned char) data;
|
||||
*addr++ = (unsigned char) (data>>8);
|
||||
*addr++ = (unsigned char) (data>>16);
|
||||
*addr++ = (unsigned char) (data>>24);
|
||||
*addrPtr = addr;
|
||||
unsigned char *addr = *addrPtr;
|
||||
*addr++ = (unsigned char) data;
|
||||
*addr++ = (unsigned char) (data>>8);
|
||||
*addr++ = (unsigned char) (data>>16);
|
||||
*addr++ = (unsigned char) (data>>24);
|
||||
*addrPtr = addr;
|
||||
}
|
||||
|
||||
/* Write short word data to a little endian format byte array. */
|
||||
static void WriteShortLE( unsigned char **addrPtr, unsigned short data )
|
||||
{
|
||||
unsigned char *addr = *addrPtr;
|
||||
*addr++ = (unsigned char) data;
|
||||
*addr++ = (unsigned char) (data>>8);
|
||||
*addrPtr = addr;
|
||||
unsigned char *addr = *addrPtr;
|
||||
*addr++ = (unsigned char) data;
|
||||
*addr++ = (unsigned char) (data>>8);
|
||||
*addrPtr = addr;
|
||||
}
|
||||
|
||||
/* Write IFF ChunkType data to a byte array. */
|
||||
static void WriteChunkType( unsigned char **addrPtr, unsigned long cktyp )
|
||||
{
|
||||
unsigned char *addr = *addrPtr;
|
||||
*addr++ = (unsigned char) (cktyp>>24);
|
||||
*addr++ = (unsigned char) (cktyp>>16);
|
||||
*addr++ = (unsigned char) (cktyp>>8);
|
||||
*addr++ = (unsigned char) cktyp;
|
||||
*addrPtr = addr;
|
||||
unsigned char *addr = *addrPtr;
|
||||
*addr++ = (unsigned char) (cktyp>>24);
|
||||
*addr++ = (unsigned char) (cktyp>>16);
|
||||
*addr++ = (unsigned char) (cktyp>>8);
|
||||
*addr++ = (unsigned char) cktyp;
|
||||
*addrPtr = addr;
|
||||
}
|
||||
|
||||
#define WAV_HEADER_SIZE (4 + 4 + 4 + /* RIFF+size+WAVE */ \
|
||||
|
|
@ -87,14 +87,14 @@ static void WriteChunkType( unsigned char **addrPtr, unsigned long cktyp )
|
|||
*/
|
||||
long Audio_WAV_OpenWriter( WAV_Writer *writer, const char *fileName, int frameRate, int samplesPerFrame )
|
||||
{
|
||||
unsigned int bytesPerSecond;
|
||||
unsigned int bytesPerSecond;
|
||||
unsigned char header[ WAV_HEADER_SIZE ];
|
||||
unsigned char *addr = header;
|
||||
unsigned char *addr = header;
|
||||
int numWritten;
|
||||
|
||||
|
||||
writer->dataSize = 0;
|
||||
writer->dataSizeOffset = 0;
|
||||
|
||||
|
||||
writer->fid = fopen( fileName, "wb" );
|
||||
if( writer->fid == NULL )
|
||||
{
|
||||
|
|
@ -102,35 +102,35 @@ long Audio_WAV_OpenWriter( WAV_Writer *writer, const char *fileName, int frameRa
|
|||
}
|
||||
|
||||
/* Write RIFF header. */
|
||||
WriteChunkType( &addr, RIFF_ID );
|
||||
WriteChunkType( &addr, RIFF_ID );
|
||||
|
||||
/* Write RIFF size as zero for now. Will patch later. */
|
||||
WriteLongLE( &addr, 0 );
|
||||
WriteLongLE( &addr, 0 );
|
||||
|
||||
/* Write WAVE form ID. */
|
||||
WriteChunkType( &addr, WAVE_ID );
|
||||
WriteChunkType( &addr, WAVE_ID );
|
||||
|
||||
/* Write format chunk based on AudioSample structure. */
|
||||
WriteChunkType( &addr, FMT_ID );
|
||||
WriteChunkType( &addr, FMT_ID );
|
||||
WriteLongLE( &addr, 16 );
|
||||
WriteShortLE( &addr, WAVE_FORMAT_PCM );
|
||||
bytesPerSecond = frameRate * samplesPerFrame * sizeof( short);
|
||||
WriteShortLE( &addr, (short) samplesPerFrame );
|
||||
WriteLongLE( &addr, frameRate );
|
||||
WriteLongLE( &addr, bytesPerSecond );
|
||||
WriteShortLE( &addr, (short) (samplesPerFrame * sizeof( short)) ); /* bytesPerBlock */
|
||||
WriteShortLE( &addr, (short) 16 ); /* bits per sample */
|
||||
bytesPerSecond = frameRate * samplesPerFrame * sizeof( short);
|
||||
WriteShortLE( &addr, (short) samplesPerFrame );
|
||||
WriteLongLE( &addr, frameRate );
|
||||
WriteLongLE( &addr, bytesPerSecond );
|
||||
WriteShortLE( &addr, (short) (samplesPerFrame * sizeof( short)) ); /* bytesPerBlock */
|
||||
WriteShortLE( &addr, (short) 16 ); /* bits per sample */
|
||||
|
||||
/* Write ID and size for 'data' chunk. */
|
||||
WriteChunkType( &addr, DATA_ID );
|
||||
WriteChunkType( &addr, DATA_ID );
|
||||
/* Save offset so we can patch it later. */
|
||||
writer->dataSizeOffset = (int) (addr - header);
|
||||
WriteLongLE( &addr, 0 );
|
||||
WriteLongLE( &addr, 0 );
|
||||
|
||||
numWritten = fwrite( header, 1, sizeof(header), writer->fid );
|
||||
if( numWritten != sizeof(header) ) return -1;
|
||||
|
||||
return (int) numWritten;
|
||||
return (int) numWritten;
|
||||
}
|
||||
|
||||
/*********************************************************************************
|
||||
|
|
@ -138,31 +138,31 @@ long Audio_WAV_OpenWriter( WAV_Writer *writer, const char *fileName, int frameRa
|
|||
* Returns bytes written or negative error code.
|
||||
*/
|
||||
long Audio_WAV_WriteShorts( WAV_Writer *writer,
|
||||
short *samples,
|
||||
int numSamples
|
||||
)
|
||||
short *samples,
|
||||
int numSamples
|
||||
)
|
||||
{
|
||||
unsigned char buffer[2];
|
||||
unsigned char buffer[2];
|
||||
unsigned char *bufferPtr;
|
||||
int i;
|
||||
short *p = samples;
|
||||
int i;
|
||||
short *p = samples;
|
||||
int numWritten;
|
||||
int bytesWritten;
|
||||
if( numSamples <= 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if( numSamples <= 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
for( i=0; i<numSamples; i++ )
|
||||
{
|
||||
{
|
||||
bufferPtr = buffer;
|
||||
WriteShortLE( &bufferPtr, *p++ );
|
||||
WriteShortLE( &bufferPtr, *p++ );
|
||||
numWritten = fwrite( buffer, 1, sizeof( buffer), writer->fid );
|
||||
if( numWritten != sizeof(buffer) ) return -1;
|
||||
}
|
||||
}
|
||||
bytesWritten = numSamples * sizeof(short);
|
||||
writer->dataSize += bytesWritten;
|
||||
return (int) bytesWritten;
|
||||
return (int) bytesWritten;
|
||||
}
|
||||
|
||||
/*********************************************************************************
|
||||
|
|
@ -171,7 +171,7 @@ long Audio_WAV_WriteShorts( WAV_Writer *writer,
|
|||
*/
|
||||
long Audio_WAV_CloseWriter( WAV_Writer *writer )
|
||||
{
|
||||
unsigned char buffer[4];
|
||||
unsigned char buffer[4];
|
||||
unsigned char *bufferPtr;
|
||||
int numWritten;
|
||||
int riffSize;
|
||||
|
|
@ -212,7 +212,7 @@ int main( void )
|
|||
#define NUM_SAMPLES (200)
|
||||
short data[NUM_SAMPLES];
|
||||
short saw = 0;
|
||||
|
||||
|
||||
for( i=0; i<NUM_SAMPLES; i++ )
|
||||
{
|
||||
data[i] = saw;
|
||||
|
|
|
|||
|
|
@ -25,13 +25,13 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* The text above constitutes the entire PortAudio license; however,
|
||||
* The text above constitutes the entire PortAudio license; however,
|
||||
* the PortAudio community also makes the following non-binding requests:
|
||||
*
|
||||
* Any person wishing to distribute modifications to the Software is
|
||||
* requested to send the modifications to the original developer so that
|
||||
* they can be incorporated into the canonical version. It is also
|
||||
* requested that these non-binding requests be included along with the
|
||||
* they can be incorporated into the canonical version. It is also
|
||||
* requested that these non-binding requests be included along with the
|
||||
* license above.
|
||||
*/
|
||||
#ifndef _WAV_WRITER_H
|
||||
|
|
@ -65,7 +65,7 @@ extern "C" {
|
|||
#define WAVE_FORMAT_PCM (1)
|
||||
#define WAVE_FORMAT_IMA_ADPCM (0x0011)
|
||||
|
||||
|
||||
|
||||
typedef struct WAV_Writer_s
|
||||
{
|
||||
FILE *fid;
|
||||
|
|
@ -86,9 +86,9 @@ long Audio_WAV_OpenWriter( WAV_Writer *writer, const char *fileName, int frameRa
|
|||
* Returns bytes written or negative error code.
|
||||
*/
|
||||
long Audio_WAV_WriteShorts( WAV_Writer *writer,
|
||||
short *samples,
|
||||
int numSamples
|
||||
);
|
||||
short *samples,
|
||||
int numSamples
|
||||
);
|
||||
|
||||
/*********************************************************************************
|
||||
* Close WAV file.
|
||||
|
|
|
|||
|
|
@ -107,8 +107,8 @@ static int gNumFailed = 0;
|
|||
} \
|
||||
else { \
|
||||
printf("ERROR - 0x%x - %s for %s\n", result, \
|
||||
((result == 0) ? "-" : Pa_GetErrorText(result)), \
|
||||
#_exp ); \
|
||||
((result == 0) ? "-" : Pa_GetErrorText(result)), \
|
||||
#_exp ); \
|
||||
gNumFailed++; \
|
||||
goto error; \
|
||||
} \
|
||||
|
|
@ -386,7 +386,7 @@ static int TestAdvance( int mode, PaDeviceIndex deviceID, double sampleRate,
|
|||
}
|
||||
else
|
||||
{
|
||||
ipp = NULL;
|
||||
ipp = NULL;
|
||||
}
|
||||
|
||||
if( mode == MODE_OUTPUT )
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
/** @file paqa_errs.c
|
||||
@ingroup qa_src
|
||||
@brief Self Testing Quality Assurance app for PortAudio
|
||||
Do lots of bad things to test error reporting.
|
||||
@author Phil Burk http://www.softsynth.com
|
||||
@ingroup qa_src
|
||||
@brief Self Testing Quality Assurance app for PortAudio
|
||||
Do lots of bad things to test error reporting.
|
||||
@author Phil Burk http://www.softsynth.com
|
||||
Pieter Suurmond adapted to V19 API.
|
||||
*/
|
||||
/*
|
||||
|
|
@ -33,16 +33,16 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* The text above constitutes the entire PortAudio license; however,
|
||||
* The text above constitutes the entire PortAudio license; however,
|
||||
* the PortAudio community also makes the following non-binding requests:
|
||||
*
|
||||
* Any person wishing to distribute modifications to the Software is
|
||||
* requested to send the modifications to the original developer so that
|
||||
* they can be incorporated into the canonical version. It is also
|
||||
* requested that these non-binding requests be included along with the
|
||||
* they can be incorporated into the canonical version. It is also
|
||||
* requested that these non-binding requests be included along with the
|
||||
* license above.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
|
|
@ -103,14 +103,14 @@ static int gNumFailed = 0;
|
|||
static int QaCallback( const void* inputBuffer,
|
||||
void* outputBuffer,
|
||||
unsigned long framesPerBuffer,
|
||||
const PaStreamCallbackTimeInfo* timeInfo,
|
||||
PaStreamCallbackFlags statusFlags,
|
||||
const PaStreamCallbackTimeInfo* timeInfo,
|
||||
PaStreamCallbackFlags statusFlags,
|
||||
void* userData )
|
||||
{
|
||||
unsigned long i;
|
||||
unsigned char* out = (unsigned char *) outputBuffer;
|
||||
PaQaData* data = (PaQaData *) userData;
|
||||
|
||||
|
||||
(void)inputBuffer; /* Prevent "unused variable" warnings. */
|
||||
|
||||
/* Zero out buffer so we don't hear terrible noise. */
|
||||
|
|
@ -174,7 +174,7 @@ static int TestBadOpens( void )
|
|||
PaStreamParameters ipp, opp;
|
||||
const PaDeviceInfo* info = NULL;
|
||||
|
||||
|
||||
|
||||
/* Setup data for synthesis thread. */
|
||||
myData.framesLeft = (unsigned long) (SAMPLE_RATE * 100); /* 100 seconds */
|
||||
myData.numChannels = 1;
|
||||
|
|
@ -222,7 +222,7 @@ static int TestBadOpens( void )
|
|||
ipp.hostApiSpecificStreamInfo = opp.hostApiSpecificStreamInfo = NULL;
|
||||
ipp.sampleFormat = opp.sampleFormat = paFloat32;
|
||||
ipp.channelCount = 0; ipp.device = Pa_GetDefaultInputDevice();
|
||||
opp.channelCount = 0; opp.device = paNoDevice; /* And no output device, and no output channels. */
|
||||
opp.channelCount = 0; opp.device = paNoDevice; /* And no output device, and no output channels. */
|
||||
HOPEFOR(((result = Pa_OpenStream(&stream, &ipp, NULL,
|
||||
SAMPLE_RATE, FRAMES_PER_BUFFER,
|
||||
paClipOff, QaCallback, &myData )) == paInvalidChannelCount));
|
||||
|
|
@ -274,7 +274,7 @@ static int TestBadOpens( void )
|
|||
HOPEFOR(((result = Pa_OpenStream(&stream, NULL, &opp,
|
||||
1.0, FRAMES_PER_BUFFER, /* 1 cycle per second (1 Hz) is too low. */
|
||||
paClipOff, QaCallback, &myData )) == paInvalidSampleRate));
|
||||
|
||||
|
||||
/*----------------------------- High sample rate: */
|
||||
ipp.hostApiSpecificStreamInfo = opp.hostApiSpecificStreamInfo = NULL;
|
||||
ipp.sampleFormat = opp.sampleFormat = paFloat32;
|
||||
|
|
@ -286,7 +286,7 @@ static int TestBadOpens( void )
|
|||
|
||||
/*----------------------------- NULL callback: */
|
||||
/* NULL callback is valid in V19 -- it means use blocking read/write stream
|
||||
|
||||
|
||||
ipp.hostApiSpecificStreamInfo = opp.hostApiSpecificStreamInfo = NULL;
|
||||
ipp.sampleFormat = opp.sampleFormat = paFloat32;
|
||||
ipp.channelCount = 0; ipp.device = paNoDevice;
|
||||
|
|
@ -366,7 +366,7 @@ static int TestBadActions( void )
|
|||
SAMPLE_RATE, FRAMES_PER_BUFFER,
|
||||
paClipOff, QaCallback, &myData )) == paNoError));
|
||||
}
|
||||
|
||||
|
||||
HOPEFOR(((deviceInfo = Pa_GetDeviceInfo(paNoDevice)) == NULL));
|
||||
HOPEFOR(((deviceInfo = Pa_GetDeviceInfo(87654)) == NULL));
|
||||
HOPEFOR(((result = Pa_StartStream(NULL)) == paBadStreamPtr));
|
||||
|
|
@ -392,7 +392,7 @@ int main(void);
|
|||
int main(void)
|
||||
{
|
||||
PaError result;
|
||||
|
||||
|
||||
EXPECT(((result = Pa_Initialize()) == paNoError));
|
||||
TestBadOpens();
|
||||
TestBadActions();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/** @file paqa_latency.c
|
||||
@ingroup qa_src
|
||||
@brief Test latency estimates.
|
||||
@author Ross Bencina <rossb@audiomulch.com>
|
||||
@ingroup qa_src
|
||||
@brief Test latency estimates.
|
||||
@author Ross Bencina <rossb@audiomulch.com>
|
||||
@author Phil Burk <philburk@softsynth.com>
|
||||
*/
|
||||
/*
|
||||
|
|
@ -32,13 +32,13 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* The text above constitutes the entire PortAudio license; however,
|
||||
* The text above constitutes the entire PortAudio license; however,
|
||||
* the PortAudio community also makes the following non-binding requests:
|
||||
*
|
||||
* Any person wishing to distribute modifications to the Software is
|
||||
* requested to send the modifications to the original developer so that
|
||||
* they can be incorporated into the canonical version. It is also
|
||||
* requested that these non-binding requests be included along with the
|
||||
* they can be incorporated into the canonical version. It is also
|
||||
* requested that these non-binding requests be included along with the
|
||||
* license above.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
|
|
@ -91,7 +91,7 @@ static int patestCallback( const void *inputBuffer, void *outputBuffer,
|
|||
(void) timeInfo; /* Prevent unused variable warnings. */
|
||||
(void) statusFlags;
|
||||
(void) inputBuffer;
|
||||
|
||||
|
||||
if( data->minFramesPerBuffer > framesPerBuffer )
|
||||
{
|
||||
data->minFramesPerBuffer = framesPerBuffer;
|
||||
|
|
@ -100,7 +100,7 @@ static int patestCallback( const void *inputBuffer, void *outputBuffer,
|
|||
{
|
||||
data->maxFramesPerBuffer = framesPerBuffer;
|
||||
}
|
||||
|
||||
|
||||
/* Measure min and max output time stamp delta. */
|
||||
if( data->callbackCount > 0 )
|
||||
{
|
||||
|
|
@ -115,7 +115,7 @@ static int patestCallback( const void *inputBuffer, void *outputBuffer,
|
|||
}
|
||||
}
|
||||
data->previousTimeInfo = *timeInfo;
|
||||
|
||||
|
||||
for( i=0; i<framesPerBuffer; i++ )
|
||||
{
|
||||
*out++ = data->sine[data->left_phase]; /* left */
|
||||
|
|
@ -125,12 +125,12 @@ static int patestCallback( const void *inputBuffer, void *outputBuffer,
|
|||
data->right_phase += 3; /* higher pitch so we can distinguish left and right. */
|
||||
if( data->right_phase >= TABLE_SIZE ) data->right_phase -= TABLE_SIZE;
|
||||
}
|
||||
|
||||
|
||||
data->callbackCount += 1;
|
||||
return paContinue;
|
||||
}
|
||||
|
||||
PaError paqaCheckLatency( PaStreamParameters *outputParamsPtr,
|
||||
PaError paqaCheckLatency( PaStreamParameters *outputParamsPtr,
|
||||
paTestData *dataPtr, double sampleRate, unsigned long framesPerBuffer )
|
||||
{
|
||||
PaError err;
|
||||
|
|
@ -142,7 +142,7 @@ PaError paqaCheckLatency( PaStreamParameters *outputParamsPtr,
|
|||
dataPtr->minDeltaDacTime = 9999999.0;
|
||||
dataPtr->maxDeltaDacTime = 0.0;
|
||||
dataPtr->callbackCount = 0;
|
||||
|
||||
|
||||
printf("Stream parameter: suggestedOutputLatency = %g\n", outputParamsPtr->suggestedLatency );
|
||||
if( framesPerBuffer == paFramesPerBufferUnspecified ){
|
||||
printf("Stream parameter: user framesPerBuffer = paFramesPerBufferUnspecified\n" );
|
||||
|
|
@ -159,7 +159,7 @@ PaError paqaCheckLatency( PaStreamParameters *outputParamsPtr,
|
|||
patestCallback,
|
||||
dataPtr );
|
||||
if( err != paNoError ) goto error1;
|
||||
|
||||
|
||||
streamInfo = Pa_GetStreamInfo( stream );
|
||||
printf("Stream info: inputLatency = %g\n", streamInfo->inputLatency );
|
||||
printf("Stream info: outputLatency = %g\n", streamInfo->outputLatency );
|
||||
|
|
@ -169,7 +169,7 @@ PaError paqaCheckLatency( PaStreamParameters *outputParamsPtr,
|
|||
|
||||
printf("Play for %d seconds.\n", NUM_SECONDS );
|
||||
Pa_Sleep( NUM_SECONDS * 1000 );
|
||||
|
||||
|
||||
printf(" minFramesPerBuffer = %4d\n", dataPtr->minFramesPerBuffer );
|
||||
printf(" maxFramesPerBuffer = %4d\n", dataPtr->maxFramesPerBuffer );
|
||||
printf(" minDeltaDacTime = %f\n", dataPtr->minDeltaDacTime );
|
||||
|
|
@ -181,7 +181,7 @@ PaError paqaCheckLatency( PaStreamParameters *outputParamsPtr,
|
|||
err = Pa_CloseStream( stream );
|
||||
Pa_Sleep( 1 * 1000 );
|
||||
|
||||
|
||||
|
||||
printf("-------------------------------------\n");
|
||||
return err;
|
||||
error2:
|
||||
|
|
@ -245,26 +245,26 @@ static int paqaCheckMultipleSuggested( PaDeviceIndex deviceIndex, int isInput )
|
|||
streamParameters.hostApiSpecificStreamInfo = NULL;
|
||||
streamParameters.sampleFormat = paFloat32;
|
||||
sampleRate = pdi->defaultSampleRate;
|
||||
|
||||
|
||||
printf(" lowLatency = %g\n", lowLatency );
|
||||
printf(" highLatency = %g\n", highLatency );
|
||||
printf(" numChannels = %d\n", numChannels );
|
||||
printf(" sampleRate = %g\n", sampleRate );
|
||||
|
||||
|
||||
if( (highLatency - lowLatency) < 0.001 )
|
||||
{
|
||||
numLoops = 1;
|
||||
}
|
||||
|
||||
for( i=0; i<numLoops; i++ )
|
||||
{
|
||||
{
|
||||
if( numLoops == 1 )
|
||||
streamParameters.suggestedLatency = lowLatency;
|
||||
else
|
||||
streamParameters.suggestedLatency = lowLatency + ((highLatency - lowLatency) * i /(numLoops - 1));
|
||||
|
||||
|
||||
printf(" suggestedLatency[%d] = %6.4f\n", i, streamParameters.suggestedLatency );
|
||||
|
||||
|
||||
err = Pa_OpenStream(
|
||||
&stream,
|
||||
(isInput ? &streamParameters : NULL),
|
||||
|
|
@ -275,11 +275,11 @@ static int paqaCheckMultipleSuggested( PaDeviceIndex deviceIndex, int isInput )
|
|||
paqaNoopCallback,
|
||||
NULL );
|
||||
if( err != paNoError ) goto error;
|
||||
|
||||
|
||||
streamInfo = Pa_GetStreamInfo( stream );
|
||||
|
||||
|
||||
err = Pa_CloseStream( stream );
|
||||
|
||||
|
||||
if( isInput )
|
||||
{
|
||||
finalLatency = streamInfo->inputLatency;
|
||||
|
|
@ -317,7 +317,7 @@ static int paqaVerifySuggestedLatency( void )
|
|||
int result = 0;
|
||||
const PaDeviceInfo *pdi;
|
||||
int numDevices = Pa_GetDeviceCount();
|
||||
|
||||
|
||||
printf("\n ------------------------ paqaVerifySuggestedLatency\n");
|
||||
for( id=0; id<numDevices; id++ ) /* Iterate through all devices. */
|
||||
{
|
||||
|
|
@ -349,7 +349,7 @@ static int paqaVerifyDeviceInfoLatency( void )
|
|||
PaDeviceIndex id;
|
||||
const PaDeviceInfo *pdi;
|
||||
int numDevices = Pa_GetDeviceCount();
|
||||
|
||||
|
||||
printf("\n ------------------------ paqaVerifyDeviceInfoLatency\n");
|
||||
for( id=0; id<numDevices; id++ ) /* Iterate through all devices. */
|
||||
{
|
||||
|
|
@ -390,7 +390,7 @@ int main(void)
|
|||
int i;
|
||||
int framesPerBuffer;
|
||||
double sampleRate = SAMPLE_RATE;
|
||||
|
||||
|
||||
printf("\nPortAudio QA: investigate output latency.\n");
|
||||
|
||||
/* initialise sinusoidal wavetable */
|
||||
|
|
@ -399,19 +399,19 @@ int main(void)
|
|||
data.sine[i] = (float) sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. );
|
||||
}
|
||||
data.left_phase = data.right_phase = 0;
|
||||
|
||||
|
||||
err = Pa_Initialize();
|
||||
if( err != paNoError ) goto error;
|
||||
|
||||
|
||||
/* Run self tests. */
|
||||
if( paqaVerifyDeviceInfoLatency() < 0 ) goto error;
|
||||
|
||||
|
||||
if( paqaVerifySuggestedLatency() < 0 ) goto error;
|
||||
|
||||
|
||||
outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */
|
||||
if (outputParameters.device == paNoDevice) {
|
||||
fprintf(stderr,"Error: No default output device.\n");
|
||||
goto error;
|
||||
fprintf(stderr,"Error: No default output device.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
printf("\n\nNow running Audio Output Tests...\n");
|
||||
|
|
@ -435,44 +435,44 @@ int main(void)
|
|||
outputParameters.suggestedLatency = deviceInfo->defaultLowOutputLatency;
|
||||
err = paqaCheckLatency( &outputParameters, &data, sampleRate, framesPerBuffer );
|
||||
if( err != paNoError ) goto error;
|
||||
|
||||
|
||||
printf("------------- 64 frame buffer with 1.1 * defaultLow latency.\n");
|
||||
framesPerBuffer = 64;
|
||||
outputParameters.suggestedLatency = deviceInfo->defaultLowOutputLatency * 1.1;
|
||||
err = paqaCheckLatency( &outputParameters, &data, sampleRate, framesPerBuffer );
|
||||
if( err != paNoError ) goto error;
|
||||
|
||||
|
||||
// Try to create a huge buffer that is bigger than the allowed device maximum.
|
||||
printf("------------- Try a huge buffer.\n");
|
||||
framesPerBuffer = 16*1024;
|
||||
outputParameters.suggestedLatency = ((double)framesPerBuffer) / sampleRate; // approximate
|
||||
err = paqaCheckLatency( &outputParameters, &data, sampleRate, framesPerBuffer );
|
||||
if( err != paNoError ) goto error;
|
||||
|
||||
|
||||
printf("------------- Try suggestedLatency = 0.0\n");
|
||||
outputParameters.suggestedLatency = 0.0;
|
||||
err = paqaCheckLatency( &outputParameters, &data, sampleRate, paFramesPerBufferUnspecified );
|
||||
if( err != paNoError ) goto error;
|
||||
|
||||
|
||||
printf("------------- Try suggestedLatency = defaultLowOutputLatency\n");
|
||||
outputParameters.suggestedLatency = deviceInfo->defaultLowOutputLatency;
|
||||
err = paqaCheckLatency( &outputParameters, &data, sampleRate, paFramesPerBufferUnspecified );
|
||||
if( err != paNoError ) goto error;
|
||||
|
||||
|
||||
printf("------------- Try suggestedLatency = defaultHighOutputLatency\n");
|
||||
outputParameters.suggestedLatency = deviceInfo->defaultHighOutputLatency;
|
||||
err = paqaCheckLatency( &outputParameters, &data, sampleRate, paFramesPerBufferUnspecified );
|
||||
if( err != paNoError ) goto error;
|
||||
|
||||
|
||||
printf("------------- Try suggestedLatency = defaultHighOutputLatency * 4\n");
|
||||
outputParameters.suggestedLatency = deviceInfo->defaultHighOutputLatency * 4;
|
||||
err = paqaCheckLatency( &outputParameters, &data, sampleRate, paFramesPerBufferUnspecified );
|
||||
if( err != paNoError ) goto error;
|
||||
|
||||
|
||||
Pa_Terminate();
|
||||
printf("SUCCESS - test finished.\n");
|
||||
return err;
|
||||
|
||||
|
||||
error:
|
||||
Pa_Terminate();
|
||||
fprintf( stderr, "ERROR - test failed.\n" );
|
||||
|
|
|
|||
Loading…
Reference in a new issue