Skip to content

[Web] Audio sample playback ignores pitch_scale for autoplay, and 2nd+ loops. #123786

Description

@jgill88

Tested versions

  • Reproducible in 4.7.2 (and latest master ca871cc). it's likely reproducible since the beginning of web samples playback, but at least as far back as here

System information

Intel MBP 15.7.9 - AMD Radeon Pro 5300M 4 GB Intel UHD Graphics 630 - but shouldn't matter.

Issue description

I know the guidance in the issue template says to submit separate issues for separate bugs, but these two bugs can be fixed by the same LOC change, and are closely related to one another (just with a slight twist).

I have put together a small fix for this and will open a PR shortly.

For web samples playback, pitch_scale is ignored in two cases:

  1. AudioStreamPlayer with autoplay=true (works fine when calling .play() directly)
  2. On the 2nd+ loops of a sample

The autoplay flavor of this bug has an additional codepath that seems to be broken (or at least, unintentionally called): the pause(enable:bool) method calls _unpause, which then unconditionally calls _restart, regardless of if the stream was playing or not.

(no ai used at all.)

Steps to reproduce

Autoplay bug:

  1. Add AudioStreamPlayer to scene
  2. Set autoplay=true
  3. Set pitch_scale=2
  4. Run scene: audio is playing at pitch_scale=1.

Loop bug:

  1. Add AudioStreamPlayer to scene
  2. Set autoplay=false
  3. Set pitch_scale=2
  4. Add an audio stream that has looping enabled
  5. Attach script, _ready(): player.play() (important!)
  6. Run scene: audio will play with pitch_scale=2 properly, until it loops. at this point, pitch_scale is 1.0.

The cause of the pitch_scale problems is that _restart does not sync the playback rate when it creates a new AudioBufferSourceNode.

Minimal reproduction project (MRP)

This scene is configured to test both of these bugs.

pitch_mrp.zip

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions