Replies: 1 comment 39 replies
-
|
So miniaudio updates the sound's cursor every time the audio thread does a processing step. The size of that step will be fixed intervals, defaulting to 10ms. You can configure that to something smaller if need be. The fact that it's running on the audio thread could be why you're getting jittering. The engine maintains a running timer in frames that is updated on the audio thread after each processing step. This might be helpful for you.
There's several ways you might be able to do this. One way is to implement your own void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
{
ma_engine_read_pcm_frames((ma_engine*)pDevice->pUserData, pOutput, frameCount, NULL);
// Inspect the value of your sound's cursors. Keep an accumulation of `frameCount` to keep track of the audio timer.
}
// Initialize the device using miniaudio's standard config/init pattern.
ma_device_config deviceConfig = ma_device_config_init(ma_device_type_playback);
deviceConfig.playback.format = ma_format_f32; // Must be f32 when using with the engine.
deviceConfig.playback.channels = 0; // 0 means to use the device's native channel count.
deviceConfig.sampleRate = 48000; // Or whatever sample rate you need. Leave as 0 to use the device's native rate.
deviceConfig.dataCallback = data_callback;
deviceConfig.pUserData = &engine;
ma_device_init(NULL, &deviceConfig, &myDevice);
// Plug your device into your engine config.
ma_engine_config engineConfig = ma_engine_config_init();
engineConfig.pDevice = &myDevice;
ma_engine_init(&engineConfig, &engine);So it'll be slightly annoying because you'll have to manage your own Another option is to plug in a custom passthrough node immediately after your sound. That will have it's processing callback fired from the audio thread, straight after the sound has had it's processing completed, and therefore it's cursor updated. Here's an example for custom node: https://github.com/mackron/miniaudio/tree/master/extras/nodes/ma_reverb_node. You would set the Finally, if you're brave, you can use the dev-0.12 branch. That branch will eventually become the 0.12 release of miniaudio, and it includes the ability to plug in a callback that get's fired just after the sound has been processed. It gets called on the audio thread so therefore it'll also be fired straight after the cursor has been updated. That branch introduces the notion of sound notifications. Do a search for the Happy to go through any of these ideas in more detail if need be. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm working on a rhythm game, and i'm trying to get sample accurate (or even just milisecond accurate) cursor time to draw my visuals at the right positions, miniaudio at the moment when using
ma_sound_get_cursor_in_secondsreturns a value which updates slowly, causing constant visual jitter.Attempting to interpolate this myself then "syncing back" to the audio time just leads to occasional jitter, as i dont "sync" to the miniaudio cursor time perfectly, since i dont know exactly when the miniaudio cursor time changes, is there a way to get some callback to run code exactly when it updates the cursor time?
As if i use
SDL_GetPerformanceCounterexactly when it updates the audio time, then im able to callSDL_GetPerformanceCounterwhenever i need an accurate time, and subtract by the new value of it by the value of it when the time updated, giving me a (accurate enough) estimate of the current real cursor timeBeta Was this translation helpful? Give feedback.
All reactions