test/testmultiaudio.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 24 Mar 2009 10:33:12 +0000
changeset 3099 82e60908fab1
parent 2867 eec7adc3d1c5
child 5535 96594ac5fd1a
permissions -rw-r--r--
Date: Mon, 23 Mar 2009 09:17:24 +0200
From: "Mike Gorchak"
Subject: New QNX patches

Please apply patch qnx4.diff, which is attached. What has been done:
1)Added back OpenGL ES renderer for QNX target. Added few corrections to
OpenGL ES renderer to let it work under QNX. OpenGL ES renderer do not
support textures under QNX, so I think some additional work must be done.
2) Added GL_OES_query_matrix extension to SDL_opengles.h header file, which
required by OpenGL ES 1.1 specification.
3) Added attribute clearing at the entrance of function
SDL_GL_GetAttribure(). Added error checking into the function
SDL_GL_GetAttribure(), because some attributes can't be obtained in OpenGL
ES 1.0.
4) Porting testdyngles to OpenGL ES 1.0 (1.1 has glColor4ub() and
glColor4f() functions, but 1.0 has glColor4f() only).
5) Added error checking after obtaining attributes using
SDL_GL_GetAttribute() function to the testgl2 and testgles.
6) Small correction to testmultiaudio with printing errors.
7) Added software and accelerated OpenGL ES 1.0 support into the QNX GF
driver.

Please remove ./src/audio/nto directory - it will not be used anymore.
Please create ./src/audio/qsa directory and add content of the archive
qsa.tar.gz into this directory. I rewrote some sound code, added support for
multiple audio cards, enumeration, etc. Added initial support for capture.

As far as I can understand SDL 1.3 is not supporting audio capture right now
? Sam, Am I right ? Or audio capture must be supported through the
PlayDevice routine ?

And last, please put file SDL_gf_opengles.c to the ./src/video/qnxgf
directory. It is OpenGL ES 1.1 emulation layer for some functions, which are
not supported by OpenGL ES 1.0.
     1 #include "SDL.h"
     2 
     3 static SDL_AudioSpec spec;
     4 static Uint8 *sound = NULL;     /* Pointer to wave data */
     5 static Uint32 soundlen = 0;     /* Length of wave data */
     6 
     7 typedef struct
     8 {
     9     SDL_AudioDeviceID dev;
    10     int soundpos;
    11     volatile int done;
    12 } callback_data;
    13 
    14 void SDLCALL
    15 play_through_once(void *arg, Uint8 * stream, int len)
    16 {
    17     callback_data *cbd = (callback_data *) arg;
    18     Uint8 *waveptr = sound + cbd->soundpos;
    19     int waveleft = soundlen - cbd->soundpos;
    20     int cpy = len;
    21     if (cpy > waveleft)
    22         cpy = waveleft;
    23 
    24     SDL_memcpy(stream, waveptr, cpy);
    25     len -= cpy;
    26     cbd->soundpos += cpy;
    27     if (len > 0) {
    28         stream += cpy;
    29         SDL_memset(stream, spec.silence, len);
    30         cbd->done++;
    31     }
    32 }
    33 
    34 static void
    35 test_multi_audio(int devcount)
    36 {
    37     callback_data cbd[64];
    38     int keep_going = 1;
    39     int i;
    40 
    41     if (devcount > 64) {
    42         fprintf(stderr, "Too many devices (%d), clamping to 64...\n",
    43                 devcount);
    44         devcount = 64;
    45     }
    46 
    47     spec.callback = play_through_once;
    48 
    49     for (i = 0; i < devcount; i++) {
    50         const char *devname = SDL_GetAudioDeviceName(i, 0);
    51         printf("playing on device #%d: ('%s')...", i, devname);
    52         fflush(stdout);
    53 
    54         SDL_memset(&cbd[0], '\0', sizeof(callback_data));
    55         spec.userdata = &cbd[0];
    56         cbd[0].dev = SDL_OpenAudioDevice(devname, 0, &spec, NULL, 0);
    57         if (cbd[0].dev == 0) {
    58             printf("\nOpen device failed: %s\n", SDL_GetError());
    59         } else {
    60             SDL_PauseAudioDevice(cbd[0].dev, 0);
    61             while (!cbd[0].done)
    62                 SDL_Delay(100);
    63             SDL_PauseAudioDevice(cbd[0].dev, 1);
    64             printf("done.\n");
    65             SDL_CloseAudioDevice(cbd[0].dev);
    66         }
    67     }
    68 
    69     SDL_memset(cbd, '\0', sizeof(cbd));
    70 
    71     printf("playing on all devices...\n");
    72     for (i = 0; i < devcount; i++) {
    73         const char *devname = SDL_GetAudioDeviceName(i, 0);
    74         spec.userdata = &cbd[i];
    75         cbd[i].dev = SDL_OpenAudioDevice(devname, 0, &spec, NULL, 0);
    76         if (cbd[i].dev == 0) {
    77             printf("Open device %d failed: %s\n", i, SDL_GetError());
    78         }
    79     }
    80 
    81     for (i = 0; i < devcount; i++) {
    82         if (cbd[i].dev) {
    83             SDL_PauseAudioDevice(cbd[i].dev, 0);
    84         }
    85     }
    86 
    87     while (keep_going) {
    88         keep_going = 0;
    89         for (i = 0; i < devcount; i++) {
    90             if ((cbd[i].dev) && (!cbd[i].done)) {
    91                 keep_going = 1;
    92             }
    93         }
    94         SDL_Delay(100);
    95     }
    96 
    97     for (i = 0; i < devcount; i++) {
    98         if (cbd[i].dev) {
    99             SDL_PauseAudioDevice(cbd[i].dev, 1);
   100             SDL_CloseAudioDevice(cbd[i].dev);
   101         }
   102     }
   103 
   104     printf("All done!\n");
   105 }
   106 
   107 
   108 int
   109 main(int argc, char **argv)
   110 {
   111     int devcount = 0;
   112 
   113     /* Load the SDL library */
   114     if (SDL_Init(SDL_INIT_AUDIO) < 0) {
   115         fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
   116         return (1);
   117     }
   118 
   119     printf("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
   120 
   121     devcount = SDL_GetNumAudioDevices(0);
   122     if (devcount < 1) {
   123         fprintf(stderr, "Don't see any specific audio devices!\n");
   124     } else {
   125         if (argv[1] == NULL) {
   126             argv[1] = "sample.wav";
   127         }
   128 
   129         /* Load the wave file into memory */
   130         if (SDL_LoadWAV(argv[1], &spec, &sound, &soundlen) == NULL) {
   131             fprintf(stderr, "Couldn't load %s: %s\n", argv[1],
   132                     SDL_GetError());
   133         } else {
   134             test_multi_audio(devcount);
   135             SDL_FreeWAV(sound);
   136         }
   137     }
   138 
   139     SDL_Quit();
   140     return 0;
   141 }