Mercurial > sdl-ios-xcode
annotate src/audio/SDL_audiodev.c @ 3810:2c5387c0a642 SDL-ryan-multiple-audio-device
Multiple audio device code is now working for dsp and dma targets.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Thu, 05 Oct 2006 04:47:13 +0000 |
parents | 7852b5b78af5 |
children |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1138
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1138
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1138
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1138
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1138
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1138
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1138
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
94
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
24 /* Get the name of the audio device we use for output */ | |
25 | |
1567
12b6d331d82a
Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
26 #if SDL_AUDIO_DRIVER_BSD || SDL_AUDIO_DRIVER_OSS || SDL_AUDIO_DRIVER_SUNAUDIO |
0 | 27 |
28 #include <fcntl.h> | |
29 #include <sys/types.h> | |
30 #include <sys/stat.h> | |
31 | |
1358
c71e05b4dc2e
More header massaging... works great on Windows. ;-)
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
32 #include "SDL_stdinc.h" |
0 | 33 #include "SDL_audiodev_c.h" |
34 | |
35 #ifndef _PATH_DEV_DSP | |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
36 #if defined(__NETBSD__) || defined(__OPENBSD__) |
94
ae6e6b73333f
Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
37 #define _PATH_DEV_DSP "/dev/audio" |
ae6e6b73333f
Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
38 #else |
ae6e6b73333f
Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
39 #define _PATH_DEV_DSP "/dev/dsp" |
ae6e6b73333f
Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
40 #endif |
0 | 41 #endif |
42 #ifndef _PATH_DEV_DSP24 | |
43 #define _PATH_DEV_DSP24 "/dev/sound/dsp" | |
44 #endif | |
45 #ifndef _PATH_DEV_AUDIO | |
46 #define _PATH_DEV_AUDIO "/dev/audio" | |
47 #endif | |
48 | |
3810
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
49 static inline void |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
50 test_device(const char *fname, int flags, int (*test)(int fd), |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
51 char ***devices, int *devCount) |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
52 { |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
53 struct stat sb; |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
54 if ( (stat(fname, &sb) == 0) && (S_ISCHR(sb.st_mode)) ) { |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
55 int audio_fd = open(fname, flags, 0); |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
56 if ( (audio_fd >= 0) && (test(audio_fd)) ) { |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
57 void *p = SDL_realloc(*devices, ((*devCount)+1) * sizeof (char *)); |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
58 if (p != NULL) { |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
59 size_t len = strlen(fname) + 1; |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
60 char *str = (char *) SDL_malloc(len); |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
61 *devices = (char **) p; |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
62 if (str != NULL) { |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
63 SDL_strlcpy(str, fname, len); |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
64 (*devices)[(*devCount)++] = str; |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
65 } |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
66 } |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
67 close(audio_fd); |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
68 } |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
69 } |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
70 } |
0 | 71 |
3810
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
72 void |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
73 SDL_FreeUnixAudioDevices(char ***devices, int *devCount) |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
74 { |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
75 int i = *devCount; |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
76 if ((i > 0) && (*devices != NULL)) { |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
77 while (i--) { |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
78 SDL_free( (*devices)[*devCount] ); |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
79 } |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
80 } |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
81 |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
82 if (*devices != NULL) { |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
83 SDL_free(*devices); |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
84 } |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
85 |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
86 *devices = NULL; |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
87 *devCount = 0; |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
88 } |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
89 |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
90 static int |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
91 test_stub(int fd) |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
92 { |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
93 return 1; |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
94 } |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
95 |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
96 void |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
97 SDL_EnumUnixAudioDevices(int flags, int classic, int (*test)(int fd), |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
98 char ***devices, int *devCount) |
0 | 99 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1567
diff
changeset
|
100 const char *audiodev; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1567
diff
changeset
|
101 char audiopath[1024]; |
0 | 102 |
3810
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
103 if (test == NULL) |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
104 test = test_stub; |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
105 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1567
diff
changeset
|
106 /* Figure out what our audio device is */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1567
diff
changeset
|
107 if (((audiodev = SDL_getenv("SDL_PATH_DSP")) == NULL) && |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1567
diff
changeset
|
108 ((audiodev = SDL_getenv("AUDIODEV")) == NULL)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1567
diff
changeset
|
109 if (classic) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1567
diff
changeset
|
110 audiodev = _PATH_DEV_AUDIO; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1567
diff
changeset
|
111 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1567
diff
changeset
|
112 struct stat sb; |
0 | 113 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1567
diff
changeset
|
114 /* Added support for /dev/sound/\* in Linux 2.4 */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1567
diff
changeset
|
115 if (((stat("/dev/sound", &sb) == 0) && S_ISDIR(sb.st_mode)) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1567
diff
changeset
|
116 && ((stat(_PATH_DEV_DSP24, &sb) == 0) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1567
diff
changeset
|
117 && S_ISCHR(sb.st_mode))) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1567
diff
changeset
|
118 audiodev = _PATH_DEV_DSP24; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1567
diff
changeset
|
119 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1567
diff
changeset
|
120 audiodev = _PATH_DEV_DSP; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1567
diff
changeset
|
121 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1567
diff
changeset
|
122 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1567
diff
changeset
|
123 } |
3810
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
124 test_device(audiodev, flags, test, devices, devCount); |
0 | 125 |
3810
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
126 if (SDL_strlen(audiodev) < (sizeof(audiopath) - 3)) { |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
127 int instance = 0; |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
128 while (instance++ <= 64) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1567
diff
changeset
|
129 SDL_snprintf(audiopath, SDL_arraysize(audiopath), |
3810
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
130 "%s%d", audiodev, instance); |
2c5387c0a642
Multiple audio device code is now working for dsp and dma targets.
Ryan C. Gordon <icculus@icculus.org>
parents:
3809
diff
changeset
|
131 test_device(audiopath, flags, test, devices, devCount); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1567
diff
changeset
|
132 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1567
diff
changeset
|
133 } |
0 | 134 } |
135 | |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
136 #endif /* Audio driver selection */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1567
diff
changeset
|
137 /* vi: set ts=4 sw=4 expandtab: */ |