Mercurial > sdl-ios-xcode
annotate src/audio/baudio/SDL_beaudio.cc @ 1997:46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Untested: No BeOS system here for compiling!
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Thu, 31 Aug 2006 22:15:07 +0000 |
parents | c121d94672cb |
children | cbac0f77a799 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
114
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
1403
376665398b25
Catch the C++ and Objective C sources too...
Sam Lantinga <slouken@libsdl.org>
parents:
1367
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
24 /* Allow access to the audio stream on BeOS */ | |
25 | |
26 #include <SoundPlayer.h> | |
27 | |
1367
e440d5c488c1
Fixes for BeOS and Solaris builds
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
28 #include "../../main/beos/SDL_BeApp.h" |
0 | 29 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
30 extern "C" |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
31 { |
0 | 32 |
33 #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
|
34 #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
|
35 #include "../SDL_sysaudio.h" |
1367
e440d5c488c1
Fixes for BeOS and Solaris builds
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
36 #include "../../thread/beos/SDL_systhread_c.h" |
0 | 37 #include "SDL_beaudio.h" |
38 | |
39 | |
40 /* Audio driver functions */ | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
41 static int BE_OpenAudio(_THIS, SDL_AudioSpec * spec); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
42 static void BE_WaitAudio(_THIS); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
43 static void BE_PlayAudio(_THIS); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
44 static Uint8 *BE_GetAudioBuf(_THIS); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
45 static void BE_CloseAudio(_THIS); |
0 | 46 |
47 /* Audio driver bootstrap functions */ | |
48 | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
49 static int Audio_Available(void) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
50 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
51 return (1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
52 } |
0 | 53 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
54 static void Audio_DeleteDevice(SDL_AudioDevice * device) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
55 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
56 SDL_free(device->hidden); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
57 SDL_free(device); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
58 } |
0 | 59 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
60 static SDL_AudioDevice *Audio_CreateDevice(int devindex) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
61 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
62 SDL_AudioDevice *device; |
0 | 63 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
64 /* Initialize all variables that we clean on shutdown */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
65 device = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice)); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
66 if (device) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
67 SDL_memset(device, 0, (sizeof *device)); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
68 device->hidden = (struct SDL_PrivateAudioData *) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
69 SDL_malloc((sizeof *device->hidden)); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
70 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
71 if ((device == NULL) || (device->hidden == NULL)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
72 SDL_OutOfMemory(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
73 if (device) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
74 SDL_free(device); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
75 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
76 return (0); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
77 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
78 SDL_memset(device->hidden, 0, (sizeof *device->hidden)); |
0 | 79 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
80 /* Set the function pointers */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
81 device->OpenAudio = BE_OpenAudio; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
82 device->WaitAudio = BE_WaitAudio; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
83 device->PlayAudio = BE_PlayAudio; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
84 device->GetAudioBuf = BE_GetAudioBuf; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
85 device->CloseAudio = BE_CloseAudio; |
0 | 86 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
87 device->free = Audio_DeleteDevice; |
0 | 88 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
89 return device; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
90 } |
0 | 91 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
92 AudioBootStrap BAUDIO_bootstrap = { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
93 "baudio", "BeOS BSoundPlayer", |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
94 Audio_Available, Audio_CreateDevice |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
95 }; |
0 | 96 |
97 /* The BeOS callback for handling the audio buffer */ | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
98 static void FillSound(void *device, void *stream, size_t len, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
99 const media_raw_audio_format & format) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
100 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
101 SDL_AudioDevice *audio = (SDL_AudioDevice *) device; |
0 | 102 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
103 /* Silence the buffer, since it's ours */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
104 SDL_memset(stream, audio->spec.silence, len); |
0 | 105 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
106 /* Only do soemthing if audio is enabled */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
107 if (!audio->enabled) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
108 return; |
0 | 109 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
110 if (!audio->paused) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
111 if (audio->convert.needed) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
112 SDL_mutexP(audio->mixer_lock); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
113 (*audio->spec.callback) (audio->spec.userdata, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
114 (Uint8 *) audio->convert.buf, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
115 audio->convert.len); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
116 SDL_mutexV(audio->mixer_lock); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
117 SDL_ConvertAudio(&audio->convert); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
118 SDL_memcpy(stream, audio->convert.buf, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
119 audio->convert.len_cvt); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
120 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
121 SDL_mutexP(audio->mixer_lock); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
122 (*audio->spec.callback) (audio->spec.userdata, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
123 (Uint8 *) stream, len); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
124 SDL_mutexV(audio->mixer_lock); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
125 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
126 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
127 return; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
128 } |
0 | 129 |
130 /* Dummy functions -- we don't use thread-based audio */ | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
131 void BE_WaitAudio(_THIS) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
132 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
133 return; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
134 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
135 void BE_PlayAudio(_THIS) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
136 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
137 return; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
138 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
139 Uint8 *BE_GetAudioBuf(_THIS) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
140 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
141 return (NULL); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
142 } |
0 | 143 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
144 void BE_CloseAudio(_THIS) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
145 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
146 if (audio_obj) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
147 audio_obj->Stop(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
148 delete audio_obj; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
149 audio_obj = NULL; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
150 } |
0 | 151 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
152 /* Quit the Be Application, if there's nothing left to do */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
153 SDL_QuitBeApp(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
154 } |
0 | 155 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
156 int BE_OpenAudio(_THIS, SDL_AudioSpec * spec) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
157 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
158 media_raw_audio_format format; |
1997
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
159 SDL_AudioFormat test_format = SDL_FirstAudioFormat(spec->format); |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
160 int valid_datatype = 0; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
161 |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
162 /* Parse the audio format and fill the Be raw audio format */ |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
163 memset(&format, '\0', sizeof (media_raw_audio_format)); |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
164 format.byte_order = B_MEDIA_LITTLE_ENDIAN; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
165 format.frame_rate = (float) spec->freq; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
166 format.channel_count = spec->channels; /* !!! FIXME: support > 2? */ |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
167 while ((!valid_datatype) && (test_format)) { |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
168 spec->format = test_format; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
169 switch (test_format) { |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
170 case AUDIO_S8: |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
171 valid_datatype = 1; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
172 format.format = media_raw_audio_format::B_AUDIO_CHAR; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
173 break; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
174 |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
175 case AUDIO_U8: |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
176 valid_datatype = 1; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
177 format.format = media_raw_audio_format::B_AUDIO_UCHAR; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
178 break; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
179 |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
180 case AUDIO_S16LSB: |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
181 valid_datatype = 1; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
182 format.format = media_raw_audio_format::B_AUDIO_SHORT; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
183 break; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
184 |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
185 case AUDIO_S16MSB: |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
186 valid_datatype = 1; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
187 format.format = media_raw_audio_format::B_AUDIO_SHORT; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
188 format.byte_order = B_MEDIA_BIG_ENDIAN; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
189 break; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
190 |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
191 case AUDIO_S32LSB: |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
192 valid_datatype = 1; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
193 format.format = media_raw_audio_format::B_AUDIO_INT; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
194 break; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
195 |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
196 case AUDIO_S32MSB: |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
197 valid_datatype = 1; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
198 format.format = media_raw_audio_format::B_AUDIO_INT; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
199 format.byte_order = B_MEDIA_BIG_ENDIAN; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
200 break; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
201 |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
202 case AUDIO_F32LSB: |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
203 valid_datatype = 1; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
204 format.format = media_raw_audio_format::B_AUDIO_FLOAT; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
205 break; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
206 |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
207 case AUDIO_F32MSB: |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
208 valid_datatype = 1; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
209 format.format = media_raw_audio_format::B_AUDIO_FLOAT; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
210 format.byte_order = B_MEDIA_BIG_ENDIAN; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
211 break; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
212 |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
213 default: |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
214 test_format = SDL_NextAudioFormat(); |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
215 break; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
216 } |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
217 } |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
218 |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
219 format.buffer_size = spec->samples; |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
220 |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
221 if (!valid_datatype) { /* shouldn't happen, but just in case... */ |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
222 SDL_SetError("Unsupported audio format"); |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
223 return (-1); |
46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents:
1895
diff
changeset
|
224 } |
0 | 225 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
226 /* Initialize the Be Application, if it's not already started */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
227 if (SDL_InitBeApp() < 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
228 return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
229 } |
0 | 230 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
231 /* Calculate the final parameters for this audio specification */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
232 SDL_CalculateAudioSpec(spec); |
0 | 233 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
234 /* Subscribe to the audio stream (creates a new thread) */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
235 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
236 sigset_t omask; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
237 SDL_MaskSignals(&omask); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
238 audio_obj = new BSoundPlayer(&format, "SDL Audio", FillSound, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
239 NULL, _this); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
240 SDL_UnmaskSignals(&omask); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
241 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
242 if (audio_obj->Start() == B_NO_ERROR) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
243 audio_obj->SetHasData(true); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
244 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
245 SDL_SetError("Unable to start Be audio"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
246 return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
247 } |
0 | 248 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
249 /* We're running! */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
250 return (1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
251 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
252 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
253 }; /* Extern C */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
254 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1403
diff
changeset
|
255 /* vi: set ts=4 sw=4 expandtab: */ |