/[pcsx2_0.9.7]/trunk/3rdparty/SDL-1.3.0-5387/test/testmultiaudio.c
ViewVC logotype

Contents of /trunk/3rdparty/SDL-1.3.0-5387/test/testmultiaudio.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 401 - (show annotations) (download)
Fri Feb 25 17:31:09 2011 UTC (9 years, 9 months ago) by william
File MIME type: text/plain
File size: 3598 byte(s)
Auto Commited Import of: pcsx2-0.9.7-DEBUG (upstream: v0.9.7.4358 local: v0.9.7.313-latest) in ./trunk
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 }

  ViewVC Help
Powered by ViewVC 1.1.22