Change static sound playbackRate and pitch settings API#16396
Change static sound playbackRate and pitch settings API#16396docEdub merged 2 commits intoBabylonJS:masterfrom
playbackRate and pitch settings API#16396Conversation
The static sound `playbackRate` and `pitch` options are confusing when it comes to sound instances. Changing those options on a sound with multiple instances playing only updates the the most recent instance, but it should update all instances. Similarly, allowing the `playbackRate` and `pitch` options to be set in the `play` function is confusing because the parent sound's properties will override the new instance's option set by the `play` function, which will cause the playback rate and pitch to change unexpectedly when the sound's properties are changed. This change fixes these issues by making the static sound's `playbackRate` and `pitch` properties apply to all playing instances, and by removing the `playbackRate` and `pitch` options from the `play` function.
There was a problem hiding this comment.
Pull Request Overview
This PR updates the static sound API to ensure that changes to playbackRate and pitch apply to all currently playing instances and removes the options from the play function to avoid unintended overrides.
- Updated type interfaces to remove the separate play options for pitch and playbackRate.
- Modified the tone setters to iterate over all sound instances instead of updating only the most recent instance.
- Updated the webAudio sound instance to source tone values from the parent rather than the play options.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/dev/core/src/AudioV2/abstractAudio/staticSound.ts | Adjusted type definitions and updated setters to update all instances rather than a single instance. |
| packages/dev/core/src/AudioV2/webAudio/webAudioStaticSound.ts | Removed redundant option updates in instance setters and updated usage to source values from the parent sound. |
|
Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s). |
|
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/16396/merge/index.html#WGZLGJ#4600 Links to test babylon tools with this snapshot: https://playground.babylonjs.com/?snapshot=refs/pull/16396/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/16396/merge#BCU1XR#0 |
|
WebGL2 visualization test reporter: |
|
Visualization tests for WebGPU |
The static sound
playbackRateandpitchoptions are confusing when it comes to sound instances. Changing those options on a sound with multiple instances playing only updates the most recent instance, but it should update all instances.Similarly, allowing the
playbackRateandpitchoptions to be set in theplayfunction is confusing because the parent sound's properties will override the new instance's option set by theplayfunction, which will cause the playback rate and pitch to change unexpectedly when the sound's properties are changed.This change fixes these issues by making the static sound's
playbackRateandpitchproperties apply to all playing instances, and by removing theplaybackRateandpitchoptions from theplayfunction.