mackron / miniaudio

Audio playback and capture library written in C, in a single source file.
https://miniaud.io
Other
4.07k stars 361 forks source link

High level API: kind of short noise when a sound finishes while another is in progress on the same ma_engine #408

Closed LouisDuVerdier closed 2 years ago

LouisDuVerdier commented 2 years ago

Hi,

First, thanks for your work, seem to be working very nicely, with a lot of feature and it looks waaay faster than certain libs I used before discovering your work!

I just found an issue under Windows (and Android, based on my tests) when there is a kind of very short saturated noise (the kind you would get when putting your finger on the jack of audio speakers) when two sounds are playing, one finishes and the other keeps going.

Code is more or less the basic High level API example, but with two sounds (e.g. for Windows):

int main(int argc, char** argv)
{
    ma_result result;
    ma_engine engine;

    result = ma_engine_init(NULL, &engine);
    if (result != MA_SUCCESS) {
        printf("Failed to initialize audio engine.");
        return -1;
    }

    ma_engine_play_sound(&engine, "short_sound.wav", NULL);
    ma_engine_play_sound(&engine, "longer_sound.wav", NULL);

    Sleep(5000);

    ma_sound_group_uninit(&group);
    ma_engine_uninit(&engine);

    return 0;
}

In case it's useful, media info of longer_sound: 1s 416 ms, 1 411,2 kb/s, 44,1 kHz, 16 bits, 2 channels. short_sound is exactly the same, but it lasts 621 ms. I can send those to you if it is useful for you to attempt to reproduce.

Using low level API doesn't give any noise (with two decoders and two devices - though I'm not sure if I'm supposed to use that this way, I'm still new with your work and still have to read more the documentation, code and examples). It might be because low level doesn't use node graph to mix sounds, unless I misread something.

There is no noise when using two ma_engines, but it looks like in general we probably should have only one for simple use cases.

MA_DEBUG_OUTPUT:

DEBUG: Loading library: ole32.dll
DEBUG: Loading symbol: CoInitializeEx
DEBUG: Loading symbol: CoUninitialize
DEBUG: Loading symbol: CoCreateInstance
DEBUG: Loading symbol: CoTaskMemFree
DEBUG: Loading symbol: PropVariantClear
DEBUG: Loading symbol: StringFromGUID2
DEBUG: Loading library: user32.dll
DEBUG: Loading symbol: GetForegroundWindow
DEBUG: Loading symbol: GetDesktopWindow
DEBUG: Loading library: advapi32.dll
DEBUG: Loading symbol: RegOpenKeyExA
DEBUG: Loading symbol: RegCloseKey
DEBUG: Loading symbol: RegQueryValueExA
DEBUG: Attempting to initialize WASAPI backend...
DEBUG: Loading library: kernel32.dll
DEBUG: Loading symbol: VerifyVersionInfoW
DEBUG: Loading symbol: VerSetConditionMask
DEBUG: System Architecture:
DEBUG:   Endian: LE
DEBUG:   SSE2:   YES
DEBUG:   AVX2:   NO
DEBUG:   NEON:   NO
DEBUG: [WASAPI] Trying IAudioClient3_InitializeSharedAudioStream(actualPeriodInFrames=480)
DEBUG:     defaultPeriodInFrames=480
DEBUG:     fundamentalPeriodInFrames=480
DEBUG:     minPeriodInFrames=480
DEBUG:     maxPeriodInFrames=480
DEBUG: [WASAPI] Using IAudioClient3
DEBUG:     periodSizeInFramesOut=480
INFO: [WASAPI]
INFO:   Casque pour téléphone (Razer Kraken 7.1 V2) (Playback)
INFO:     Format:      32-bit IEEE Floating Point -> 32-bit IEEE Floating Point
INFO:     Channels:    2 -> 2
INFO:     Sample Rate: 48000 -> 48000
INFO:     Buffer Size: 480*3 (1440)
INFO:     Conversion:
INFO:       Pre Format Conversion:  NO
INFO:       Post Format Conversion: NO
INFO:       Channel Routing:        NO
INFO:       Resampling:             NO
INFO:       Passthrough:            YES

Tested with dev and 0.11.5, headphones and speakers, same result.

Would you per chance have an idea?

Please do not hesitate if you need anything!

Thank you, Louis

mackron commented 2 years ago

Thanks for the report. If it's OK, are you able to send me those files? You can send them to me privately via email or whatever suits you.

I'll investigate this one ASAP. Most likely it's mixing in some garbage by accident in the node graph.

With the low level stuff you certainly don't want to be using two devices. You would use one device and mix your two sounds.

LouisDuVerdier commented 2 years ago

Hi,

I just sent those files via email. Please don't hesitate if you need anything! Regarding low level, ok, that makes sense, I wasn't sure, thanks for the info! :)

Thank you very much! Louis

mackron commented 2 years ago

I think this should be fixed now. The fix is in the dev branch. Are you able to give that a try on your end?

LouisDuVerdier commented 2 years ago

Looks good for both Windows and Android, that was fast, thank you very much!

mackron commented 2 years ago

Great. Thanks for testing that and the sample files. This will be released soon.

mackron commented 2 years ago

This has been released.