annotate src/audio/bsd/SDL_bsdaudio.c @ 2866:e532417a6977

Fixed SDL 1.2 compatibility problem. The API specifies that SDL_OpenAudio() will fill out the 'desired' audio spec with the correct samples and size set by the driver. This value is important since it may be used by applications that size audio buffers, etc. However, we want to allow advanced applications to call SDL_OpenAudioDevice() which gets passed a const 'desired' parameter, and have the correct data filled into the 'obtained' parameter, possibly allowing or not allowing format changes. So... 'obtained' becomes the audio format the user callback is expected to use, and we add flags to allow the application to specify which format changes are allowed. Note: We really need to add a way to query the 'obtained' audio spec.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 13 Dec 2008 06:36:47 +0000
parents 99210400e8b9
children 2929ed239d2a
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
2859
99210400e8b9 Updated copyright date
Sam Lantinga <slouken@libsdl.org>
parents: 2735
diff changeset
3 Copyright (C) 1997-2009 Sam Lantinga
1567
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 }
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2065
diff changeset
273 } while (p < written);
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
274
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
275 /* 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
276 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
277 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
278 }
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 /* 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
281 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
282 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
283 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
284 #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
285 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
286 #endif
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
287 }
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 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
290 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
291 {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
292 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
293 }
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 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
296 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
297 {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
298 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
299 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
300 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
301 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
302 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
303 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
304 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
305 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
306 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
307 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
308 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
309 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
310 }
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
311
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312 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
313 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
314 {
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
315 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
316 SDL_AudioFormat format = 0;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
317 audio_info_t info;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
318
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
319 /* 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
320 /* ...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
321 if (devname == NULL) {
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
322 if (((iscapture) && (inputDeviceCount == 0)) ||
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
323 ((!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
324 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
325 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
326 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
327 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
328 }
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 /* 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
331 this->hidden = (struct SDL_PrivateAudioData *)
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
332 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
333 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
334 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
335 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
336 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
337 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
338
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
339 /* 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
340 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
341 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
342 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
343 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
344 }
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
345
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
346 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
347
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
348 /* 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
349 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
350
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
351 /* Set to play mode */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
352 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
353 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
354 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
355 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
356 return 0;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
357 }
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
358
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
359 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
360 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
361 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
362 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
363 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
364 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
365 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
366 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
367 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
368 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
369 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
370 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
371 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
372 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
373 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
374 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
375 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
376 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
377 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
378 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
379 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
380 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
381 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
382 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
383 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
384 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
385 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
386 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
387 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
388 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
389 }
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
390
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
391 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
392 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
393 }
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
394 }
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
395
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
396 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
397 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
398 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
399 return 0;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
400 }
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
401
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
402 this->spec.format = format;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
403
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
404 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
405 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
406 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
407 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
408 }
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
409 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
410 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
411 info.blocksize = this->spec.size;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
412 info.hiwat = 5;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
413 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
414 (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
415 (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
416 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
417 /* 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
418 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
419 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
420 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
421 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
422 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
423 return 0;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
424 }
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
425 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
426
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
427 BSDAUDIO_Status(this);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
428
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
429 /* 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
430 return (0);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
431 }
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
432
2049
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
433 static int
2060
866052b01ee5 indent is evil
Sam Lantinga <slouken@libsdl.org>
parents: 2049
diff changeset
434 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
435 {
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
436 /* 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
437 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
438 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
439 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
440 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
441 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
442 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
443 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
444 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
445
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
446 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
447 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
448 }
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 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
452 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
453 };
5f6550e5184f Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
454
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
455 /* vi: set ts=4 sw=4 expandtab: */