-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Add audio setVolume
method with ramp duration and shape options
#16781
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
base: master
Are you sure you want to change the base?
Add audio setVolume
method with ramp duration and shape options
#16781
Conversation
Works on macOS Chrome and Firefox. Works on macOS Safari. Works on iOS Safari. Works on Quest3 Chrome.
Uncaught DOMException: AudioParam.setValueCurveAtTime: Can't add events during a curve event _setAudioParam webAudioEngine.ts:398 setTimeout handler*_setAudioParam webAudioEngine.ts:395 setVolume volumeWebAudioSubNode.ts:88 setVolume abstractAudioOutNode.ts:76
This removes the need for using a `setTimeout` delay, which I thought was a Firefox issue but was actually a mistake on my part.
Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s). |
Snapshot stored with reference name: Test environment: To test a playground add it to the URL, for example: https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/16781/merge/index.html#WGZLGJ#4600 Links to test babylon tools with this snapshot: https://playground.babylonjs.com/?snapshot=refs/pull/16781/merge To test the snapshot in the playground with a playground ID add it after the snapshot query string: https://playground.babylonjs.com/?snapshot=refs/pull/16781/merge#BCU1XR#0 |
WebGL2 visualization test reporter: |
Visualization tests for WebGPU |
There was a problem hiding this 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 new audio API for setting volume with ramp duration and ramp shape options, and updates related tests and WebAudio components accordingly.
- Added setVolume with optional ramp duration and shape options to various audio nodes and engines.
- Updated tests to validate volume setting and ramping behavior.
- Introduced _WebAudioParameterComponent to handle smooth parameter transitions.
Reviewed Changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
packages/tools/tests/test/audioV2/utils/audioV2.utils.ts | Updated output node type to include new setVolume method. |
packages/tools/tests/test/audioV2/shared/abstractAudioNode.volume.ts | Added tests for immediate and ramped volume changes. |
packages/dev/core/src/AudioV2/webAudio/webAudioStaticSound.ts | Refactored dispose logic and applied _WebAudioParameterComponent for pitch and playbackRate. |
packages/dev/core/src/AudioV2/webAudio/webAudioMainOut.ts | Replaced primitive volume with a parameter component and added setVolume method. |
packages/dev/core/src/AudioV2/webAudio/webAudioEngine.ts | Added engine-level setVolume routing to main output. |
Additional files | Updated type definitions and implementations for volume handling and ramping across various subnodes, buses, and utility functions. |
Comments suppressed due to low confidence (1)
Logger.Log("---"); | ||
Logger.Log(`Try audio parameter curve @ ${startTime}, from: ${this._targetValue}, to: ${value}, duration: ${duration}.`); | ||
|
||
if (startTime < this._rampEndTime) { | ||
const timeLeft = this._rampEndTime - startTime; | ||
Logger.Log(`... time left: ${timeLeft}.`); | ||
|
||
if (MaxWaitTime < timeLeft) { | ||
throw new Error("Audio parameter not set. Wait for current ramp to finish."); | ||
} else { | ||
Logger.Log(`Fit audio parameter curve, timeLeft: ${timeLeft}.`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] It appears that debugging log statements (Logger.Log) are used during parameter ramping. Consider controlling or removing these logs in production builds to avoid unnecessary console output.
Logger.Log("---"); | |
Logger.Log(`Try audio parameter curve @ ${startTime}, from: ${this._targetValue}, to: ${value}, duration: ${duration}.`); | |
if (startTime < this._rampEndTime) { | |
const timeLeft = this._rampEndTime - startTime; | |
Logger.Log(`... time left: ${timeLeft}.`); | |
if (MaxWaitTime < timeLeft) { | |
throw new Error("Audio parameter not set. Wait for current ramp to finish."); | |
} else { | |
Logger.Log(`Fit audio parameter curve, timeLeft: ${timeLeft}.`); | |
if (DEBUG) { | |
Logger.Log("---"); | |
Logger.Log(`Try audio parameter curve @ ${startTime}, from: ${this._targetValue}, to: ${value}, duration: ${duration}.`); | |
} | |
if (startTime < this._rampEndTime) { | |
const timeLeft = this._rampEndTime - startTime; | |
if (DEBUG) { | |
Logger.Log(`... time left: ${timeLeft}.`); | |
} | |
if (MaxWaitTime < timeLeft) { | |
throw new Error("Audio parameter not set. Wait for current ramp to finish."); | |
} else { | |
if (DEBUG) { | |
Logger.Log(`Fit audio parameter curve, timeLeft: ${timeLeft}.`); | |
} |
Copilot uses AI. Check for mistakes.
WebGL2 visualization test reporter: |
Visualization tests for WebGPU |
WebGL2 visualization test reporter: |
Visualization tests for WebGPU |
No description provided.