annotate test/testaudioinfo.c @ 3846:66fb40445587 SDL-ryan-multiple-audio-device

Removed distinction between "available" and "init" in audio backends, since both had to be checked for success as a pair at the higher level and several of the Available methods were just always-succeed placeholders anyhow. Now the availability check is done in the init code, and the higher level tries all possible drivers until one manages to initialize successfully.
author Ryan C. Gordon <icculus@icculus.org>
date Tue, 17 Oct 2006 09:09:21 +0000
parents 7dc7327cd626
children
rev   line source
3789
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 #include "SDL.h"
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 static void print_devices(int iscapture)
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4 {
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 const char *typestr = ((iscapture) ? "capture" : "output");
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 int n = SDL_GetNumAudioDevices(iscapture);
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7
3795
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 3792
diff changeset
8 printf("%s devices:\n", typestr);
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 3792
diff changeset
9
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 3792
diff changeset
10 if (n == -1)
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 3792
diff changeset
11 printf(" Driver can't detect specific devices.\n\n", typestr);
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 3792
diff changeset
12 else if (n == 0)
589bc3d060cd More 1.3 audio work...moved dsp and dma drivers over to new model. Untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 3792
diff changeset
13 printf(" No %s devices found.\n\n", typestr);
3789
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14 else
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15 {
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16 int i;
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17 for (i = 0; i < n; i++) {
3792
866c310e2cb5 Changed some 1.3 audio symbol names.
Ryan C. Gordon <icculus@icculus.org>
parents: 3789
diff changeset
18 printf(" %s\n", SDL_GetAudioDeviceName(i, iscapture));
3789
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19 }
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 printf("\n");
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 }
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22 }
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24 int main(int argc, char **argv)
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 {
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 /* Print available audio drivers */
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27 int n = SDL_GetNumAudioDrivers();
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 if (n == 0) {
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 printf("No built-in audio drivers\n\n");
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30 } else {
3836
7dc7327cd626 Patched to build on pre-C99 compilers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3795
diff changeset
31 int i;
3789
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 printf("Built-in audio drivers:\n");
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 for (i = 0; i < n; ++i) {
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34 printf(" %s\n", SDL_GetAudioDriver(i));
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 }
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36 printf("\n");
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37 }
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39 /* Load the SDL library */
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40 if (SDL_Init(SDL_INIT_AUDIO) < 0) {
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 return (1);
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43 }
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45 printf("Using audio driver: %s\n\n", SDL_GetCurrentAudioDriver());
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47 print_devices(0);
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48 print_devices(1);
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 SDL_Quit();
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51 return 0;
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52 }
e2f68b579a01 Added testaudioinfo.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53