What's going on here? Last week I wrote about the frustrations of programming audio. Last week I was stuck on a problem where I had no idea what the issue was. It turns out that in PulseAudio, if you use the async server and don't close it properly, it enters a state where it no longer works or stays in async mode, I'm not exactly sure why. All I know is that when switching back to the simple sync API, if the audio doesn't play even though PulseAudio says it had no problems writing and draining the audio from your buffer into the audio device's buffer, try changing the server name. It seemed to work for me. This time I've ensured the server closes before my program exits.
Mini DJ
This morning, after I got the audio working, I was finally able to enjoy experimenting with frequencies and linking them to buttons. Essentially, I built a mini DJ station. Currently it only has about four or five frequencies, but it's incredibly fun. The beauty of it is that once you get it working, it's bloody simple to play sound. Just fill a buffer and send it to the system; that's all there is to it. Sure, when starting out it takes some time, but that's true for most things that are worthwhile. Once it's done, though, it's the same code for every other project you'll ever need. The PulseAudio library is more than twenty years old at this point, so it's safe to assume my code will work for a long while. Thanks to the generous work of the Linux kernel developers.