2 questions about duplex devices and automatic sample rate conversion #468
-
|
Hi, I'm trying to build a better understanding about what's going on with my duplex device after noticing this line in the example for duplex devices:
So for example, if I have a mic with a sample rate of 16kHz and a playback device with a sample rate 48kHz paired as my duplex device, I have two questions:
void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
{
MA_ASSERT(pDevice->capture.format == pDevice->playback.format);
MA_ASSERT(pDevice->capture.channels == pDevice->playback.channels);
/* In this example the format and channel count are the same for both input and output which means we can just memcpy(). */
MA_COPY_MEMORY(pOutput, pInput, frameCount * ma_get_bytes_per_frame(pDevice->capture.format, pDevice->capture.channels));
}Thank you in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The data flows like this: Of course, the resampling step only happens if it's necessary. |
Beta Was this translation helpful? Give feedback.
When you specify an explicit sample rate in the device config, that'll be the rate that's used and both the capture and playback side's will be resampled to that if necessary. Otherwise, if you leave the sample rate set to 0, it'll use the capture device's native sample rate, meaning the playback device will be resampled to match the capture side's sample rate.
Yes, if resampling is required on the capture side,
pInputwill already have been resampled by the time it hits the callback. You can assumepOutputis the same sample rate. If the playback side requires resampling, it'll be done internally by miniaudio after the callback returns.The data flows like this: