annotate src/audio/bsd/SDL_bsdaudio.c @ 2191:29e07f91bc1f

Rename LockAudio,UnlockAudio to LockDevice,UnlockDevice. Also some small fixes
author Patrice Mandin <patmandin@gmail.com>
date Fri, 13 Jul 2007 23:58:22 +0000
parents 2e36e0ecde33
children e27bdcc80744
rev   line source
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 Copyright (C) 1997-2004 Sam Lantinga
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Library General Public
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2 of the License, or (at your option) any later version.
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Library General Public License for more details.
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Library General Public
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 #include "SDL_config.h"
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 /*
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 * Driver for native OpenBSD/NetBSD audio(4).
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 * vedge@vedge.com.ar.
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 #include <errno.h>
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 #include <unistd.h>
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 #include <fcntl.h>
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 #include <sys/time.h>
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 #include <sys/ioctl.h>
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 #include <sys/stat.h>
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 #include <sys/types.h>
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 #include <sys/audioio.h>
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 #include "SDL_timer.h"
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 #include "SDL_audio.h"
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 #include "../SDL_audiomem.h"
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 #include "../SDL_audio_c.h"
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 #include "../SDL_audiodev_c.h"
1583
95451df282c3 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 1567
diff changeset
43 #include "SDL_bsdaudio.h"
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 /* The tag name used by NetBSD/OpenBSD audio */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 #ifdef __NetBSD__
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 #define BSD_AUDIO_DRIVER_NAME "netbsd"
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 #define BSD_AUDIO_DRIVER_DESC "Native NetBSD audio"
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 #else
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 #define BSD_AUDIO_DRIVER_NAME "openbsd"
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 #define BSD_AUDIO_DRIVER_DESC "Native OpenBSD audio"
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 #endif
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 /* Open the audio device for playback, and don't block if busy */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 /* #define USE_BLOCKING_WRITES */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 /* Use timer for synchronization */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 /* #define USE_TIMER_SYNC */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 /* #define DEBUG_AUDIO */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 /* #define DEBUG_AUDIO_STREAM */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 #ifdef USE_BLOCKING_WRITES
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
64 #define OPEN_FLAGS_OUTPUT O_WRONLY
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
65 #define OPEN_FLAGS_INPUT O_RDONLY
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 #else
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
67 #define OPEN_FLAGS_OUTPUT (O_WRONLY|O_NONBLOCK)
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
68 #define OPEN_FLAGS_INPUT (O_RDONLY|O_NONBLOCK)
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 #endif
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
71 /* !!! FIXME: so much cut and paste with dsp/dma drivers... */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
72 static char **outputDevices = NULL;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
73 static int outputDeviceCount = 0;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
74 static char **inputDevices = NULL;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
75 static int inputDeviceCount = 0;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
77 static inline void
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
78 free_device_list(char ***devs, int *count)
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
79 {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
80 SDL_FreeUnixAudioDevices(devs, count);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 }
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
83 static inline void
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
84 build_device_list(int iscapture, char ***devs, int *count)
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 {
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
86 const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
87 free_device_list(devs, count);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
88 SDL_EnumUnixAudioDevices(flags, 0, NULL, devs, count);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 }
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
91 static inline void
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
92 build_device_lists(void)
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 {
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
94 build_device_list(0, &outputDevices, &outputDeviceCount);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
95 build_device_list(1, &inputDevices, &inputDeviceCount);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
96 }
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
99 static inline void
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
100 free_device_lists(void)
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
101 {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
102 free_device_list(&outputDevices, &outputDeviceCount);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
103 free_device_list(&inputDevices, &inputDeviceCount);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 }
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 static void
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
108 BSDAUDIO_Deinitialize(void)
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 {
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
110 free_device_lists();
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
111 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
112
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
114 static int
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
115 BSDAUDIO_DetectDevices(int iscapture)
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
116 {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
117 if (iscapture) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
118 build_device_list(1, &inputDevices, &inputDeviceCount);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
119 return inputDeviceCount;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
120 } else {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
121 build_device_list(0, &outputDevices, &outputDeviceCount);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
122 return outputDeviceCount;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
123 }
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
125 return 0; /* shouldn't ever hit this. */
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 }
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
128 static const char *
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
129 BSDAUDIO_GetDeviceName(int index, int iscapture)
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 {
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
131 if ((iscapture) && (index < inputDeviceCount)) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
132 return inputDevices[index];
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
133 } else if ((!iscapture) && (index < outputDeviceCount)) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
134 return outputDevices[index];
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
135 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
136
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
137 SDL_SetError("No such device");
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
138 return NULL;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 }
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
141
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 static void
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
143 BSDAUDIO_Status(_THIS)
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 {
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 #ifdef DEBUG_AUDIO
2065
2e36e0ecde33 @#$% indent
Sam Lantinga <slouken@libsdl.org>
parents: 2064
diff changeset
146 /* *INDENT-OFF* */
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 audio_info_t info;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
149 if (ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info) < 0) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
150 fprintf(stderr, "AUDIO_GETINFO failed.\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
151 return;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
153 fprintf(stderr, "\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
154 "[play/record info]\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
155 "buffer size : %d bytes\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
156 "sample rate : %i Hz\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
157 "channels : %i\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
158 "precision : %i-bit\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
159 "encoding : 0x%x\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
160 "seek : %i\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
161 "sample count : %i\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
162 "EOF count : %i\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
163 "paused : %s\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
164 "error occured : %s\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
165 "waiting : %s\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
166 "active : %s\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
167 "",
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
168 info.play.buffer_size,
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
169 info.play.sample_rate,
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
170 info.play.channels,
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
171 info.play.precision,
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
172 info.play.encoding,
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
173 info.play.seek,
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
174 info.play.samples,
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
175 info.play.eof,
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
176 info.play.pause ? "yes" : "no",
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
177 info.play.error ? "yes" : "no",
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
178 info.play.waiting ? "yes" : "no",
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
179 info.play.active ? "yes" : "no");
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
181 fprintf(stderr, "\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
182 "[audio info]\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
183 "monitor_gain : %i\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
184 "hw block size : %d bytes\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
185 "hi watermark : %i\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
186 "lo watermark : %i\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
187 "audio mode : %s\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
188 "",
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
189 info.monitor_gain,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
190 info.blocksize,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
191 info.hiwat, info.lowat,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
192 (info.mode == AUMODE_PLAY) ? "PLAY"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
193 : (info.mode = AUMODE_RECORD) ? "RECORD"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
194 : (info.mode == AUMODE_PLAY_ALL ? "PLAY_ALL" : "?"));
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
195 /* *INDENT-ON* */
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
196 #endif /* DEBUG_AUDIO */
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 }
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
198
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
199
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
200 /* This function waits until it is possible to write a full sound buffer */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
201 static void
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
202 BSDAUDIO_WaitDevice(_THIS)
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
203 {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
204 #ifndef USE_BLOCKING_WRITES /* Not necessary when using blocking writes */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
205 /* See if we need to use timed audio synchronization */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
206 if (this->hidden->frame_ticks) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
207 /* Use timer for general audio synchronization */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
208 Sint32 ticks;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
209
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
210 ticks =
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
211 ((Sint32) (this->hidden->next_frame - SDL_GetTicks())) -
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
212 FUDGE_TICKS;
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
213 if (ticks > 0) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
214 SDL_Delay(ticks);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
215 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
216 } else {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
217 /* Use select() for audio synchronization */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
218 fd_set fdset;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
219 struct timeval timeout;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
220
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
221 FD_ZERO(&fdset);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
222 FD_SET(this->hidden->audio_fd, &fdset);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
223 timeout.tv_sec = 10;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
224 timeout.tv_usec = 0;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
225 #ifdef DEBUG_AUDIO
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
226 fprintf(stderr, "Waiting for audio to get ready\n");
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
227 #endif
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
228 if (select(this->hidden->audio_fd + 1, NULL, &fdset, NULL, &timeout)
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
229 <= 0) {
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
230 const char *message =
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
231 "Audio timeout - buggy audio driver? (disabled)";
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
232 /* In general we should never print to the screen,
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
233 but in this case we have no other way of letting
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
234 the user know what happened.
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
235 */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
236 fprintf(stderr, "SDL: %s\n", message);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
237 this->enabled = 0;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
238 /* Don't try to close - may hang */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
239 this->hidden->audio_fd = -1;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
240 #ifdef DEBUG_AUDIO
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
241 fprintf(stderr, "Done disabling audio\n");
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
242 #endif
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
243 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
244 #ifdef DEBUG_AUDIO
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
245 fprintf(stderr, "Ready!\n");
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
246 #endif
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
247 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
248 #endif /* !USE_BLOCKING_WRITES */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
249 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
250
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
251 static void
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
252 BSDAUDIO_PlayDevice(_THIS)
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
253 {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
254 int written, p = 0;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
255
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
256 /* Write the audio data, checking for EAGAIN on broken audio drivers */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
257 do {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
258 written = write(this->hidden->audio_fd,
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
259 &this->hidden->mixbuf[p], this->hidden->mixlen - p);
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
260
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
261 if (written > 0)
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
262 p += written;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
263 if (written == -1 && errno != 0 && errno != EAGAIN && errno != EINTR) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
264 /* Non recoverable error has occurred. It should be reported!!! */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
265 perror("audio");
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
266 break;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
267 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
268
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
269 if (p < written
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
270 || ((written < 0) && ((errno == 0) || (errno == EAGAIN)))) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
271 SDL_Delay(1); /* Let a little CPU time go by */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
272 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
273 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
274 while (p < written);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
275
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
276 /* If timer synchronization is enabled, set the next write frame */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
277 if (this->hidden->frame_ticks) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
278 this->hidden->next_frame += this->hidden->frame_ticks;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
279 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
280
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
281 /* If we couldn't write, assume fatal error for now */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
282 if (written < 0) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
283 this->enabled = 0;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
284 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
285 #ifdef DEBUG_AUDIO
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
286 fprintf(stderr, "Wrote %d bytes of audio data\n", written);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
287 #endif
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
288 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
289
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
290 static Uint8 *
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
291 BSDAUDIO_GetDeviceBuf(_THIS)
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
292 {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
293 return (this->hidden->mixbuf);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
294 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
295
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
296 static void
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
297 BSDAUDIO_CloseDevice(_THIS)
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
298 {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
299 if (this->hidden != NULL) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
300 if (this->hidden->mixbuf != NULL) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
301 SDL_FreeAudioMem(this->hidden->mixbuf);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
302 this->hidden->mixbuf = NULL;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
303 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
304 if (this->hidden->audio_fd >= 0) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
305 close(this->hidden->audio_fd);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
306 this->hidden->audio_fd = -1;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
307 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
308 SDL_free(this->hidden);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
309 this->hidden = NULL;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
310 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
311 }
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
313 static int
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
314 BSDAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
315 {
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
316 const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
317 SDL_AudioFormat format = 0;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
318 audio_info_t info;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
319
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
320 /* We don't care what the devname is...we'll try to open anything. */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
321 /* ...but default to first name in the list... */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
322 if (devname == NULL) {
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
323 if (((iscapture) && (inputDeviceCount == 0)) ||
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
324 ((!iscapture) && (outputDeviceCount == 0))) {
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
325 SDL_SetError("No such audio device");
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
326 return 0;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
327 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
328 devname = ((iscapture) ? inputDevices[0] : outputDevices[0]);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
329 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
330
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
331 /* Initialize all variables that we clean on shutdown */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
332 this->hidden = (struct SDL_PrivateAudioData *)
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
333 SDL_malloc((sizeof *this->hidden));
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
334 if (this->hidden == NULL) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
335 SDL_OutOfMemory();
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
336 return 0;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
337 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
338 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
339
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
340 /* Open the audio device */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
341 this->hidden->audio_fd = open(devname, flags, 0);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
342 if (this->hidden->audio_fd < 0) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
343 SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
344 return 0;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
345 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
346
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
347 AUDIO_INITINFO(&info);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
348
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
349 /* Calculate the final parameters for this audio specification */
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
350 SDL_CalculateAudioSpec(&this->spec);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
351
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
352 /* Set to play mode */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
353 info.mode = AUMODE_PLAY;
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
354 if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) < 0) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
355 BSDAUDIO_CloseDevice(this);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
356 SDL_SetError("Couldn't put device into play mode");
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
357 return 0;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
358 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
359
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
360 AUDIO_INITINFO(&info);
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
361 for (format = SDL_FirstAudioFormat(this->spec.format);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
362 format; format = SDL_NextAudioFormat()) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
363 switch (format) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
364 case AUDIO_U8:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
365 info.play.encoding = AUDIO_ENCODING_ULINEAR;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
366 info.play.precision = 8;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
367 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
368 case AUDIO_S8:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
369 info.play.encoding = AUDIO_ENCODING_SLINEAR;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
370 info.play.precision = 8;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
371 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
372 case AUDIO_S16LSB:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
373 info.play.encoding = AUDIO_ENCODING_SLINEAR_LE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
374 info.play.precision = 16;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
375 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
376 case AUDIO_S16MSB:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
377 info.play.encoding = AUDIO_ENCODING_SLINEAR_BE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
378 info.play.precision = 16;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
379 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
380 case AUDIO_U16LSB:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
381 info.play.encoding = AUDIO_ENCODING_ULINEAR_LE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
382 info.play.precision = 16;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
383 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
384 case AUDIO_U16MSB:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
385 info.play.encoding = AUDIO_ENCODING_ULINEAR_BE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
386 info.play.precision = 16;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
387 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
388 default:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
389 continue;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
390 }
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
391
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
392 if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) == 0) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
393 break;
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
394 }
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
395 }
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
396
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
397 if (!format) {
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
398 BSDAUDIO_CloseDevice(this);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
399 SDL_SetError("No supported encoding for 0x%x", this->spec.format);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
400 return 0;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
401 }
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
402
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
403 this->spec.format = format;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
404
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
405 AUDIO_INITINFO(&info);
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
406 info.play.channels = this->spec.channels;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
407 if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) == -1) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
408 this->spec.channels = 1;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
409 }
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
410 AUDIO_INITINFO(&info);
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
411 info.play.sample_rate = this->spec.freq;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
412 info.blocksize = this->spec.size;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
413 info.hiwat = 5;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
414 info.lowat = 3;
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
415 (void) ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
416 (void) ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
417 this->spec.freq = info.play.sample_rate;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
418 /* Allocate mixing buffer */
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
419 this->hidden->mixlen = this->spec.size;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
420 this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
421 if (this->hidden->mixbuf == NULL) {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
422 BSDAUDIO_CloseDevice(this);
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
423 SDL_OutOfMemory();
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
424 return 0;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
425 }
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
426 SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
427
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
428 BSDAUDIO_Status(this);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
429
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
430 /* We're ready to rock and roll. :-) */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
431 return (0);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
432 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
433
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
434 static int
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
435 BSDAUDIO_Init(SDL_AudioDriverImpl * impl)
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
436 {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
437 /* Set the function pointers */
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
438 impl->DetectDevices = BSDAUDIO_DetectDevices;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
439 impl->GetDeviceName = BSDAUDIO_GetDeviceName;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
440 impl->OpenDevice = BSDAUDIO_OpenDevice;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
441 impl->PlayDevice = BSDAUDIO_PlayDevice;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
442 impl->WaitDevice = BSDAUDIO_WaitDevice;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
443 impl->GetDeviceBuf = BSDAUDIO_GetDeviceBuf;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
444 impl->CloseDevice = BSDAUDIO_CloseDevice;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
445 impl->Deinitialize = BSDAUDIO_Deinitialize;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
446
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
447 build_device_lists();
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
448 return 1;
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
449 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
450
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
451
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
452 AudioBootStrap BSD_AUDIO_bootstrap = {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
453 BSD_AUDIO_DRIVER_NAME, BSD_AUDIO_DRIVER_DESC, BSDAUDIO_Init, 0
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
454 };
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
455
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
456 /* vi: set ts=4 sw=4 expandtab: */