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

Latest commit

 

History

History
223 lines (180 loc) · 6.53 KB

SDL_beaudio.cc

File metadata and controls

223 lines (180 loc) · 6.53 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
#include "SDL_beaudio.h"
Oct 6, 2006
Oct 6, 2006
39
}
Apr 26, 2001
Apr 26, 2001
40
41
Oct 8, 2006
Oct 8, 2006
42
static int BEOSAUDIO_Available(void)
Oct 6, 2006
Oct 6, 2006
43
44
45
{
return 1; /* Always available on BeOS. */
}
Jul 10, 2006
Jul 10, 2006
46
47
Oct 6, 2006
Oct 6, 2006
48
49
50
51
52
53
54
/* !!! FIXME: have the callback call the higher level to avoid code dupe. */
/* The BeOS callback for handling the audio buffer */
static void
FillSound(void *device, void *stream, size_t len,
const media_raw_audio_format & format)
{
SDL_AudioDevice *audio = (SDL_AudioDevice *) device;
Jul 10, 2006
Jul 10, 2006
55
Oct 6, 2006
Oct 6, 2006
56
57
/* Silence the buffer, since it's ours */
SDL_memset(stream, audio->spec.silence, len);
Jul 10, 2006
Jul 10, 2006
58
Oct 6, 2006
Oct 6, 2006
59
60
61
/* Only do soemthing if audio is enabled */
if (!audio->enabled)
return;
Apr 26, 2001
Apr 26, 2001
62
Oct 6, 2006
Oct 6, 2006
63
64
65
66
if (!audio->paused) {
if (audio->convert.needed) {
SDL_mutexP(audio->mixer_lock);
(*audio->spec.callback) (audio->spec.userdata,
Jul 10, 2006
Jul 10, 2006
67
68
(Uint8 *) audio->convert.buf,
audio->convert.len);
Oct 6, 2006
Oct 6, 2006
69
70
71
72
73
74
75
76
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);
Jul 10, 2006
Jul 10, 2006
77
78
}
}
Oct 6, 2006
Oct 6, 2006
79
}
Jul 10, 2006
Jul 10, 2006
80
Oct 6, 2006
Oct 6, 2006
81
static void
Oct 8, 2006
Oct 8, 2006
82
BEOSAUDIO_CloseDevice(_THIS)
Oct 6, 2006
Oct 6, 2006
83
84
85
86
87
88
{
if (_this->hidden != NULL) {
if (_this->hidden->audio_obj) {
_this->hidden->audio_obj->Stop();
delete _this->hidden->audio_obj;
_this->hidden->audio_obj = NULL;
Jul 10, 2006
Jul 10, 2006
89
90
}
Oct 6, 2006
Oct 6, 2006
91
92
delete _this->hidden;
_this->hidden = NULL;
Jul 10, 2006
Jul 10, 2006
93
}
Oct 6, 2006
Oct 6, 2006
94
95
96
}
static int
Oct 8, 2006
Oct 8, 2006
97
BEOSAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
Oct 6, 2006
Oct 6, 2006
98
99
100
{
int valid_datatype = 0;
media_raw_audio_format format;
Oct 8, 2006
Oct 8, 2006
101
SDL_AudioFormat test_format = SDL_FirstAudioFormat(_this->spec.format);
Oct 6, 2006
Oct 6, 2006
102
103
104
105
106
107
108
109
/* Initialize all variables that we clean on shutdown */
_this->hidden = new SDL_PrivateAudioData;
if (_this->hidden == NULL) {
SDL_OutOfMemory();
return 0;
}
SDL_memset(_this->hidden, 0, (sizeof *_this->hidden));
Jul 10, 2006
Jul 10, 2006
110
Oct 6, 2006
Oct 6, 2006
111
/* Parse the audio format and fill the Be raw audio format */
Oct 7, 2006
Oct 7, 2006
112
SDL_memset(&format, '\0', sizeof(media_raw_audio_format));
Oct 6, 2006
Oct 6, 2006
113
format.byte_order = B_MEDIA_LITTLE_ENDIAN;
Oct 8, 2006
Oct 8, 2006
114
115
format.frame_rate = (float) _this->spec.freq;
format.channel_count = _this->spec.channels; /* !!! FIXME: support > 2? */
Oct 6, 2006
Oct 6, 2006
116
117
while ((!valid_datatype) && (test_format)) {
valid_datatype = 1;
Oct 8, 2006
Oct 8, 2006
118
_this->spec.format = test_format;
Oct 6, 2006
Oct 6, 2006
119
switch (test_format) {
Sep 24, 2006
Sep 24, 2006
120
121
122
123
124
125
126
127
128
129
130
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
case AUDIO_S8:
format.format = media_raw_audio_format::B_AUDIO_CHAR;
break;
case AUDIO_U8:
format.format = media_raw_audio_format::B_AUDIO_UCHAR;
break;
case AUDIO_S16LSB:
format.format = media_raw_audio_format::B_AUDIO_SHORT;
break;
case AUDIO_S16MSB:
format.format = media_raw_audio_format::B_AUDIO_SHORT;
format.byte_order = B_MEDIA_BIG_ENDIAN;
break;
case AUDIO_S32LSB:
format.format = media_raw_audio_format::B_AUDIO_INT;
break;
case AUDIO_S32MSB:
format.format = media_raw_audio_format::B_AUDIO_INT;
format.byte_order = B_MEDIA_BIG_ENDIAN;
break;
case AUDIO_F32LSB:
format.format = media_raw_audio_format::B_AUDIO_FLOAT;
break;
case AUDIO_F32MSB:
format.format = media_raw_audio_format::B_AUDIO_FLOAT;
format.byte_order = B_MEDIA_BIG_ENDIAN;
break;
default:
valid_datatype = 0;
test_format = SDL_NextAudioFormat();
break;
Jul 10, 2006
Jul 10, 2006
159
}
Oct 6, 2006
Oct 6, 2006
160
}
Aug 31, 2006
Aug 31, 2006
161
Oct 8, 2006
Oct 8, 2006
162
format.buffer_size = _this->spec.samples;
Jul 10, 2006
Jul 10, 2006
163
Oct 6, 2006
Oct 6, 2006
164
if (!valid_datatype) { /* shouldn't happen, but just in case... */
Oct 8, 2006
Oct 8, 2006
165
BEOSAUDIO_CloseDevice(_this);
Oct 6, 2006
Oct 6, 2006
166
167
168
SDL_SetError("Unsupported audio format");
return 0;
}
Aug 31, 2006
Aug 31, 2006
169
Oct 6, 2006
Oct 6, 2006
170
/* Calculate the final parameters for this audio specification */
Oct 8, 2006
Oct 8, 2006
171
SDL_CalculateAudioSpec(&_this->spec);
Oct 6, 2006
Oct 6, 2006
172
173
174
175
176
177
178
179
180
181
182
/* Subscribe to the audio stream (creates a new thread) */
sigset_t omask;
SDL_MaskSignals(&omask);
_this->hidden->audio_obj = new BSoundPlayer(&format, "SDL Audio",
FillSound, NULL, _this);
SDL_UnmaskSignals(&omask);
if (_this->hidden->audio_obj->Start() == B_NO_ERROR) {
_this->hidden->audio_obj->SetHasData(true);
} else {
Oct 8, 2006
Oct 8, 2006
183
BEOSAUDIO_CloseDevice(_this);
Oct 6, 2006
Oct 6, 2006
184
185
186
SDL_SetError("Unable to start Be audio");
return 0;
}
Aug 31, 2006
Aug 31, 2006
187
Oct 6, 2006
Oct 6, 2006
188
189
190
/* We're running! */
return 1;
}
Jul 10, 2006
Jul 10, 2006
191
Oct 8, 2006
Oct 8, 2006
192
193
194
195
196
197
static void
BEOSAUDIO_Deinitialize(void)
{
SDL_QuitBeApp();
}
Oct 6, 2006
Oct 6, 2006
198
static int
Oct 8, 2006
Oct 8, 2006
199
BEOSAUDIO_Init(SDL_AudioDriverImpl *impl)
Oct 6, 2006
Oct 6, 2006
200
{
Oct 8, 2006
Oct 8, 2006
201
202
203
204
205
/* Initialize the Be Application, if it's not already started */
if (SDL_InitBeApp() < 0) {
return 0;
}
Oct 6, 2006
Oct 6, 2006
206
/* Set the function pointers */
Oct 8, 2006
Oct 8, 2006
207
208
209
impl->OpenDevice = BEOSAUDIO_OpenDevice;
impl->CloseDevice = BEOSAUDIO_CloseDevice;
impl->Deinitialize = BEOSAUDIO_Deinitialize;
Oct 6, 2006
Oct 6, 2006
210
211
212
213
214
impl->ProvidesOwnCallbackThread = 1;
impl->OnlyHasDefaultOutputDevice = 1;
return 1;
}
Jul 10, 2006
Jul 10, 2006
215
Oct 8, 2006
Oct 8, 2006
216
217
extern "C" { extern AudioBootStrap BEOSAUDIO_bootstrap; }
AudioBootStrap BEOSAUDIO_bootstrap = {
Oct 6, 2006
Oct 6, 2006
218
"baudio", "BeOS BSoundPlayer",
Oct 8, 2006
Oct 8, 2006
219
BEOSAUDIO_Available, BEOSAUDIO_Init, 0
Oct 6, 2006
Oct 6, 2006
220
};
Jul 10, 2006
Jul 10, 2006
221
222
/* vi: set ts=4 sw=4 expandtab: */