allegro_s.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifdef WITH_ALLEGRO
00013
00014 #include "../stdafx.h"
00015
00016 #include "../mixer.h"
00017 #include "../debug.h"
00018 #include "allegro_s.h"
00019 #include <allegro.h>
00020
00021 static FSoundDriver_Allegro iFSoundDriver_Allegro;
00023 static AUDIOSTREAM *_stream = NULL;
00025 static int _buffer_size;
00026
00027 void SoundDriver_Allegro::MainLoop()
00028 {
00029
00030 if (_stream == NULL) return;
00031
00032 void *data = get_audio_stream_buffer(_stream);
00033
00034 if (data == NULL) return;
00035
00036
00037 MxMixSamples(data, _buffer_size);
00038
00039
00040 uint16 *snd = (uint16*)data;
00041 for (int i = 0; i < _buffer_size * 2; i++) snd[i] ^= 0x8000;
00042
00043
00044 free_audio_stream_buffer(_stream);
00045 }
00046
00049 extern int _allegro_instance_count;
00050
00051 const char *SoundDriver_Allegro::Start(const char * const *parm)
00052 {
00053 if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, NULL)) {
00054 DEBUG(driver, 0, "allegro: install_allegro failed '%s'", allegro_error);
00055 return "Failed to set up Allegro";
00056 }
00057 _allegro_instance_count++;
00058
00059
00060 if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0) {
00061 DEBUG(driver, 0, "allegro: install_sound failed '%s'", allegro_error);
00062 return "Failed to set up Allegro sound";
00063 }
00064
00065
00066 if (digi_card == DIGI_NONE) {
00067 DEBUG(driver, 0, "allegro: no sound card found");
00068 return "No sound card found";
00069 }
00070
00071 int hz = GetDriverParamInt(parm, "hz", 44100);
00072 _buffer_size = GetDriverParamInt(parm, "samples", 1024) * hz / 11025;
00073 _stream = play_audio_stream(_buffer_size, 16, true, hz, 255, 128);
00074 MxInitialize(hz);
00075 return NULL;
00076 }
00077
00078 void SoundDriver_Allegro::Stop()
00079 {
00080 if (_stream != NULL) {
00081 stop_audio_stream(_stream);
00082 _stream = NULL;
00083 }
00084 remove_sound();
00085
00086 if (--_allegro_instance_count == 0) allegro_exit();
00087 }
00088
00089 #endif