Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
214 lines (179 loc) · 6.42 KB

SDL_beaudio.cc

File metadata and controls

214 lines (179 loc) · 6.42 KB
 
Apr 26, 2001
Apr 26, 2001
1
2
/*
SDL - Simple DirectMedia Layer
Feb 1, 2006
Feb 1, 2006
3
Copyright (C) 1997-2006 Sam Lantinga
Apr 26, 2001
Apr 26, 2001
4
5
This library is free software; you can redistribute it and/or
Feb 1, 2006
Feb 1, 2006
6
modify it under the terms of the GNU Lesser General Public
Apr 26, 2001
Apr 26, 2001
7
License as published by the Free Software Foundation; either
Feb 1, 2006
Feb 1, 2006
8
version 2.1 of the License, or (at your option) any later version.
Apr 26, 2001
Apr 26, 2001
9
10
11
12
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Feb 1, 2006
Feb 1, 2006
13
Lesser General Public License for more details.
Apr 26, 2001
Apr 26, 2001
14
Feb 1, 2006
Feb 1, 2006
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Apr 26, 2001
Apr 26, 2001
18
19
Sam Lantinga
Dec 14, 2001
Dec 14, 2001
20
slouken@libsdl.org
Apr 26, 2001
Apr 26, 2001
21
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Apr 26, 2001
Apr 26, 2001
23
24
25
26
27
/* Allow access to the audio stream on BeOS */
#include <SoundPlayer.h>
Feb 17, 2006
Feb 17, 2006
28
#include "../../main/beos/SDL_BeApp.h"
Apr 26, 2001
Apr 26, 2001
29
Jul 10, 2006
Jul 10, 2006
30
31
extern "C"
{
Apr 26, 2001
Apr 26, 2001
32
33
#include "SDL_audio.h"
Feb 16, 2006
Feb 16, 2006
34
35
#include "../SDL_audio_c.h"
#include "../SDL_sysaudio.h"
Feb 17, 2006
Feb 17, 2006
36
#include "../../thread/beos/SDL_systhread_c.h"
Apr 26, 2001
Apr 26, 2001
37
38
39
40
#include "SDL_beaudio.h"
/* Audio driver functions */
Jul 10, 2006
Jul 10, 2006
41
42
43
44
45
static int BE_OpenAudio(_THIS, SDL_AudioSpec * spec);
static void BE_WaitAudio(_THIS);
static void BE_PlayAudio(_THIS);
static Uint8 *BE_GetAudioBuf(_THIS);
static void BE_CloseAudio(_THIS);
Apr 26, 2001
Apr 26, 2001
46
47
48
/* Audio driver bootstrap functions */
Jul 10, 2006
Jul 10, 2006
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
static int Audio_Available(void)
{
return (1);
}
static void Audio_DeleteDevice(SDL_AudioDevice * device)
{
SDL_free(device->hidden);
SDL_free(device);
}
static SDL_AudioDevice *Audio_CreateDevice(int devindex)
{
SDL_AudioDevice *device;
/* Initialize all variables that we clean on shutdown */
device = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
if (device) {
SDL_memset(device, 0, (sizeof *device));
device->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *device->hidden));
}
if ((device == NULL) || (device->hidden == NULL)) {
SDL_OutOfMemory();
if (device) {
SDL_free(device);
}
return (0);
}
SDL_memset(device->hidden, 0, (sizeof *device->hidden));
/* Set the function pointers */
device->OpenAudio = BE_OpenAudio;
device->WaitAudio = BE_WaitAudio;
device->PlayAudio = BE_PlayAudio;
device->GetAudioBuf = BE_GetAudioBuf;
device->CloseAudio = BE_CloseAudio;
device->free = Audio_DeleteDevice;
return device;
}
AudioBootStrap BAUDIO_bootstrap = {
"baudio", "BeOS BSoundPlayer",
Audio_Available, Audio_CreateDevice
};
Apr 26, 2001
Apr 26, 2001
96
97
/* The BeOS callback for handling the audio buffer */
Jul 10, 2006
Jul 10, 2006
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
static void FillSound(void *device, void *stream, size_t len,
const media_raw_audio_format & format)
{
SDL_AudioDevice *audio = (SDL_AudioDevice *) device;
/* Silence the buffer, since it's ours */
SDL_memset(stream, audio->spec.silence, len);
/* Only do soemthing if audio is enabled */
if (!audio->enabled)
return;
if (!audio->paused) {
if (audio->convert.needed) {
SDL_mutexP(audio->mixer_lock);
(*audio->spec.callback) (audio->spec.userdata,
(Uint8 *) audio->convert.buf,
audio->convert.len);
SDL_mutexV(audio->mixer_lock);
SDL_ConvertAudio(&audio->convert);
SDL_memcpy(stream, audio->convert.buf,
audio->convert.len_cvt);
} else {
SDL_mutexP(audio->mixer_lock);
(*audio->spec.callback) (audio->spec.userdata,
(Uint8 *) stream, len);
SDL_mutexV(audio->mixer_lock);
}
}
return;
}
Apr 26, 2001
Apr 26, 2001
129
130
/* Dummy functions -- we don't use thread-based audio */
Jul 10, 2006
Jul 10, 2006
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
void BE_WaitAudio(_THIS)
{
return;
}
void BE_PlayAudio(_THIS)
{
return;
}
Uint8 *BE_GetAudioBuf(_THIS)
{
return (NULL);
}
void BE_CloseAudio(_THIS)
{
if (audio_obj) {
audio_obj->Stop();
delete audio_obj;
audio_obj = NULL;
}
/* Quit the Be Application, if there's nothing left to do */
SDL_QuitBeApp();
}
int BE_OpenAudio(_THIS, SDL_AudioSpec * spec)
{
media_raw_audio_format format;
/* Initialize the Be Application, if it's not already started */
if (SDL_InitBeApp() < 0) {
return (-1);
}
/* Parse the audio format and fill the Be raw audio format */
format.frame_rate = (float) spec->freq;
format.channel_count = spec->channels;
switch (spec->format & ~0x1000) {
case AUDIO_S8:
/* Signed 8-bit audio unsupported, convert to U8 */
spec->format = AUDIO_U8;
case AUDIO_U8:
format.format = media_raw_audio_format::B_AUDIO_UCHAR;
format.byte_order = 0;
break;
case AUDIO_U16:
/* Unsigned 16-bit audio unsupported, convert to S16 */
spec->format ^= 0x8000;
case AUDIO_S16:
format.format = media_raw_audio_format::B_AUDIO_SHORT;
if (spec->format & 0x1000) {
format.byte_order = 1; /* Big endian */
} else {
format.byte_order = 2; /* Little endian */
}
break;
}
format.buffer_size = spec->samples;
/* Calculate the final parameters for this audio specification */
SDL_CalculateAudioSpec(spec);
/* Subscribe to the audio stream (creates a new thread) */
{
sigset_t omask;
SDL_MaskSignals(&omask);
audio_obj = new BSoundPlayer(&format, "SDL Audio", FillSound,
NULL, _this);
SDL_UnmaskSignals(&omask);
}
if (audio_obj->Start() == B_NO_ERROR) {
audio_obj->SetHasData(true);
} else {
SDL_SetError("Unable to start Be audio");
return (-1);
}
/* We're running! */
return (1);
}
}; /* Extern C */
/* vi: set ts=4 sw=4 expandtab: */