Closed maximecb closed 1 year ago
I have a basic audio output API working now: https://github.com/maximecb/uvm/commit/04160058682ae49eaa3625f145a71ba7f3385f99
And the ball example now makes use of it: https://github.com/maximecb/uvm/commit/a729283f983c96242689268405e82539d8a82168
We could use some more compelling audio examples though :)
I'd like to have an API to output audio data so people can make games and audio software. I think that audio output is generally more important than input, so we could start with output, and add input later.
We'll need a syscall to open an audio device, with a number of channels and a sample rate. This will interface with SDL audio internally, but the details of SDL APIs should be hidden from software running on UVM.
It might also be useful to have a function that just says "play these sample right now". This could be used for playing back something like a simple sound effect when someone clicks a button, without having to worry about buffers or things like that. This would be useful for simple games as well.
For more advanced usage, we're going to want a way to register a callback to generate audio samples as needed. The SDL API for generating samples calls a function from a separate thread. In order to keep working with a single-threaded event loop model in UVM, we may need to take a VM lock from the audio thread in order to call the user-registered callback inside UVM.
Sketch of syscalls we would minimally need:
audio_open_output(sample_rate, num_channels, flags: u32) -> device_id
audio_output_cb(out_device_id, callback_ptr)
register a callback to generate output samplesaudio_close_output(device_id)
Input/feedback/help welcome.