Sorry, but where exactly do I start with the example provided? #369
-
Sorry for being such a dumbo but I can't figure out how to pause just in case and then resume again? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I'm assuming you're talking about the simple_playback example or the one in the readme (they're the same). That example is only really intended to be used as a starting point. To answer your question though, use The programming manual has pretty much everything you need to get started. You can find it at the top of miniaudio.h or online here: https://miniaud.io/docs/manual/index.html. |
Beta Was this translation helpful? Give feedback.
-
The data callback will have a parameter called A way to "pause" decoding is to simply not read from the decoder in the data callback. An important concept to consider is that the decoder and the device are entirely decoupled. If you don't read anything from the decoder you'll simply not hear anything and therefore the playback of the decoder will essentially be paused. Here's a quick sample (not tested): ma_bool32 g_IsPaused = MA_FALSE;
ma_bool32 g_Restart = MA_FALSE;
void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
{
// Restart if requested.
if (g_Restart) {
ma_decoder_seek_to_pcm_frame(pDecoder, 0);
g_Restart = MA_FALSE;
}
// Only read if the sound is not paused.
if (!g_IsPaused) {
ma_decoder_read_pcm_frames(pDecoder, pOutput, frameCount);
}
} For restarting you'll want to use Finally, one alternative you might consider is the work-in-progress high level API that I'm developing in the dev-0.11 branch. There's documentation and examples in that branch. This will save you with needing to deal with the low-level API and the multithreading stuff. The high level API uses the notion of a "sound" which you can just pause and resume and restart without needing to worry about the data callback. |
Beta Was this translation helpful? Give feedback.
The data callback will have a parameter called
frameCount
which is how many frames you should be reading from the decoder. If there are less frames available for decoding thanframeCount
it's all good. When you read, just read straight into the data callback's output buffer (pOutput
in the examples). You just need to make sure the decoder and device are configured with the same format or else you'll get horrible glitching.A way to "pause" decoding is to simply not read from the decoder in the data callback. An important concept to consider is that the decoder and the device are entirely decoupled. If you don't read anything from the decoder you'll simply not hear anything and therefore t…