2018-08-24 20:59:24 +00:00
|
|
|
#ifdef USE_LIBAO
|
2021-05-31 17:44:55 +00:00
|
|
|
#include "audiostream.h"
|
2018-08-24 20:59:24 +00:00
|
|
|
#include <ao/ao.h>
|
|
|
|
|
2022-10-22 10:08:05 +00:00
|
|
|
class LibAOBackend : public AudioBackend
|
2018-08-24 20:59:24 +00:00
|
|
|
{
|
2022-10-22 10:08:05 +00:00
|
|
|
ao_device *aodevice = nullptr;
|
2019-04-05 19:05:18 +00:00
|
|
|
|
2022-10-22 10:08:05 +00:00
|
|
|
public:
|
|
|
|
LibAOBackend()
|
|
|
|
: AudioBackend("libao", "libao") {}
|
2019-04-05 19:05:18 +00:00
|
|
|
|
2022-10-22 10:08:05 +00:00
|
|
|
bool init() override
|
|
|
|
{
|
|
|
|
ao_initialize();
|
|
|
|
|
|
|
|
ao_sample_format aoformat {};
|
|
|
|
aoformat.bits = 16;
|
|
|
|
aoformat.channels = 2;
|
|
|
|
aoformat.rate = 44100;
|
|
|
|
aoformat.byte_format = AO_FMT_LITTLE;
|
|
|
|
|
|
|
|
aodevice = ao_open_live(ao_default_driver_id(), &aoformat, NULL); // Live output
|
|
|
|
if (aodevice == nullptr)
|
|
|
|
aodevice = ao_open_live(ao_driver_id("null"), &aoformat, NULL);
|
|
|
|
if (aodevice == nullptr) {
|
|
|
|
ERROR_LOG(AUDIO, "Cannot open libao driver");
|
|
|
|
ao_shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
return aodevice != nullptr;
|
|
|
|
}
|
2018-08-24 20:59:24 +00:00
|
|
|
|
2022-10-22 10:08:05 +00:00
|
|
|
u32 push(const void* frame, u32 samples, bool wait) override
|
|
|
|
{
|
|
|
|
if (aodevice != nullptr)
|
|
|
|
ao_play(aodevice, (char*)frame, samples * 4);
|
2019-04-05 19:05:18 +00:00
|
|
|
|
2022-10-22 10:08:05 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2018-08-24 20:59:24 +00:00
|
|
|
|
2022-10-22 10:08:05 +00:00
|
|
|
void term() override
|
2018-08-24 20:59:24 +00:00
|
|
|
{
|
2022-10-22 10:08:05 +00:00
|
|
|
if (aodevice != nullptr)
|
|
|
|
{
|
|
|
|
ao_close(aodevice);
|
|
|
|
aodevice = nullptr;
|
|
|
|
ao_shutdown();
|
|
|
|
}
|
2018-08-24 20:59:24 +00:00
|
|
|
}
|
|
|
|
};
|
2022-10-22 10:08:05 +00:00
|
|
|
static LibAOBackend libAOBackend;
|
2018-08-24 20:59:24 +00:00
|
|
|
|
|
|
|
#endif
|