annotate src/audio/openbsd/SDL_openbsdaudio.c @ 1471:9fb0eee04dd9

Enabled libc support on Win32, so we don't break binary compatibility in 1.2
author Sam Lantinga <slouken@libsdl.org>
date Mon, 06 Mar 2006 07:42:36 +0000
parents d910939febfa
children 57431b199aed
rev   line source
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1 /*
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
769
b8d311d90021 Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents: 543
diff changeset
3 Copyright (C) 1997-2004 Sam Lantinga
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
6 modify it under the terms of the GNU Library General Public
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
8 version 2 of the License, or (at your option) any later version.
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
13 Library General Public License for more details.
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
15 You should have received a copy of the GNU Library General Public
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
16 License along with this library; if not, write to the Free
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
18
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
19 Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 131
diff changeset
20 slouken@libsdl.org
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21 */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
22 #include "SDL_config.h"
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24 /*
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25 * Driver for native OpenBSD audio(4).
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
26 * vedge@vedge.com.ar.
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
27 */
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
28
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
29 #include <errno.h>
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
30 #include <unistd.h>
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31 #include <fcntl.h>
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
32 #include <sys/time.h>
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
33 #include <sys/ioctl.h>
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
34 #include <sys/stat.h>
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
35 #include <sys/types.h>
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
36 #include <sys/audioio.h>
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
37
1358
c71e05b4dc2e More header massaging... works great on Windows. ;-)
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
38 #include "SDL_timer.h"
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
39 #include "SDL_audio.h"
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
40 #include "../SDL_audiomem.h"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
41 #include "../SDL_audio_c.h"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
42 #include "../SDL_audiodev_c.h"
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
43 #include "SDL_openbsdaudio.h"
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
44
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
45 /* The tag name used by OpenBSD audio */
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
46 #define OBSD_DRIVER_NAME "openbsd"
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
47
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
48 /* Open the audio device for playback, and don't block if busy */
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
49 /* #define USE_BLOCKING_WRITES */
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
50
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
51 /* Use timer for synchronization */
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
52 /* #define USE_TIMER_SYNC */
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
53
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
54 /* #define DEBUG_AUDIO */
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
55 /* #define DEBUG_AUDIO_STREAM */
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
56
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
57 #ifdef USE_BLOCKING_WRITES
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
58 #define OPEN_FLAGS O_WRONLY
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
59 #else
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
60 #define OPEN_FLAGS (O_WRONLY|O_NONBLOCK)
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
61 #endif
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
62
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
63 /* Audio driver functions */
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
64 static void OBSD_WaitAudio(_THIS);
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
65 static int OBSD_OpenAudio(_THIS, SDL_AudioSpec *spec);
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
66 static void OBSD_PlayAudio(_THIS);
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
67 static Uint8 *OBSD_GetAudioBuf(_THIS);
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
68 static void OBSD_CloseAudio(_THIS);
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
69
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
70 #ifdef DEBUG_AUDIO
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
71 static void OBSD_Status(_THIS);
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
72 #endif
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
73
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
74 /* Audio driver bootstrap functions */
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
75
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
76 static int
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
77 Audio_Available(void)
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
78 {
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
79 int fd;
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
80 int available;
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
81
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
82 available = 0;
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
83 fd = SDL_OpenAudioPath(NULL, 0, OPEN_FLAGS, 0);
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
84 if(fd >= 0) {
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
85 available = 1;
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
86 close(fd);
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
87 }
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
88 return(available);
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
89 }
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
90
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
91 static void
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
92 Audio_DeleteDevice(SDL_AudioDevice *device)
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
93 {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1186
diff changeset
94 SDL_free(device->hidden);
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1186
diff changeset
95 SDL_free(device);
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
96 }
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
97
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
98 static SDL_AudioDevice
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
99 *Audio_CreateDevice(int devindex)
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
100 {
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
101 SDL_AudioDevice *this;
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
102
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
103 /* Initialize all variables that we clean on shutdown */
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1186
diff changeset
104 this = (SDL_AudioDevice*)SDL_malloc(sizeof(SDL_AudioDevice));
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
105 if(this) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1186
diff changeset
106 SDL_memset(this, 0, (sizeof *this));
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
107 this->hidden =
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1186
diff changeset
108 (struct SDL_PrivateAudioData*)SDL_malloc((sizeof *this->hidden));
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
109 }
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
110 if((this == NULL) || (this->hidden == NULL)) {
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
111 SDL_OutOfMemory();
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1186
diff changeset
112 if(this) SDL_free(this);
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
113 return(0);
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
114 }
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1186
diff changeset
115 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
116 audio_fd = -1;
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
117
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
118 /* Set the function pointers */
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
119 this->OpenAudio = OBSD_OpenAudio;
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
120 this->WaitAudio = OBSD_WaitAudio;
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
121 this->PlayAudio = OBSD_PlayAudio;
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
122 this->GetAudioBuf = OBSD_GetAudioBuf;
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
123 this->CloseAudio = OBSD_CloseAudio;
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
124
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
125 this->free = Audio_DeleteDevice;
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
126
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
127 return this;
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
128 }
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
129
121
43febd46d49d Name changed from OBSD to OPENBSD_AUDIO
Sam Lantinga <slouken@libsdl.org>
parents: 94
diff changeset
130 AudioBootStrap OPENBSD_AUDIO_bootstrap = {
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
131 OBSD_DRIVER_NAME, "Native OpenBSD audio",
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
132 Audio_Available, Audio_CreateDevice
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
133 };
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
134
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
135 /* This function waits until it is possible to write a full sound buffer */
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
136 static void
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
137 OBSD_WaitAudio(_THIS)
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
138 {
94
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
139 /* Check to see if the thread-parent process is still alive */
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
140 { static int cnt = 0;
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
141 /* Note that this only works with thread implementations
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
142 that use a different process id for each thread.
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
143 */
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
144 if (parent && (((++cnt)%10) == 0)) { /* Check every 10 loops */
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
145 if ( kill(parent, 0) < 0 ) {
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
146 this->enabled = 0;
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
147 }
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
148 }
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
149 }
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
150
94
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
151 #ifndef USE_BLOCKING_WRITES /* Not necessary when using blocking writes */
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
152 /* See if we need to use timed audio synchronization */
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
153 if ( frame_ticks ) {
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
154 /* Use timer for general audio synchronization */
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
155 Sint32 ticks;
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
156
94
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
157 ticks = ((Sint32)(next_frame - SDL_GetTicks()))-FUDGE_TICKS;
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
158 if ( ticks > 0 ) {
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
159 SDL_Delay(ticks);
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
160 }
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
161 } else {
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
162 /* Use select() for audio synchronization */
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
163 fd_set fdset;
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
164 struct timeval timeout;
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
165
94
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
166 FD_ZERO(&fdset);
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
167 FD_SET(audio_fd, &fdset);
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
168 timeout.tv_sec = 10;
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
169 timeout.tv_usec = 0;
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
170 #ifdef DEBUG_AUDIO
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
171 fprintf(stderr, "Waiting for audio to get ready\n");
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
172 #endif
94
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
173 if ( select(audio_fd+1, NULL, &fdset, NULL, &timeout) <= 0 ) {
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
174 const char *message =
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
175 "Audio timeout - buggy audio driver? (disabled)";
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
176 /* In general we should never print to the screen,
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
177 but in this case we have no other way of letting
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
178 the user know what happened.
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
179 */
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
180 fprintf(stderr, "SDL: %s\n", message);
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
181 this->enabled = 0;
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
182 /* Don't try to close - may hang */
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
183 audio_fd = -1;
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
184 #ifdef DEBUG_AUDIO
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
185 fprintf(stderr, "Done disabling audio\n");
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
186 #endif
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
187 }
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
188 #ifdef DEBUG_AUDIO
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
189 fprintf(stderr, "Ready!\n");
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
190 #endif
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
191 }
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
192 #endif /* !USE_BLOCKING_WRITES */
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
193 }
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
194
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
195 static void
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
196 OBSD_PlayAudio(_THIS)
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
197 {
94
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
198 int written, p=0;
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
199
94
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
200 /* Write the audio data, checking for EAGAIN on broken audio drivers */
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
201 do {
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
202 written = write(audio_fd, &mixbuf[p], mixlen-p);
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
203 if (written>0)
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
204 p += written;
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
205 if (written == -1 && errno != 0 && errno != EAGAIN && errno != EINTR)
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
206 {
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
207 /* Non recoverable error has occurred. It should be reported!!! */
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
208 perror("audio");
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
209 break;
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
210 }
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
211
94
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
212 if ( p < written || ((written < 0) && ((errno == 0) || (errno == EAGAIN))) ) {
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
213 SDL_Delay(1); /* Let a little CPU time go by */
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
214 }
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
215 } while ( p < written );
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
216
94
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
217 /* If timer synchronization is enabled, set the next write frame */
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
218 if ( frame_ticks ) {
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
219 next_frame += frame_ticks;
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
220 }
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
221
94
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
222 /* If we couldn't write, assume fatal error for now */
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
223 if ( written < 0 ) {
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
224 this->enabled = 0;
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
225 }
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
226 #ifdef DEBUG_AUDIO
ae6e6b73333f Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents: 37
diff changeset
227 fprintf(stderr, "Wrote %d bytes of audio data\n", written);
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
228 #endif
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
229 }
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
230
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
231 static Uint8
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
232 *OBSD_GetAudioBuf(_THIS)
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
233 {
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
234 return(mixbuf);
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
235 }
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
236
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
237 static void
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
238 OBSD_CloseAudio(_THIS)
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
239 {
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
240 if(mixbuf != NULL) {
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
241 SDL_FreeAudioMem(mixbuf);
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
242 mixbuf = NULL;
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
243 }
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
244 if(audio_fd >= 0) {
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
245 close(audio_fd);
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
246 audio_fd = -1;
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
247 }
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
248 }
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
249
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
250 #ifdef DEBUG_AUDIO
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
251 void
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
252 OBSD_Status(_THIS)
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
253 {
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
254 audio_info_t info;
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
255
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
256 if(ioctl(audio_fd, AUDIO_GETINFO, &info) < 0) {
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
257 fprintf(stderr,"AUDIO_GETINFO failed.\n");
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
258 return;
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
259 }
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
260
1186
0276947bee66 Patched OpenBSD audio to compile on newer GCC versions.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
261 fprintf(stderr,"\n"
0276947bee66 Patched OpenBSD audio to compile on newer GCC versions.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
262 "[play/record info]\n"
0276947bee66 Patched OpenBSD audio to compile on newer GCC versions.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
263 "buffer size : %d bytes\n"
0276947bee66 Patched OpenBSD audio to compile on newer GCC versions.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
264 "sample rate : %i Hz\n"
0276947bee66 Patched OpenBSD audio to compile on newer GCC versions.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
265 "channels : %i\n"
0276947bee66 Patched OpenBSD audio to compile on newer GCC versions.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
266 "precision : %i-bit\n"
0276947bee66 Patched OpenBSD audio to compile on newer GCC versions.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
267 "encoding : 0x%x\n"
0276947bee66 Patched OpenBSD audio to compile on newer GCC versions.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
268 "seek : %i\n"
0276947bee66 Patched OpenBSD audio to compile on newer GCC versions.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
269 "sample count : %i\n"
0276947bee66 Patched OpenBSD audio to compile on newer GCC versions.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
270 "EOF count : %i\n"
0276947bee66 Patched OpenBSD audio to compile on newer GCC versions.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
271 "paused : %s\n"
0276947bee66 Patched OpenBSD audio to compile on newer GCC versions.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
272 "error occured : %s\n"
0276947bee66 Patched OpenBSD audio to compile on newer GCC versions.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
273 "waiting : %s\n"
0276947bee66 Patched OpenBSD audio to compile on newer GCC versions.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
274 "active : %s\n"
0276947bee66 Patched OpenBSD audio to compile on newer GCC versions.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
275 "",
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
276 info.play.buffer_size,
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
277 info.play.sample_rate,
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
278 info.play.channels,
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
279 info.play.precision,
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
280 info.play.encoding,
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
281 info.play.seek,
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
282 info.play.samples,
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
283 info.play.eof,
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
284 info.play.pause ? "yes" : "no",
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
285 info.play.error ? "yes" : "no",
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
286 info.play.waiting ? "yes" : "no",
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
287 info.play.active ? "yes": "no");
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
288
1186
0276947bee66 Patched OpenBSD audio to compile on newer GCC versions.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
289 fprintf(stderr,"\n"
0276947bee66 Patched OpenBSD audio to compile on newer GCC versions.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
290 "[audio info]\n"
0276947bee66 Patched OpenBSD audio to compile on newer GCC versions.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
291 "monitor_gain : %i\n"
0276947bee66 Patched OpenBSD audio to compile on newer GCC versions.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
292 "hw block size : %d bytes\n"
0276947bee66 Patched OpenBSD audio to compile on newer GCC versions.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
293 "hi watermark : %i\n"
0276947bee66 Patched OpenBSD audio to compile on newer GCC versions.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
294 "lo watermark : %i\n"
0276947bee66 Patched OpenBSD audio to compile on newer GCC versions.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
295 "audio mode : %s\n"
0276947bee66 Patched OpenBSD audio to compile on newer GCC versions.
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
296 "",
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
297 info.monitor_gain,
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
298 info.blocksize,
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
299 info.hiwat, info.lowat,
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
300 (info.mode == AUMODE_PLAY) ? "PLAY"
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
301 : (info.mode = AUMODE_RECORD) ? "RECORD"
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
302 : (info.mode == AUMODE_PLAY_ALL ? "PLAY_ALL"
543
522e5202014d *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
303 : "?"));
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
304 }
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
305 #endif /* DEBUG_AUDIO */
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
306
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
307 static int
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
308 OBSD_OpenAudio(_THIS, SDL_AudioSpec *spec)
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
309 {
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
310 char audiodev[64];
131
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
311 Uint16 format;
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
312 audio_info_t info;
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
313
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
314 AUDIO_INITINFO(&info);
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
315
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
316 /* Calculate the final parameters for this audio specification */
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
317 SDL_CalculateAudioSpec(spec);
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
318
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
319 #ifdef USE_TIMER_SYNC
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
320 frame_ticks = 0.0;
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
321 #endif
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
322
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
323 /* Open the audio device */
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
324 audio_fd = SDL_OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 0);
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
325 if(audio_fd < 0) {
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
326 SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno));
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
327 return(-1);
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
328 }
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
329
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
330 /* Set to play mode */
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
331 info.mode = AUMODE_PLAY;
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
332 if(ioctl(audio_fd, AUDIO_SETINFO, &info) < 0) {
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
333 SDL_SetError("Couldn't put device into play mode");
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
334 return(-1);
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
335 }
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
336
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
337 mixbuf = NULL;
131
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
338 AUDIO_INITINFO(&info);
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
339 for (format = SDL_FirstAudioFormat(spec->format);
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
340 format; format = SDL_NextAudioFormat())
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
341 {
131
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
342 switch(format) {
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
343 case AUDIO_U8:
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
344 info.play.encoding = AUDIO_ENCODING_ULINEAR;
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
345 info.play.precision = 8;
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
346 break;
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
347 case AUDIO_S8:
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
348 info.play.encoding = AUDIO_ENCODING_SLINEAR;
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
349 info.play.precision = 8;
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
350 break;
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
351 case AUDIO_S16LSB:
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
352 info.play.encoding = AUDIO_ENCODING_SLINEAR_LE;
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
353 info.play.precision = 16;
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
354 break;
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
355 case AUDIO_S16MSB:
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
356 info.play.encoding = AUDIO_ENCODING_SLINEAR_BE;
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
357 info.play.precision = 16;
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
358 break;
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
359 case AUDIO_U16LSB:
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
360 info.play.encoding = AUDIO_ENCODING_ULINEAR_LE;
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
361 info.play.precision = 16;
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
362 break;
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
363 case AUDIO_U16MSB:
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
364 info.play.encoding = AUDIO_ENCODING_ULINEAR_BE;
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
365 info.play.precision = 16;
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
366 break;
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
367 default:
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
368 continue;
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
369 }
131
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
370 if (ioctl(audio_fd, AUDIO_SETINFO, &info) == 0)
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
371 break;
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
372 }
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
373
131
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
374 if(!format) {
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
375 SDL_SetError("No supported encoding for 0x%x", spec->format);
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
376 return(-1);
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
377 }
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
378
131
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
379 spec->format = format;
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
380
131
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
381 AUDIO_INITINFO(&info);
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
382 info.play.channels = spec->channels;
131
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
383 if (ioctl(audio_fd, AUDIO_SETINFO, &info) == -1)
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
384 spec->channels = 1;
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
385 AUDIO_INITINFO(&info);
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
386 info.play.sample_rate = spec->freq;
131
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
387 (void)ioctl(audio_fd, AUDIO_SETINFO, &info);
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
388 (void)ioctl(audio_fd, AUDIO_GETINFO, &info);
5d08b230932e Fixed audio format selection for OpenBSD (thanks Peter!)
Sam Lantinga <slouken@libsdl.org>
parents: 121
diff changeset
389 spec->freq = info.play.sample_rate;
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
390 /* Allocate mixing buffer */
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
391 mixlen = spec->size;
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
392 mixbuf = (Uint8*)SDL_AllocAudioMem(mixlen);
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
393 if(mixbuf == NULL) {
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
394 return(-1);
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
395 }
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1186
diff changeset
396 SDL_memset(mixbuf, spec->silence, spec->size);
37
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
397
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
398 /* Get the parent process id (we're the parent of the audio thread) */
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
399 parent = getpid();
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
400
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
401 #ifdef DEBUG_AUDIO
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
402 OBSD_Status(this);
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
403 #endif
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
404
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
405 /* We're ready to rock and roll. :-) */
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
406 return(0);
3ad7157c6cfa Added native OpenBSD audio driver (thanks vedge!)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
407 }