]> Repos - portaudio/commitdiff
added test for wmme low level latency params
authorrossb <rossb@0f58301d-fd10-0410-b4af-bbb618454e57>
Mon, 22 Feb 2010 16:07:56 +0000 (16:07 +0000)
committerrossb <rossb@0f58301d-fd10-0410-b4af-bbb618454e57>
Mon, 22 Feb 2010 16:07:56 +0000 (16:07 +0000)
test/patest_wmme_low_level_latency_params.c [new file with mode: 0644]

diff --git a/test/patest_wmme_low_level_latency_params.c b/test/patest_wmme_low_level_latency_params.c
new file mode 100644 (file)
index 0000000..f691d67
--- /dev/null
@@ -0,0 +1,192 @@
+/*\r
+ * $Id: $\r
+ * Portable Audio I/O Library\r
+ * Windows MME low level buffer parameters test\r
+ *\r
+ * Copyright (c) 2007 Ross Bencina\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining\r
+ * a copy of this software and associated documentation files\r
+ * (the "Software"), to deal in the Software without restriction,\r
+ * including without limitation the rights to use, copy, modify, merge,\r
+ * publish, distribute, sublicense, and/or sell copies of the Software,\r
+ * and to permit persons to whom the Software is furnished to do so,\r
+ * subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be\r
+ * included in all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\r
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR\r
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF\r
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+/*\r
+ * The text above constitutes the entire PortAudio license; however, \r
+ * the PortAudio community also makes the following non-binding requests:\r
+ *\r
+ * Any person wishing to distribute modifications to the Software is\r
+ * requested to send the modifications to the original developer so that\r
+ * they can be incorporated into the canonical version. It is also \r
+ * requested that these non-binding requests be included along with the \r
+ * license above.\r
+ */\r
+\r
+#include <stdio.h>\r
+#include <math.h>\r
+\r
+#include <windows.h>    /* required when using pa_win_wmme.h */\r
+#include <mmsystem.h>   /* required when using pa_win_wmme.h */\r
+\r
+#include "portaudio.h"\r
+#include "pa_win_wmme.h"\r
+\r
+#define NUM_SECONDS         (6)\r
+#define SAMPLE_RATE         (44100)\r
+#define FRAMES_PER_BUFFER   (441)\r
+\r
+#define WMME_FRAMES_PER_BUFFER  (441)\r
+#define WMME_BUFFER_COUNT       (5)\r
+\r
+\r
+#ifndef M_PI\r
+#define M_PI  (3.14159265)\r
+#endif\r
+\r
+#define TABLE_SIZE          (2048)\r
+\r
+#define CHANNEL_COUNT       (2)\r
+\r
+\r
+typedef struct\r
+{\r
+    float sine[TABLE_SIZE];\r
+       double phase;\r
+}\r
+paTestData;\r
+\r
+/* This routine will be called by the PortAudio engine when audio is needed.\r
+** It may called at interrupt level on some machines so don't do anything\r
+** that could mess up the system like calling malloc() or free().\r
+*/\r
+static int patestCallback( const void *inputBuffer, void *outputBuffer,\r
+                            unsigned long framesPerBuffer,\r
+                            const PaStreamCallbackTimeInfo* timeInfo,\r
+                            PaStreamCallbackFlags statusFlags,\r
+                            void *userData )\r
+{\r
+    paTestData *data = (paTestData*)userData;\r
+    float *out = (float*)outputBuffer;\r
+    unsigned long i,j;\r
+\r
+    (void) timeInfo; /* Prevent unused variable warnings. */\r
+    (void) statusFlags;\r
+    (void) inputBuffer;\r
+    \r
+    for( i=0; i<framesPerBuffer; i++ )\r
+    {\r
+        float x = data->sine[(int)data->phase];\r
+        data->phase += 20;\r
+        if( data->phase >= TABLE_SIZE ){\r
+                       data->phase -= TABLE_SIZE;\r
+               }\r
+\r
+               for( j = 0; j < CHANNEL_COUNT; ++j ){\r
+            *out++ = x;\r
+               }\r
+       }\r
+    \r
+    return paContinue;\r
+}\r
+\r
+/*******************************************************************/\r
+int main(int argc, char* argv[])\r
+{\r
+    PaStreamParameters outputParameters;\r
+    PaWinMmeStreamInfo wmmeStreamInfo;\r
+    PaStream *stream;\r
+    PaError err;\r
+    paTestData data;\r
+    int i;\r
+    int deviceIndex;\r
+\r
+    printf("PortAudio Test: output a sine blip on each channel. SR = %d, BufSize = %d, Chans = %d\n", SAMPLE_RATE, FRAMES_PER_BUFFER, CHANNEL_COUNT);\r
+\r
+    err = Pa_Initialize();\r
+    if( err != paNoError ) goto error;\r
+\r
+       deviceIndex = Pa_GetHostApiInfo( Pa_HostApiTypeIdToHostApiIndex( paMME ) )->defaultOutputDevice;\r
+       if( argc == 2 ){\r
+               sscanf( argv[1], "%d", &deviceIndex );\r
+       }\r
+\r
+       printf( "using device id %d (%s)\n", deviceIndex, Pa_GetDeviceInfo(deviceIndex)->name );\r
+\r
+    /* initialise sinusoidal wavetable */\r
+    for( i=0; i<TABLE_SIZE; i++ )\r
+    {\r
+        data.sine[i] = (float) sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. );\r
+    }\r
+\r
+       data.phase = 0;\r
+\r
+    outputParameters.device = deviceIndex;\r
+    outputParameters.channelCount = CHANNEL_COUNT;\r
+    outputParameters.sampleFormat = paFloat32; /* 32 bit floating point processing */\r
+    outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;\r
+    outputParameters.hostApiSpecificStreamInfo = NULL;\r
+\r
+    wmmeStreamInfo.size = sizeof(PaWinMmeStreamInfo);\r
+    wmmeStreamInfo.hostApiType = paMME; \r
+    wmmeStreamInfo.version = 1;\r
+    wmmeStreamInfo.flags = paWinMmeUseLowLevelLatencyParameters;\r
+    wmmeStreamInfo.framesPerBuffer = WMME_FRAMES_PER_BUFFER;\r
+    wmmeStreamInfo.bufferCount = WMME_BUFFER_COUNT;\r
+    outputParameters.hostApiSpecificStreamInfo = &wmmeStreamInfo;\r
+   \r
+\r
+       if( Pa_IsFormatSupported( 0, &outputParameters, SAMPLE_RATE ) == paFormatIsSupported  ){\r
+               printf( "Pa_IsFormatSupported reports device will support %d channels.\n", CHANNEL_COUNT );\r
+       }else{\r
+               printf( "Pa_IsFormatSupported reports device will not support %d channels.\n", CHANNEL_COUNT );\r
+       }\r
+\r
+    err = Pa_OpenStream(\r
+              &stream,\r
+              NULL, /* no input */\r
+              &outputParameters,\r
+              SAMPLE_RATE,\r
+              FRAMES_PER_BUFFER,\r
+              paClipOff,      /* we won't output out of range samples so don't bother clipping them */\r
+              patestCallback,\r
+              &data );\r
+    if( err != paNoError ) goto error;\r
+\r
+    err = Pa_StartStream( stream );\r
+    if( err != paNoError ) goto error;\r
+\r
+    printf("Play for %d seconds.\n", NUM_SECONDS );\r
+    Pa_Sleep( NUM_SECONDS * 1000 );\r
+\r
+    err = Pa_StopStream( stream );\r
+    if( err != paNoError ) goto error;\r
+\r
+    err = Pa_CloseStream( stream );\r
+    if( err != paNoError ) goto error;\r
+\r
+    Pa_Terminate();\r
+    printf("Test finished.\n");\r
+    \r
+    return err;\r
+error:\r
+    Pa_Terminate();\r
+    fprintf( stderr, "An error occured while using the portaudio stream\n" );\r
+    fprintf( stderr, "Error number: %d\n", err );\r
+    fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );\r
+    return err;\r
+}\r
+\r