53 #define NUM_SECONDS (20)
54 #define SAMPLE_RATE (48000)
55 #define FRAMES_PER_BUFFER (64)
58 #define M_PI (3.14159265)
61 #define TABLE_SIZE (100)
63 #define CHANNEL_COUNT (2)
70 int bufferSampleCount;
79 static int patestCallback(
const void *inputBuffer,
void *outputBuffer,
80 unsigned long framesPerBuffer,
86 short *out = (
short*)outputBuffer;
95 for( i=0; i<framesPerBuffer; i++ )
97 for( j = 0; j < CHANNEL_COUNT; ++j ){
98 *out++ = data->buffer[ data->playbackIndex++ ];
100 if( data->playbackIndex >= data->bufferSampleCount )
101 data->playbackIndex = 0;
109 int main(
int argc,
char* argv[])
118 const char *fileName =
"c:\\test_48k.ac3.spdif";
121 printf(
"usage: patest_wmme_ac3 fileName [paDeviceIndex]\n");
122 printf(
"**IMPORTANT*** The provided file must include the spdif preamble at the start of every AC-3 frame. Using a normal ac3 file won't work.\n");
123 printf(
"PortAudio Test: output a raw spdif ac3 stream. SR = %d, BufSize = %d, Chans = %d\n",
124 SAMPLE_RATE, FRAMES_PER_BUFFER, CHANNEL_COUNT);
130 printf(
"reading spdif ac3 raw stream file %s\n", fileName );
132 fp = fopen( fileName,
"rb" );
134 fprintf( stderr,
"error opening spdif ac3 file.\n" );
138 fseek( fp, 0, SEEK_END );
139 data.bufferSampleCount = ftell( fp ) /
sizeof(short);
140 fseek( fp, 0, SEEK_SET );
143 data.buffer = (
short*)malloc( data.bufferSampleCount *
sizeof(
short) );
145 fprintf( stderr,
"error allocating buffer.\n" );
149 fread( data.buffer,
sizeof(
short), data.bufferSampleCount, fp );
152 data.playbackIndex = 0;
155 if( err != paNoError )
goto error;
159 sscanf( argv[1],
"%d", &deviceIndex );
162 printf(
"using device id %d (%s)\n", deviceIndex,
Pa_GetDeviceInfo(deviceIndex)->name );
165 outputParameters.
device = deviceIndex;
174 wmmeStreamInfo.flags = paWinMmeWaveFormatDolbyAc3Spdif;
179 printf(
"Pa_IsFormatSupported reports device will support %d channels.\n", CHANNEL_COUNT );
181 printf(
"Pa_IsFormatSupported reports device will not support %d channels.\n", CHANNEL_COUNT );
193 if( err != paNoError )
goto error;
196 if( err != paNoError )
goto error;
198 printf(
"Play for %d seconds.\n", NUM_SECONDS );
202 if( err != paNoError )
goto error;
205 if( err != paNoError )
goto error;
209 printf(
"Test finished.\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)
PaHostApiTypeId hostApiType
PaError Pa_StopStream(PaStream *stream)
PaError Pa_OpenStream(PaStream **stream, const PaStreamParameters *inputParameters, const PaStreamParameters *outputParameters, double sampleRate, unsigned long framesPerBuffer, PaStreamFlags streamFlags, PaStreamCallback *streamCallback, void *userData)
PaError Pa_IsFormatSupported(const PaStreamParameters *inputParameters, const PaStreamParameters *outputParameters, double sampleRate)
PaError Pa_StartStream(PaStream *stream)
void * hostApiSpecificStreamInfo
The portable PortAudio API.
WMME-specific PortAudio API extension header file.
PaSampleFormat sampleFormat
unsigned long PaStreamCallbackFlags
PaDeviceIndex defaultOutputDevice
const PaHostApiInfo * Pa_GetHostApiInfo(PaHostApiIndex hostApi)
const PaDeviceInfo * Pa_GetDeviceInfo(PaDeviceIndex device)
#define paFormatIsSupported
const char * Pa_GetErrorText(PaError errorCode)
PaHostApiIndex Pa_HostApiTypeIdToHostApiIndex(PaHostApiTypeId type)
PaError Pa_CloseStream(PaStream *stream)
PaError Pa_Terminate(void)