jarikomppa / soloud

Free, easy, portable audio engine for games
http://soloud-audio.com
Other
1.69k stars 270 forks source link

Delay when playing a lot of audio at the same time #351

Closed congard closed 1 year ago

congard commented 1 year ago

Expected behavior:

Continuous playback (recorded on the same machine using pydub):

https://user-images.githubusercontent.com/35779485/188732482-df7a66b5-c8ce-463d-9190-fa74074c155b.mp4

Actual behavior:

As the title says - there is some delay (?) when playing a lot of audio at the same time, it seems that audio is playing in some "portions", like there is some kind of queue.

https://user-images.githubusercontent.com/35779485/188732559-e77c6598-d952-4432-844a-84a78cf22272.mp4

Also, if you remove usleep(10 * 1000) from the code below, you will hear something like this:

https://user-images.githubusercontent.com/35779485/188735046-2c47a402-bf00-430d-8030-9ef2229526ec.mp4

Steps to reproduce the problem:

The problem can be reproduced with the following code:

SoLoud::Soloud soloud;
soloud.init();

SoLoud::Bus bus;
soloud.play(bus);

SoLoud::Wav wave;
wave.load("audio/SfxCrystal1.ogg");

for (int i = 0; i < 50; ++i) {
    usleep(10 * 1000);
    bus.play(wave);
    // soloud.play(wave); // same here
}

SoLoud version, operating system, backend used, any other potentially useful information:

Attachments:

congard commented 1 year ago

Fixed:

SoLoud::Soloud soloud;
soloud.setMaxActiveVoiceCount(64);
soloud.init();

:D