summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/portaudio/test/patest_callbackstop.c
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/portaudio/test/patest_callbackstop.c')
-rw-r--r--3rdparty/portaudio/test/patest_callbackstop.c80
1 files changed, 58 insertions, 22 deletions
diff --git a/3rdparty/portaudio/test/patest_callbackstop.c b/3rdparty/portaudio/test/patest_callbackstop.c
index bd6e8299792..3f4152b213f 100644
--- a/3rdparty/portaudio/test/patest_callbackstop.c
+++ b/3rdparty/portaudio/test/patest_callbackstop.c
@@ -1,7 +1,7 @@
/** @file patest_callbackstop.c
- @ingroup test_src
- @brief Test the paComplete callback result code.
- @author Ross Bencina <rossb@audiomulch.com>
+ @ingroup test_src
+ @brief Test the paComplete callback result code.
+ @author Ross Bencina <rossb@audiomulch.com>
*/
/*
* $Id$
@@ -31,13 +31,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.
*/
@@ -86,18 +86,18 @@ static int TestCallback( const void *input, void *output,
(void) timeInfo;
(void) statusFlags;
-
+
if( data->callbackReturnedPaComplete )
data->callbackInvokedAfterReturningPaComplete = 1;
for( i=0; i<frameCount; i++ )
{
/* generate tone */
-
+
x = data->sine[ data->phase++ ];
if( data->phase >= TABLE_SIZE )
data->phase -= TABLE_SIZE;
-
+
*out++ = x; /* left */
*out++ = x; /* right */
}
@@ -119,38 +119,61 @@ static int TestCallback( const void *input, void *output,
*/
static void StreamFinished( void* userData )
{
- TestData *data = (TestData *) userData;
- printf( "Stream Completed: %s\n", data->message );
+ TestData *data = (TestData *) userData;
+ printf( "Stream Completed: %s\n", data->message );
}
+/**
+ * @return paNoError if successful, otherwise a negative error.
+ */
+static PaError CheckActiveStopped(PaStream *stream,
+ PaError expectedActive,
+ PaError expectedStopped,
+ int lineNumber)
+{
+ PaError testResult = paNoError;
+ PaError actualActive = Pa_IsStreamActive(stream);
+ if (expectedActive != actualActive) {
+ printf("ERROR at line %d - active is %d, expected %d\n",
+ lineNumber, actualActive, expectedActive);
+ testResult = (actualActive < 0) ? actualActive : paInternalError;
+ }
+ PaError actualStopped = Pa_IsStreamStopped(stream);
+ if (expectedStopped != actualStopped) {
+ printf("ERROR at line %d - stopped is %d, expected %d\n",
+ lineNumber, actualStopped, expectedStopped);
+ testResult = (actualStopped < 0) ? actualStopped : paInternalError;
+ }
+ return testResult;
+}
/*----------------------------------------------------------------------------*/
int main(void);
int main(void)
{
PaStreamParameters outputParameters;
- PaStream *stream;
+ PaStream *stream = NULL;
PaError err;
TestData data;
int i, j;
-
+
printf( "PortAudio Test: output sine wave. SR = %d, BufSize = %d\n",
SAMPLE_RATE, FRAMES_PER_BUFFER );
-
+
/* initialise sinusoidal wavetable */
for( i=0; i<TABLE_SIZE; i++ )
{
data.sine[i] = (float) sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. );
}
-
+
err = Pa_Initialize();
if( err != paNoError ) goto error;
- outputParameters.device = Pa_GetDefaultOutputDevice();
+ outputParameters.device = Pa_GetDefaultOutputDevice();
if (outputParameters.device == paNoDevice) {
- fprintf(stderr,"Error: No default output device.\n");
- goto error;
+ fprintf(stderr,"Error: No default output device.\n");
+ goto error;
}
outputParameters.channelCount = 2; /* stereo output */
outputParameters.sampleFormat = paFloat32; /* 32 bit floating point output */
@@ -172,8 +195,9 @@ int main(void)
err = Pa_SetStreamFinishedCallback( stream, &StreamFinished );
if( err != paNoError ) goto error;
+
printf("Repeating test %d times.\n", NUM_LOOPS );
-
+
for( i=0; i < NUM_LOOPS; ++i )
{
data.phase = 0;
@@ -182,9 +206,13 @@ int main(void)
data.callbackInvokedAfterReturningPaComplete = 0;
sprintf( data.message, "Loop: %d", i );
+ if( (err = CheckActiveStopped(stream, 0, 1, __LINE__)) < 0 ) goto error;
+
err = Pa_StartStream( stream );
if( err != paNoError ) goto error;
+ if( (err = CheckActiveStopped(stream, 1, 0, __LINE__)) < 0 ) goto error;
+
printf("Play for %d seconds.\n", NUM_SECONDS );
/* wait for the callback to complete generating NUM_SECONDS of tone */
@@ -201,7 +229,7 @@ int main(void)
/* wait for stream to become inactive,
or for a timeout of approximately NUM_SECONDS
*/
-
+
j = 0;
while( (err = Pa_IsStreamActive( stream )) == 1 && j < NUM_SECONDS * 2 )
{
@@ -228,10 +256,14 @@ int main(void)
printf( "TEST FAILED: Callback was invoked after returning paComplete.\n" );
}
+ /* Stream should not be "stopped" until Pa_StopStream() called. */
+ if( (err = CheckActiveStopped(stream, 0, 0, __LINE__)) < 0 ) goto error;
err = Pa_StopStream( stream );
if( err != paNoError ) goto error;
+ if( (err = CheckActiveStopped(stream, 0, 1, __LINE__)) < 0 ) goto error;
+
printf( "sleeping for 1 second...\n" );
Pa_Sleep( 1000 );
}
@@ -241,11 +273,15 @@ int main(void)
Pa_Terminate();
printf("Test finished.\n");
-
+
return err;
error:
+ if( stream != NULL )
+ {
+ Pa_CloseStream( stream );
+ }
Pa_Terminate();
- fprintf( stderr, "An error occured while using the portaudio stream\n" );
+ fprintf( stderr, "An error occurred while using the portaudio stream\n" );
fprintf( stderr, "Error number: %d\n", err );
fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
return err;