annotate src/portaudio/qa/paqa_devs.c @ 31:642a72ce5e62

Add Vamp SDK, move serd/sord to more obvious locations
author Chris Cannam
date Fri, 04 Jul 2014 08:16:02 +0100
parents e13257ea84a4
children
rev   line source
Chris@4 1 /** @file paqa_devs.c
Chris@4 2 @ingroup qa_src
Chris@4 3 @brief Self Testing Quality Assurance app for PortAudio
Chris@4 4 Try to open each device and run through all the
Chris@4 5 possible configurations. This test does not verify
Chris@4 6 that the configuration works well. It just verifies
Chris@4 7 that it does not crash. It requires a human to listen to
Chris@4 8 the outputs.
Chris@4 9
Chris@4 10 @author Phil Burk http://www.softsynth.com
Chris@4 11
Chris@4 12 Pieter adapted to V19 API. Test now relies heavily on
Chris@4 13 Pa_IsFormatSupported(). Uses same 'standard' sample rates
Chris@4 14 as in test pa_devs.c.
Chris@4 15 */
Chris@4 16 /*
Chris@4 17 * $Id: paqa_devs.c 1756 2011-09-08 06:09:29Z philburk $
Chris@4 18 *
Chris@4 19 * This program uses the PortAudio Portable Audio Library.
Chris@4 20 * For more information see: http://www.portaudio.com
Chris@4 21 * Copyright (c) 1999-2000 Ross Bencina and Phil Burk
Chris@4 22 *
Chris@4 23 * Permission is hereby granted, free of charge, to any person obtaining
Chris@4 24 * a copy of this software and associated documentation files
Chris@4 25 * (the "Software"), to deal in the Software without restriction,
Chris@4 26 * including without limitation the rights to use, copy, modify, merge,
Chris@4 27 * publish, distribute, sublicense, and/or sell copies of the Software,
Chris@4 28 * and to permit persons to whom the Software is furnished to do so,
Chris@4 29 * subject to the following conditions:
Chris@4 30 *
Chris@4 31 * The above copyright notice and this permission notice shall be
Chris@4 32 * included in all copies or substantial portions of the Software.
Chris@4 33 *
Chris@4 34 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Chris@4 35 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Chris@4 36 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Chris@4 37 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
Chris@4 38 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
Chris@4 39 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
Chris@4 40 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Chris@4 41 */
Chris@4 42
Chris@4 43 /*
Chris@4 44 * The text above constitutes the entire PortAudio license; however,
Chris@4 45 * the PortAudio community also makes the following non-binding requests:
Chris@4 46 *
Chris@4 47 * Any person wishing to distribute modifications to the Software is
Chris@4 48 * requested to send the modifications to the original developer so that
Chris@4 49 * they can be incorporated into the canonical version. It is also
Chris@4 50 * requested that these non-binding requests be included along with the
Chris@4 51 * license above.
Chris@4 52 */
Chris@4 53
Chris@4 54 #include <stdio.h>
Chris@4 55 #include <math.h>
Chris@4 56 #include "portaudio.h"
Chris@4 57 #include "pa_trace.h"
Chris@4 58
Chris@4 59 /****************************************** Definitions ***********/
Chris@4 60 #define MODE_INPUT (0)
Chris@4 61 #define MODE_OUTPUT (1)
Chris@4 62
Chris@4 63 typedef struct PaQaData
Chris@4 64 {
Chris@4 65 unsigned long framesLeft;
Chris@4 66 int numChannels;
Chris@4 67 int bytesPerSample;
Chris@4 68 int mode;
Chris@4 69 short sawPhase;
Chris@4 70 PaSampleFormat format;
Chris@4 71 }
Chris@4 72 PaQaData;
Chris@4 73
Chris@4 74 /****************************************** Prototypes ***********/
Chris@4 75 static void TestDevices( int mode );
Chris@4 76 static void TestFormats( int mode, PaDeviceIndex deviceID, double sampleRate,
Chris@4 77 int numChannels );
Chris@4 78 static int TestAdvance( int mode, PaDeviceIndex deviceID, double sampleRate,
Chris@4 79 int numChannels, PaSampleFormat format );
Chris@4 80 static int QaCallback( const void *inputBuffer, void *outputBuffer,
Chris@4 81 unsigned long framesPerBuffer,
Chris@4 82 const PaStreamCallbackTimeInfo* timeInfo,
Chris@4 83 PaStreamCallbackFlags statusFlags,
Chris@4 84 void *userData );
Chris@4 85
Chris@4 86 /****************************************** Globals ***********/
Chris@4 87 static int gNumPassed = 0;
Chris@4 88 static int gNumFailed = 0;
Chris@4 89
Chris@4 90 /****************************************** Macros ***********/
Chris@4 91 /* Print ERROR if it fails. Tally success or failure. */
Chris@4 92 /* Odd do-while wrapper seems to be needed for some compilers. */
Chris@4 93 #define EXPECT(_exp) \
Chris@4 94 do \
Chris@4 95 { \
Chris@4 96 if ((_exp)) {\
Chris@4 97 /* printf("SUCCESS for %s\n", #_exp ); */ \
Chris@4 98 gNumPassed++; \
Chris@4 99 } \
Chris@4 100 else { \
Chris@4 101 printf("ERROR - 0x%x - %s for %s\n", result, \
Chris@4 102 ((result == 0) ? "-" : Pa_GetErrorText(result)), \
Chris@4 103 #_exp ); \
Chris@4 104 gNumFailed++; \
Chris@4 105 goto error; \
Chris@4 106 } \
Chris@4 107 } while(0)
Chris@4 108
Chris@4 109 /*******************************************************************/
Chris@4 110 /* This routine will be called by the PortAudio engine when audio is needed.
Chris@4 111 ** It may be called at interrupt level on some machines so don't do anything
Chris@4 112 ** that could mess up the system like calling malloc() or free().
Chris@4 113 */
Chris@4 114 static int QaCallback( const void *inputBuffer, void *outputBuffer,
Chris@4 115 unsigned long framesPerBuffer,
Chris@4 116 const PaStreamCallbackTimeInfo* timeInfo,
Chris@4 117 PaStreamCallbackFlags statusFlags,
Chris@4 118 void *userData )
Chris@4 119 {
Chris@4 120 unsigned long i;
Chris@4 121 short phase;
Chris@4 122 PaQaData *data = (PaQaData *) userData;
Chris@4 123 (void) inputBuffer;
Chris@4 124
Chris@4 125 /* Play simple sawtooth wave. */
Chris@4 126 if( data->mode == MODE_OUTPUT )
Chris@4 127 {
Chris@4 128 phase = data->sawPhase;
Chris@4 129 switch( data->format )
Chris@4 130 {
Chris@4 131 case paFloat32:
Chris@4 132 {
Chris@4 133 float *out = (float *) outputBuffer;
Chris@4 134 for( i=0; i<framesPerBuffer; i++ )
Chris@4 135 {
Chris@4 136 phase += 0x123;
Chris@4 137 *out++ = (float) (phase * (1.0 / 32768.0));
Chris@4 138 if( data->numChannels == 2 )
Chris@4 139 {
Chris@4 140 *out++ = (float) (phase * (1.0 / 32768.0));
Chris@4 141 }
Chris@4 142 }
Chris@4 143 }
Chris@4 144 break;
Chris@4 145
Chris@4 146 case paInt32:
Chris@4 147 {
Chris@4 148 int *out = (int *) outputBuffer;
Chris@4 149 for( i=0; i<framesPerBuffer; i++ )
Chris@4 150 {
Chris@4 151 phase += 0x123;
Chris@4 152 *out++ = ((int) phase ) << 16;
Chris@4 153 if( data->numChannels == 2 )
Chris@4 154 {
Chris@4 155 *out++ = ((int) phase ) << 16;
Chris@4 156 }
Chris@4 157 }
Chris@4 158 }
Chris@4 159 break;
Chris@4 160
Chris@4 161 case paInt16:
Chris@4 162 {
Chris@4 163 short *out = (short *) outputBuffer;
Chris@4 164 for( i=0; i<framesPerBuffer; i++ )
Chris@4 165 {
Chris@4 166 phase += 0x123;
Chris@4 167 *out++ = phase;
Chris@4 168 if( data->numChannels == 2 )
Chris@4 169 {
Chris@4 170 *out++ = phase;
Chris@4 171 }
Chris@4 172 }
Chris@4 173 }
Chris@4 174 break;
Chris@4 175
Chris@4 176 default:
Chris@4 177 {
Chris@4 178 unsigned char *out = (unsigned char *) outputBuffer;
Chris@4 179 unsigned long numBytes = framesPerBuffer * data->numChannels * data->bytesPerSample;
Chris@4 180 for( i=0; i<numBytes; i++ )
Chris@4 181 {
Chris@4 182 *out++ = 0;
Chris@4 183 }
Chris@4 184 }
Chris@4 185 break;
Chris@4 186 }
Chris@4 187 data->sawPhase = phase;
Chris@4 188 }
Chris@4 189 /* Are we through yet? */
Chris@4 190 if( data->framesLeft > framesPerBuffer )
Chris@4 191 {
Chris@4 192 PaUtil_AddTraceMessage("QaCallback: running. framesLeft", data->framesLeft );
Chris@4 193 data->framesLeft -= framesPerBuffer;
Chris@4 194 return 0;
Chris@4 195 }
Chris@4 196 else
Chris@4 197 {
Chris@4 198 PaUtil_AddTraceMessage("QaCallback: DONE! framesLeft", data->framesLeft );
Chris@4 199 data->framesLeft = 0;
Chris@4 200 return 1;
Chris@4 201 }
Chris@4 202 }
Chris@4 203
Chris@4 204 /*******************************************************************/
Chris@4 205 int main(void);
Chris@4 206 int main(void)
Chris@4 207 {
Chris@4 208 PaError result;
Chris@4 209 EXPECT( ((result=Pa_Initialize()) == 0) );
Chris@4 210 printf("Test OUTPUT ---------------\n");
Chris@4 211 TestDevices( MODE_OUTPUT );
Chris@4 212 printf("Test INPUT ---------------\n");
Chris@4 213 TestDevices( MODE_INPUT );
Chris@4 214 error:
Chris@4 215 Pa_Terminate();
Chris@4 216 printf("QA Report: %d passed, %d failed.\n", gNumPassed, gNumFailed );
Chris@4 217 return (gNumFailed > 0) ? 1 : 0;
Chris@4 218 }
Chris@4 219
Chris@4 220 /*******************************************************************
Chris@4 221 * Try each output device, through its full range of capabilities. */
Chris@4 222 static void TestDevices( int mode )
Chris@4 223 {
Chris@4 224 int id, jc, i;
Chris@4 225 int maxChannels;
Chris@4 226 const PaDeviceInfo *pdi;
Chris@4 227 static double standardSampleRates[] = { 8000.0, 9600.0, 11025.0, 12000.0,
Chris@4 228 16000.0, 22050.0, 24000.0,
Chris@4 229 32000.0, 44100.0, 48000.0,
Chris@4 230 88200.0, 96000.0,
Chris@4 231 -1.0 }; /* Negative terminated list. */
Chris@4 232 int numDevices = Pa_GetDeviceCount();
Chris@4 233 for( id=0; id<numDevices; id++ ) /* Iterate through all devices. */
Chris@4 234 {
Chris@4 235 pdi = Pa_GetDeviceInfo( id );
Chris@4 236 /* Try 1 to maxChannels on each device. */
Chris@4 237 maxChannels = (( mode == MODE_INPUT ) ? pdi->maxInputChannels : pdi->maxOutputChannels);
Chris@4 238
Chris@4 239 for( jc=1; jc<=maxChannels; jc++ )
Chris@4 240 {
Chris@4 241 printf("\n========================================================================\n");
Chris@4 242 printf(" Device = %s\n", pdi->name );
Chris@4 243 printf("========================================================================\n");
Chris@4 244 /* Try each standard sample rate. */
Chris@4 245 for( i=0; standardSampleRates[i] > 0; i++ )
Chris@4 246 {
Chris@4 247 TestFormats( mode, (PaDeviceIndex)id, standardSampleRates[i], jc );
Chris@4 248 }
Chris@4 249 }
Chris@4 250 }
Chris@4 251 }
Chris@4 252
Chris@4 253 /*******************************************************************/
Chris@4 254 static void TestFormats( int mode, PaDeviceIndex deviceID, double sampleRate,
Chris@4 255 int numChannels )
Chris@4 256 {
Chris@4 257 TestAdvance( mode, deviceID, sampleRate, numChannels, paFloat32 );
Chris@4 258 TestAdvance( mode, deviceID, sampleRate, numChannels, paInt16 );
Chris@4 259 TestAdvance( mode, deviceID, sampleRate, numChannels, paInt32 );
Chris@4 260 /* TestAdvance( mode, deviceID, sampleRate, numChannels, paInt24 ); */
Chris@4 261 }
Chris@4 262
Chris@4 263 /*******************************************************************/
Chris@4 264 static int TestAdvance( int mode, PaDeviceIndex deviceID, double sampleRate,
Chris@4 265 int numChannels, PaSampleFormat format )
Chris@4 266 {
Chris@4 267 PaStreamParameters inputParameters, outputParameters, *ipp, *opp;
Chris@4 268 PaStream *stream = NULL;
Chris@4 269 PaError result = paNoError;
Chris@4 270 PaQaData myData;
Chris@4 271 #define FRAMES_PER_BUFFER (64)
Chris@4 272 const int kNumSeconds = 100;
Chris@4 273
Chris@4 274 /* Setup data for synthesis thread. */
Chris@4 275 myData.framesLeft = (unsigned long) (sampleRate * kNumSeconds);
Chris@4 276 myData.numChannels = numChannels;
Chris@4 277 myData.mode = mode;
Chris@4 278 myData.format = format;
Chris@4 279 switch( format )
Chris@4 280 {
Chris@4 281 case paFloat32:
Chris@4 282 case paInt32:
Chris@4 283 case paInt24:
Chris@4 284 myData.bytesPerSample = 4;
Chris@4 285 break;
Chris@4 286 /* case paPackedInt24:
Chris@4 287 myData.bytesPerSample = 3;
Chris@4 288 break; */
Chris@4 289 default:
Chris@4 290 myData.bytesPerSample = 2;
Chris@4 291 break;
Chris@4 292 }
Chris@4 293
Chris@4 294 if( mode == MODE_INPUT )
Chris@4 295 {
Chris@4 296 inputParameters.device = deviceID;
Chris@4 297 inputParameters.channelCount = numChannels;
Chris@4 298 inputParameters.sampleFormat = format;
Chris@4 299 inputParameters.suggestedLatency = Pa_GetDeviceInfo( inputParameters.device )->defaultLowInputLatency;
Chris@4 300 inputParameters.hostApiSpecificStreamInfo = NULL;
Chris@4 301 ipp = &inputParameters;
Chris@4 302 }
Chris@4 303 else
Chris@4 304 {
Chris@4 305 ipp = NULL;
Chris@4 306 }
Chris@4 307
Chris@4 308 if( mode == MODE_OUTPUT )
Chris@4 309 {
Chris@4 310 outputParameters.device = deviceID;
Chris@4 311 outputParameters.channelCount = numChannels;
Chris@4 312 outputParameters.sampleFormat = format;
Chris@4 313 outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
Chris@4 314 outputParameters.hostApiSpecificStreamInfo = NULL;
Chris@4 315 opp = &outputParameters;
Chris@4 316 }
Chris@4 317 else
Chris@4 318 {
Chris@4 319 opp = NULL;
Chris@4 320 }
Chris@4 321
Chris@4 322 if(paFormatIsSupported == Pa_IsFormatSupported( ipp, opp, sampleRate ))
Chris@4 323 {
Chris@4 324 printf("------ TestAdvance: %s, device = %d, rate = %g, numChannels = %d, format = %lu -------\n",
Chris@4 325 ( mode == MODE_INPUT ) ? "INPUT" : "OUTPUT",
Chris@4 326 deviceID, sampleRate, numChannels, (unsigned long)format);
Chris@4 327 EXPECT( ((result = Pa_OpenStream( &stream,
Chris@4 328 ipp,
Chris@4 329 opp,
Chris@4 330 sampleRate,
Chris@4 331 FRAMES_PER_BUFFER,
Chris@4 332 paClipOff, /* we won't output out of range samples so don't bother clipping them */
Chris@4 333 QaCallback,
Chris@4 334 &myData ) ) == 0) );
Chris@4 335 if( stream )
Chris@4 336 {
Chris@4 337 PaTime oldStamp, newStamp;
Chris@4 338 unsigned long oldFrames;
Chris@4 339 int minDelay = ( mode == MODE_INPUT ) ? 1000 : 400;
Chris@4 340 /* Was:
Chris@4 341 int minNumBuffers = Pa_GetMinNumBuffers( FRAMES_PER_BUFFER, sampleRate );
Chris@4 342 int msec = (int) ((minNumBuffers * 3 * 1000.0 * FRAMES_PER_BUFFER) / sampleRate);
Chris@4 343 */
Chris@4 344 int msec = (int)( 3.0 *
Chris@4 345 (( mode == MODE_INPUT ) ? inputParameters.suggestedLatency : outputParameters.suggestedLatency ));
Chris@4 346 if( msec < minDelay ) msec = minDelay;
Chris@4 347 printf("msec = %d\n", msec); /**/
Chris@4 348 EXPECT( ((result=Pa_StartStream( stream )) == 0) );
Chris@4 349 /* Check to make sure PortAudio is advancing timeStamp. */
Chris@4 350 oldStamp = Pa_GetStreamTime(stream);
Chris@4 351 Pa_Sleep(msec);
Chris@4 352 newStamp = Pa_GetStreamTime(stream);
Chris@4 353 printf("oldStamp = %g, newStamp = %g\n", oldStamp, newStamp ); /**/
Chris@4 354 EXPECT( (oldStamp < newStamp) );
Chris@4 355 /* Check to make sure callback is decrementing framesLeft. */
Chris@4 356 oldFrames = myData.framesLeft;
Chris@4 357 Pa_Sleep(msec);
Chris@4 358 printf("oldFrames = %lu, myData.framesLeft = %lu\n", oldFrames, myData.framesLeft ); /**/
Chris@4 359 EXPECT( (oldFrames > myData.framesLeft) );
Chris@4 360 EXPECT( ((result=Pa_CloseStream( stream )) == 0) );
Chris@4 361 stream = NULL;
Chris@4 362 }
Chris@4 363 }
Chris@4 364 return 0;
Chris@4 365 error:
Chris@4 366 if( stream != NULL ) Pa_CloseStream( stream );
Chris@4 367 return -1;
Chris@4 368 }