52 #define SAMPLE_RATE (44100) 53 #define FRAMES_PER_BUFFER (1024) 54 #define NUM_CHANNELS (2) 55 #define NUM_SECONDS (15) 57 #define DITHER_FLAG (0) 60 #define CHECK_OVERFLOW (0) 61 #define CHECK_UNDERFLOW (0) 66 #define PA_SAMPLE_TYPE paFloat32 67 #define SAMPLE_SIZE (4) 68 #define SAMPLE_SILENCE (0.0f) 69 #define CLEAR(a) memset( (a), 0, FRAMES_PER_BUFFER * NUM_CHANNELS * SAMPLE_SIZE ) 70 #define PRINTF_S_FORMAT "%.8f" 72 #define PA_SAMPLE_TYPE paInt16 73 #define SAMPLE_SIZE (2) 74 #define SAMPLE_SILENCE (0) 75 #define CLEAR(a) memset( (a), 0, FRAMES_PER_BUFFER * NUM_CHANNELS * SAMPLE_SIZE ) 76 #define PRINTF_S_FORMAT "%d" 78 #define PA_SAMPLE_TYPE paInt24 79 #define SAMPLE_SIZE (3) 80 #define SAMPLE_SILENCE (0) 81 #define CLEAR(a) memset( (a), 0, FRAMES_PER_BUFFER * NUM_CHANNELS * SAMPLE_SIZE ) 82 #define PRINTF_S_FORMAT "%d" 84 #define PA_SAMPLE_TYPE paInt8 85 #define SAMPLE_SIZE (1) 86 #define SAMPLE_SILENCE (0) 87 #define CLEAR(a) memset( (a), 0, FRAMES_PER_BUFFER * NUM_CHANNELS * SAMPLE_SIZE ) 88 #define PRINTF_S_FORMAT "%d" 90 #define PA_SAMPLE_TYPE paUInt8 91 #define SAMPLE_SIZE (1) 92 #define SAMPLE_SILENCE (128) 93 #define CLEAR( a ) { \ 95 for( i=0; i<FRAMES_PER_BUFFER*NUM_CHANNELS; i++ ) \ 96 ((unsigned char *)a)[i] = (SAMPLE_SILENCE); \ 98 #define PRINTF_S_FORMAT "%d" 114 printf(
"patest_read_write_wire.c\n"); fflush(stdout);
116 numBytes = FRAMES_PER_BUFFER * NUM_CHANNELS * SAMPLE_SIZE ;
117 sampleBlock = (
char *) malloc( numBytes );
118 if( sampleBlock == NULL )
120 printf(
"Could not allocate record array.\n");
123 CLEAR( sampleBlock );
126 if( err != paNoError )
goto error;
129 printf(
"Input device # %d.\n", inputParameters.
device );
138 printf(
"Output device # %d.\n", outputParameters.
device );
157 if( err != paNoError )
goto error;
160 if( err != paNoError )
goto error;
161 printf(
"Wire on. Will run %d seconds.\n", NUM_SECONDS); fflush(stdout);
163 for( i=0; i<(NUM_SECONDS*SAMPLE_RATE)/FRAMES_PER_BUFFER; ++i )
166 if( err && CHECK_UNDERFLOW )
goto xrun;
167 err =
Pa_ReadStream( stream, sampleBlock, FRAMES_PER_BUFFER );
168 if( err && CHECK_OVERFLOW )
goto xrun;
171 if( err != paNoError )
goto error;
173 CLEAR( sampleBlock );
204 fprintf( stderr,
"Input Overflow.\n" );
206 fprintf( stderr,
"Output Underflow.\n" );
216 fprintf( stderr,
"An error occured while using the portaudio stream\n" );
217 fprintf( stderr,
"Error number: %d\n", err );
PaError Pa_Initialize(void)
PaTime defaultHighInputLatency
PaDeviceIndex Pa_GetDefaultInputDevice(void)
PaError Pa_StopStream(PaStream *stream)
#define paOutputUnderflow
PaError Pa_OpenStream(PaStream **stream, const PaStreamParameters *inputParameters, const PaStreamParameters *outputParameters, double sampleRate, unsigned long framesPerBuffer, PaStreamFlags streamFlags, PaStreamCallback *streamCallback, void *userData)
PaTime defaultLowInputLatency
PaError Pa_StartStream(PaStream *stream)
void * hostApiSpecificStreamInfo
The portable PortAudio API.
PaSampleFormat sampleFormat
PaError Pa_AbortStream(PaStream *stream)
const PaDeviceInfo * Pa_GetDeviceInfo(PaDeviceIndex device)
PaDeviceIndex Pa_GetDefaultOutputDevice(void)
PaError Pa_ReadStream(PaStream *stream, void *buffer, unsigned long frames)
PaError Pa_WriteStream(PaStream *stream, const void *buffer, unsigned long frames)
const char * Pa_GetErrorText(PaError errorCode)
PaError Pa_CloseStream(PaStream *stream)
PaError Pa_Terminate(void)