Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pop sound on init under linux #121

Open
hasenbanck opened this issue Feb 7, 2025 · 4 comments
Open

Pop sound on init under linux #121

hasenbanck opened this issue Feb 7, 2025 · 4 comments

Comments

@hasenbanck
Copy link

Some of our users report, that on linux (current fedora linux in their case), the sound system has a "pop" sound playing when the on init. I attached a screen recording that contains the "pop" sound. The "pop" sound seems to have been occuring for them since we updated from kira 0.9 to kira 0.10.

It only manifests on linux systems (they use alsa). On windows / mac we can't reproduce the issue. Do you have any idea, how this "pop" sound could be generated? The BGM that plays at the start is a sound stream.

sound-pop-init.mp4
@tesselode
Copy link
Owner

I'm not able to replicate this using a simple example:

use std::{error::Error, io::stdin};

use kira::{
	sound::{static_sound::StaticSoundData, streaming::StreamingSoundData},
	AudioManager, AudioManagerSettings, DefaultBackend,
};

fn main() -> Result<(), Box<dyn Error>> {
	let mut manager = AudioManager::<DefaultBackend>::new(AudioManagerSettings::default())?;
	manager.play(StreamingSoundData::from_file("01.mp3")?)?;

	stdin().read_line(&mut "".into())?;

	Ok(())
}

I'm using the same mp3 that I'm hearing in the video. I'm on Arch using PulseAudio (I think).

@hasenbanck
Copy link
Author

It seems to be related again to the spatial sounds we have on our map. When we defer the loading of our spatial sound files (not playng! just loadin!), to when the window is visible, the "pop" sound dissappears (as referenced in the draft PR we have open in our project). Very odd cause and effect relationship of the bug.

@tesselode
Copy link
Owner

When are spatial sounds loaded and played otherwise?

I wasn't able to reproduce the pop by playing the music in a spatial sub track.

@hasenbanck
Copy link
Author

  1. On programm start: Init the audio engine, adds all tracks, add a spatial listener to (0.0, 0.0, 0.0) and sets the music track to 10% of maximal output volume. new()
  2. After Init: Load default map and then register then loads all spatial sound of the map as static sounds (sounds are loaded async in a loader thread) and finally built the KD-tree of all ambient sound locations registered. load() and add_ambient_sound()
  3. Queue the main menu BGM for playback (The name of the function is missleading, since the playback will not start until the first call to "AudioEngine::update()"). play_background_music_track()

Program now waits for the graphics engine init and window to become visible and renders the first frame. For each frame then:

  1. Update the spatial listener to the position of the camera (moves from the origin to somewhere on the map). set_spatial_listener()
  • This queries the KD-tree that contains all ambient sounds of a map and queues the playback for all ambient sounds in range.
  • The new position and orientation of the spatial listener is tweened over 50 ms.
  1. Calls the "AudioEngine::update()" function update()
  • Resolves all async loads (static sound effects are added to the cache)
  • Starts the playback of the BGM if queued.
  • Starts the playback fo all queued static non-spatial sound effects, spatial sound effects, and ambient map sounds.
  • Restarts sound effects if they are marked as "cycling"

When we defer the loading of the ambient sounds, so that while the first frame is rendered the ambient sound files are still loading in the async thread, then the pop disappears. The first frame would only start the playback of the BGM track and at later frames, when the ambient sounds have been loaded, would start the playback of the ambient , spatial sounds (two ambient sounds of birds are in range of the camera location of the main menu).

On the other hand, if we remove the defered loading and make sure the ambient sound haves been fully loaded, then the ambient, spatial sounds of the birds and the BGM will start to play at the same frame. In this case the "pop" can be heard on linux systems.

(I can provide you with a test setup of our client if you want. Please write me a PM over discord if you want to have the needed files.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants