audio: Properly round sound duration
Previously it was always rounded down. Change it to the nearest integer.
This commit is contained in:
parent
6310e31023
commit
79bcee07f5
|
@ -427,9 +427,10 @@ impl AudioBackend for CpalAudioBackend {
|
|||
|
||||
fn get_sound_duration(&self, sound: SoundHandle) -> Option<u32> {
|
||||
if let Some(sound) = self.sounds.get(sound) {
|
||||
// AS duration does not subtract skip_sample_frames.
|
||||
let num_sample_frames = u64::from(sound.num_sample_frames);
|
||||
let ms = num_sample_frames * 1000 / u64::from(sound.format.sample_rate);
|
||||
// AS duration does not subtract `skip_sample_frames`.
|
||||
let num_sample_frames: f64 = sound.num_sample_frames.into();
|
||||
let sample_rate: f64 = sound.format.sample_rate.into();
|
||||
let ms = (num_sample_frames * 1000.0 / sample_rate).round();
|
||||
Some(ms as u32)
|
||||
} else {
|
||||
None
|
||||
|
|
|
@ -1029,9 +1029,10 @@ impl AudioBackend for WebAudioBackend {
|
|||
|
||||
fn get_sound_duration(&self, sound: SoundHandle) -> Option<u32> {
|
||||
if let Some(sound) = self.sounds.get(sound) {
|
||||
// AS duration does not subtract skip_sample_frames.
|
||||
let num_sample_frames = u64::from(sound.num_sample_frames);
|
||||
let ms = num_sample_frames * 1000 / u64::from(sound.format.sample_rate);
|
||||
// AS duration does not subtract `skip_sample_frames`.
|
||||
let num_sample_frames: f64 = sound.num_sample_frames.into();
|
||||
let sample_rate: f64 = sound.format.sample_rate.into();
|
||||
let ms = (num_sample_frames * 1000.0 / sample_rate).round();
|
||||
Some(ms as u32)
|
||||
} else {
|
||||
None
|
||||
|
|
Loading…
Reference in New Issue