core: `NullAudioBackend` should not report latency seek data as part of the size of a sound.

This commit is contained in:
David Wendt 2021-08-13 18:37:59 -04:00 committed by kmeisthax
parent d7f2f782c4
commit e4c6e29b8a
2 changed files with 9 additions and 4 deletions

View File

@ -64,9 +64,7 @@ pub fn bytes_total<'gc>(
) -> Result<Value<'gc>, Error> {
if let Some(sound) = this.and_then(|this| this.as_sound()) {
if let Some(length) = activation.context.audio.get_sound_size(sound) {
//TODO: The length of the sound data is consistently off by two in SWFs.
//This probably needs to go away when we start decoding network sounds
return Ok((length - 2).into());
return Ok((length).into());
}
}

View File

@ -135,6 +135,13 @@ impl AudioBackend for NullAudioBackend {
fn play(&mut self) {}
fn pause(&mut self) {}
fn register_sound(&mut self, sound: &swf::Sound) -> Result<SoundHandle, Error> {
// Slice off latency seek for MP3 data.
let data = if sound.format.compression == swf::AudioCompression::Mp3 {
&sound.data[2..]
} else {
sound.data
};
// AS duration does not subtract `skip_sample_frames`.
let num_sample_frames: f64 = sound.num_samples.into();
let sample_rate: f64 = sound.format.sample_rate.into();
@ -142,7 +149,7 @@ impl AudioBackend for NullAudioBackend {
Ok(self.sounds.insert(NullSound {
duration: ms as u32,
size: sound.data.len() as u32,
size: data.len() as u32,
}))
}