| 1 | This is just a little experiment to explore some ideas for the kind of API that I would build if I |
| 2 | was building my own operation system. The name "osaudio" means Operating System Audio. Or maybe you |
| 3 | can think of it as Open Source Audio. It's whatever you want it to be. |
| 4 | |
| 5 | The idea behind this project came about after considering the absurd complexity of audio APIs on |
| 6 | various platforms after years of working on miniaudio. This project aims to disprove the idea that |
| 7 | complete and flexible audio solutions and simple APIs are mutually exclusive and that it's possible |
| 8 | to have both. I challenge anybody to prove me wrong. |
| 9 | |
| 10 | In addition to the above, I also wanted to explore some ideas for a different API design to |
| 11 | miniaudio. miniaudio uses a callback model for data transfer, whereas osaudio uses a blocking |
| 12 | read/write model. |
| 13 | |
| 14 | This project is essentially just a header file with a reference implementation that uses miniaudio |
| 15 | under the hood. You can compile this very easily - just compile osaudio_miniaudio.c, and use |
| 16 | osaudio.h just like any other header. There are no dependencies for the header, and the miniaudio |
| 17 | implementation obviously requires miniaudio. Adjust the include path in osaudio_miniaudio.c if need |
| 18 | be. |
| 19 | |
| 20 | See osaudio.h for full documentation. Below is an example to get you started: |
| 21 | |
| 22 | ```c |
| 23 | #include "osaudio.h" |
| 24 | |
| 25 | ... |
| 26 | |
| 27 | osaudio_t audio; |
| 28 | osaudio_config_t config; |
| 29 | |
| 30 | osaudio_config_init(&config, OSAUDIO_OUTPUT); |
| 31 | config.format = OSAUDIO_FORMAT_F32; |
| 32 | config.channels = 2; |
| 33 | config.rate = 48000; |
| 34 | |
| 35 | osaudio_open(&audio, &config); |
| 36 | |
| 37 | osaudio_write(audio, myAudioData, frameCount); // <-- This will block until all of the data has been sent to the device. |
| 38 | |
| 39 | osaudio_close(audio); |
| 40 | ``` |
| 41 | |
| 42 | Compare the code above with the likes of other APIs like Core Audio and PipeWire. I challenge |
| 43 | anybody to argue their APIs are cleaner and easier to use than this when it comes to simple audio |
| 44 | playback. |
| 45 | |
| 46 | If you have any feedback on this I'd be interested to hear it. In particular, I'd really like to |
| 47 | hear from people who believe the likes of Core Audio (Apple), PipeWire, PulseAudio or any other |
| 48 | audio API actually have good APIs (they don't!) and what makes their's better and/or worse than |
| 49 | this project. |