Migrate `set_frame_rate` into the core `AudioBackend` trait

This commit is contained in:
David Wendt 2019-11-08 15:07:01 -05:00
parent c1cf73ccb3
commit 2137b9f1fd
3 changed files with 12 additions and 5 deletions

View File

@ -76,6 +76,13 @@ pub trait AudioBackend {
true true
} }
fn tick(&mut self) {} fn tick(&mut self) {}
/// Inform the audio backend of the current stage frame rate.
///
/// This is only necessary if your particular audio backend needs to know
/// what the stage frame rate is. Otherwise, you are free to avoid
/// implementing it.
fn set_frame_rate(&mut self, frame_rate: f64) {}
} }
/// Rust does not auto-impl a Trait for Box<Trait> or Deref<Target=Trait> /// Rust does not auto-impl a Trait for Box<Trait> or Deref<Target=Trait>

View File

@ -123,10 +123,6 @@ impl WebAudioBackend {
}) })
} }
pub fn set_frame_rate(&mut self, frame_rate: f64) {
self.frame_rate = frame_rate
}
fn start_sound_internal( fn start_sound_internal(
&mut self, &mut self,
handle: SoundHandle, handle: SoundHandle,
@ -542,6 +538,10 @@ impl WebAudioBackend {
} }
impl AudioBackend for WebAudioBackend { impl AudioBackend for WebAudioBackend {
fn set_frame_rate(&mut self, frame_rate: f64) {
self.frame_rate = frame_rate
}
fn register_sound(&mut self, sound: &swf::Sound) -> Result<SoundHandle, Error> { fn register_sound(&mut self, sound: &swf::Sound) -> Result<SoundHandle, Error> {
// Slice off latency seek for MP3 data. // Slice off latency seek for MP3 data.
let (skip_sample_frames, data) = if sound.format.compression == AudioCompression::Mp3 { let (skip_sample_frames, data) = if sound.format.compression == AudioCompression::Mp3 {

View File

@ -11,7 +11,7 @@ use crate::{
}; };
use generational_arena::{Arena, Index}; use generational_arena::{Arena, Index};
use js_sys::Uint8Array; use js_sys::Uint8Array;
use ruffle_core::{backend::render::RenderBackend, PlayerEvent}; use ruffle_core::{backend::audio::AudioBackend, backend::render::RenderBackend, PlayerEvent};
use std::{cell::RefCell, error::Error, num::NonZeroI32}; use std::{cell::RefCell, error::Error, num::NonZeroI32};
use wasm_bindgen::{prelude::*, JsCast, JsValue}; use wasm_bindgen::{prelude::*, JsCast, JsValue};
use web_sys::{Element, EventTarget, HtmlCanvasElement, KeyboardEvent, PointerEvent}; use web_sys::{Element, EventTarget, HtmlCanvasElement, KeyboardEvent, PointerEvent};