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

Ramp audio parameter values to avoid audible discontinuities #16364

Merged
merged 2 commits into from
Mar 19, 2025

Conversation

docEdub
Copy link
Contributor

@docEdub docEdub commented Mar 19, 2025

Audio parameter changes are currently performed at the graphics frame rate, which is too slow to avoid audible discontinuities in the audio output stream. This results in audio artifacts like "crackles", "zippers" and "pops", which lower the quality of the audio output and damage audio hardware over time.

To avoid these issues, this change uses linear ramps when changing audio parameter values so they are performed at the audio sample rate, typically 48000 times per second or higher.

Audio parameter changes are currently performed at the graphics frame rate, which is too slow to avoid audible discontinuities in the audio output stream. This results in audio artifacts like "crackles", "zippers" and "pops", which lower the quality of the audio output and damage audio hardware over time.

To avoid these issues, this change uses linear ramps when changing audio parameter values so they are performed at the audio sample rate, typically 48000 times per second or higher.
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a mechanism to apply smooth, sample-rate–based ramps to audio parameter transitions in order to eliminate audible artifacts such as crackles and pops. Key changes include adding a new parameter (parameterRampDuration) to the audio engine options, updating the audio node setter methods to use a linear ramp function, and consistently applying these changes across multiple audio subnodes.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/dev/core/src/AudioV2/abstractAudio/audioEngineV2.ts Adds parameterRampDuration to engine options and state
packages/dev/core/src/AudioV2/webAudio/subNodes/volumeWebAudioSubNode.ts Updates volume setter to use ramping via engine._setAudioParam
packages/dev/core/src/AudioV2/webAudio/subNodes/stereoWebAudioSubNode.ts Updates pan setter to use ramping via engine._setAudioParam
packages/dev/core/src/AudioV2/webAudio/webAudioMainOut.ts Updates main output volume setter to use ramping via engine._setAudioParam
packages/dev/core/src/AudioV2/webAudio/subNodes/spatialWebAudioSubNode.ts Replaces direct assignment with _setAudioParam calls for position and orientation
packages/dev/core/src/AudioV2/webAudio/webAudioEngine.ts Adjusts constructor to pass options and adds the _setAudioParam method
packages/dev/core/src/AudioV2/webAudio/webAudioStaticSound.ts Updates detune and playbackRate setters to use _setAudioParam
packages/dev/core/src/AudioV2/webAudio/subProperties/spatialWebAudioListener.ts Updates listener property setters to use ramping via engine._setAudioParam
Comments suppressed due to low confidence (1)

packages/dev/core/src/AudioV2/abstractAudio/audioEngineV2.ts:63

  • Consider validating that the provided parameterRampDuration is non-negative to avoid potential audio ramping issues. You might add a condition to either clamp negative values to 0 or throw an error.
if (typeof options.parameterRampDuration === "number") {

@bjsplat

This comment was marked as resolved.

@docEdub docEdub requested a review from RaananW March 19, 2025 18:17
@bjsplat

This comment was marked as resolved.

@bjsplat
Copy link
Collaborator

bjsplat commented Mar 19, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Mar 19, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Mar 19, 2025

@RaananW RaananW merged commit 4ac060c into BabylonJS:master Mar 19, 2025
16 checks passed
@docEdub docEdub deleted the 250318-ramp-audioparam-values branch April 7, 2025 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants