2019-09-07 12:37:39 +00:00
|
|
|
#include "audiostream.h"
|
2018-08-24 20:59:24 +00:00
|
|
|
#ifdef USE_LIBAO
|
|
|
|
|
|
|
|
#include <ao/ao.h>
|
|
|
|
|
|
|
|
static ao_device *aodevice;
|
|
|
|
static ao_sample_format aoformat;
|
|
|
|
|
|
|
|
static void libao_init()
|
|
|
|
{
|
|
|
|
ao_initialize();
|
|
|
|
memset(&aoformat, 0, sizeof(aoformat));
|
2019-04-05 19:05:18 +00:00
|
|
|
|
2018-08-24 20:59:24 +00:00
|
|
|
aoformat.bits = 16;
|
|
|
|
aoformat.channels = 2;
|
|
|
|
aoformat.rate = 44100;
|
|
|
|
aoformat.byte_format = AO_FMT_LITTLE;
|
2019-04-05 19:05:18 +00:00
|
|
|
|
2018-08-24 20:59:24 +00:00
|
|
|
aodevice = ao_open_live(ao_default_driver_id(), &aoformat, NULL); // Live output
|
|
|
|
if (!aodevice)
|
|
|
|
aodevice = ao_open_live(ao_driver_id("null"), &aoformat, NULL);
|
|
|
|
}
|
|
|
|
|
2020-03-14 21:46:40 +00:00
|
|
|
static u32 libao_push(const void* frame, u32 samples, bool wait)
|
2018-08-24 20:59:24 +00:00
|
|
|
{
|
2019-04-05 19:05:18 +00:00
|
|
|
if (aodevice)
|
2020-03-16 17:03:43 +00:00
|
|
|
ao_play(aodevice, (char*)frame, samples * 4);
|
2019-04-05 19:05:18 +00:00
|
|
|
|
2018-08-24 20:59:24 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-04-05 19:05:18 +00:00
|
|
|
static void libao_term()
|
2018-08-24 20:59:24 +00:00
|
|
|
{
|
|
|
|
if (aodevice)
|
|
|
|
{
|
|
|
|
ao_close(aodevice);
|
|
|
|
ao_shutdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-14 21:46:40 +00:00
|
|
|
static audiobackend_t audiobackend_libao = {
|
2018-08-24 20:59:24 +00:00
|
|
|
"libao", // Slug
|
|
|
|
"libao", // Name
|
|
|
|
&libao_init,
|
|
|
|
&libao_push,
|
2019-05-02 17:02:34 +00:00
|
|
|
&libao_term,
|
|
|
|
NULL
|
2018-08-24 20:59:24 +00:00
|
|
|
};
|
|
|
|
|
2019-04-05 19:05:18 +00:00
|
|
|
static bool ao = RegisterAudioBackend(&audiobackend_libao);
|
2018-08-24 20:59:24 +00:00
|
|
|
#endif
|