12 #include "../stdafx.h"
19 #include "../safeguards.h"
23 static AUDIOSTREAM *_stream =
nullptr;
25 static int _buffer_size;
30 if (_stream ==
nullptr)
return;
32 void *data = get_audio_stream_buffer(_stream);
34 if (data ==
nullptr)
return;
37 MxMixSamples(data, _buffer_size);
40 uint16_t *snd = (uint16_t*)data;
41 for (
int i = 0; i < _buffer_size * 2; i++) snd[i] ^= 0x8000;
44 free_audio_stream_buffer(_stream);
51 extern int _allegro_instance_count;
55 if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno,
nullptr)) {
56 Debug(driver, 0,
"allegro: install_allegro failed '{}'", allegro_error);
57 return "Failed to set up Allegro";
59 _allegro_instance_count++;
62 if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT,
nullptr) != 0) {
63 Debug(driver, 0,
"allegro: install_sound failed '{}'", allegro_error);
64 return "Failed to set up Allegro sound";
68 if (digi_card == DIGI_NONE) {
69 Debug(driver, 0,
"allegro: no sound card found");
70 return "No sound card found";
75 _stream = play_audio_stream(_buffer_size, 16,
true, hz, 255, 128);
82 if (_stream !=
nullptr) {
83 stop_audio_stream(_stream);
88 if (--_allegro_instance_count == 0) allegro_exit();
Base for playing sound via Allegro.
Factory for the allegro sound driver.
void Stop() override
Stop this driver.
void MainLoop() override
Called once every tick.
std::optional< std::string_view > Start(const StringList ¶m) override
Start this driver.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
int GetDriverParamInt(const StringList &parm, const char *name, int def)
Get an integer parameter the list of parameters.
std::vector< std::string > StringList
Type for a list of strings.