comparison src/audio/baudio/SDL_beaudio.cc @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
36 #include "../../thread/beos/SDL_systhread_c.h" 36 #include "../../thread/beos/SDL_systhread_c.h"
37 #include "SDL_beaudio.h" 37 #include "SDL_beaudio.h"
38 38
39 39
40 /* Audio driver functions */ 40 /* Audio driver functions */
41 static int BE_OpenAudio (_THIS, SDL_AudioSpec * spec); 41 static int BE_OpenAudio(_THIS, SDL_AudioSpec * spec);
42 static void BE_WaitAudio (_THIS); 42 static void BE_WaitAudio(_THIS);
43 static void BE_PlayAudio (_THIS); 43 static void BE_PlayAudio(_THIS);
44 static Uint8 *BE_GetAudioBuf (_THIS); 44 static Uint8 *BE_GetAudioBuf(_THIS);
45 static void BE_CloseAudio (_THIS); 45 static void BE_CloseAudio(_THIS);
46 46
47 /* Audio driver bootstrap functions */ 47 /* Audio driver bootstrap functions */
48 48
49 static int Audio_Available (void) 49 static int Audio_Available(void)
50 { 50 {
51 return (1); 51 return (1);
52 } 52 }
53 53
54 static void Audio_DeleteDevice (SDL_AudioDevice * device) 54 static void Audio_DeleteDevice(SDL_AudioDevice * device)
55 { 55 {
56 SDL_free (device->hidden); 56 SDL_free(device->hidden);
57 SDL_free (device); 57 SDL_free(device);
58 } 58 }
59 59
60 static SDL_AudioDevice *Audio_CreateDevice (int devindex) 60 static SDL_AudioDevice *Audio_CreateDevice(int devindex)
61 { 61 {
62 SDL_AudioDevice *device; 62 SDL_AudioDevice *device;
63 63
64 /* Initialize all variables that we clean on shutdown */ 64 /* Initialize all variables that we clean on shutdown */
65 device = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); 65 device = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
66 if (device) { 66 if (device) {
67 SDL_memset (device, 0, (sizeof *device)); 67 SDL_memset(device, 0, (sizeof *device));
68 device->hidden = (struct SDL_PrivateAudioData *) 68 device->hidden = (struct SDL_PrivateAudioData *)
69 SDL_malloc ((sizeof *device->hidden)); 69 SDL_malloc((sizeof *device->hidden));
70 } 70 }
71 if ((device == NULL) || (device->hidden == NULL)) { 71 if ((device == NULL) || (device->hidden == NULL)) {
72 SDL_OutOfMemory (); 72 SDL_OutOfMemory();
73 if (device) { 73 if (device) {
74 SDL_free (device); 74 SDL_free(device);
75 } 75 }
76 return (0); 76 return (0);
77 } 77 }
78 SDL_memset (device->hidden, 0, (sizeof *device->hidden)); 78 SDL_memset(device->hidden, 0, (sizeof *device->hidden));
79 79
80 /* Set the function pointers */ 80 /* Set the function pointers */
81 device->OpenAudio = BE_OpenAudio; 81 device->OpenAudio = BE_OpenAudio;
82 device->WaitAudio = BE_WaitAudio; 82 device->WaitAudio = BE_WaitAudio;
83 device->PlayAudio = BE_PlayAudio; 83 device->PlayAudio = BE_PlayAudio;
93 "baudio", "BeOS BSoundPlayer", 93 "baudio", "BeOS BSoundPlayer",
94 Audio_Available, Audio_CreateDevice 94 Audio_Available, Audio_CreateDevice
95 }; 95 };
96 96
97 /* The BeOS callback for handling the audio buffer */ 97 /* The BeOS callback for handling the audio buffer */
98 static void FillSound (void *device, void *stream, size_t len, 98 static void FillSound(void *device, void *stream, size_t len,
99 const media_raw_audio_format & format) 99 const media_raw_audio_format & format)
100 { 100 {
101 SDL_AudioDevice *audio = (SDL_AudioDevice *) device; 101 SDL_AudioDevice *audio = (SDL_AudioDevice *) device;
102 102
103 /* Silence the buffer, since it's ours */ 103 /* Silence the buffer, since it's ours */
104 SDL_memset (stream, audio->spec.silence, len); 104 SDL_memset(stream, audio->spec.silence, len);
105 105
106 /* Only do soemthing if audio is enabled */ 106 /* Only do soemthing if audio is enabled */
107 if (!audio->enabled) 107 if (!audio->enabled)
108 return; 108 return;
109 109
110 if (!audio->paused) { 110 if (!audio->paused) {
111 if (audio->convert.needed) { 111 if (audio->convert.needed) {
112 SDL_mutexP (audio->mixer_lock); 112 SDL_mutexP(audio->mixer_lock);
113 (*audio->spec.callback) (audio->spec.userdata, 113 (*audio->spec.callback) (audio->spec.userdata,
114 (Uint8 *) audio->convert.buf, 114 (Uint8 *) audio->convert.buf,
115 audio->convert.len); 115 audio->convert.len);
116 SDL_mutexV (audio->mixer_lock); 116 SDL_mutexV(audio->mixer_lock);
117 SDL_ConvertAudio (&audio->convert); 117 SDL_ConvertAudio(&audio->convert);
118 SDL_memcpy (stream, audio->convert.buf, 118 SDL_memcpy(stream, audio->convert.buf,
119 audio->convert.len_cvt); 119 audio->convert.len_cvt);
120 } else { 120 } else {
121 SDL_mutexP (audio->mixer_lock); 121 SDL_mutexP(audio->mixer_lock);
122 (*audio->spec.callback) (audio->spec.userdata, 122 (*audio->spec.callback) (audio->spec.userdata,
123 (Uint8 *) stream, len); 123 (Uint8 *) stream, len);
124 SDL_mutexV (audio->mixer_lock); 124 SDL_mutexV(audio->mixer_lock);
125 } 125 }
126 } 126 }
127 return; 127 return;
128 } 128 }
129 129
130 /* Dummy functions -- we don't use thread-based audio */ 130 /* Dummy functions -- we don't use thread-based audio */
131 void BE_WaitAudio (_THIS) 131 void BE_WaitAudio(_THIS)
132 { 132 {
133 return; 133 return;
134 } 134 }
135 void BE_PlayAudio (_THIS) 135 void BE_PlayAudio(_THIS)
136 { 136 {
137 return; 137 return;
138 } 138 }
139 Uint8 *BE_GetAudioBuf (_THIS) 139 Uint8 *BE_GetAudioBuf(_THIS)
140 { 140 {
141 return (NULL); 141 return (NULL);
142 } 142 }
143 143
144 void BE_CloseAudio (_THIS) 144 void BE_CloseAudio(_THIS)
145 { 145 {
146 if (audio_obj) { 146 if (audio_obj) {
147 audio_obj->Stop (); 147 audio_obj->Stop();
148 delete audio_obj; 148 delete audio_obj;
149 audio_obj = NULL; 149 audio_obj = NULL;
150 } 150 }
151 151
152 /* Quit the Be Application, if there's nothing left to do */ 152 /* Quit the Be Application, if there's nothing left to do */
153 SDL_QuitBeApp (); 153 SDL_QuitBeApp();
154 } 154 }
155 155
156 int BE_OpenAudio (_THIS, SDL_AudioSpec * spec) 156 int BE_OpenAudio(_THIS, SDL_AudioSpec * spec)
157 { 157 {
158 media_raw_audio_format format; 158 media_raw_audio_format format;
159 159
160 /* Initialize the Be Application, if it's not already started */ 160 /* Initialize the Be Application, if it's not already started */
161 if (SDL_InitBeApp () < 0) { 161 if (SDL_InitBeApp() < 0) {
162 return (-1); 162 return (-1);
163 } 163 }
164 164
165 /* Parse the audio format and fill the Be raw audio format */ 165 /* Parse the audio format and fill the Be raw audio format */
166 format.frame_rate = (float) spec->freq; 166 format.frame_rate = (float) spec->freq;
186 break; 186 break;
187 } 187 }
188 format.buffer_size = spec->samples; 188 format.buffer_size = spec->samples;
189 189
190 /* Calculate the final parameters for this audio specification */ 190 /* Calculate the final parameters for this audio specification */
191 SDL_CalculateAudioSpec (spec); 191 SDL_CalculateAudioSpec(spec);
192 192
193 /* Subscribe to the audio stream (creates a new thread) */ 193 /* Subscribe to the audio stream (creates a new thread) */
194 { 194 {
195 sigset_t omask; 195 sigset_t omask;
196 SDL_MaskSignals (&omask); 196 SDL_MaskSignals(&omask);
197 audio_obj = new BSoundPlayer (&format, "SDL Audio", FillSound, 197 audio_obj = new BSoundPlayer(&format, "SDL Audio", FillSound,
198 NULL, _this); 198 NULL, _this);
199 SDL_UnmaskSignals (&omask); 199 SDL_UnmaskSignals(&omask);
200 } 200 }
201 if (audio_obj->Start () == B_NO_ERROR) { 201 if (audio_obj->Start() == B_NO_ERROR) {
202 audio_obj->SetHasData (true); 202 audio_obj->SetHasData(true);
203 } else { 203 } else {
204 SDL_SetError ("Unable to start Be audio"); 204 SDL_SetError("Unable to start Be audio");
205 return (-1); 205 return (-1);
206 } 206 }
207 207
208 /* We're running! */ 208 /* We're running! */
209 return (1); 209 return (1);