Mercurial > sdl-ios-xcode
annotate src/audio/baudio/SDL_beaudio.cc @ 1323:be736c197ceb
Fixed compile warning
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 03 Feb 2006 06:01:23 +0000 |
parents | c9b51268668f |
children | 3692456e7b0f |
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 */ |
22 | |
23 /* Allow access to the audio stream on BeOS */ | |
24 | |
25 #include <stdlib.h> | |
26 #include <stdio.h> | |
27 #include <string.h> | |
28 #include <SoundPlayer.h> | |
29 | |
30 #include "SDL_BeApp.h" | |
31 | |
32 extern "C" { | |
33 | |
34 #include "SDL_audio.h" | |
35 #include "SDL_audio_c.h" | |
36 #include "SDL_sysaudio.h" | |
37 #include "SDL_systhread_c.h" | |
38 #include "SDL_beaudio.h" | |
39 | |
40 | |
41 /* Audio driver functions */ | |
42 static int BE_OpenAudio(_THIS, SDL_AudioSpec *spec); | |
43 static void BE_WaitAudio(_THIS); | |
44 static void BE_PlayAudio(_THIS); | |
45 static Uint8 *BE_GetAudioBuf(_THIS); | |
46 static void BE_CloseAudio(_THIS); | |
47 | |
48 /* Audio driver bootstrap functions */ | |
49 | |
50 static int Audio_Available(void) | |
51 { | |
52 return(1); | |
53 } | |
54 | |
55 static void Audio_DeleteDevice(SDL_AudioDevice *device) | |
56 { | |
57 free(device->hidden); | |
58 free(device); | |
59 } | |
60 | |
61 static SDL_AudioDevice *Audio_CreateDevice(int devindex) | |
62 { | |
63 SDL_AudioDevice *device; | |
64 | |
65 /* Initialize all variables that we clean on shutdown */ | |
66 device = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice)); | |
67 if ( device ) { | |
68 memset(device, 0, (sizeof *device)); | |
69 device->hidden = (struct SDL_PrivateAudioData *) | |
70 malloc((sizeof *device->hidden)); | |
71 } | |
72 if ( (device == NULL) || (device->hidden == NULL) ) { | |
73 SDL_OutOfMemory(); | |
74 if ( device ) { | |
75 free(device); | |
76 } | |
77 return(0); | |
78 } | |
79 memset(device->hidden, 0, (sizeof *device->hidden)); | |
80 | |
81 /* Set the function pointers */ | |
82 device->OpenAudio = BE_OpenAudio; | |
83 device->WaitAudio = BE_WaitAudio; | |
84 device->PlayAudio = BE_PlayAudio; | |
85 device->GetAudioBuf = BE_GetAudioBuf; | |
86 device->CloseAudio = BE_CloseAudio; | |
87 | |
88 device->free = Audio_DeleteDevice; | |
89 | |
90 return device; | |
91 } | |
92 | |
93 AudioBootStrap BAUDIO_bootstrap = { | |
94 "baudio", "BeOS BSoundPlayer", | |
95 Audio_Available, Audio_CreateDevice | |
96 }; | |
97 | |
98 /* The BeOS callback for handling the audio buffer */ | |
99 static void FillSound(void *device, void *stream, size_t len, | |
100 const media_raw_audio_format &format) | |
101 { | |
102 SDL_AudioDevice *audio = (SDL_AudioDevice *)device; | |
103 | |
104 /* Silence the buffer, since it's ours */ | |
105 memset(stream, audio->spec.silence, len); | |
106 | |
107 /* Only do soemthing if audio is enabled */ | |
108 if ( ! audio->enabled ) | |
109 return; | |
110 | |
111 if ( ! audio->paused ) { | |
112 if ( audio->convert.needed ) { | |
113 SDL_mutexP(audio->mixer_lock); | |
114 (*audio->spec.callback)(audio->spec.userdata, | |
115 (Uint8 *)audio->convert.buf,audio->convert.len); | |
116 SDL_mutexV(audio->mixer_lock); | |
117 SDL_ConvertAudio(&audio->convert); | |
118 memcpy(stream,audio->convert.buf,audio->convert.len_cvt); | |
119 } else { | |
120 SDL_mutexP(audio->mixer_lock); | |
121 (*audio->spec.callback)(audio->spec.userdata, | |
122 (Uint8 *)stream, len); | |
123 SDL_mutexV(audio->mixer_lock); | |
124 } | |
125 } | |
126 return; | |
127 } | |
128 | |
129 /* Dummy functions -- we don't use thread-based audio */ | |
130 void BE_WaitAudio(_THIS) | |
131 { | |
132 return; | |
133 } | |
134 void BE_PlayAudio(_THIS) | |
135 { | |
136 return; | |
137 } | |
138 Uint8 *BE_GetAudioBuf(_THIS) | |
139 { | |
140 return(NULL); | |
141 } | |
142 | |
143 void BE_CloseAudio(_THIS) | |
144 { | |
145 if ( audio_obj ) { | |
146 audio_obj->Stop(); | |
147 delete audio_obj; | |
148 audio_obj = NULL; | |
149 } | |
150 | |
151 /* Quit the Be Application, if there's nothing left to do */ | |
152 SDL_QuitBeApp(); | |
153 } | |
154 | |
155 int BE_OpenAudio(_THIS, SDL_AudioSpec *spec) | |
156 { | |
157 media_raw_audio_format format; | |
158 | |
159 /* Initialize the Be Application, if it's not already started */ | |
160 if ( SDL_InitBeApp() < 0 ) { | |
161 return(-1); | |
162 } | |
163 | |
164 /* Parse the audio format and fill the Be raw audio format */ | |
165 format.frame_rate = (float)spec->freq; | |
166 format.channel_count = spec->channels; | |
167 switch (spec->format&~0x1000) { | |
168 case AUDIO_S8: | |
169 /* Signed 8-bit audio unsupported, convert to U8 */ | |
170 spec->format = AUDIO_U8; | |
171 case AUDIO_U8: | |
172 format.format = media_raw_audio_format::B_AUDIO_UCHAR; | |
173 format.byte_order = 0; | |
174 break; | |
175 case AUDIO_U16: | |
176 /* Unsigned 16-bit audio unsupported, convert to S16 */ | |
177 spec->format ^= 0x8000; | |
178 case AUDIO_S16: | |
179 format.format = media_raw_audio_format::B_AUDIO_SHORT; | |
180 if ( spec->format & 0x1000 ) { | |
181 format.byte_order = 1; /* Big endian */ | |
182 } else { | |
183 format.byte_order = 2; /* Little endian */ | |
184 } | |
185 break; | |
186 } | |
187 format.buffer_size = spec->samples; | |
188 | |
189 /* Calculate the final parameters for this audio specification */ | |
190 SDL_CalculateAudioSpec(spec); | |
191 | |
192 /* Subscribe to the audio stream (creates a new thread) */ | |
193 { sigset_t omask; | |
194 SDL_MaskSignals(&omask); | |
195 audio_obj = new BSoundPlayer(&format, "SDL Audio", FillSound, | |
196 NULL, _this); | |
197 SDL_UnmaskSignals(&omask); | |
198 } | |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
199 if ( audio_obj->Start() == B_NO_ERROR ) { |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
200 audio_obj->SetHasData(true); |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
201 } else { |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
202 SDL_SetError("Unable to start Be audio"); |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
203 return(-1); |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
204 } |
0 | 205 |
206 /* We're running! */ | |
207 return(1); | |
208 } | |
209 | |
210 }; /* Extern C */ |