19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*
29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL - Simple DirectMedia Layer
39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Copyright (C) 1997-2012 Sam Lantinga
49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is free software; you can redistribute it and/or
69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    modify it under the terms of the GNU Lesser General Public
79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License as published by the Free Software Foundation; either
89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    version 2.1 of the License, or (at your option) any later version.
99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is distributed in the hope that it will be useful,
119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    but WITHOUT ANY WARRANTY; without even the implied warranty of
129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Lesser General Public License for more details.
149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    You should have received a copy of the GNU Lesser General Public
169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License along with this library; if not, write to the Free Software
179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Sam Lantinga
209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    slouken@libsdl.org
219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/
229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_config.h"
239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Allow access to the audio stream on BeOS */
259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <SoundPlayer.h>
279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../../main/beos/SDL_BeApp.h"
299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern "C" {
319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_audio.h"
339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../SDL_audio_c.h"
349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../SDL_sysaudio.h"
359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../../thread/beos/SDL_systhread_c.h"
369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_beaudio.h"
379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Audio driver functions */
409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int BE_OpenAudio(_THIS, SDL_AudioSpec *spec);
419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void BE_WaitAudio(_THIS);
429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void BE_PlayAudio(_THIS);
439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic Uint8 *BE_GetAudioBuf(_THIS);
449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void BE_CloseAudio(_THIS);
459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Audio driver bootstrap functions */
479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int Audio_Available(void)
499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return(1);
519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void Audio_DeleteDevice(SDL_AudioDevice *device)
549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_free(device->hidden);
569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_free(device);
579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic SDL_AudioDevice *Audio_CreateDevice(int devindex)
609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_AudioDevice *device;
629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Initialize all variables that we clean on shutdown */
649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	device = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( device ) {
669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		SDL_memset(device, 0, (sizeof *device));
679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		device->hidden = (struct SDL_PrivateAudioData *)
689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				SDL_malloc((sizeof *device->hidden));
699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( (device == NULL) || (device->hidden == NULL) ) {
719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		SDL_OutOfMemory();
729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( device ) {
739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDL_free(device);
749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return(0);
769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_memset(device->hidden, 0, (sizeof *device->hidden));
789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Set the function pointers */
809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	device->OpenAudio = BE_OpenAudio;
819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	device->WaitAudio = BE_WaitAudio;
829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	device->PlayAudio = BE_PlayAudio;
839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	device->GetAudioBuf = BE_GetAudioBuf;
849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	device->CloseAudio = BE_CloseAudio;
859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	device->free = Audio_DeleteDevice;
879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return device;
899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallAudioBootStrap BAUDIO_bootstrap = {
929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	"baudio", "BeOS BSoundPlayer",
939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	Audio_Available, Audio_CreateDevice
949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall};
959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* The BeOS callback for handling the audio buffer */
979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void FillSound(void *device, void *stream, size_t len,
989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall					const media_raw_audio_format &format)
999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_AudioDevice *audio = (SDL_AudioDevice *)device;
1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Silence the buffer, since it's ours */
1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_memset(stream, audio->spec.silence, len);
1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Only do soemthing if audio is enabled */
1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( ! audio->enabled )
1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return;
1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( ! audio->paused ) {
1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( audio->convert.needed ) {
1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDL_mutexP(audio->mixer_lock);
1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			(*audio->spec.callback)(audio->spec.userdata,
1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				(Uint8 *)audio->convert.buf,audio->convert.len);
1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDL_mutexV(audio->mixer_lock);
1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDL_ConvertAudio(&audio->convert);
1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDL_memcpy(stream,audio->convert.buf,audio->convert.len_cvt);
1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		} else {
1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDL_mutexP(audio->mixer_lock);
1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			(*audio->spec.callback)(audio->spec.userdata,
1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall						(Uint8 *)stream, len);
1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDL_mutexV(audio->mixer_lock);
1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return;
1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Dummy functions -- we don't use thread-based audio */
1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid BE_WaitAudio(_THIS)
1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return;
1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid BE_PlayAudio(_THIS)
1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return;
1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallUint8 *BE_GetAudioBuf(_THIS)
1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return(NULL);
1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid BE_CloseAudio(_THIS)
1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( audio_obj ) {
1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		audio_obj->Stop();
1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		delete audio_obj;
1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		audio_obj = NULL;
1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Quit the Be Application, if there's nothing left to do */
1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_QuitBeApp();
1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint BE_OpenAudio(_THIS, SDL_AudioSpec *spec)
1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    int valid_datatype = 0;
1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    media_raw_audio_format format;
1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Uint16 test_format = SDL_FirstAudioFormat(spec->format);
1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* Parse the audio format and fill the Be raw audio format */
1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    memset(&format, '\0', sizeof (media_raw_audio_format));
1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    format.byte_order = B_MEDIA_LITTLE_ENDIAN;
1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    format.frame_rate = (float) spec->freq;
1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    format.channel_count = spec->channels;  /* !!! FIXME: support > 2? */
1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    while ((!valid_datatype) && (test_format)) {
1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        valid_datatype = 1;
1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        spec->format = test_format;
1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        switch (test_format) {
1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            case AUDIO_S8:
1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                format.format = media_raw_audio_format::B_AUDIO_CHAR;
1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                break;
1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            case AUDIO_U8:
1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                format.format = media_raw_audio_format::B_AUDIO_UCHAR;
1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                break;
1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            case AUDIO_S16LSB:
1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                format.format = media_raw_audio_format::B_AUDIO_SHORT;
1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                break;
1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            case AUDIO_S16MSB:
1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                format.format = media_raw_audio_format::B_AUDIO_SHORT;
1829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                format.byte_order = B_MEDIA_BIG_ENDIAN;
1839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                break;
1849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            default:
1869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                valid_datatype = 0;
1879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                test_format = SDL_NextAudioFormat();
1889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                break;
1899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        }
1909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
1919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (!valid_datatype) { /* shouldn't happen, but just in case... */
1939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        SDL_SetError("Unsupported audio format");
1949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        return (-1);
1959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
1969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    /* Initialize the Be Application, if it's not already started */
1989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (SDL_InitBeApp() < 0) {
1999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        return (-1);
2009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
2019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    format.buffer_size = spec->samples;
2039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Calculate the final parameters for this audio specification */
2059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_CalculateAudioSpec(spec);
2069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Subscribe to the audio stream (creates a new thread) */
2089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	{ sigset_t omask;
2099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		SDL_MaskSignals(&omask);
2109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		audio_obj = new BSoundPlayer(&format, "SDL Audio", FillSound,
2119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		                                                 NULL, _this);
2129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		SDL_UnmaskSignals(&omask);
2139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
2149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( audio_obj->Start() == B_NO_ERROR ) {
2159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		audio_obj->SetHasData(true);
2169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	} else {
2179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		SDL_SetError("Unable to start Be audio");
2189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return(-1);
2199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
2209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* We're running! */
2229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return(1);
2239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall};	/* Extern C */
226