flycast/core/oslib/audiobackend_libao.cpp

52 lines
930 B
C++
Raw Normal View History

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));
2018-08-24 20:59:24 +00:00
aoformat.bits = 16;
aoformat.channels = 2;
aoformat.rate = 44100;
aoformat.byte_format = AO_FMT_LITTLE;
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);
}
static u32 libao_push(const void* frame, u32 samples, bool wait)
2018-08-24 20:59:24 +00:00
{
if (aodevice)
2020-03-16 17:03:43 +00:00
ao_play(aodevice, (char*)frame, samples * 4);
2018-08-24 20:59:24 +00:00
return 1;
}
static void libao_term()
2018-08-24 20:59:24 +00:00
{
if (aodevice)
{
ao_close(aodevice);
ao_shutdown();
}
}
static audiobackend_t audiobackend_libao = {
2018-08-24 20:59:24 +00:00
"libao", // Slug
"libao", // Name
&libao_init,
&libao_push,
&libao_term,
NULL
2018-08-24 20:59:24 +00:00
};
static bool ao = RegisterAudioBackend(&audiobackend_libao);
2018-08-24 20:59:24 +00:00
#endif