mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-04 17:49:45 +02:00
------------------------------------------------------------------------ r1910 | gineera | 2013-09-07 05:14:52 -0500 (Sat, 07 Sep 2013) | 1 line paqa_devs: limit max number of channels tested (to 4); add a fixed decimal format to the timestamp printout. ------------------------------------------------------------------------ r1909 | rbencina | 2013-08-28 19:36:56 -0500 (Wed, 28 Aug 2013) | 1 line pa_mac_core.c line 664 fixed incorrect memset size (was using sizeof(ptr) not sizeof(struct type) ------------------------------------------------------------------------ r1908 | gineera | 2013-08-27 12:14:51 -0500 (Tue, 27 Aug 2013) | 1 line Alsa: Add function to prevent duplicate parts in the visible pa device name string, that occur when the pcm-device name starts with the card name (since they are both used). Achieved by trimming the pcm-device string beginning. ------------------------------------------------------------------------ r1907 | gineera | 2013-08-22 17:01:17 -0500 (Thu, 22 Aug 2013) | 1 line Alsa: Fix memory leak as nonMmapBuffers were not freed (since change to realloc). Clean out corresponding dead code chunk. ------------------------------------------------------------------------ r1906 | gineera | 2013-08-22 14:43:07 -0500 (Thu, 22 Aug 2013) | 1 line Alsa: Rename some variables in pa_linux_alsa where the meaning is mis-leading or wrong in the Alsa context. Also tweak one debug message and a few typos. ------------------------------------------------------------------------ r1897 | gineera | 2013-08-13 15:37:04 -0500 (Tue, 13 Aug 2013) | 1 line Alsa: Fix handling of poll descriptors in PaAlsaStream_WaitForFrames(). Otherwise if capture signals before playback a duplex stream could poll the wrong descriptor, causing a loop (reported by Alexander Kartashov). ------------------------------------------------------------------------ r1896 | rbencina | 2013-08-06 03:26:55 -0500 (Tue, 06 Aug 2013) | 1 line fixed bug that was causing memory corruption in PA/ALSA when host sample format was lager than user format. e.g. using 16 bit output with a sound card that used 24 bit buffers. the incorrect input zeroer was being used. Thanks to Anders Tornvig for identifying the problem ------------------------------------------------------------------------ r1895 | rbencina | 2013-07-24 10:37:15 -0500 (Wed, 24 Jul 2013) | 1 line fixed doxygen markup for a few line breaks in the tutorial ------------------------------------------------------------------------ r1894 | gineera | 2013-06-08 14:30:41 -0500 (Sat, 08 Jun 2013) | 1 line OSS: revise default latency reporting: previous fixed values could not actually be achieved with OSS power-of-2 sizes. Instead try a configuration and correctly report the default latency based on one less than the number of fragments; also fix the stream component 'bufSz' calculation. ------------------------------------------------------------------------ r1893 | gineera | 2013-06-08 14:12:25 -0500 (Sat, 08 Jun 2013) | 1 line Alsa: revise latency use and calculations, since the latency should be equivalent to one Alsa period less than the Alsa ringbuffer (was based on the whole). Also fixes failure if zero latency was specified. ------------------------------------------------------------------------ r1892 | gineera | 2013-05-30 06:30:28 -0500 (Thu, 30 May 2013) | 1 line qa-latency: fix printout typos; re-enable checks of default high vs low latency - but allow them to be equal; remove rogue tab. ------------------------------------------------------------------------ r1891 | rbencina | 2013-05-05 09:00:02 -0500 (Sun, 05 May 2013) | 1 line added code to print error result from Pa_Initialize() in pa_devs.c example ------------------------------------------------------------------------ r1890 | rbencina | 2013-05-01 20:06:01 -0500 (Wed, 01 May 2013) | 1 line factored out InitPaDeviceInfoFromAsioDriver function. skip device rather than failing entire init process if a single ASIO driver returns an error during init. This was happening with MOTU devices if the device wasn't present. See ticket #221 ------------------------------------------------------------------------ r1889 | rbencina | 2013-04-07 09:15:24 -0500 (Sun, 07 Apr 2013) | 1 line move static variables into x86 section so they don't generate warnings when trying to build on 64 bit ------------------------------------------------------------------------ r1888 | rbencina | 2013-04-07 05:20:18 -0500 (Sun, 07 Apr 2013) | 1 line configure.in fix from Leland '[Portaudio] Small patch to fix Mac build' march 4
372 lines
14 KiB
C
372 lines
14 KiB
C
/** @file paqa_devs.c
|
|
@ingroup qa_src
|
|
@brief Self Testing Quality Assurance app for PortAudio
|
|
Try to open each device and run through all the
|
|
possible configurations. This test does not verify
|
|
that the configuration works well. It just verifies
|
|
that it does not crash. It requires a human to listen to
|
|
the outputs.
|
|
|
|
@author Phil Burk http://www.softsynth.com
|
|
|
|
Pieter adapted to V19 API. Test now relies heavily on
|
|
Pa_IsFormatSupported(). Uses same 'standard' sample rates
|
|
as in test pa_devs.c.
|
|
*/
|
|
/*
|
|
* $Id: paqa_devs.c 1756 2011-09-08 06:09:29Z philburk $
|
|
*
|
|
* 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 <math.h>
|
|
#include "portaudio.h"
|
|
#include "pa_trace.h"
|
|
|
|
/****************************************** Definitions ***********/
|
|
#define MODE_INPUT (0)
|
|
#define MODE_OUTPUT (1)
|
|
#define MAX_TEST_CHANNELS 4
|
|
|
|
typedef struct PaQaData
|
|
{
|
|
unsigned long framesLeft;
|
|
int numChannels;
|
|
int bytesPerSample;
|
|
int mode;
|
|
short sawPhase;
|
|
PaSampleFormat format;
|
|
}
|
|
PaQaData;
|
|
|
|
/****************************************** Prototypes ***********/
|
|
static void TestDevices( int mode );
|
|
static void TestFormats( int mode, PaDeviceIndex deviceID, double sampleRate,
|
|
int numChannels );
|
|
static int TestAdvance( int mode, PaDeviceIndex deviceID, double sampleRate,
|
|
int numChannels, PaSampleFormat format );
|
|
static int QaCallback( const void *inputBuffer, void *outputBuffer,
|
|
unsigned long framesPerBuffer,
|
|
const PaStreamCallbackTimeInfo* timeInfo,
|
|
PaStreamCallbackFlags statusFlags,
|
|
void *userData );
|
|
|
|
/****************************************** Globals ***********/
|
|
static int gNumPassed = 0;
|
|
static int gNumFailed = 0;
|
|
|
|
/****************************************** Macros ***********/
|
|
/* Print ERROR if it fails. Tally success or failure. */
|
|
/* Odd do-while wrapper seems to be needed for some compilers. */
|
|
#define EXPECT(_exp) \
|
|
do \
|
|
{ \
|
|
if ((_exp)) {\
|
|
/* printf("SUCCESS for %s\n", #_exp ); */ \
|
|
gNumPassed++; \
|
|
} \
|
|
else { \
|
|
printf("ERROR - 0x%x - %s for %s\n", result, \
|
|
((result == 0) ? "-" : Pa_GetErrorText(result)), \
|
|
#_exp ); \
|
|
gNumFailed++; \
|
|
goto error; \
|
|
} \
|
|
} while(0)
|
|
|
|
/*******************************************************************/
|
|
/* This routine will be called by the PortAudio engine when audio is needed.
|
|
** It may be called at interrupt level on some machines so don't do anything
|
|
** that could mess up the system like calling malloc() or free().
|
|
*/
|
|
static int QaCallback( const void *inputBuffer, void *outputBuffer,
|
|
unsigned long framesPerBuffer,
|
|
const PaStreamCallbackTimeInfo* timeInfo,
|
|
PaStreamCallbackFlags statusFlags,
|
|
void *userData )
|
|
{
|
|
unsigned long i;
|
|
short phase;
|
|
PaQaData *data = (PaQaData *) userData;
|
|
(void) inputBuffer;
|
|
|
|
/* Play simple sawtooth wave. */
|
|
if( data->mode == MODE_OUTPUT )
|
|
{
|
|
phase = data->sawPhase;
|
|
switch( data->format )
|
|
{
|
|
case paFloat32:
|
|
{
|
|
float *out = (float *) outputBuffer;
|
|
for( i=0; i<framesPerBuffer; i++ )
|
|
{
|
|
phase += 0x123;
|
|
*out++ = (float) (phase * (1.0 / 32768.0));
|
|
if( data->numChannels == 2 )
|
|
{
|
|
*out++ = (float) (phase * (1.0 / 32768.0));
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
|
|
case paInt32:
|
|
{
|
|
int *out = (int *) outputBuffer;
|
|
for( i=0; i<framesPerBuffer; i++ )
|
|
{
|
|
phase += 0x123;
|
|
*out++ = ((int) phase ) << 16;
|
|
if( data->numChannels == 2 )
|
|
{
|
|
*out++ = ((int) phase ) << 16;
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
|
|
case paInt16:
|
|
{
|
|
short *out = (short *) outputBuffer;
|
|
for( i=0; i<framesPerBuffer; i++ )
|
|
{
|
|
phase += 0x123;
|
|
*out++ = phase;
|
|
if( data->numChannels == 2 )
|
|
{
|
|
*out++ = phase;
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
|
|
default:
|
|
{
|
|
unsigned char *out = (unsigned char *) outputBuffer;
|
|
unsigned long numBytes = framesPerBuffer * data->numChannels * data->bytesPerSample;
|
|
for( i=0; i<numBytes; i++ )
|
|
{
|
|
*out++ = 0;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
data->sawPhase = phase;
|
|
}
|
|
/* Are we through yet? */
|
|
if( data->framesLeft > framesPerBuffer )
|
|
{
|
|
PaUtil_AddTraceMessage("QaCallback: running. framesLeft", data->framesLeft );
|
|
data->framesLeft -= framesPerBuffer;
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
PaUtil_AddTraceMessage("QaCallback: DONE! framesLeft", data->framesLeft );
|
|
data->framesLeft = 0;
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
/*******************************************************************/
|
|
int main(void);
|
|
int main(void)
|
|
{
|
|
PaError result;
|
|
EXPECT( ((result=Pa_Initialize()) == 0) );
|
|
printf("Test OUTPUT ---------------\n");
|
|
TestDevices( MODE_OUTPUT );
|
|
printf("Test INPUT ---------------\n");
|
|
TestDevices( MODE_INPUT );
|
|
error:
|
|
Pa_Terminate();
|
|
printf("QA Report: %d passed, %d failed.\n", gNumPassed, gNumFailed );
|
|
return (gNumFailed > 0) ? 1 : 0;
|
|
}
|
|
|
|
/*******************************************************************
|
|
* Try each output device, through its full range of capabilities. */
|
|
static void TestDevices( int mode )
|
|
{
|
|
int id, jc, i;
|
|
int maxChannels;
|
|
const PaDeviceInfo *pdi;
|
|
static double standardSampleRates[] = { 8000.0, 9600.0, 11025.0, 12000.0,
|
|
16000.0, 22050.0, 24000.0,
|
|
32000.0, 44100.0, 48000.0,
|
|
88200.0, 96000.0,
|
|
-1.0 }; /* Negative terminated list. */
|
|
int numDevices = Pa_GetDeviceCount();
|
|
for( id=0; id<numDevices; id++ ) /* Iterate through all devices. */
|
|
{
|
|
pdi = Pa_GetDeviceInfo( id );
|
|
/* Try 1 to maxChannels on each device. */
|
|
maxChannels = (( mode == MODE_INPUT ) ? pdi->maxInputChannels : pdi->maxOutputChannels);
|
|
if( maxChannels > MAX_TEST_CHANNELS )
|
|
maxChannels = MAX_TEST_CHANNELS;
|
|
|
|
for( jc=1; jc<=maxChannels; jc++ )
|
|
{
|
|
printf("\n========================================================================\n");
|
|
printf(" Device = %s\n", pdi->name );
|
|
printf("========================================================================\n");
|
|
/* Try each standard sample rate. */
|
|
for( i=0; standardSampleRates[i] > 0; i++ )
|
|
{
|
|
TestFormats( mode, (PaDeviceIndex)id, standardSampleRates[i], jc );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/*******************************************************************/
|
|
static void TestFormats( int mode, PaDeviceIndex deviceID, double sampleRate,
|
|
int numChannels )
|
|
{
|
|
TestAdvance( mode, deviceID, sampleRate, numChannels, paFloat32 );
|
|
TestAdvance( mode, deviceID, sampleRate, numChannels, paInt16 );
|
|
TestAdvance( mode, deviceID, sampleRate, numChannels, paInt32 );
|
|
/* TestAdvance( mode, deviceID, sampleRate, numChannels, paInt24 ); */
|
|
}
|
|
|
|
/*******************************************************************/
|
|
static int TestAdvance( int mode, PaDeviceIndex deviceID, double sampleRate,
|
|
int numChannels, PaSampleFormat format )
|
|
{
|
|
PaStreamParameters inputParameters, outputParameters, *ipp, *opp;
|
|
PaStream *stream = NULL;
|
|
PaError result = paNoError;
|
|
PaQaData myData;
|
|
#define FRAMES_PER_BUFFER (64)
|
|
const int kNumSeconds = 100;
|
|
|
|
/* Setup data for synthesis thread. */
|
|
myData.framesLeft = (unsigned long) (sampleRate * kNumSeconds);
|
|
myData.numChannels = numChannels;
|
|
myData.mode = mode;
|
|
myData.format = format;
|
|
switch( format )
|
|
{
|
|
case paFloat32:
|
|
case paInt32:
|
|
case paInt24:
|
|
myData.bytesPerSample = 4;
|
|
break;
|
|
/* case paPackedInt24:
|
|
myData.bytesPerSample = 3;
|
|
break; */
|
|
default:
|
|
myData.bytesPerSample = 2;
|
|
break;
|
|
}
|
|
|
|
if( mode == MODE_INPUT )
|
|
{
|
|
inputParameters.device = deviceID;
|
|
inputParameters.channelCount = numChannels;
|
|
inputParameters.sampleFormat = format;
|
|
inputParameters.suggestedLatency = Pa_GetDeviceInfo( inputParameters.device )->defaultLowInputLatency;
|
|
inputParameters.hostApiSpecificStreamInfo = NULL;
|
|
ipp = &inputParameters;
|
|
}
|
|
else
|
|
{
|
|
ipp = NULL;
|
|
}
|
|
|
|
if( mode == MODE_OUTPUT )
|
|
{
|
|
outputParameters.device = deviceID;
|
|
outputParameters.channelCount = numChannels;
|
|
outputParameters.sampleFormat = format;
|
|
outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
|
|
outputParameters.hostApiSpecificStreamInfo = NULL;
|
|
opp = &outputParameters;
|
|
}
|
|
else
|
|
{
|
|
opp = NULL;
|
|
}
|
|
|
|
if(paFormatIsSupported == Pa_IsFormatSupported( ipp, opp, sampleRate ))
|
|
{
|
|
printf("------ TestAdvance: %s, device = %d, rate = %g, numChannels = %d, format = %lu -------\n",
|
|
( mode == MODE_INPUT ) ? "INPUT" : "OUTPUT",
|
|
deviceID, sampleRate, numChannels, (unsigned long)format);
|
|
EXPECT( ((result = Pa_OpenStream( &stream,
|
|
ipp,
|
|
opp,
|
|
sampleRate,
|
|
FRAMES_PER_BUFFER,
|
|
paClipOff, /* we won't output out of range samples so don't bother clipping them */
|
|
QaCallback,
|
|
&myData ) ) == 0) );
|
|
if( stream )
|
|
{
|
|
PaTime oldStamp, newStamp;
|
|
unsigned long oldFrames;
|
|
int minDelay = ( mode == MODE_INPUT ) ? 1000 : 400;
|
|
/* Was:
|
|
int minNumBuffers = Pa_GetMinNumBuffers( FRAMES_PER_BUFFER, sampleRate );
|
|
int msec = (int) ((minNumBuffers * 3 * 1000.0 * FRAMES_PER_BUFFER) / sampleRate);
|
|
*/
|
|
int msec = (int)( 3.0 *
|
|
(( mode == MODE_INPUT ) ? inputParameters.suggestedLatency : outputParameters.suggestedLatency ));
|
|
if( msec < minDelay ) msec = minDelay;
|
|
printf("msec = %d\n", msec); /**/
|
|
EXPECT( ((result=Pa_StartStream( stream )) == 0) );
|
|
/* Check to make sure PortAudio is advancing timeStamp. */
|
|
oldStamp = Pa_GetStreamTime(stream);
|
|
Pa_Sleep(msec);
|
|
newStamp = Pa_GetStreamTime(stream);
|
|
printf("oldStamp = %9.6f, newStamp = %9.6f\n", oldStamp, newStamp ); /**/
|
|
EXPECT( (oldStamp < newStamp) );
|
|
/* Check to make sure callback is decrementing framesLeft. */
|
|
oldFrames = myData.framesLeft;
|
|
Pa_Sleep(msec);
|
|
printf("oldFrames = %lu, myData.framesLeft = %lu\n", oldFrames, myData.framesLeft ); /**/
|
|
EXPECT( (oldFrames > myData.framesLeft) );
|
|
EXPECT( ((result=Pa_CloseStream( stream )) == 0) );
|
|
stream = NULL;
|
|
}
|
|
}
|
|
return 0;
|
|
error:
|
|
if( stream != NULL ) Pa_CloseStream( stream );
|
|
return -1;
|
|
}
|