You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Again, thank you very much for your work, really amazing to be able to use your library!
I come today because I think I found a bug while troubleshooting some sound cracking issues that I recently introduced in a project I'm working on.
In short, when doing the following:
Load a sound with ma_resource_manager_register_encoded_data() - required in particular for Android where paths are special
Start a sound
Wait for a bit
Then call ma_sound_get_length_in_seconds() - in my case it was to get the progress before stopping the sound, but reason is not really important
This call from time to time generates a "cracking sound"
I could reproduce this under Windows (easier with DirectSound than WASAPI) and I could hear this under Android as well, so feels platform/backend unrelated. Also, I tried with .ogg and .mp3 files, with same results.
Here is a sample of code to reproduce the issue:
#defineMA_DEBUG_OUTPUT
#defineMINIAUDIO_IMPLEMENTATION
#defineMA_NO_WASAPI
#include<miniaudio.h>
#include<windows.h>
#include<fstream>voidtestCrackingSound()
{
ma_engine_config engineConfig = ma_engine_config_init();
ma_engine engine;
auto result = ma_engine_init(&engineConfig, &engine);
if (result != MA_SUCCESS)
{
std::cerr << "Failed to initialize audio engine due to error:" << static_cast<int>(result) << std::endl;
return;
}
constchar *path = "C:\\Users\\[...]\\myfile.mp3";
constchar *aliasPath = "Ambiance_01.mp3"; // Different file to ensure original path is not loaded
std::ifstream file(path, std::ios::binary);
file.seekg(0, std::ios::end);
std::streamsize size = file.tellg();
file.seekg(0, std::ios::beg);
std::vector<char> buffer(size);
if (!file.read(buffer.data(), size)) {
std::cerr << "Error: Could not read the file" << std::endl;
return;
}
result = ma_resource_manager_register_encoded_data(engine.pResourceManager, aliasPath, buffer.data(), buffer.size());
if (result != MA_SUCCESS)
{
std::cerr << "Failed to register encoded data from audio file due to error:" << ma_result_description(result);
return;
}
for (int i = 0; i < 20; ++i)
{
ma_sound sound;
result = ma_sound_init_from_file(&engine, aliasPath, MA_SOUND_FLAG_DECODE | MA_SOUND_FLAG_NO_PITCH | MA_SOUND_FLAG_NO_SPATIALIZATION, nullptr, nullptr, &sound);
if (result != MA_SUCCESS)
{
std::cerr << "ma_sound_init_from_file failed" << std::endl;
return;
}
auto getLength = [](ma_sound &sound)
{
float length = 0;
ma_sound_get_length_in_seconds(&sound, &length);
returnstatic_cast<int>(length * 1000);
};
result = ma_sound_start(&sound);
if (result != MA_SUCCESS)
{
std::cerr << "Failed to start" << path << "due to error:" << ma_result_description(result) << std::endl;
return;
}
Sleep(1500);
int length = getLength(sound);
std::cout << "Length: " << length << std::endl;
Sleep(1500);
ma_sound_uninit(&sound);
}
ma_engine_uninit(&engine);
}
The test does the following:
Create an engine/etc.
Load manually a sound and register it with ma_resource_manager_register_encoded_data()
Then repeat N times the test, i.e. ma_sound_init_from_file() with the registered alias + start it, and call 1.5sec later ma_sound_get_length_in_seconds(), that sometimes causes the sound to crack
You may see in the output that one occurrence returned length 75528 instead of 75552 - but issue happened in this run around 30% of runs, so not directly related
If you change line ma_sound_init_from_file(&engine, aliasPath, [...] to use path instead of aliasPath (to let miniaudio load the sound by itself), there is no issue
I'm currently using latest "dev" branch (12a8d4e).
Does it ring some bell to you by any chance? Please let me know if you need anything else!
Thank you,
Louis
The text was updated successfully, but these errors were encountered:
Oh I think I get it, when looking at the code of ma_dr_mp3_get_mp3_and_pcm_frame_count for example, it seems that it first seeks to start of stream, then counts the size, then seeks back at old position, which can create a glitch if sound is running (that probably explains as well why it returned different values from time to time as well).
Not sure why I can't reproduce with "path" instead of "aliasPath", might just be a timing issue.
That seems to mean that ma_data_source_get_length_in_pcm_frames() is unsafe and that it shouldn't be called while a sound is playing, e.g. by caching that on my side when loading it? What do you think?
Hello!
Again, thank you very much for your work, really amazing to be able to use your library!
I come today because I think I found a bug while troubleshooting some sound cracking issues that I recently introduced in a project I'm working on.
In short, when doing the following:
I could reproduce this under Windows (easier with DirectSound than WASAPI) and I could hear this under Android as well, so feels platform/backend unrelated. Also, I tried with .ogg and .mp3 files, with same results.
Here is a sample of code to reproduce the issue:
The test does the following:
Example of output:
My findings so far:
I'm currently using latest "dev" branch (12a8d4e).
Does it ring some bell to you by any chance? Please let me know if you need anything else!
Thank you,
Louis
The text was updated successfully, but these errors were encountered: