mackron / miniaudio

Audio playback and capture library written in C, in a single source file.
https://miniaud.io
Other
4.07k stars 361 forks source link

Add examples/simple_playback_woowoo.c. #477

Closed smcpeak closed 2 years ago

smcpeak commented 2 years ago

This PR adds a new example. It is similar to simple_playback_sine.c, but it does not use the wa_waveform API, making it just a little bit easier for a new user to understand how to populate the sample buffer. I also added comments in data_callback that explain a little more of what is going on.

I initially created this example for myself, and thought others might find it useful too.

The name "woowoo" is a crude approximation of the sound it makes by default.

mackron commented 2 years ago

That's for this, but unfortunately I'm not going to accept this one. It's just an extra maintenance cost for me which I don't want to take on, and I don't think it's different enough from the sine wave example to justify it.

The sine wave example is actually there for a very specific reason - it's the most basic way of testing that audio playback is working without needing to pass in a sound file. It's what I get people to run when they complain of their own program not working properly thereby giving me an indication as to whether or not the problem is with miniaudio or their own program.

smcpeak commented 2 years ago

No problem.

But let me just add a bit more context, then, about why I thought this could help. I found my way here while answering a Stack Overflow question someone had about miniaudio: What is the input data format of a sound card (in library miniaudio or others)?.

I found simple_playback_sine.c, and wanted to use that as the basis for answering the question since, like you say, it has no dependencies. But it delegates to ma_waveform to generate the samples, making it not ideal for answering the newbie question, since I'd have to also explain what ma_waveform_read_pcm_frames does. Therefore I created the new one to be even simpler, and explicitly show the process of generating samples, since that's the usual interface between the application and the audio library.

An alternative to this new example would be to adjust simple_playback_sine.c to be a bit clearer for those new to the library, perhaps by adding more comments inside data_callback that explain what is happening.