Latency issues #439
-
Dear @mackron , For a project I am using the miniaudio library for file playback and decoding. The goal is to make an application for an embedded Linux system with less powerful hardware (ARM single core, 500 MHz CLK). When testing on the less powerful hardware I noticed there is some latency when trying to playback larger files (in this case a 160MB mp3 file). So I switched back to a simple example you once provided on this forum and added a timer to check the latency. I used the code below:
I ran this test program twice using the 160MB mp3, once on my desktop running Ubuntu and once on the ARM processor running a light weight debian distro and got the following results (note: the binaries have different names because they need different compilers, but they are both compiled from the code above): So on my PC it took 0.26 seconds and on the ARM processor it took over 6 seconds which I believe is quite a number. Am I doing something wrong or do you have some advice in order to decrease these numbers? Thank you in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 2 replies
-
Both of those seem quite slow to me. My suggestion is to move your timers around to try and isolate the specific function call that's taking so long. Currently your timer encompasses device initialization and startup in addition to loading the resource. If you can narrow down your timer a bit it might give us some better intelligence as to what might be causing the slow down. For a stream, the size of the file shouldn't make any difference to load times. I'm also suspecting that it could be device initialization that's taking so long. |
Beta Was this translation helpful? Give feedback.
-
Dear @mackron , Thank you for your answer. I narrowed the latency down to the
The first test uses a 160MB file resulting in a latency of 0.26 seconds, in the second test a file of only 5MB is used resulting in a latency of 0.04 seconds: |
Beta Was this translation helpful? Give feedback.
-
I have an idea on what might be happening, but not 100% sure. Are you able to do an experiment? In miniaudio.h, there's this function: MA_API ma_result ma_mp3_get_length_in_pcm_frames(ma_mp3* pMP3, ma_uint64* pLength)
{
if (pLength == NULL) {
return MA_INVALID_ARGS;
}
*pLength = 0; /* Safety. */
if (pMP3 == NULL) {
return MA_INVALID_ARGS;
}
#if !defined(MA_NO_MP3)
{
*pLength = drmp3_get_pcm_frame_count(&pMP3->dr);
return MA_SUCCESS;
}
#else
{
/* mp3 is disabled. Should never hit this since initialization would have failed. */
MA_ASSERT(MA_FALSE);
return MA_NOT_IMPLEMENTED;
}
#endif
} Are you able to comment out this line: |
Beta Was this translation helpful? Give feedback.
-
@mackron Yes!!! Your answer above seems to be fixing the problem. Here are the results, both with the 160MB mp3 file again, once with the line commented out and once not: Thank you so so much! :-) |
Beta Was this translation helpful? Give feedback.
-
OK, I'll review the code for stream initialization and avoid calling that function. I don't think it should be necessary off the top of my head. Thanks for checking that for me. |
Beta Was this translation helpful? Give feedback.
-
I just did some more experiments and it is hard to prove but adding the I would love to do some more tests with the |
Beta Was this translation helpful? Give feedback.
-
What you're explaining sounds exactly what I would expect. There's no real way around it so long as the length is getting retrieved at initialization time. In the dev branch I've added a new flag called |
Beta Was this translation helpful? Give feedback.
-
Dear @mackron, Just a suggestion but isn't there a way to run the |
Beta Was this translation helpful? Give feedback.
I have an idea on what might be happening, but not 100% sure. Are you able to do an experiment? In miniaudio.h, there's this function: