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