Skip to content

audio: Implement Sound.position #5482

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

Merged
merged 5 commits into from
Oct 17, 2021
Merged

Conversation

Herschel
Copy link
Member

@Herschel Herschel commented Oct 16, 2021

Implement AudioBackend::get_sound_position and wire it into AVM1 Sound.position.

  • Desktop AudioMixer backend re-organzied with a Stream trait that allows getting the sample position of the underlying decoder.
  • Web audio unfortunately doesn't provide a nice way to get the position of a currently playing audio buffer (Exposing a playbackPosition property on AudioBufferSourceNode. WebAudio/web-audio-api#2397), so our web audio backend stores AudioContext.currentTime when a sound starts playing, and uses this to estimate the current position by comparing to AudioMixer.getOutputTimestamp().

Fixes #340, #1898.
#2235 partially fixed (but seems to have some other issues, I think it's another case of variables persisting on unloaded clips).

 * Change `AudioBackend::get_sound_position` to return `f64` to
   match `AudioBackend::get_sound_duration`.
 * Wire up `AudioBackend::get_sound_position` to `Sound.position`.
 * Remove unimplmeneted warning from `Sound.position`.
@torokati44
Copy link
Member

Hmm, I don't see how #1891 is related. Did you perhaps mean to refer to #1898? Just a guess...

@torokati44
Copy link
Member

torokati44 commented Oct 16, 2021

For some reason, #340 doesn't look like it's fixed to me. If I press pause, then press it again to resume, it starts again from the beginning of the "chapter". Same thing on both web and desktop.

@kmeisthax
Copy link
Member

We probably should also unstub AVM2 SoundChannel.position.

@zumbasana
Copy link

Conductor game.zip
Uploading Conductor game and MP3s as per MWelsh request on Discord, tx
Ann Zumwinkle

@Herschel
Copy link
Member Author

For some reason, #340 doesn't look like it's fixed to me. If I press pause, then press it again to resume, it starts again from the beginning of the "chapter". Same thing on both web and desktop.

Thanks! This is indeed still broken because of some other issue (I suspect a goto issue).

@Herschel
Copy link
Member Author

Herschel commented Oct 16, 2021

Whoops, it's dumber than I thought. Sound.position was only added in SWFv6, and #340 is a v5 SWF, so Ruffle was returning undefined. But unlike most properties, position and duration are not version-gated in the official player and will still be available in v5 SWFs if they are playing in Flash Player 6 or higher.

Since #340 was created with a third party tool, it naturally does weird stuff and uses this property even though it's a v5 SWF. It should be working now.

Even though they were added in SWFv6, they will be available when
playing a v5 SWF in Flash Player 6 and higher.

See #340 for an example in the wild.
Fix various issues with `SoundChannel`:
 * Change `avm2::Object::as_sound_instance` to `as_sound_channel`.
 * Cache sound position in `SoundChannelObject`.
 * `SoundInfo::in_sample` is in units of 44100Hz.
 * Clamp `num_loops` to 1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sound.stop() and Sound.position()
4 participants