52 #define SAMPLE_RATE (44100)
53 #define FRAMES_PER_BUFFER (512)
54 #define NUM_SECONDS (10)
56 #define DITHER_FLAG (0)
60 #define PA_SAMPLE_TYPE paFloat32
61 #define SAMPLE_SIZE (4)
62 #define SAMPLE_SILENCE (0.0f)
63 #define PRINTF_S_FORMAT "%.8f"
65 #define PA_SAMPLE_TYPE paInt16
66 #define SAMPLE_SIZE (2)
67 #define SAMPLE_SILENCE (0)
68 #define PRINTF_S_FORMAT "%d"
70 #define PA_SAMPLE_TYPE paInt24
71 #define SAMPLE_SIZE (3)
72 #define SAMPLE_SILENCE (0)
73 #define PRINTF_S_FORMAT "%d"
75 #define PA_SAMPLE_TYPE paInt8
76 #define SAMPLE_SIZE (1)
77 #define SAMPLE_SILENCE (0)
78 #define PRINTF_S_FORMAT "%d"
80 #define PA_SAMPLE_TYPE paUInt8
81 #define SAMPLE_SIZE (1)
82 #define SAMPLE_SILENCE (128)
83 #define PRINTF_S_FORMAT "%d"
95 char *sampleBlock = NULL;
100 printf(
"patest_read_write_wire.c\n"); fflush(stdout);
101 printf(
"sizeof(int) = %lu\n", (
unsigned long)
sizeof(
int)); fflush(stdout);
102 printf(
"sizeof(long) = %lu\n", (
unsigned long)
sizeof(
long)); fflush(stdout);
105 if( err != paNoError )
goto error2;
108 printf(
"Input device # %d.\n", inputParameters.
device );
110 printf(
" Name: %s\n", inputInfo->
name );
115 printf(
"Output device # %d.\n", outputParameters.
device );
117 printf(
" Name: %s\n", outputInfo->
name );
118 printf(
" LL: %g s\n", outputInfo->defaultLowOutputLatency );
119 printf(
" HL: %g s\n", outputInfo->defaultHighOutputLatency );
121 numChannels = inputInfo->maxInputChannels < outputInfo->maxOutputChannels
122 ? inputInfo->maxInputChannels : outputInfo->maxOutputChannels;
123 printf(
"Num channels = %d.\n", numChannels );
146 if( err != paNoError )
goto error2;
148 numBytes = FRAMES_PER_BUFFER * numChannels * SAMPLE_SIZE ;
149 sampleBlock = (
char *) malloc( numBytes );
150 if( sampleBlock == NULL )
152 printf(
"Could not allocate record array.\n");
155 memset( sampleBlock, SAMPLE_SILENCE, numBytes );
158 if( err != paNoError )
goto error1;
159 printf(
"Wire on. Will run %d seconds.\n", NUM_SECONDS); fflush(stdout);
161 for( i=0; i<(NUM_SECONDS*SAMPLE_RATE)/FRAMES_PER_BUFFER; ++i )
166 err =
Pa_ReadStream( stream, sampleBlock, FRAMES_PER_BUFFER );
169 printf(
"Wire off.\n"); fflush(stdout);
172 if( err != paNoError )
goto error1;
180 printf(
"err = %d\n", err); fflush(stdout);
188 fprintf( stderr,
"Input Overflow.\n" );
190 fprintf( stderr,
"Output Underflow.\n" );
200 fprintf( stderr,
"An error occurred while using the portaudio stream\n" );
201 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)