Mercurial > sdl-ios-xcode
comparison src/audio/baudio/SDL_beaudio.cc @ 3837:7c9663fb0860 SDL-ryan-multiple-audio-device
BeOS audio now works in 1.3 branch.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sun, 08 Oct 2006 01:39:01 +0000 |
parents | 29e83f221c62 |
children | 66fb40445587 |
comparison
equal
deleted
inserted
replaced
3836:7dc7327cd626 | 3837:7c9663fb0860 |
---|---|
37 #include "SDL_beaudio.h" | 37 #include "SDL_beaudio.h" |
38 | 38 |
39 } | 39 } |
40 | 40 |
41 | 41 |
42 static int BEAUDIO_Available(void) | 42 static int BEOSAUDIO_Available(void) |
43 { | 43 { |
44 return 1; /* Always available on BeOS. */ | 44 return 1; /* Always available on BeOS. */ |
45 } | 45 } |
46 | 46 |
47 | 47 |
77 } | 77 } |
78 } | 78 } |
79 } | 79 } |
80 | 80 |
81 static void | 81 static void |
82 BEAUDIO_CloseDevice(_THIS) | 82 BEOSAUDIO_CloseDevice(_THIS) |
83 { | 83 { |
84 if (_this->hidden != NULL) { | 84 if (_this->hidden != NULL) { |
85 if (_this->hidden->audio_obj) { | 85 if (_this->hidden->audio_obj) { |
86 _this->hidden->audio_obj->Stop(); | 86 _this->hidden->audio_obj->Stop(); |
87 delete _this->hidden->audio_obj; | 87 delete _this->hidden->audio_obj; |
88 _this->hidden->audio_obj = NULL; | 88 _this->hidden->audio_obj = NULL; |
89 } | 89 } |
90 | 90 |
91 delete _this->hidden; | 91 delete _this->hidden; |
92 _this->hidden = NULL; | 92 _this->hidden = NULL; |
93 | |
94 /* Quit the Be Application, if there's nothing left to do */ | |
95 SDL_QuitBeApp(); | |
96 } | 93 } |
97 } | 94 } |
98 | 95 |
99 static int | 96 static int |
100 BEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) | 97 BEOSAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) |
101 { | 98 { |
102 int valid_datatype = 0; | 99 int valid_datatype = 0; |
103 media_raw_audio_format format; | 100 media_raw_audio_format format; |
104 SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format); | 101 SDL_AudioFormat test_format = SDL_FirstAudioFormat(_this->spec.format); |
105 | 102 |
106 /* Initialize all variables that we clean on shutdown */ | 103 /* Initialize all variables that we clean on shutdown */ |
107 _this->hidden = new SDL_PrivateAudioData; | 104 _this->hidden = new SDL_PrivateAudioData; |
108 if (_this->hidden == NULL) { | 105 if (_this->hidden == NULL) { |
109 SDL_OutOfMemory(); | 106 SDL_OutOfMemory(); |
110 return 0; | 107 return 0; |
111 } | 108 } |
112 SDL_memset(_this->hidden, 0, (sizeof *_this->hidden)); | 109 SDL_memset(_this->hidden, 0, (sizeof *_this->hidden)); |
113 | 110 |
114 /* Initialize the Be Application, if it's not already started */ | |
115 if (SDL_InitBeApp() < 0) { | |
116 return 0; | |
117 } | |
118 | |
119 /* Parse the audio format and fill the Be raw audio format */ | 111 /* Parse the audio format and fill the Be raw audio format */ |
120 SDL_memset(&format, '\0', sizeof(media_raw_audio_format)); | 112 SDL_memset(&format, '\0', sizeof(media_raw_audio_format)); |
121 format.byte_order = B_MEDIA_LITTLE_ENDIAN; | 113 format.byte_order = B_MEDIA_LITTLE_ENDIAN; |
122 format.frame_rate = (float) this->spec.freq; | 114 format.frame_rate = (float) _this->spec.freq; |
123 format.channel_count = this->spec.channels; /* !!! FIXME: support > 2? */ | 115 format.channel_count = _this->spec.channels; /* !!! FIXME: support > 2? */ |
124 while ((!valid_datatype) && (test_format)) { | 116 while ((!valid_datatype) && (test_format)) { |
125 valid_datatype = 1; | 117 valid_datatype = 1; |
126 this->spec.format = test_format; | 118 _this->spec.format = test_format; |
127 switch (test_format) { | 119 switch (test_format) { |
128 case AUDIO_S8: | 120 case AUDIO_S8: |
129 format.format = media_raw_audio_format::B_AUDIO_CHAR; | 121 format.format = media_raw_audio_format::B_AUDIO_CHAR; |
130 break; | 122 break; |
131 | 123 |
165 test_format = SDL_NextAudioFormat(); | 157 test_format = SDL_NextAudioFormat(); |
166 break; | 158 break; |
167 } | 159 } |
168 } | 160 } |
169 | 161 |
170 format.buffer_size = this->spec.samples; | 162 format.buffer_size = _this->spec.samples; |
171 | 163 |
172 if (!valid_datatype) { /* shouldn't happen, but just in case... */ | 164 if (!valid_datatype) { /* shouldn't happen, but just in case... */ |
165 BEOSAUDIO_CloseDevice(_this); | |
173 SDL_SetError("Unsupported audio format"); | 166 SDL_SetError("Unsupported audio format"); |
174 return 0; | 167 return 0; |
175 } | 168 } |
176 | 169 |
177 /* Calculate the final parameters for this audio specification */ | 170 /* Calculate the final parameters for this audio specification */ |
178 SDL_CalculateAudioSpec(&this->spec); | 171 SDL_CalculateAudioSpec(&_this->spec); |
179 | 172 |
180 /* Subscribe to the audio stream (creates a new thread) */ | 173 /* Subscribe to the audio stream (creates a new thread) */ |
181 sigset_t omask; | 174 sigset_t omask; |
182 SDL_MaskSignals(&omask); | 175 SDL_MaskSignals(&omask); |
183 _this->hidden->audio_obj = new BSoundPlayer(&format, "SDL Audio", | 176 _this->hidden->audio_obj = new BSoundPlayer(&format, "SDL Audio", |
185 SDL_UnmaskSignals(&omask); | 178 SDL_UnmaskSignals(&omask); |
186 | 179 |
187 if (_this->hidden->audio_obj->Start() == B_NO_ERROR) { | 180 if (_this->hidden->audio_obj->Start() == B_NO_ERROR) { |
188 _this->hidden->audio_obj->SetHasData(true); | 181 _this->hidden->audio_obj->SetHasData(true); |
189 } else { | 182 } else { |
183 BEOSAUDIO_CloseDevice(_this); | |
190 SDL_SetError("Unable to start Be audio"); | 184 SDL_SetError("Unable to start Be audio"); |
191 return 0; | 185 return 0; |
192 } | 186 } |
193 | 187 |
194 /* We're running! */ | 188 /* We're running! */ |
195 return 1; | 189 return 1; |
196 } | 190 } |
197 | 191 |
192 static void | |
193 BEOSAUDIO_Deinitialize(void) | |
194 { | |
195 SDL_QuitBeApp(); | |
196 } | |
197 | |
198 static int | 198 static int |
199 BEAUDIO_Init(SDL_AudioDriverImpl *impl) | 199 BEOSAUDIO_Init(SDL_AudioDriverImpl *impl) |
200 { | 200 { |
201 /* Initialize the Be Application, if it's not already started */ | |
202 if (SDL_InitBeApp() < 0) { | |
203 return 0; | |
204 } | |
205 | |
201 /* Set the function pointers */ | 206 /* Set the function pointers */ |
202 impl->OpenDevice = DSP_OpenDevice; | 207 impl->OpenDevice = BEOSAUDIO_OpenDevice; |
203 impl->CloseDevice = DSP_CloseDevice; | 208 impl->CloseDevice = BEOSAUDIO_CloseDevice; |
209 impl->Deinitialize = BEOSAUDIO_Deinitialize; | |
204 impl->ProvidesOwnCallbackThread = 1; | 210 impl->ProvidesOwnCallbackThread = 1; |
205 impl->OnlyHasDefaultOutputDevice = 1; | 211 impl->OnlyHasDefaultOutputDevice = 1; |
206 | 212 |
207 return 1; | 213 return 1; |
208 } | 214 } |
209 | 215 |
210 | 216 extern "C" { extern AudioBootStrap BEOSAUDIO_bootstrap; } |
211 AudioBootStrap BEAUDIO_bootstrap = { | 217 AudioBootStrap BEOSAUDIO_bootstrap = { |
212 "baudio", "BeOS BSoundPlayer", | 218 "baudio", "BeOS BSoundPlayer", |
213 BEAUDIO_Available, BEAUDIO_Init, 0 | 219 BEOSAUDIO_Available, BEOSAUDIO_Init, 0 |
214 }; | 220 }; |
215 | 221 |
216 /* vi: set ts=4 sw=4 expandtab: */ | 222 /* vi: set ts=4 sw=4 expandtab: */ |
223 |