Skip to content

Sometimes a sync'd Oscillator continues playing. #1382

@scytacki

Description

@scytacki

Describe the bug

When:

  1. an Oscillator is sync'd with the transport,
  2. the Oscillator is started at time X
  3. the transport is started and passes time X
  4. the transport position is set before time X (without stopping)

Sometimes when the transport position is set before time X, the oscillator sound does not stop. When the transport time reaches X again, a second ToneOscillatorNode is created. The first ToneOscillatorNode will continue sounding and will now be orphaned. So stopping the transport will stop the second ToneOscillatorNode but it will not stop the orphaned ToneOscillatorNode.

This bug could not be reliably reproduced by simply following the steps above. The demo uses a slider so the transport position can be quickly set to before and after the Oscillator start time.

To Reproduce

https://codesandbox.io/p/sandbox/mystifying-wu-kdxkdr

Expected behavior

  1. When an Oscillator is sync'd with the Transport, it should always stop when the Transport stops.
  2. When an Oscillator is sync'd with the Transport, and configured to start after Transport time X, when the Transport position is set before X, the Oscillator shouldn't be sounding anymore.

What I've tried
I've looked at the code and seen how the Oscillator#_start is not checking for an existing _oscillator before creating a new one.

I haven't tried to figure out why Oscillator#_stop is not being called sometimes. I suspect there is some case where the _stop is getting skipped because of the rapid changes to the Transport position which are causing lots of start and stopping.

Additional context
There are notes in the codesandbox html which provide a little more info.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions