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 "../driver.h"
00017 #include "../mixer.h"
00018 #include "../debug.h"
00019 #include "allegro_s.h"
00020 #include <allegro.h>
00021
00022 static FSoundDriver_Allegro iFSoundDriver_Allegro;
00024 static AUDIOSTREAM *_stream = NULL;
00026 static const int BUFFER_SIZE = 4096;
00027
00028 void SoundDriver_Allegro::MainLoop()
00029 {
00030
00031 if (_stream == NULL) return;
00032
00033 void *data = get_audio_stream_buffer(_stream);
00034
00035 if (data == NULL) return;
00036
00037
00038 MxMixSamples(data, BUFFER_SIZE);
00039
00040
00041 uint16 *snd = (uint16*)data;
00042 for (int i = 0; i < BUFFER_SIZE * 2; i++) snd[i] ^= 0x8000;
00043
00044
00045 free_audio_stream_buffer(_stream);
00046 }
00047
00050 extern int _allegro_instance_count;
00051
00052 const char *SoundDriver_Allegro::Start(const char * const *parm)
00053 {
00054 if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, NULL)) {
00055 DEBUG(driver, 0, "allegro: install_allegro failed '%s'", allegro_error);
00056 return "Failed to set up Allegro";
00057 }
00058 _allegro_instance_count++;
00059
00060
00061 if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0) {
00062 DEBUG(driver, 0, "allegro: install_sound failed '%s'", allegro_error);
00063 return "Failed to set up Allegro sound";
00064 }
00065
00066
00067 if (digi_card == DIGI_NONE) {
00068 DEBUG(driver, 0, "allegro: no sound card found");
00069 return "No sound card found";
00070 }
00071
00072 _stream = play_audio_stream(BUFFER_SIZE, 16, true, 44100, 255, 128);
00073 MxInitialize(44100);
00074 return NULL;
00075 }
00076
00077 void SoundDriver_Allegro::Stop()
00078 {
00079 if (_stream != NULL) {
00080 stop_audio_stream(_stream);
00081 _stream = NULL;
00082 }
00083 remove_sound();
00084
00085 if (--_allegro_instance_count == 0) allegro_exit();
00086 }
00087
00088 #endif