From cb1fec867910f64622540d9b9e9775d92b5add0a Mon Sep 17 00:00:00 2001 From: ashley Date: Wed, 27 Sep 2023 15:30:35 -0400 Subject: [PATCH] Bugfix in soundtrack --- Cargo.toml | 2 +- src/reskit/soundtrack/formats/dmf.rs | 12 +++++++++--- src/reskit/soundtrack/types.rs | 3 ++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 89c88e3..e25630f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "reskit" -version = "0.0.2" +version = "0.0.3" authors = ["ne0ndrag0n "] edition = "2018" diff --git a/src/reskit/soundtrack/formats/dmf.rs b/src/reskit/soundtrack/formats/dmf.rs index 7ceef64..9260e0e 100644 --- a/src/reskit/soundtrack/formats/dmf.rs +++ b/src/reskit/soundtrack/formats/dmf.rs @@ -1,7 +1,7 @@ use std::{error::Error, fs::File, io::Read, convert::TryInto, collections::HashMap}; use flate2::read::ZlibDecoder; use linked_hash_set::LinkedHashSet; -use crate::reskit::{utility::{get_string, get_u8, skip, get_u32, get_i8, get_i32, get_u16, get_i16, print_info, sanitize_string}, soundtrack::types::{SampleFormat, PsgEnvelope, Note, Sample, PsgSettings, PatternRow, Effect, DcsgChannelMode, NoiseType, Instrument, InstrumentType, Fm2612Operator, Fm2612Settings, Channel, CombinedAssets}}; +use crate::reskit::{utility::{get_string, get_u8, skip, get_u32, get_i8, get_i32, get_u16, get_i16, print_info, sanitize_string, print_warning}, soundtrack::types::{SampleFormat, PsgEnvelope, Note, Sample, PsgSettings, PatternRow, Effect, DcsgChannelMode, NoiseType, Instrument, InstrumentType, Fm2612Operator, Fm2612Settings, Channel, CombinedAssets}}; const DMF_MAGIC_NUMBER: &'static str = ".DelekDefleMask."; const DMF_SUPPORTED_VERSION: u8 = 27; @@ -669,7 +669,10 @@ impl DmfModule { let bitrate = match get_u8( bytes.by_ref() )? { 8 => SampleFormat::Bits8, 16 => SampleFormat::Bits16, - invalid => return Err( format!( "invalid file: invalid bitrate {}", invalid ) )? + invalid => { + print_warning( &format!( "sample with invalid bitrate: {}", invalid ) ); + SampleFormat::Invalid + } }; @@ -685,7 +688,10 @@ impl DmfModule { sample.data.push( get_i16( bytes.by_ref() )? ); } - samples.push( sample ); + // Don't push no-names or invalid bitrates + if sample.name != "" && !matches!( sample.bitrate, SampleFormat::Invalid ) { + samples.push( sample ); + } } Ok( diff --git a/src/reskit/soundtrack/types.rs b/src/reskit/soundtrack/types.rs index 3ae7881..70fd8cc 100644 --- a/src/reskit/soundtrack/types.rs +++ b/src/reskit/soundtrack/types.rs @@ -63,7 +63,8 @@ pub struct CombinedAssets { #[derive(Clone, PartialEq, Debug)] pub enum SampleFormat { Bits8, - Bits16 + Bits16, + Invalid } #[derive(Clone, PartialEq, Debug)]