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;
79static 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;
109int main(
int argc,
char* argv[])
119 const char *fileName =
"c:\\test_48k.ac3.spdif";
122 printf(
"usage: patest_wmme_ac3 fileName [paDeviceIndex]\n");
123 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");
124 printf(
"PortAudio Test: output a raw spdif ac3 stream. SR = %d, BufSize = %d, Chans = %d\n",
125 SAMPLE_RATE, FRAMES_PER_BUFFER, CHANNEL_COUNT);
131 printf(
"reading spdif ac3 raw stream file %s\n", fileName );
133 fp = fopen( fileName,
"rb" );
135 fprintf( stderr,
"error opening spdif ac3 file.\n" );
139 fseek( fp, 0, SEEK_END );
140 data.bufferSampleCount = ftell( fp ) /
sizeof(short);
141 fseek( fp, 0, SEEK_SET );
144 data.buffer = (
short*)malloc( data.bufferSampleCount *
sizeof(
short) );
146 fprintf( stderr,
"error allocating buffer.\n" );
150 fread( data.buffer,
sizeof(
short), data.bufferSampleCount, fp );
153 data.playbackIndex = 0;
156 if( err != paNoError )
goto error;
160 sscanf( argv[1],
"%d", &deviceIndex );
163 printf(
"using device id %d (%s)\n", deviceIndex,
Pa_GetDeviceInfo(deviceIndex)->name );
166 outputParameters.
device = deviceIndex;
175 wmmeStreamInfo.flags = paWinMmeWaveFormatDolbyAc3Spdif;
180 printf(
"Pa_IsFormatSupported reports device will support %d channels.\n", CHANNEL_COUNT );
182 printf(
"Pa_IsFormatSupported reports device will not support %d channels.\n", CHANNEL_COUNT );
194 if( err != paNoError )
goto error;
197 if( err != paNoError )
goto error;
199 printf(
"Play for %d seconds.\n", NUM_SECONDS );
203 if( err != paNoError )
goto error;
206 if( err != paNoError )
goto error;
210 printf(
"Test finished.\n");
217 fprintf( stderr,
"An error occured while using the portaudio stream\n" );
218 fprintf( stderr,
"Error number: %d\n", err );
WMME-specific PortAudio API extension header file.
The portable PortAudio API.
PaHostApiIndex Pa_HostApiTypeIdToHostApiIndex(PaHostApiTypeId type)
PaError Pa_Terminate(void)
#define paFormatIsSupported
PaError Pa_OpenStream(PaStream **stream, const PaStreamParameters *inputParameters, const PaStreamParameters *outputParameters, double sampleRate, unsigned long framesPerBuffer, PaStreamFlags streamFlags, PaStreamCallback *streamCallback, void *userData)
unsigned long PaStreamCallbackFlags
PaError Pa_StartStream(PaStream *stream)
PaError Pa_CloseStream(PaStream *stream)
const PaDeviceInfo * Pa_GetDeviceInfo(PaDeviceIndex device)
PaError Pa_IsFormatSupported(const PaStreamParameters *inputParameters, const PaStreamParameters *outputParameters, double sampleRate)
PaError Pa_Initialize(void)
const char * Pa_GetErrorText(PaError errorCode)
PaError Pa_StopStream(PaStream *stream)
const PaHostApiInfo * Pa_GetHostApiInfo(PaHostApiIndex hostApi)
PaDeviceIndex defaultOutputDevice
PaSampleFormat sampleFormat
void * hostApiSpecificStreamInfo
PaHostApiTypeId hostApiType