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