Skip to content

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

Draft
wants to merge 25 commits into
base: master
Choose a base branch
from

Conversation

docEdub
Copy link
Contributor

@docEdub docEdub commented Jun 20, 2025

No description provided.

docEdub added 21 commits June 3, 2025 16:35
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.
@bjsplat
Copy link
Collaborator

bjsplat commented Jun 20, 2025

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Collaborator

bjsplat commented Jun 20, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Jun 20, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Jun 20, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Jun 20, 2025

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 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)

Comment on lines 85 to 95
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}.`);
Copy link
Preview

Copilot AI Jun 21, 2025

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.

Suggested change
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.

@bjsplat
Copy link
Collaborator

bjsplat commented Jun 23, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Jun 23, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Jun 23, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Jun 23, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Jun 23, 2025

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.

2 participants