1
/* $Id: allegro_s.cpp 15305 2009-02-01 11:52:41Z rubidium $ */
3
/** @file allegro_s.cpp Playing sound via Allegro. */
13
#include "allegro_s.h"
16
static FSoundDriver_Allegro iFSoundDriver_Allegro;
17
/** The stream we are writing too */
18
static AUDIOSTREAM *_stream = NULL;
19
/** The number of samples in the buffer */
20
static const int BUFFER_SIZE = 512;
22
void SoundDriver_Allegro::MainLoop()
24
/* We haven't opened a stream yet */
25
if (_stream == NULL) return;
27
void *data = get_audio_stream_buffer(_stream);
28
/* We don't have to fill the stream yet */
29
if (data == NULL) return;
32
MxMixSamples(data, BUFFER_SIZE);
34
/* Allegro sound is always unsigned, so we need to correct that */
35
uint16 *snd = (uint16*)data;
36
for (int i = 0; i < BUFFER_SIZE * 2; i++) snd[i] ^= 0x8000;
38
/* Tell we've filled the stream */
39
free_audio_stream_buffer(_stream);
42
/** There are multiple modules that might be using Allegro and
43
* Allegro can only be initiated once. */
44
extern int _allegro_instance_count;
46
const char *SoundDriver_Allegro::Start(const char * const *parm)
48
if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, NULL)) return NULL;
49
_allegro_instance_count++;
51
/* Initialise the sound */
52
if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0) return NULL;
54
/* Okay, there's no soundcard */
55
if (digi_card == DIGI_NONE) {
56
DEBUG(driver, 0, "allegro: no sound card found");
60
_stream = play_audio_stream(BUFFER_SIZE, 16, true, 11025, 255, 128);
64
void SoundDriver_Allegro::Stop()
66
if (_stream != NULL) {
67
stop_audio_stream(_stream);
72
if (--_allegro_instance_count == 0) allegro_exit();
75
#endif /* WITH_ALLEGRO */