Skip to content

Commit

Permalink
refactor: note volume computation
Browse files Browse the repository at this point in the history
  • Loading branch information
nenikitov committed Feb 20, 2024
1 parent c39b9bd commit 9dee522
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions engine/src/asset/sound/dat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ fn uncompress(bytes: &[u8]) -> Vec<i16> {
.collect()
}
}

fn convert_volume(volume: u8) -> f32 {
volume as f32 / 64.0
}
4 changes: 2 additions & 2 deletions engine/src/asset/sound/dat/pattern_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*,
Expand Down Expand Up @@ -248,7 +248,7 @@ impl AssetParser<Wildcard> for Option<PatternEventVolume> {
if volume == u8::MAX {
PatternEventVolume::Sample
} else {
PatternEventVolume::Value(volume as f32 / u8::MAX as f32)
PatternEventVolume::Value(convert_volume(volume))
}
}),
))
Expand Down
6 changes: 3 additions & 3 deletions engine/src/asset/sound/dat/t_instrument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*,
Expand Down Expand Up @@ -103,7 +103,7 @@ impl AssetParser<Wildcard> 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))

Check warning on line 106 in engine/src/asset/sound/dat/t_instrument.rs

View workflow job for this annotation

GitHub Actions / clippy

redundant closure

warning: redundant closure --> engine/src/asset/sound/dat/t_instrument.rs:106:30 | 106 | .map(|v| convert_volume(v)) | ^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `convert_volume` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure = note: `#[warn(clippy::redundant_closure)]` on by default
.collect::<Vec<_>>();
TInstrumentVolume::Envelope(TInstrumentVolumeEnvelope {
data,
Expand Down Expand Up @@ -254,7 +254,7 @@ impl AssetParser<Wildcard> 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),
Expand Down

0 comments on commit 9dee522

Please sign in to comment.