src/audio/baudio/SDL_beaudio.cc
changeset 1895 c121d94672cb
parent 1403 376665398b25
child 1997 46319c67b3d7
     1.1 --- a/src/audio/baudio/SDL_beaudio.cc	Thu Jul 06 18:01:37 2006 +0000
     1.2 +++ b/src/audio/baudio/SDL_beaudio.cc	Mon Jul 10 21:04:37 2006 +0000
     1.3 @@ -27,7 +27,8 @@
     1.4  
     1.5  #include "../../main/beos/SDL_BeApp.h"
     1.6  
     1.7 -extern "C" {
     1.8 +extern "C"
     1.9 +{
    1.10  
    1.11  #include "SDL_audio.h"
    1.12  #include "../SDL_audio_c.h"
    1.13 @@ -37,172 +38,177 @@
    1.14  
    1.15  
    1.16  /* Audio driver functions */
    1.17 -static int BE_OpenAudio(_THIS, SDL_AudioSpec *spec);
    1.18 -static void BE_WaitAudio(_THIS);
    1.19 -static void BE_PlayAudio(_THIS);
    1.20 -static Uint8 *BE_GetAudioBuf(_THIS);
    1.21 -static void BE_CloseAudio(_THIS);
    1.22 +    static int BE_OpenAudio(_THIS, SDL_AudioSpec * spec);
    1.23 +    static void BE_WaitAudio(_THIS);
    1.24 +    static void BE_PlayAudio(_THIS);
    1.25 +    static Uint8 *BE_GetAudioBuf(_THIS);
    1.26 +    static void BE_CloseAudio(_THIS);
    1.27  
    1.28  /* Audio driver bootstrap functions */
    1.29  
    1.30 -static int Audio_Available(void)
    1.31 -{
    1.32 -	return(1);
    1.33 -}
    1.34 +    static int Audio_Available(void)
    1.35 +    {
    1.36 +        return (1);
    1.37 +    }
    1.38  
    1.39 -static void Audio_DeleteDevice(SDL_AudioDevice *device)
    1.40 -{
    1.41 -	SDL_free(device->hidden);
    1.42 -	SDL_free(device);
    1.43 -}
    1.44 +    static void Audio_DeleteDevice(SDL_AudioDevice * device)
    1.45 +    {
    1.46 +        SDL_free(device->hidden);
    1.47 +        SDL_free(device);
    1.48 +    }
    1.49  
    1.50 -static SDL_AudioDevice *Audio_CreateDevice(int devindex)
    1.51 -{
    1.52 -	SDL_AudioDevice *device;
    1.53 +    static SDL_AudioDevice *Audio_CreateDevice(int devindex)
    1.54 +    {
    1.55 +        SDL_AudioDevice *device;
    1.56  
    1.57 -	/* Initialize all variables that we clean on shutdown */
    1.58 -	device = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
    1.59 -	if ( device ) {
    1.60 -		SDL_memset(device, 0, (sizeof *device));
    1.61 -		device->hidden = (struct SDL_PrivateAudioData *)
    1.62 -				SDL_malloc((sizeof *device->hidden));
    1.63 -	}
    1.64 -	if ( (device == NULL) || (device->hidden == NULL) ) {
    1.65 -		SDL_OutOfMemory();
    1.66 -		if ( device ) {
    1.67 -			SDL_free(device);
    1.68 -		}
    1.69 -		return(0);
    1.70 -	}
    1.71 -	SDL_memset(device->hidden, 0, (sizeof *device->hidden));
    1.72 +        /* Initialize all variables that we clean on shutdown */
    1.73 +        device = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
    1.74 +        if (device) {
    1.75 +            SDL_memset(device, 0, (sizeof *device));
    1.76 +            device->hidden = (struct SDL_PrivateAudioData *)
    1.77 +                SDL_malloc((sizeof *device->hidden));
    1.78 +        }
    1.79 +        if ((device == NULL) || (device->hidden == NULL)) {
    1.80 +            SDL_OutOfMemory();
    1.81 +            if (device) {
    1.82 +                SDL_free(device);
    1.83 +            }
    1.84 +            return (0);
    1.85 +        }
    1.86 +        SDL_memset(device->hidden, 0, (sizeof *device->hidden));
    1.87  
    1.88 -	/* Set the function pointers */
    1.89 -	device->OpenAudio = BE_OpenAudio;
    1.90 -	device->WaitAudio = BE_WaitAudio;
    1.91 -	device->PlayAudio = BE_PlayAudio;
    1.92 -	device->GetAudioBuf = BE_GetAudioBuf;
    1.93 -	device->CloseAudio = BE_CloseAudio;
    1.94 +        /* Set the function pointers */
    1.95 +        device->OpenAudio = BE_OpenAudio;
    1.96 +        device->WaitAudio = BE_WaitAudio;
    1.97 +        device->PlayAudio = BE_PlayAudio;
    1.98 +        device->GetAudioBuf = BE_GetAudioBuf;
    1.99 +        device->CloseAudio = BE_CloseAudio;
   1.100  
   1.101 -	device->free = Audio_DeleteDevice;
   1.102 +        device->free = Audio_DeleteDevice;
   1.103  
   1.104 -	return device;
   1.105 -}
   1.106 +        return device;
   1.107 +    }
   1.108  
   1.109 -AudioBootStrap BAUDIO_bootstrap = {
   1.110 -	"baudio", "BeOS BSoundPlayer",
   1.111 -	Audio_Available, Audio_CreateDevice
   1.112 -};
   1.113 +    AudioBootStrap BAUDIO_bootstrap = {
   1.114 +        "baudio", "BeOS BSoundPlayer",
   1.115 +        Audio_Available, Audio_CreateDevice
   1.116 +    };
   1.117  
   1.118  /* The BeOS callback for handling the audio buffer */
   1.119 -static void FillSound(void *device, void *stream, size_t len, 
   1.120 -					const media_raw_audio_format &format)
   1.121 -{
   1.122 -	SDL_AudioDevice *audio = (SDL_AudioDevice *)device;
   1.123 +    static void FillSound(void *device, void *stream, size_t len,
   1.124 +                          const media_raw_audio_format & format)
   1.125 +    {
   1.126 +        SDL_AudioDevice *audio = (SDL_AudioDevice *) device;
   1.127  
   1.128 -	/* Silence the buffer, since it's ours */
   1.129 -	SDL_memset(stream, audio->spec.silence, len);
   1.130 +        /* Silence the buffer, since it's ours */
   1.131 +        SDL_memset(stream, audio->spec.silence, len);
   1.132  
   1.133 -	/* Only do soemthing if audio is enabled */
   1.134 -	if ( ! audio->enabled )
   1.135 -		return;
   1.136 +        /* Only do soemthing if audio is enabled */
   1.137 +        if (!audio->enabled)
   1.138 +            return;
   1.139  
   1.140 -	if ( ! audio->paused ) {
   1.141 -		if ( audio->convert.needed ) {
   1.142 -			SDL_mutexP(audio->mixer_lock);
   1.143 -			(*audio->spec.callback)(audio->spec.userdata,
   1.144 -				(Uint8 *)audio->convert.buf,audio->convert.len);
   1.145 -			SDL_mutexV(audio->mixer_lock);
   1.146 -			SDL_ConvertAudio(&audio->convert);
   1.147 -			SDL_memcpy(stream,audio->convert.buf,audio->convert.len_cvt);
   1.148 -		} else {
   1.149 -			SDL_mutexP(audio->mixer_lock);
   1.150 -			(*audio->spec.callback)(audio->spec.userdata,
   1.151 -						(Uint8 *)stream, len);
   1.152 -			SDL_mutexV(audio->mixer_lock);
   1.153 -		}
   1.154 -	}
   1.155 -	return;
   1.156 -}
   1.157 +        if (!audio->paused) {
   1.158 +            if (audio->convert.needed) {
   1.159 +                SDL_mutexP(audio->mixer_lock);
   1.160 +                (*audio->spec.callback) (audio->spec.userdata,
   1.161 +                                         (Uint8 *) audio->convert.buf,
   1.162 +                                         audio->convert.len);
   1.163 +                SDL_mutexV(audio->mixer_lock);
   1.164 +                SDL_ConvertAudio(&audio->convert);
   1.165 +                SDL_memcpy(stream, audio->convert.buf,
   1.166 +                           audio->convert.len_cvt);
   1.167 +            } else {
   1.168 +                SDL_mutexP(audio->mixer_lock);
   1.169 +                (*audio->spec.callback) (audio->spec.userdata,
   1.170 +                                         (Uint8 *) stream, len);
   1.171 +                SDL_mutexV(audio->mixer_lock);
   1.172 +            }
   1.173 +        }
   1.174 +        return;
   1.175 +    }
   1.176  
   1.177  /* Dummy functions -- we don't use thread-based audio */
   1.178 -void BE_WaitAudio(_THIS)
   1.179 -{
   1.180 -	return;
   1.181 -}
   1.182 -void BE_PlayAudio(_THIS)
   1.183 -{
   1.184 -	return;
   1.185 -}
   1.186 -Uint8 *BE_GetAudioBuf(_THIS)
   1.187 -{
   1.188 -	return(NULL);
   1.189 -}
   1.190 +    void BE_WaitAudio(_THIS)
   1.191 +    {
   1.192 +        return;
   1.193 +    }
   1.194 +    void BE_PlayAudio(_THIS)
   1.195 +    {
   1.196 +        return;
   1.197 +    }
   1.198 +    Uint8 *BE_GetAudioBuf(_THIS)
   1.199 +    {
   1.200 +        return (NULL);
   1.201 +    }
   1.202  
   1.203 -void BE_CloseAudio(_THIS)
   1.204 -{
   1.205 -	if ( audio_obj ) {
   1.206 -		audio_obj->Stop();
   1.207 -		delete audio_obj;
   1.208 -		audio_obj = NULL;
   1.209 -	}
   1.210 +    void BE_CloseAudio(_THIS)
   1.211 +    {
   1.212 +        if (audio_obj) {
   1.213 +            audio_obj->Stop();
   1.214 +            delete audio_obj;
   1.215 +            audio_obj = NULL;
   1.216 +        }
   1.217  
   1.218 -	/* Quit the Be Application, if there's nothing left to do */
   1.219 -	SDL_QuitBeApp();
   1.220 -}
   1.221 +        /* Quit the Be Application, if there's nothing left to do */
   1.222 +        SDL_QuitBeApp();
   1.223 +    }
   1.224  
   1.225 -int BE_OpenAudio(_THIS, SDL_AudioSpec *spec)
   1.226 -{
   1.227 -	media_raw_audio_format format;
   1.228 +    int BE_OpenAudio(_THIS, SDL_AudioSpec * spec)
   1.229 +    {
   1.230 +        media_raw_audio_format format;
   1.231  
   1.232 -	/* Initialize the Be Application, if it's not already started */
   1.233 -	if ( SDL_InitBeApp() < 0 ) {
   1.234 -		return(-1);
   1.235 -	}
   1.236 +        /* Initialize the Be Application, if it's not already started */
   1.237 +        if (SDL_InitBeApp() < 0) {
   1.238 +            return (-1);
   1.239 +        }
   1.240  
   1.241 -	/* Parse the audio format and fill the Be raw audio format */
   1.242 -	format.frame_rate = (float)spec->freq;
   1.243 -	format.channel_count = spec->channels;
   1.244 -	switch (spec->format&~0x1000) {
   1.245 -		case AUDIO_S8:
   1.246 -			/* Signed 8-bit audio unsupported, convert to U8 */
   1.247 -			spec->format = AUDIO_U8;
   1.248 -		case AUDIO_U8:
   1.249 -			format.format = media_raw_audio_format::B_AUDIO_UCHAR;
   1.250 -			format.byte_order = 0;
   1.251 -			break;
   1.252 -		case AUDIO_U16:
   1.253 -			/* Unsigned 16-bit audio unsupported, convert to S16 */
   1.254 -			spec->format ^= 0x8000;
   1.255 -		case AUDIO_S16:
   1.256 -			format.format = media_raw_audio_format::B_AUDIO_SHORT;
   1.257 -			if ( spec->format & 0x1000 ) {
   1.258 -				format.byte_order = 1; /* Big endian */
   1.259 -			} else {
   1.260 -				format.byte_order = 2; /* Little endian */
   1.261 -			}
   1.262 -			break;
   1.263 -	}
   1.264 -	format.buffer_size = spec->samples;
   1.265 -	
   1.266 -	/* Calculate the final parameters for this audio specification */
   1.267 -	SDL_CalculateAudioSpec(spec);
   1.268 +        /* Parse the audio format and fill the Be raw audio format */
   1.269 +        format.frame_rate = (float) spec->freq;
   1.270 +        format.channel_count = spec->channels;
   1.271 +        switch (spec->format & ~0x1000) {
   1.272 +        case AUDIO_S8:
   1.273 +            /* Signed 8-bit audio unsupported, convert to U8 */
   1.274 +            spec->format = AUDIO_U8;
   1.275 +        case AUDIO_U8:
   1.276 +            format.format = media_raw_audio_format::B_AUDIO_UCHAR;
   1.277 +            format.byte_order = 0;
   1.278 +            break;
   1.279 +        case AUDIO_U16:
   1.280 +            /* Unsigned 16-bit audio unsupported, convert to S16 */
   1.281 +            spec->format ^= 0x8000;
   1.282 +        case AUDIO_S16:
   1.283 +            format.format = media_raw_audio_format::B_AUDIO_SHORT;
   1.284 +            if (spec->format & 0x1000) {
   1.285 +                format.byte_order = 1;  /* Big endian */
   1.286 +            } else {
   1.287 +                format.byte_order = 2;  /* Little endian */
   1.288 +            }
   1.289 +            break;
   1.290 +        }
   1.291 +        format.buffer_size = spec->samples;
   1.292  
   1.293 -	/* Subscribe to the audio stream (creates a new thread) */
   1.294 -	{ sigset_t omask;
   1.295 -		SDL_MaskSignals(&omask);
   1.296 -		audio_obj = new BSoundPlayer(&format, "SDL Audio", FillSound,
   1.297 -		                                                 NULL, _this);
   1.298 -		SDL_UnmaskSignals(&omask);
   1.299 -	}
   1.300 -	if ( audio_obj->Start() == B_NO_ERROR ) {
   1.301 -		audio_obj->SetHasData(true);
   1.302 -	} else {
   1.303 -		SDL_SetError("Unable to start Be audio");
   1.304 -		return(-1);
   1.305 -	}
   1.306 +        /* Calculate the final parameters for this audio specification */
   1.307 +        SDL_CalculateAudioSpec(spec);
   1.308  
   1.309 -	/* We're running! */
   1.310 -	return(1);
   1.311 -}
   1.312 +        /* Subscribe to the audio stream (creates a new thread) */
   1.313 +        {
   1.314 +            sigset_t omask;
   1.315 +            SDL_MaskSignals(&omask);
   1.316 +            audio_obj = new BSoundPlayer(&format, "SDL Audio", FillSound,
   1.317 +                                         NULL, _this);
   1.318 +            SDL_UnmaskSignals(&omask);
   1.319 +        }
   1.320 +        if (audio_obj->Start() == B_NO_ERROR) {
   1.321 +            audio_obj->SetHasData(true);
   1.322 +        } else {
   1.323 +            SDL_SetError("Unable to start Be audio");
   1.324 +            return (-1);
   1.325 +        }
   1.326  
   1.327 -};	/* Extern C */
   1.328 +        /* We're running! */
   1.329 +        return (1);
   1.330 +    }
   1.331 +
   1.332 +};                              /* Extern C */
   1.333 +
   1.334 +/* vi: set ts=4 sw=4 expandtab: */