From 9dee52240eb8ac0c434e4cc3559dbfcd752cfd71 Mon Sep 17 00:00:00 2001 From: nenikitov Date: Tue, 20 Feb 2024 00:45:34 -0500 Subject: [PATCH] refactor: note volume computation --- engine/src/asset/sound/dat/mod.rs | 4 ++++ engine/src/asset/sound/dat/pattern_event.rs | 4 ++-- engine/src/asset/sound/dat/t_instrument.rs | 6 +++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/engine/src/asset/sound/dat/mod.rs b/engine/src/asset/sound/dat/mod.rs index 21ce860..699ea98 100644 --- a/engine/src/asset/sound/dat/mod.rs +++ b/engine/src/asset/sound/dat/mod.rs @@ -49,3 +49,7 @@ fn uncompress(bytes: &[u8]) -> Vec { .collect() } } + +fn convert_volume(volume: u8) -> f32 { + volume as f32 / 64.0 +} diff --git a/engine/src/asset/sound/dat/pattern_event.rs b/engine/src/asset/sound/dat/pattern_event.rs index 380b6d3..2fa5475 100644 --- a/engine/src/asset/sound/dat/pattern_event.rs +++ b/engine/src/asset/sound/dat/pattern_event.rs @@ -2,7 +2,7 @@ use std::rc::Rc; use bitflags::bitflags; -use super::{finetune::FineTune, t_instrument::*}; +use super::{convert_volume, finetune::FineTune, t_instrument::*}; use crate::{ asset::{extension::*, AssetParser}, utils::nom::*, @@ -248,7 +248,7 @@ impl AssetParser for Option { if volume == u8::MAX { PatternEventVolume::Sample } else { - PatternEventVolume::Value(volume as f32 / u8::MAX as f32) + PatternEventVolume::Value(convert_volume(volume)) } }), )) diff --git a/engine/src/asset/sound/dat/t_instrument.rs b/engine/src/asset/sound/dat/t_instrument.rs index ddac3be..ee066e6 100644 --- a/engine/src/asset/sound/dat/t_instrument.rs +++ b/engine/src/asset/sound/dat/t_instrument.rs @@ -2,7 +2,7 @@ use std::{cmp, rc::Rc}; use bitflags::bitflags; -use super::finetune::FineTune; +use super::{convert_volume, finetune::FineTune}; use crate::{ asset::{extension::*, AssetParser}, utils::nom::*, @@ -103,7 +103,7 @@ impl AssetParser for TInstrumentVolume { .into_iter() .skip(begin as usize) .take(cmp::min(cmp::min(end, end_total), 325) as usize) - .map(|v| v as f32 / u8::MAX as f32) + .map(|v| convert_volume(v)) .collect::>(); TInstrumentVolume::Envelope(TInstrumentVolumeEnvelope { data, @@ -254,7 +254,7 @@ impl AssetParser for TSample { input, Self { flags: TSampleFlags::from_bits(flags).expect("Flags should be valid"), - volume: volume as f32 / u8::MAX as f32, + volume: convert_volume(volume), panning, align, finetune: FineTune::new(finetune),