annotate src/audio/baudio/SDL_beaudio.cc @ 3833:de857f0708f5 SDL-ryan-multiple-audio-device

Whoops, changed that symbol name...
author Ryan C. Gordon <icculus@icculus.org>
date Sat, 07 Oct 2006 20:23:02 +0000
parents 29e83f221c62
children 7c9663fb0860
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 static int BEAUDIO_Available(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
43 {
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 return 1; /* Always available on BeOS. */
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 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
46
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
47
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
48 /* !!! 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
49 /* 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
50 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
51 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
52 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
53 {
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 SDL_AudioDevice *audio = (SDL_AudioDevice *) device;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
55
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
56 /* 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
57 SDL_memset(stream, audio->spec.silence, len);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
58
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
59 /* 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
60 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
61 return;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
62
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 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
64 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
65 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
66 (*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
67 (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
68 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
69 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
70 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
71 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
72 } 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
73 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
74 (*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
75 (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
76 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
77 }
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
78 }
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
79 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
80
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
81 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
82 BEAUDIO_CloseDevice(_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
83 {
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
84 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
85 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
86 _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
87 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
88 _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
89 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
90
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
91 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
92 _this->hidden = NULL;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
93
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
94 /* Quit the Be Application, if there's nothing left to do */
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
95 SDL_QuitBeApp();
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
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 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
98
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
99 static int
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 BEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
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 {
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 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
103 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
104 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
105
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
106 /* 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
107 _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
108 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
109 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
110 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
111 }
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
112 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
113
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
114 /* Initialize the Be Application, if it's not already started */
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
115 if (SDL_InitBeApp() < 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
116 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
117 }
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
118
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
119 /* 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
120 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
121 format.byte_order = B_MEDIA_LITTLE_ENDIAN;
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
122 format.frame_rate = (float) this->spec.freq;
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
123 format.channel_count = this->spec.channels; /* !!! FIXME: support > 2? */
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
124 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
125 valid_datatype = 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
126 this->spec.format = 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
127 switch (test_format) {
2043
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
128 case AUDIO_S8:
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
129 format.format = media_raw_audio_format::B_AUDIO_CHAR;
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
130 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
131
2043
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
132 case AUDIO_U8:
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
133 format.format = media_raw_audio_format::B_AUDIO_UCHAR;
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
134 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
135
2043
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
136 case AUDIO_S16LSB:
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
137 format.format = media_raw_audio_format::B_AUDIO_SHORT;
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_S16MSB:
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
141 format.format = media_raw_audio_format::B_AUDIO_SHORT;
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
142 format.byte_order = B_MEDIA_BIG_ENDIAN;
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
143 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
144
2043
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
145 case AUDIO_S32LSB:
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
146 format.format = media_raw_audio_format::B_AUDIO_INT;
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 case AUDIO_S32MSB:
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
150 format.format = media_raw_audio_format::B_AUDIO_INT;
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
151 format.byte_order = B_MEDIA_BIG_ENDIAN;
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
2043
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
154 case AUDIO_F32LSB:
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
155 format.format = media_raw_audio_format::B_AUDIO_FLOAT;
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
156 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
157
2043
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
158 case AUDIO_F32MSB:
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
159 format.format = media_raw_audio_format::B_AUDIO_FLOAT;
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
160 format.byte_order = B_MEDIA_BIG_ENDIAN;
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
161 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
162
2043
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
163 default:
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
164 valid_datatype = 0;
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
165 test_format = SDL_NextAudioFormat();
adf732f1f016 Formatting update
Sam Lantinga <slouken@libsdl.org>
parents: 2001
diff changeset
166 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
167 }
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
168 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
169
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
170 format.buffer_size = this->spec.samples;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
171
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
172 if (!valid_datatype) { /* shouldn't happen, but just in case... */
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 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
174 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
175 }
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
176
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
177 /* Calculate the final parameters for this audio specification */
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_CalculateAudioSpec(&this->spec);
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
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 /* 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
181 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
182 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
183 _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
184 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
185 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
186
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
187 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
188 _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
189 } 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
190 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
191 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
192 }
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
193
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 /* 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
195 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
196 }
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
197
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
198 static int
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
199 BEAUDIO_Init(SDL_AudioDriverImpl *impl)
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 {
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
201 /* Set the function pointers */
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
202 impl->OpenDevice = DSP_OpenDevice;
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
203 impl->CloseDevice = DSP_CloseDevice;
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
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
210
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
211 AudioBootStrap BEAUDIO_bootstrap = {
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
212 "baudio", "BeOS BSoundPlayer",
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 BEAUDIO_Available, BEAUDIO_Init, 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
214 };
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
215
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
216 /* vi: set ts=4 sw=4 expandtab: */