paex_wmme_surround.c
Go to the documentation of this file.00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #include <stdio.h>
00045 #include <math.h>
00046
00047 #include <windows.h>
00048 #include <mmsystem.h>
00049
00050 #include "portaudio.h"
00051 #include "pa_win_wmme.h"
00052
00053 #define NUM_SECONDS (12)
00054 #define SAMPLE_RATE (44100)
00055 #define FRAMES_PER_BUFFER (64)
00056
00057 #ifndef M_PI
00058 #define M_PI (3.14159265)
00059 #endif
00060
00061 #define TABLE_SIZE (100)
00062
00063 #define CHANNEL_COUNT (6)
00064
00065
00066
00067 typedef struct
00068 {
00069 float sine[TABLE_SIZE];
00070 int phase;
00071 int currentChannel;
00072 int cycleCount;
00073 }
00074 paTestData;
00075
00076
00077
00078
00079
00080 static int patestCallback( const void *inputBuffer, void *outputBuffer,
00081 unsigned long framesPerBuffer,
00082 const PaStreamCallbackTimeInfo* timeInfo,
00083 PaStreamCallbackFlags statusFlags,
00084 void *userData )
00085 {
00086 paTestData *data = (paTestData*)userData;
00087 float *out = (float*)outputBuffer;
00088 unsigned long i,j;
00089
00090 (void) timeInfo;
00091 (void) statusFlags;
00092 (void) inputBuffer;
00093
00094 for( i=0; i<framesPerBuffer; i++ )
00095 {
00096 for( j = 0; j < CHANNEL_COUNT; ++j ){
00097 if( j == data->currentChannel && data->cycleCount < 4410 ){
00098 *out++ = data->sine[data->phase];
00099 data->phase += 1 + j;
00100 if( data->phase >= TABLE_SIZE ){
00101 data->phase -= TABLE_SIZE;
00102 }
00103 }else{
00104 *out++ = 0;
00105 }
00106 }
00107
00108 data->cycleCount++;
00109 if( data->cycleCount > 44100 ){
00110 data->cycleCount = 0;
00111
00112 ++data->currentChannel;
00113 if( data->currentChannel >= CHANNEL_COUNT )
00114 data->currentChannel -= CHANNEL_COUNT;
00115 }
00116 }
00117
00118 return paContinue;
00119 }
00120
00121
00122 int main(int argc, char* argv[])
00123 {
00124 PaStreamParameters outputParameters;
00125 PaWinMmeStreamInfo wmmeStreamInfo;
00126 PaStream *stream;
00127 PaError err;
00128 paTestData data;
00129 int i;
00130 int deviceIndex;
00131
00132 printf("PortAudio Test: output a sine blip on each channel. SR = %d, BufSize = %d, Chans = %d\n", SAMPLE_RATE, FRAMES_PER_BUFFER, CHANNEL_COUNT);
00133
00134 err = Pa_Initialize();
00135 if( err != paNoError ) goto error;
00136
00137 deviceIndex = Pa_GetHostApiInfo( Pa_HostApiTypeIdToHostApiIndex( paMME ) )->defaultOutputDevice;
00138 if( argc == 2 ){
00139 sscanf( argv[1], "%d", &deviceIndex );
00140 }
00141
00142 printf( "using device id %d (%s)\n", deviceIndex, Pa_GetDeviceInfo(deviceIndex)->name );
00143
00144
00145 for( i=0; i<TABLE_SIZE; i++ )
00146 {
00147 data.sine[i] = (float) sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. );
00148 }
00149
00150 data.phase = 0;
00151 data.currentChannel = 0;
00152 data.cycleCount = 0;
00153
00154 outputParameters.device = deviceIndex;
00155 outputParameters.channelCount = CHANNEL_COUNT;
00156 outputParameters.sampleFormat = paFloat32;
00157 outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
00158 outputParameters.hostApiSpecificStreamInfo = NULL;
00159
00160
00161
00162
00163 wmmeStreamInfo.size = sizeof(PaWinMmeStreamInfo);
00164 wmmeStreamInfo.hostApiType = paMME;
00165 wmmeStreamInfo.version = 1;
00166 wmmeStreamInfo.flags = paWinMmeUseChannelMask;
00167 wmmeStreamInfo.channelMask = PAWIN_SPEAKER_5POINT1;
00168 outputParameters.hostApiSpecificStreamInfo = &wmmeStreamInfo;
00169
00170
00171 if( Pa_IsFormatSupported( 0, &outputParameters, SAMPLE_RATE ) == paFormatIsSupported ){
00172 printf( "Pa_IsFormatSupported reports device will support %d channels.\n", CHANNEL_COUNT );
00173 }else{
00174 printf( "Pa_IsFormatSupported reports device will not support %d channels.\n", CHANNEL_COUNT );
00175 }
00176
00177 err = Pa_OpenStream(
00178 &stream,
00179 NULL,
00180 &outputParameters,
00181 SAMPLE_RATE,
00182 FRAMES_PER_BUFFER,
00183 paClipOff,
00184 patestCallback,
00185 &data );
00186 if( err != paNoError ) goto error;
00187
00188 err = Pa_StartStream( stream );
00189 if( err != paNoError ) goto error;
00190
00191 printf("Play for %d seconds.\n", NUM_SECONDS );
00192 Pa_Sleep( NUM_SECONDS * 1000 );
00193
00194 err = Pa_StopStream( stream );
00195 if( err != paNoError ) goto error;
00196
00197 err = Pa_CloseStream( stream );
00198 if( err != paNoError ) goto error;
00199
00200 Pa_Terminate();
00201 printf("Test finished.\n");
00202
00203 return err;
00204 error:
00205 Pa_Terminate();
00206 fprintf( stderr, "An error occured while using the portaudio stream\n" );
00207 fprintf( stderr, "Error number: %d\n", err );
00208 fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
00209 return err;
00210 }
00211