cute_sound: ALSA Backend - Looking for Pull Request
From #12
Even if I'm a windows user, the geek in me knows that an ALSA backend would be a great addition. FYI, http://github.com/yui0/aplay-/blob/master/alsa.h (PD)
Another PD licensed solution here https://github.com/dr-soft/mini_al
I'll try implementing this today, assuming I can successfully use WSL on Windows to test it out.
Hmm, looks like ALSA is not supported with WSL. I'll try virtual box then.
@r-lyeh Alright, I've got a basic port going. Though there are some problems.
- When I first boot up my machine and run the ALSA demo, there's a segfault. I have no idea why. It only happens the first time the program is run after a machine restart. Which makes it very annoying to debug. And unfortunately the segfault occurs after some audio starts playing.
- Timing is all weird. I have no idea why. This could be because of
usleep, or because I have a low-end machine in my virtual box, or because the ALSA handling is poor. I really am not sure. I don't currently understand very well how timings with ALSA work, in terms of feeding in the correct number of samples over a period of time. I fear I might be mixing in too much silence when no audio is playing, causing a time warp effect where silence can be really long or shorter randomly.
Anyways, I'm going to call it good enough for now. Maybe someone else will have a little more knowledge about ALSA and comment here, by the time I take another look.
My main reference for implementation came from SDL: https://github.com/spurious/SDL-mirror/blob/17af4584cb28cdb3c2feba17e7d989a806007d9f/src/audio/alsa/SDL_alsa_audio.c
Hmm, looks like there's a callback API I completely missed. ALSA can probably be setup just like CoreAudio and SDL, which might be a lot easier than the current strategy. I found a nice page to reference for this: https://alsa.opensrc.org/Asynchronous_Playback_(Howto)#Initializing_the_Callback
Going to nix this and just stick with SDL2 backend for Linux.