annotate src/audio/baudio/SDL_beaudio.cc @ 3846:66fb40445587 SDL-ryan-multiple-audio-device

Removed distinction between "available" and "init" in audio backends, since both had to be checked for success as a pair at the higher level and several of the Available methods were just always-succeed placeholders anyhow. Now the availability check is done in the init code, and the higher level tries all possible drivers until one manages to initialize successfully.
author Ryan C. Gordon <icculus@icculus.org>
date Tue, 17 Oct 2006 09:09:21 +0000
parents 7c9663fb0860
children
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
3 Copyright (C) 1997-2006 Sam Lantinga
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
6 modify it under the terms of the GNU Lesser General Public
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
13 Lesser General Public License for more details.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
15 You should have received a copy of the GNU Lesser General Public
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
16 License along with this library; if not, write to the Free Software
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
19 Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 114
diff changeset
20 slouken@libsdl.org
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21 */
1403
376665398b25 Catch the C++ and Objective C sources too...
Sam Lantinga <slouken@libsdl.org>
parents: 1367
diff changeset
22 #include "SDL_config.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24 /* Allow access to the audio stream on BeOS */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
26 #include <SoundPlayer.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
27
1367
e440d5c488c1 Fixes for BeOS and Solaris builds
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
28 #include "../../main/beos/SDL_BeApp.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
29
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1403
diff changeset
30 extern "C"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1403
diff changeset
31 {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
32
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
33 #include "SDL_audio.h"
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
34 #include "../SDL_audio_c.h"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
35 #include "../SDL_sysaudio.h"
1367
e440d5c488c1 Fixes for BeOS and Solaris builds
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
36 #include "../../thread/beos/SDL_systhread_c.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
37 #include "SDL_beaudio.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
38
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
39 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
40
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
41
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
42 /* !!! FIXME: have the callback call the higher level to avoid code dupe. */
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
43 /* The BeOS callback for handling the audio buffer */
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
44 static void
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
45 FillSound(void *device, void *stream, size_t len,
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
46 const media_raw_audio_format & format)
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
47 {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
48 SDL_AudioDevice *audio = (SDL_AudioDevice *) device;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
49
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
50 /* Silence the buffer, since it's ours */
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
51 SDL_memset(stream, audio->spec.silence, len);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
52
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
53 /* Only do soemthing if audio is enabled */
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
54 if (!audio->enabled)
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
55 return;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
56
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
57 if (!audio->paused) {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
58 if (audio->convert.needed) {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
59 SDL_mutexP(audio->mixer_lock);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
60 (*audio->spec.callback) (audio->spec.userdata,
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1403
diff changeset
61 (Uint8 *) audio->convert.buf,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1403
diff changeset
62 audio->convert.len);
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
63 SDL_mutexV(audio->mixer_lock);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
64 SDL_ConvertAudio(&audio->convert);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
65 SDL_memcpy(stream, audio->convert.buf, audio->convert.len_cvt);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
66 } else {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
67 SDL_mutexP(audio->mixer_lock);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
68 (*audio->spec.callback) (audio->spec.userdata,
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
69 (Uint8 *) stream, len);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
70 SDL_mutexV(audio->mixer_lock);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1403
diff changeset
71 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1403
diff changeset
72 }
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
73 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
74
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
75 static void
3837
7c9663fb0860 BeOS audio now works in 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 3830
diff changeset
76 BEOSAUDIO_CloseDevice(_THIS)
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
77 {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
78 if (_this->hidden != NULL) {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
79 if (_this->hidden->audio_obj) {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
80 _this->hidden->audio_obj->Stop();
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
81 delete _this->hidden->audio_obj;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
82 _this->hidden->audio_obj = NULL;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
83 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
84
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
85 delete _this->hidden;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
86 _this->hidden = NULL;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1403
diff changeset
87 }
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
88 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
89
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
90 static int
3837
7c9663fb0860 BeOS audio now works in 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 3830
diff changeset
91 BEOSAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
92 {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
93 int valid_datatype = 0;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
94 media_raw_audio_format format;
3837
7c9663fb0860 BeOS audio now works in 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 3830
diff changeset
95 SDL_AudioFormat test_format = SDL_FirstAudioFormat(_this->spec.format);
1997
46319c67b3d7 Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
96
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
97 /* Initialize all variables that we clean on shutdown */
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
98 _this->hidden = new SDL_PrivateAudioData;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
99 if (_this->hidden == NULL) {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
100 SDL_OutOfMemory();
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
101 return 0;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
102 }
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
103 SDL_memset(_this->hidden, 0, (sizeof *_this->hidden));
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
104
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
105 /* Parse the audio format and fill the Be raw audio format */
3830
29e83f221c62 Fixed some things to use SDL C runtime functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 3819
diff changeset
106 SDL_memset(&format, '\0', sizeof(media_raw_audio_format));
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
107 format.byte_order = B_MEDIA_LITTLE_ENDIAN;
3837
7c9663fb0860 BeOS audio now works in 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 3830
diff changeset
108 format.frame_rate = (float) _this->spec.freq;
7c9663fb0860 BeOS audio now works in 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 3830
diff changeset
109 format.channel_count = _this->spec.channels; /* !!! FIXME: support > 2? */
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
110 while ((!valid_datatype) && (test_format)) {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
111 valid_datatype = 1;
3837
7c9663fb0860 BeOS audio now works in 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 3830
diff changeset
112 _this->spec.format = test_format;
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
113 switch (test_format) {
2043
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
114 case AUDIO_S8:
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
115 format.format = media_raw_audio_format::B_AUDIO_CHAR;
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
116 break;
1997
46319c67b3d7 Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
117
2043
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
118 case AUDIO_U8:
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
119 format.format = media_raw_audio_format::B_AUDIO_UCHAR;
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
120 break;
1997
46319c67b3d7 Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
121
2043
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
122 case AUDIO_S16LSB:
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
123 format.format = media_raw_audio_format::B_AUDIO_SHORT;
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
124 break;
1997
46319c67b3d7 Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
125
2043
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
126 case AUDIO_S16MSB:
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
127 format.format = media_raw_audio_format::B_AUDIO_SHORT;
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
128 format.byte_order = B_MEDIA_BIG_ENDIAN;
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
129 break;
1997
46319c67b3d7 Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
130
2043
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
131 case AUDIO_S32LSB:
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
132 format.format = media_raw_audio_format::B_AUDIO_INT;
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
133 break;
1997
46319c67b3d7 Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
134
2043
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
135 case AUDIO_S32MSB:
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
136 format.format = media_raw_audio_format::B_AUDIO_INT;
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
137 format.byte_order = B_MEDIA_BIG_ENDIAN;
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
138 break;
1997
46319c67b3d7 Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
139
2043
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
140 case AUDIO_F32LSB:
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
141 format.format = media_raw_audio_format::B_AUDIO_FLOAT;
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
142 break;
1997
46319c67b3d7 Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
143
2043
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
144 case AUDIO_F32MSB:
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
145 format.format = media_raw_audio_format::B_AUDIO_FLOAT;
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
146 format.byte_order = B_MEDIA_BIG_ENDIAN;
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
147 break;
1997
46319c67b3d7 Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
148
2043
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
149 default:
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
150 valid_datatype = 0;
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
151 test_format = SDL_NextAudioFormat();
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
152 break;
1997
46319c67b3d7 Added int32 and float32 support (and some others!) to BeOS audio backend.
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
153 }
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
154 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
155
3837
7c9663fb0860 BeOS audio now works in 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 3830
diff changeset
156 format.buffer_size = _this->spec.samples;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
157
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
158 if (!valid_datatype) { /* shouldn't happen, but just in case... */
3837
7c9663fb0860 BeOS audio now works in 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 3830
diff changeset
159 BEOSAUDIO_CloseDevice(_this);
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
160 SDL_SetError("Unsupported audio format");
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
161 return 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1403
diff changeset
162 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1403
diff changeset
163
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
164 /* Calculate the final parameters for this audio specification */
3837
7c9663fb0860 BeOS audio now works in 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 3830
diff changeset
165 SDL_CalculateAudioSpec(&_this->spec);
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
166
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
167 /* Subscribe to the audio stream (creates a new thread) */
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
168 sigset_t omask;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
169 SDL_MaskSignals(&omask);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
170 _this->hidden->audio_obj = new BSoundPlayer(&format, "SDL Audio",
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
171 FillSound, NULL, _this);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
172 SDL_UnmaskSignals(&omask);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
173
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
174 if (_this->hidden->audio_obj->Start() == B_NO_ERROR) {
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
175 _this->hidden->audio_obj->SetHasData(true);
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
176 } else {
3837
7c9663fb0860 BeOS audio now works in 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 3830
diff changeset
177 BEOSAUDIO_CloseDevice(_this);
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
178 SDL_SetError("Unable to start Be audio");
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
179 return 0;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
180 }
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
181
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
182 /* We're running! */
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
183 return 1;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
184 }
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
185
3837
7c9663fb0860 BeOS audio now works in 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 3830
diff changeset
186 static void
7c9663fb0860 BeOS audio now works in 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 3830
diff changeset
187 BEOSAUDIO_Deinitialize(void)
7c9663fb0860 BeOS audio now works in 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 3830
diff changeset
188 {
7c9663fb0860 BeOS audio now works in 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 3830
diff changeset
189 SDL_QuitBeApp();
7c9663fb0860 BeOS audio now works in 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 3830
diff changeset
190 }
7c9663fb0860 BeOS audio now works in 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 3830
diff changeset
191
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
192 static int
3837
7c9663fb0860 BeOS audio now works in 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 3830
diff changeset
193 BEOSAUDIO_Init(SDL_AudioDriverImpl *impl)
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
194 {
3837
7c9663fb0860 BeOS audio now works in 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 3830
diff changeset
195 /* Initialize the Be Application, if it's not already started */
7c9663fb0860 BeOS audio now works in 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 3830
diff changeset
196 if (SDL_InitBeApp() < 0) {
7c9663fb0860 BeOS audio now works in 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 3830
diff changeset
197 return 0;
7c9663fb0860 BeOS audio now works in 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 3830
diff changeset
198 }
7c9663fb0860 BeOS audio now works in 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 3830
diff changeset
199
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
200 /* Set the function pointers */
3837
7c9663fb0860 BeOS audio now works in 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 3830
diff changeset
201 impl->OpenDevice = BEOSAUDIO_OpenDevice;
7c9663fb0860 BeOS audio now works in 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 3830
diff changeset
202 impl->CloseDevice = BEOSAUDIO_CloseDevice;
7c9663fb0860 BeOS audio now works in 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 3830
diff changeset
203 impl->Deinitialize = BEOSAUDIO_Deinitialize;
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
204 impl->ProvidesOwnCallbackThread = 1;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
205 impl->OnlyHasDefaultOutputDevice = 1;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
206
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
207 return 1;
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
208 }
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
209
3837
7c9663fb0860 BeOS audio now works in 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 3830
diff changeset
210 extern "C" { extern AudioBootStrap BEOSAUDIO_bootstrap; }
7c9663fb0860 BeOS audio now works in 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 3830
diff changeset
211 AudioBootStrap BEOSAUDIO_bootstrap = {
3846
66fb40445587 Removed distinction between "available" and "init" in audio backends, since
Ryan C. Gordon <icculus@icculus.org>
parents: 3837
diff changeset
212 "baudio", "BeOS BSoundPlayer", BEOSAUDIO_Init, 0
3819
b225d9820ee3 Updated a bunch of audio backends to 1.3 API (Dreamcast, OS/2, ALSA, and
Ryan C. Gordon <icculus@icculus.org>
parents: 2043
diff changeset
213 };
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1403
diff changeset
214
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1403
diff changeset
215 /* vi: set ts=4 sw=4 expandtab: */
3837
7c9663fb0860 BeOS audio now works in 1.3 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 3830
diff changeset
216