diff options
Diffstat (limited to '3rdparty/portaudio/test')
33 files changed, 482 insertions, 62 deletions
diff --git a/3rdparty/portaudio/test/pa_minlat.c b/3rdparty/portaudio/test/pa_minlat.c index 995d6082a42..0106cf3be16 100644 --- a/3rdparty/portaudio/test/pa_minlat.c +++ b/3rdparty/portaudio/test/pa_minlat.c @@ -5,7 +5,7 @@ @author Phil Burk http://www.softsynth.com */ /* - * $Id: pa_minlat.c 1612 2011-02-28 23:56:48Z philburk $ + * $Id$ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com diff --git a/3rdparty/portaudio/test/patest1.c b/3rdparty/portaudio/test/patest1.c index 9f0fc8a4b7f..a0fae47394e 100644 --- a/3rdparty/portaudio/test/patest1.c +++ b/3rdparty/portaudio/test/patest1.c @@ -4,7 +4,7 @@ @author Ross Bencina <rossb@audiomulch.com> */ /* - * $Id: patest1.c 1368 2008-03-01 00:38:27Z rossb $ + * $Id$ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com diff --git a/3rdparty/portaudio/test/patest_buffer.c b/3rdparty/portaudio/test/patest_buffer.c index 44e9afbab41..830b3ace7f2 100644 --- a/3rdparty/portaudio/test/patest_buffer.c +++ b/3rdparty/portaudio/test/patest_buffer.c @@ -4,7 +4,7 @@ @author Phil Burk http://www.softsynth.com */ /* - * $Id: patest_buffer.c 1368 2008-03-01 00:38:27Z rossb $ + * $Id$ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com diff --git a/3rdparty/portaudio/test/patest_callbackstop.c b/3rdparty/portaudio/test/patest_callbackstop.c index a3b9a94e3e4..bd6e8299792 100644 --- a/3rdparty/portaudio/test/patest_callbackstop.c +++ b/3rdparty/portaudio/test/patest_callbackstop.c @@ -4,7 +4,7 @@ @author Ross Bencina <rossb@audiomulch.com> */ /* - * $Id: patest_callbackstop.c 1368 2008-03-01 00:38:27Z rossb $ + * $Id$ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com/ diff --git a/3rdparty/portaudio/test/patest_clip.c b/3rdparty/portaudio/test/patest_clip.c index 26337956523..e86d0ac82d5 100644 --- a/3rdparty/portaudio/test/patest_clip.c +++ b/3rdparty/portaudio/test/patest_clip.c @@ -6,7 +6,7 @@ @author Phil Burk http://www.softsynth.com */ /* - * $Id: patest_clip.c 1368 2008-03-01 00:38:27Z rossb $ + * $Id$ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com diff --git a/3rdparty/portaudio/test/patest_dither.c b/3rdparty/portaudio/test/patest_dither.c index ac50320aba5..e694c8b674a 100644 --- a/3rdparty/portaudio/test/patest_dither.c +++ b/3rdparty/portaudio/test/patest_dither.c @@ -7,7 +7,7 @@ @author Phil Burk http://www.softsynth.com */ /* - * $Id: patest_dither.c 1368 2008-03-01 00:38:27Z rossb $ + * $Id$ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com diff --git a/3rdparty/portaudio/test/patest_hang.c b/3rdparty/portaudio/test/patest_hang.c index fd2cda3be25..6bda6294389 100644 --- a/3rdparty/portaudio/test/patest_hang.c +++ b/3rdparty/portaudio/test/patest_hang.c @@ -5,7 +5,7 @@ @author Phil Burk <philburk@softsynth.com> */ /* - * $Id: patest_hang.c 1368 2008-03-01 00:38:27Z rossb $ + * $Id$ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com diff --git a/3rdparty/portaudio/test/patest_in_overflow.c b/3rdparty/portaudio/test/patest_in_overflow.c index 9904d2cc31b..1f2a83771ad 100644 --- a/3rdparty/portaudio/test/patest_in_overflow.c +++ b/3rdparty/portaudio/test/patest_in_overflow.c @@ -11,7 +11,7 @@ @author Phil Burk <philburk@softsynth.com> */ /* - * $Id: patest_in_overflow.c 1368 2008-03-01 00:38:27Z rossb $ + * $Id$ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com diff --git a/3rdparty/portaudio/test/patest_latency.c b/3rdparty/portaudio/test/patest_latency.c index 652d97165da..bbc6fe635f5 100644 --- a/3rdparty/portaudio/test/patest_latency.c +++ b/3rdparty/portaudio/test/patest_latency.c @@ -5,7 +5,7 @@ @author Phil Burk <philburk@softsynth.com>, and Darren Gibbs */ /* - * $Id: patest_latency.c 1368 2008-03-01 00:38:27Z rossb $ + * $Id$ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com diff --git a/3rdparty/portaudio/test/patest_leftright.c b/3rdparty/portaudio/test/patest_leftright.c index 9d5ada34319..33ccf12c595 100644 --- a/3rdparty/portaudio/test/patest_leftright.c +++ b/3rdparty/portaudio/test/patest_leftright.c @@ -9,7 +9,7 @@ @author Phil Burk <philburk@softsynth.com> */ /* - * $Id: patest_leftright.c 1609 2011-02-27 00:06:07Z philburk $ + * $Id$ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com diff --git a/3rdparty/portaudio/test/patest_longsine.c b/3rdparty/portaudio/test/patest_longsine.c index d839644941b..3eba0ce2a93 100644 --- a/3rdparty/portaudio/test/patest_longsine.c +++ b/3rdparty/portaudio/test/patest_longsine.c @@ -4,7 +4,7 @@ @author Phil Burk http://www.softsynth.com */ /* - * $Id: patest_longsine.c 1368 2008-03-01 00:38:27Z rossb $ + * $Id$ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com diff --git a/3rdparty/portaudio/test/patest_many.c b/3rdparty/portaudio/test/patest_many.c index 1145ddead56..083fdb4895c 100644 --- a/3rdparty/portaudio/test/patest_many.c +++ b/3rdparty/portaudio/test/patest_many.c @@ -4,7 +4,7 @@ @author Phil Burk http://www.softsynth.com */ /* - * $Id: patest_many.c 1368 2008-03-01 00:38:27Z rossb $ + * $Id$ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com diff --git a/3rdparty/portaudio/test/patest_maxsines.c b/3rdparty/portaudio/test/patest_maxsines.c index cfac85842a9..49db8d21c74 100644 --- a/3rdparty/portaudio/test/patest_maxsines.c +++ b/3rdparty/portaudio/test/patest_maxsines.c @@ -5,7 +5,7 @@ @author Phil Burk <philburk@softsynth.com> */ /* - * $Id: patest_maxsines.c 1368 2008-03-01 00:38:27Z rossb $ + * $Id$ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com @@ -46,8 +46,8 @@ #include <math.h> #include "portaudio.h" -#define MAX_SINES (500) -#define MAX_USAGE (0.8) +#define MAX_SINES (2000) +#define MAX_USAGE (0.5) #define SAMPLE_RATE (44100) #define FREQ_TO_PHASE_INC(freq) (freq/(float)SAMPLE_RATE) @@ -60,7 +60,7 @@ #endif #define TWOPI (M_PI * 2.0) -#define TABLE_SIZE (512) +#define TABLE_SIZE (1024) typedef struct paTestData { @@ -70,7 +70,7 @@ typedef struct paTestData } paTestData; -/* Convert phase between and 1.0 to sine value +/* Convert phase between 0.0 and 1.0 to sine value * using linear interpolation. */ float LookupSine( paTestData *data, float phase ); @@ -187,14 +187,14 @@ int main(void) /* Play an increasing number of sine waves until we hit MAX_USAGE */ do { - data.numSines++; + data.numSines += 10; Pa_Sleep(200); load = Pa_GetStreamCpuLoad(stream); printf("numSines = %d, CPU load = %f\n", data.numSines, load ); fflush(stdout); } while((load < MAX_USAGE) && (data.numSines < MAX_SINES)); - Pa_Sleep(2000); /* Stay for 2 seconds around 80% CPU. */ + Pa_Sleep(2000); /* Stay for 2 seconds at max CPU. */ err = Pa_StopStream( stream ); if( err != paNoError ) diff --git a/3rdparty/portaudio/test/patest_mono.c b/3rdparty/portaudio/test/patest_mono.c index 7fb490919a6..40c9d64903e 100644 --- a/3rdparty/portaudio/test/patest_mono.c +++ b/3rdparty/portaudio/test/patest_mono.c @@ -4,7 +4,7 @@ @author Phil Burk http://www.softsynth.com */ /* - * $Id: patest_mono.c 1915 2014-01-16 17:51:26Z philburk $ + * $Id$ * * Authors: * Ross Bencina <rossb@audiomulch.com> diff --git a/3rdparty/portaudio/test/patest_multi_sine.c b/3rdparty/portaudio/test/patest_multi_sine.c index c8f990f9fbc..2b11bfca562 100644 --- a/3rdparty/portaudio/test/patest_multi_sine.c +++ b/3rdparty/portaudio/test/patest_multi_sine.c @@ -4,7 +4,7 @@ @author Phil Burk http://www.softsynth.com */ /* - * $Id: patest_multi_sine.c 1368 2008-03-01 00:38:27Z rossb $ + * $Id$ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com @@ -47,7 +47,7 @@ #include "portaudio.h" #define SAMPLE_RATE (44100) -#define FRAMES_PER_BUFFER (256) +#define FRAMES_PER_BUFFER (128) #define FREQ_INCR (300.0 / SAMPLE_RATE) #define MAX_CHANNELS (64) diff --git a/3rdparty/portaudio/test/patest_out_underflow.c b/3rdparty/portaudio/test/patest_out_underflow.c index ad9fdc8dd42..dee90f8fdc2 100644 --- a/3rdparty/portaudio/test/patest_out_underflow.c +++ b/3rdparty/portaudio/test/patest_out_underflow.c @@ -6,7 +6,7 @@ @author Phil Burk <philburk@softsynth.com> */ /* - * $Id: patest_out_underflow.c 1609 2011-02-27 00:06:07Z philburk $ + * $Id$ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com @@ -85,8 +85,9 @@ static int patestCallback( const void *inputBuffer, void *outputBuffer, if( data->countUnderflows && (statusFlags & paOutputUnderflow) ) + { data->outputUnderflowCount++; - + } for( i=0; i<framesPerBuffer; i++ ) { float output = 0.0; @@ -121,9 +122,11 @@ int main(void) PaStream *stream; PaError err; int safeSineCount, stressedSineCount; + int sineCount; int safeUnderflowCount, stressedUnderflowCount; paTestData data = {0}; double load; + double suggestedLatency; printf("PortAudio Test: output sine waves, count underflows. SR = %d, BufSize = %d. MAX_LOAD = %f\n", @@ -139,7 +142,8 @@ int main(void) } outputParameters.channelCount = 1; /* mono output */ outputParameters.sampleFormat = paFloat32; /* 32 bit floating point output */ - outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency; + suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency; + outputParameters.suggestedLatency = suggestedLatency; outputParameters.hostApiSpecificStreamInfo = NULL; err = Pa_OpenStream( @@ -160,24 +164,23 @@ int main(void) /* Determine number of sines required to get to 50% */ do { - Pa_Sleep( 100 ); + Pa_Sleep( 100 ); load = Pa_GetStreamCpuLoad( stream ); printf("sineCount = %d, CPU load = %f\n", data.sineCount, load ); - if( load < 0.3 ) - { - data.sineCount += 10; - } - else if( load < 0.4 ) - { - data.sineCount += 2; - } - else - { - data.sineCount += 1; - } - + if( load < 0.3 ) + { + data.sineCount += 10; + } + else if( load < 0.4 ) + { + data.sineCount += 2; + } + else + { + data.sineCount += 1; + } } while( load < 0.5 && data.sineCount < (MAX_SINES-1)); @@ -187,16 +190,18 @@ int main(void) stressedSineCount = (int) (2.0 * data.sineCount * MAX_LOAD ); if( stressedSineCount > MAX_SINES ) stressedSineCount = MAX_SINES; - for( ; data.sineCount < stressedSineCount; data.sineCount+=4 ) + sineCount = data.sineCount; + for( ; sineCount < stressedSineCount; sineCount+=4 ) { + data.sineCount = sineCount; Pa_Sleep( 100 ); load = Pa_GetStreamCpuLoad( stream ); - printf("STRESSING: sineCount = %d, CPU load = %f\n", data.sineCount, load ); + printf("STRESSING: sineCount = %d, CPU load = %f\n", sineCount, load ); } - printf("Counting underflows for 5 seconds.\n"); + printf("Counting underflows for 2 seconds.\n"); data.countUnderflows = 1; - Pa_Sleep( 5000 ); + Pa_Sleep( 2000 ); stressedUnderflowCount = data.outputUnderflowCount; @@ -225,12 +230,16 @@ int main(void) Pa_Terminate(); + printf("suggestedLatency = %f\n", suggestedLatency); + + // Report pass or fail if( stressedUnderflowCount == 0 ) - printf("Test failed, no output underflows detected under stress.\n"); - else if( safeUnderflowCount != 0 ) - printf("Test failed, %d unexpected underflows detected under safe load.\n", safeUnderflowCount); + printf("Test FAILED, no output underflows detected under stress.\n"); else - printf("Test passed, %d expected output underflows detected under stress, 0 unexpected underflows detected under safe load.\n", stressedUnderflowCount ); + printf("Test %s, %d expected output underflows detected under stress, " + "%d unexpected underflows detected under safe load.\n", + (safeUnderflowCount == 0) ? "PASSED" : "FAILED", + stressedUnderflowCount, safeUnderflowCount ); return err; error: diff --git a/3rdparty/portaudio/test/patest_prime.c b/3rdparty/portaudio/test/patest_prime.c index cf7dfbe560d..045757e355b 100644 --- a/3rdparty/portaudio/test/patest_prime.c +++ b/3rdparty/portaudio/test/patest_prime.c @@ -5,7 +5,7 @@ */ /* - * $Id: patest_prime.c 1371 2008-03-11 14:27:26Z bjornroche $ + * $Id$ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com diff --git a/3rdparty/portaudio/test/patest_read_record.c b/3rdparty/portaudio/test/patest_read_record.c index 471ffa6efee..e8e5561cd59 100644 --- a/3rdparty/portaudio/test/patest_read_record.c +++ b/3rdparty/portaudio/test/patest_read_record.c @@ -6,7 +6,7 @@ @author Ross Bencina rossb@audiomulch.com */ /* - * $Id: patest_read_record.c 1368 2008-03-01 00:38:27Z rossb $ + * $Id$ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com diff --git a/3rdparty/portaudio/test/patest_ringmix.c b/3rdparty/portaudio/test/patest_ringmix.c index 6f1432e9dd3..2b365fb6e5a 100644 --- a/3rdparty/portaudio/test/patest_ringmix.c +++ b/3rdparty/portaudio/test/patest_ringmix.c @@ -3,7 +3,7 @@ @brief Ring modulate inputs to left output, mix inputs to right output. */ /* - * $Id: patest_ringmix.c 1097 2006-08-26 08:27:53Z rossb $ + * $Id$ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com diff --git a/3rdparty/portaudio/test/patest_sine8.c b/3rdparty/portaudio/test/patest_sine8.c index 91751290524..c00319a003b 100644 --- a/3rdparty/portaudio/test/patest_sine8.c +++ b/3rdparty/portaudio/test/patest_sine8.c @@ -4,7 +4,7 @@ @author Ross Bencina <rossb@audiomulch.com> */ /* - * $Id: patest_sine8.c 1748 2011-09-01 22:08:32Z philburk $ + * $Id$ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com diff --git a/3rdparty/portaudio/test/patest_sine_formats.c b/3rdparty/portaudio/test/patest_sine_formats.c index 22bfa594f54..5d011553c07 100644 --- a/3rdparty/portaudio/test/patest_sine_formats.c +++ b/3rdparty/portaudio/test/patest_sine_formats.c @@ -4,7 +4,7 @@ @author Phil Burk */ /* - * $Id: patest_sine_formats.c 1097 2006-08-26 08:27:53Z rossb $ + * $Id$ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com diff --git a/3rdparty/portaudio/test/patest_sine_time.c b/3rdparty/portaudio/test/patest_sine_time.c index 3382d886189..0d6a1da6b23 100644 --- a/3rdparty/portaudio/test/patest_sine_time.c +++ b/3rdparty/portaudio/test/patest_sine_time.c @@ -6,7 +6,7 @@ @author Phil Burk <philburk@softsynth.com> */ /* - * $Id: patest_sine_time.c 1368 2008-03-01 00:38:27Z rossb $ + * $Id$ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com diff --git a/3rdparty/portaudio/test/patest_start_stop.c b/3rdparty/portaudio/test/patest_start_stop.c index c07d42e4d58..cf82b6778da 100644 --- a/3rdparty/portaudio/test/patest_start_stop.c +++ b/3rdparty/portaudio/test/patest_start_stop.c @@ -6,7 +6,7 @@ @author Phil Burk <philburk@softsynth.com> */ /* - * $Id: patest_start_stop.c 1447 2010-01-24 12:35:36Z rossb $ + * $Id$ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com/ diff --git a/3rdparty/portaudio/test/patest_stop.c b/3rdparty/portaudio/test/patest_stop.c index dc0eeedded6..bc417cc289c 100644 --- a/3rdparty/portaudio/test/patest_stop.c +++ b/3rdparty/portaudio/test/patest_stop.c @@ -14,7 +14,7 @@ @author Phil Burk <philburk@softsynth.com> */ /* - * $Id: patest_stop.c 1368 2008-03-01 00:38:27Z rossb $ + * $Id$ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com diff --git a/3rdparty/portaudio/test/patest_stop_playout.c b/3rdparty/portaudio/test/patest_stop_playout.c index c61c3f4c5e4..9a451eba2bd 100644 --- a/3rdparty/portaudio/test/patest_stop_playout.c +++ b/3rdparty/portaudio/test/patest_stop_playout.c @@ -6,7 +6,7 @@ @author Ross Bencina <rossb@audiomulch.com> */ /* - * $Id: patest_stop_playout.c 1446 2010-01-24 12:27:31Z rossb $ + * $Id$ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com/ diff --git a/3rdparty/portaudio/test/patest_sync.c b/3rdparty/portaudio/test/patest_sync.c index 19839f8d551..a064be15330 100644 --- a/3rdparty/portaudio/test/patest_sync.c +++ b/3rdparty/portaudio/test/patest_sync.c @@ -16,7 +16,7 @@ @author Phil Burk http://www.softsynth.com */ /* - * $Id: patest_sync.c 1368 2008-03-01 00:38:27Z rossb $ + * $Id$ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com diff --git a/3rdparty/portaudio/test/patest_toomanysines.c b/3rdparty/portaudio/test/patest_toomanysines.c index e3dae324484..4722f5eaf08 100644 --- a/3rdparty/portaudio/test/patest_toomanysines.c +++ b/3rdparty/portaudio/test/patest_toomanysines.c @@ -6,7 +6,7 @@ @author Phil Burk <philburk@softsynth.com> */ /* - * $Id: patest_toomanysines.c 1609 2011-02-27 00:06:07Z philburk $ + * $Id$ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com diff --git a/3rdparty/portaudio/test/patest_two_rates.c b/3rdparty/portaudio/test/patest_two_rates.c index 9bd92425fef..5a2b178987c 100644 --- a/3rdparty/portaudio/test/patest_two_rates.c +++ b/3rdparty/portaudio/test/patest_two_rates.c @@ -4,7 +4,7 @@ @author Phil Burk <philburk@softsynth.com> */ /* - * $Id: patest_two_rates.c 1640 2011-03-07 00:52:47Z philburk $ + * $Id$ * * Author: Phil Burk http://www.softsynth.com * diff --git a/3rdparty/portaudio/test/patest_underflow.c b/3rdparty/portaudio/test/patest_underflow.c index 0cb8757de7c..e1726a613d9 100644 --- a/3rdparty/portaudio/test/patest_underflow.c +++ b/3rdparty/portaudio/test/patest_underflow.c @@ -6,7 +6,7 @@ @author Phil Burk <philburk@softsynth.com> */ /* - * $Id: patest_underflow.c 1368 2008-03-01 00:38:27Z rossb $ + * $Id$ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com diff --git a/3rdparty/portaudio/test/patest_unplug.c b/3rdparty/portaudio/test/patest_unplug.c new file mode 100644 index 00000000000..ba55b7dee15 --- /dev/null +++ b/3rdparty/portaudio/test/patest_unplug.c @@ -0,0 +1,243 @@ +/** @file patest_unplug.c + @ingroup test_src + @brief Debug a crash involving unplugging a USB device. + @author Phil Burk http://www.softsynth.com +*/ +/* + * $Id$ + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * 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 + * license above. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <memory.h> +#include <math.h> +#include "portaudio.h" + +#define NUM_SECONDS (8) +#define SAMPLE_RATE (44100) +#ifndef M_PI +#define M_PI (3.14159265) +#endif +#define TABLE_SIZE (200) +#define FRAMES_PER_BUFFER (64) +#define MAX_CHANNELS (8) + +typedef struct +{ + short sine[TABLE_SIZE]; + int32_t phases[MAX_CHANNELS]; + int32_t numChannels; + int32_t sampsToGo; +} +paTestData; + + +static int inputCallback( const void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + const PaStreamCallbackTimeInfo* timeInfo, + PaStreamCallbackFlags statusFlags, + void *userData ) +{ + paTestData *data = (paTestData*)userData; + int finished = 0; + (void) inputBuffer; /* Prevent "unused variable" warnings. */ + (void) outputBuffer; /* Prevent "unused variable" warnings. */ + + data->sampsToGo -= framesPerBuffer; + if (data->sampsToGo <= 0) + { + data->sampsToGo = 0; + finished = 1; + } + return finished; +} + +static int outputCallback( const void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + const PaStreamCallbackTimeInfo* timeInfo, + PaStreamCallbackFlags statusFlags, + void *userData ) +{ + paTestData *data = (paTestData*)userData; + short *out = (short*)outputBuffer; + unsigned int i; + int finished = 0; + (void) inputBuffer; /* Prevent "unused variable" warnings. */ + + for( i=0; i<framesPerBuffer; i++ ) + { + for (int channelIndex = 0; channelIndex < data->numChannels; channelIndex++) + { + int phase = data->phases[channelIndex]; + *out++ = data->sine[phase]; + phase += channelIndex + 2; + if( phase >= TABLE_SIZE ) phase -= TABLE_SIZE; + data->phases[channelIndex] = phase; + } + } + return finished; +} + +/*******************************************************************/ +int main(int argc, char **args); +int main(int argc, char **args) +{ + PaStreamParameters inputParameters; + PaStreamParameters outputParameters; + PaStream *inputStream; + PaStream *outputStream; + const PaDeviceInfo *deviceInfo; + PaError err; + paTestData data; + int i; + int totalSamps; + int inputDevice = -1; + int outputDevice = -1; + + printf("Test unplugging a USB device.\n"); + + if( argc > 1 ) { + inputDevice = outputDevice = atoi( args[1] ); + printf("Using device number %d.\n\n", inputDevice ); + } else { + printf("Using default device.\n\n" ); + } + + memset(&data, 0, sizeof(data)); + + /* initialise sinusoidal wavetable */ + for( i=0; i<TABLE_SIZE; i++ ) + { + data.sine[i] = (short) (32767.0 * sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. )); + } + data.numChannels = 2; + data.sampsToGo = totalSamps = NUM_SECONDS * SAMPLE_RATE; /* Play for a few seconds. */ + + + err = Pa_Initialize(); + if( err != paNoError ) goto error; + + if( inputDevice == -1 ) + inputParameters.device = Pa_GetDefaultInputDevice(); /* default input device */ + else + inputParameters.device = inputDevice ; + + if (inputParameters.device == paNoDevice) { + fprintf(stderr,"Error: No default input device.\n"); + goto error; + } + + if( outputDevice == -1 ) + outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */ + else + outputParameters.device = outputDevice ; + + if (outputParameters.device == paNoDevice) { + fprintf(stderr,"Error: No default output device.\n"); + goto error; + } + + inputParameters.channelCount = 2; + inputParameters.sampleFormat = paInt16; + deviceInfo = Pa_GetDeviceInfo( inputParameters.device ); + if( deviceInfo == NULL ) + { + fprintf( stderr, "No matching input device.\n" ); + goto error; + } + inputParameters.suggestedLatency = deviceInfo->defaultLowInputLatency; + inputParameters.hostApiSpecificStreamInfo = NULL; + err = Pa_OpenStream( + &inputStream, + &inputParameters, + NULL, + SAMPLE_RATE, + FRAMES_PER_BUFFER, + 0, + inputCallback, + &data ); + if( err != paNoError ) goto error; + + outputParameters.channelCount = 2; + outputParameters.sampleFormat = paInt16; + deviceInfo = Pa_GetDeviceInfo( outputParameters.device ); + if( deviceInfo == NULL ) + { + fprintf( stderr, "No matching output device.\n" ); + goto error; + } + outputParameters.suggestedLatency = deviceInfo->defaultLowOutputLatency; + outputParameters.hostApiSpecificStreamInfo = NULL; + err = Pa_OpenStream( + &outputStream, + NULL, + &outputParameters, + SAMPLE_RATE, + FRAMES_PER_BUFFER, + (paClipOff | paDitherOff), + outputCallback, + &data ); + if( err != paNoError ) goto error; + + err = Pa_StartStream( inputStream ); + if( err != paNoError ) goto error; + err = Pa_StartStream( outputStream ); + if( err != paNoError ) goto error; + + printf("When you hear sound, unplug the USB device.\n"); + do + { + Pa_Sleep(500); + printf("Frames remaining = %d\n", data.sampsToGo); + printf("Pa_IsStreamActive(inputStream) = %d\n", Pa_IsStreamActive(inputStream)); + printf("Pa_IsStreamActive(outputStream) = %d\n", Pa_IsStreamActive(outputStream)); + } while( Pa_IsStreamActive(inputStream) && Pa_IsStreamActive(outputStream) ); + + err = Pa_CloseStream( inputStream ); + if( err != paNoError ) goto error; + err = Pa_CloseStream( outputStream ); + if( err != paNoError ) goto error; + Pa_Terminate(); + return paNoError; +error: + Pa_Terminate(); + fprintf( stderr, "An error occured while using the portaudio stream\n" ); + fprintf( stderr, "Error number: %d\n", err ); + fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) ); + fprintf( stderr, "Host Error message: %s\n", Pa_GetLastHostErrorInfo()->errorText ); + return err; +} diff --git a/3rdparty/portaudio/test/patest_wire.c b/3rdparty/portaudio/test/patest_wire.c index 3601ef91792..ba3477b3689 100644 --- a/3rdparty/portaudio/test/patest_wire.c +++ b/3rdparty/portaudio/test/patest_wire.c @@ -13,7 +13,7 @@ */ /* - * $Id: patest_wire.c 1843 2012-06-22 21:58:10Z philburk $ + * $Id$ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com diff --git a/3rdparty/portaudio/test/patest_write_stop.c b/3rdparty/portaudio/test/patest_write_stop.c index 7b051653c46..243e774c2f6 100644 --- a/3rdparty/portaudio/test/patest_write_stop.c +++ b/3rdparty/portaudio/test/patest_write_stop.c @@ -5,7 +5,7 @@ @author Phil Burk */ /* - * $Id: patest_write_stop.c 1083 2006-08-23 07:30:49Z rossb $ + * $Id$ * * This program uses the PortAudio Portable Audio Library. * For more information see: http://www.portaudio.com/ diff --git a/3rdparty/portaudio/test/patest_write_stop_hang_illegal.c b/3rdparty/portaudio/test/patest_write_stop_hang_illegal.c new file mode 100644 index 00000000000..ed93425e33b --- /dev/null +++ b/3rdparty/portaudio/test/patest_write_stop_hang_illegal.c @@ -0,0 +1,168 @@ +/** @file patest_write_stop_threads.c + @brief Call Pa_StopStream() from another thread to see if PortAudio hangs. + @author Bjorn Roche of XO Audio (www.xoaudio.com) + @author Ross Bencina + @author Phil Burk +*/ +/* + * $Id$ + * + * This program uses the PortAudio Portable Audio Library. + * For more information see: http://www.portaudio.com/ + * Copyright (c) 1999-2000 Ross Bencina and Phil Burk + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * 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 + * license above. + */ + +#include <stdio.h> +#include <unistd.h> +#include <math.h> +#include <memory.h> +/* pthread may only be available on Mac and Linux. */ +#include <pthread.h> +#include "portaudio.h" + +#define SAMPLE_RATE (44100) +#define FRAMES_PER_BUFFER (2048) + +static float s_buffer[FRAMES_PER_BUFFER][2]; /* stereo output buffer */ + +/** + * WARNING: PortAudio is NOT thread safe. DO NOT call PortAudio + * from multiple threads without synchronization. This test uses + * PA in an ILLEGAL WAY in order to try to flush out potential hang bugs. + * The test calls Pa_WriteStream() and Pa_StopStream() simultaneously + * from separate threads in order to try to cause Pa_StopStream() to hang. + * In the main thread we write to the stream in a loop. + * Then try stopping PA from another thread to see if it hangs. + * + * @note: Do not expect this test to pass. The test is only here + * as a debugging aid for hang bugs. Since this test uses PA in an + * illegal way, it may fail for reasons that are not PA bugs. + */ + +/* Wait for awhile then abort the stream. */ +void *stop_thread_proc(void *arg) +{ + PaStream *stream = (PaStream *)arg; + PaTime time; + for (int i = 0; i < 20; i++) + { + /* ILLEGAL unsynchronised call to PA, see comment above */ + time = Pa_GetStreamTime( stream ); + printf("Stream time = %f\n", time); + fflush(stdout); + usleep(100 * 1000); + } + printf("Call Pa_StopStream()\n"); + fflush(stdout); + /* ILLEGAL unsynchronised call to PA, see comment above */ + PaError err = Pa_StopStream( stream ); + printf("Pa_StopStream() returned %d\n", err); + fflush(stdout); + + return stream; +} + +int main(void); +int main(void) +{ + PaStreamParameters outputParameters; + PaStream *stream; + PaError err; + int result; + pthread_t thread; + + printf( "PortAudio Test: output silence and stop from another thread. SR = %d, BufSize = %d\n", + SAMPLE_RATE, FRAMES_PER_BUFFER); + + err = Pa_Initialize(); + if( err != paNoError ) goto error; + + outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */ + outputParameters.channelCount = 2; /* stereo output */ + outputParameters.sampleFormat = paFloat32; /* 32 bit floating point output */ + outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultHighOutputLatency * 5; + outputParameters.hostApiSpecificStreamInfo = NULL; + + /* open the stream */ + err = Pa_OpenStream( + &stream, + NULL, /* no input */ + &outputParameters, + SAMPLE_RATE, + FRAMES_PER_BUFFER, + paClipOff, /* we won't output out of range samples so don't bother clipping them */ + NULL, /* no callback, use blocking API */ + NULL ); /* no callback, so no callback userData */ + if( err != paNoError ) goto error; + + result = pthread_create(&thread, NULL /* attributes */, stop_thread_proc, stream); + + /* start the stream */ + err = Pa_StartStream( stream ); + if( err != paNoError ) goto error; + + /* clear buffer */ + memset( s_buffer, 0, sizeof(s_buffer) ); + + /* play the silent buffer many times */ + while( Pa_IsStreamActive(stream) > 0 ) + { + err = Pa_WriteStream( stream, s_buffer, FRAMES_PER_BUFFER ); + printf("Pa_WriteStream returns %d = %s\n", err, Pa_GetErrorText( err )); + if( err != paNoError ) + { + err = paNoError; + break; + }; + } + + printf("Try to join the thread that called Pa_StopStream().\n"); + result = pthread_join( thread, NULL ); + printf("pthread_join returned %d\n", result); + + /* close, and terminate */ + printf("Call Pa_CloseStream\n"); + err = Pa_CloseStream( stream ); + if( err != paNoError ) goto error; + + Pa_Terminate(); + printf("Test finished.\n"); + + return err; +error: + Pa_Terminate(); + fprintf( stderr, "An error occured while using the portaudio stream\n" ); + fprintf( stderr, "Error number: %d\n", err ); + fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) ); + return err; +} |