okay I noticed something very very weird. I am not sure if I am doing something wrong here or if it is your library.
I created a little dummy project to experiment with the sound system and it looks like this atm:
- Note that it is not the final usecase to play raw pcm files, but little pcm frames after one and another. -
But the problem is the same
File pcmData = ...;
ScheduledExecutorService executorService = Executors.newScheduledThreadPool(0);
SoundSystemConfig.addLibrary(LibraryJavaSound.class);
SoundSystemConfig.setCodec("wav", CodecWav.class);
SoundSystemConfig.setNumberStreamingChannels(5);
SoundSystemConfig.setNumberNormalChannels(27);
SoundSystem mySoundSystem = new SoundSystem();
mySoundSystem.rawDataStream(
new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 48000, 16, 1, 2, 48000, false),
false,
"test1",
0,
0,
0,
SoundSystemConfig.ATTENUATION_ROLLOFF,
SoundSystemConfig.getDefaultRolloff());
mySoundSystem.rawDataStream(
new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 48000, 16, 1, 2, 48000, false),
false,
"test2",
0,
0,
0,
SoundSystemConfig.ATTENUATION_ROLLOFF,
SoundSystemConfig.getDefaultRolloff());
executorService.submit(
() -> {
try {
mySoundSystem.feedRawAudioData("test1", new byte[] {});
mySoundSystem.feedRawAudioData("test1", Files.toByteArray(pcmData));
mySoundSystem.play("test1");
} catch (IOException e) {
e.printStackTrace();
}
});
executorService.schedule(
() -> {
try {
mySoundSystem.feedRawAudioData("test2", new byte[] {});
mySoundSystem.feedRawAudioData("test2", Files.toByteArray(pcmData));
mySoundSystem.play("test2");
} catch (Exception ex) {
ex.printStackTrace();
}
},
2,
TimeUnit.SECONDS);
While doing this, I would expect the file to be played once at the beginning and a second time starting 2 seconds after the first in parallel. But it does not. It does not even cut off the other source, but rather waits until the first is finished until it finally plays the second time. I have also notices the feedRawAudioData method is blocking when trying to play the second sound until the first one has finished.
This behavior is exactly the same I have noticed previously with pcm audio chunks in my voicechat.
Oh and I started debugging if both sources are playing on the same channel: They absolutely don't. They all have their own channel how it should be.
It looks like the whole command queue thread of the sound system is interrupted while playing some audio there.
I really dont think this was done on purpose.