Hi all,
I’m new to Defold and I’d like to contribute to the engine, especially to its audio implementation on Android and iOS. But I have a hard time figuring out how audio is implemented in Defold.
First of all: it seems that Defold uses multiple versions of OpenSL ES (in device_opensl.cpp and in opensl.c), and I don’t find a CoreAudio device for iOS except the openAL Alc backend coreaudio.c).
In sound.cpp I further find that the SoundSystem
runs on its own thread and calls UpdateInternal
to update the mixer. In sound.cpp I also find that the SoundSystem
can be updated from the main thread via the Update
function.
Coming from an audio programming background I am somewhat surprised since the audio systems on mobile run on a high-prio thread and provide the data in via a callback. I would therefore expect that the SoundSystem
is updated via this callback. Something like
static void sound_mix(float* buffer, int samples)
{
for (int i = 0; i < SOUNDS; i++)
{
if (sounds[i].state == STATE_PLAYING)
{
mix(buffer, &(sounds[i].source.buffer), samples);
}
}
static void audio_callback(float* input, float* output, int samples)
{
// from microphone
input_filter(input, buffer, samples);
// mix with active sounds
sound_mix(buffer, samples);
// post processing
output_filter(buffer, samples);
// to speakers
buffer_to_output(buffer, output, samples);
}
Could someone elaborate on this a bit? Thanks in advance!