diff --git a/src/reskit/soundtrack/engines/echo/dmf.rs b/src/reskit/soundtrack/engines/echo/dmf.rs index 5b44830..a0d74e1 100644 --- a/src/reskit/soundtrack/engines/echo/dmf.rs +++ b/src/reskit/soundtrack/engines/echo/dmf.rs @@ -2,7 +2,7 @@ use std::{collections::HashMap, cmp::{max, min}, error::Error}; use convert_case::{Case, Casing}; use samplerate::convert; use uuid::Uuid; -use crate::reskit::{soundtrack::{formats::dmf::{DmfModule, ECHO_EWF_SAMPLE_RATE}, types::{InstrumentType, SampleFormat, Channel, PatternRow, Effect, DcsgChannelMode, NoiseType}}, utility::{print_warning, Ring, print_info}}; +use crate::reskit::{soundtrack::{formats::dmf::{DmfModule, ECHO_EWF_SAMPLE_RATE}, types::{InstrumentType, SampleFormat, Channel, PatternRow}}, utility::{print_warning, Ring}}; use super::engine::{EchoFormat, ESF_FM_1, ESF_FM_2, ESF_FM_3, ESF_FM_4, ESF_FM_5, ESF_FM_6, ESF_PSG_1, ESF_PSG_2, ESF_PSG_3, ESF_PSG_4, EchoEvent, get_events_for_row, compact_delays}; @@ -16,7 +16,8 @@ impl EchoFormat for DmfModule { for instrument in &self.instruments { match &instrument.instrument_type { InstrumentType::Fm2612( settings ) => { - instrument_filenames.push( format!( "{}.eif", instrument.name ) ); + let uuid = Uuid::new_v4().to_string(); + instrument_filenames.push( format!( "{}.eif", if instrument.name.is_empty() { format!( "fm_{}", uuid ) } else { instrument.name.to_owned() } ) ); // Create feedback + algorithm byte let alg_fb: u8 = ( settings.fb << 3 ) | settings.alg; @@ -70,10 +71,11 @@ impl EchoFormat for DmfModule { eif.extend( rr_sl ); eif.extend( ssg_eg ); - files.insert( format!( "{}.eif", if instrument.name.is_empty() { Uuid::new_v4().to_string() } else { instrument.name.to_owned() } ), eif ); + files.insert( format!( "{}.eif", if instrument.name.is_empty() { format!( "fm_{}", uuid ) } else { instrument.name.to_owned() } ), eif ); }, InstrumentType::PsgDcsg( settings ) => { - instrument_filenames.push( format!( "{}.eef", instrument.name ) ); + let uuid = Uuid::new_v4().to_string(); + instrument_filenames.push( format!( "{}.eef", if instrument.name.is_empty() { format!( "psg_{}", uuid ) } else { instrument.name.to_owned() } ) ); // Echo uses volume and arpeggio envelopes // Noise envelopes are usable but cannot be articulated in an instrument. @@ -202,13 +204,14 @@ impl EchoFormat for DmfModule { // Echo end loop command envelope.push( 0xFF ); - files.insert( format!( "{}.eef", if instrument.name.is_empty() { Uuid::new_v4().to_string() } else { instrument.name.to_owned() } ), envelope ); + files.insert( format!( "{}.eef", if instrument.name.is_empty() { format!( "psg_{}", uuid ) } else { instrument.name.to_owned() } ), envelope ); } } } for sample in &self.samples { - instrument_filenames.push( format!( "{}.ewf", sample.name ) ); + let uuid = Uuid::new_v4().to_string(); + instrument_filenames.push( format!( "{}.ewf", if sample.name.is_empty() { format!( "sample_{}", uuid ) } else { sample.name.to_owned() } ) ); // Amplify data in original sample let data: Vec = sample.data @@ -259,7 +262,7 @@ impl EchoFormat for DmfModule { // Terminate stream data.push( 0xFF ); - files.insert( format!( "{}.ewf", if sample.name.is_empty() { Uuid::new_v4().to_string() } else { sample.name.to_owned() } ), data ); + files.insert( format!( "{}.ewf", if sample.name.is_empty() { format!( "sample_{}", uuid ) } else { sample.name.to_owned() } ), data ); } // Write Echo ASM file that includes all the instruments @@ -270,13 +273,13 @@ impl EchoFormat for DmfModule { echo_asm += &format!( "{}:\n", instr_list_label ); for filename in &instrument_filenames { - echo_asm += &format!( "\tEcho_ListEntry Instr_{}\n", filename.replace( ".", "_" ).to_case( Case::Pascal ) ); + echo_asm += &format!( "\tEcho_ListEntry Instr_{}\n", filename.replace( ".", "_" ).replace( "-", "_" ).to_case( Case::Pascal ) ); } echo_asm += &format!( "\tEcho_ListEnd\n\n" ); for filename in &instrument_filenames { - echo_asm += &format!( "Instr_{}:\n", filename.replace( ".", "_" ).to_case( Case::Pascal ) ); + echo_asm += &format!( "Instr_{}:\n", filename.replace( ".", "_" ).replace( "-", "_" ).to_case( Case::Pascal ) ); echo_asm += &format!( "\tincbin '{}{}'\n\n", artifact_path, filename ); } diff --git a/src/reskit/soundtrack/engines/echo/engine.rs b/src/reskit/soundtrack/engines/echo/engine.rs index 9a98246..4ba5ac9 100644 --- a/src/reskit/soundtrack/engines/echo/engine.rs +++ b/src/reskit/soundtrack/engines/echo/engine.rs @@ -336,26 +336,14 @@ pub fn get_events_for_channel( channels: &mut [Channel], active_channel: usize, let index = channels.iter().position( | channel | channel.id == ESF_PSG_3 ).ok_or( "internal error: where is psg3??" )?; // Copy over the active note to psg3 channels[ index ].active_note = channels[ active_channel ].active_note; - // Issue a set frequency for psg3 - events.push( vec![ - ESF_SET_FREQUENCY | channels[ index ].id, - ( 0x000F & channels[ index ].active_note.ok_or( "internal error: wtf happened here (1)??" )?.frequency ) as u8, - ( ( 0x3F0 & channels[ index ].active_note.ok_or( "internal error: wtf happened here (2)??" )?.frequency ) >> 4 ) as u8 - ] ); } } else { return Err( "internal error: wtf happened here (3)??" )? } } else { let index = channels.iter().position( | channel | channel.id == ESF_PSG_3 ).ok_or( "internal error: where is psg3??" )?; - // Copy over the active note + // Copy over the active note to psg3 channels[ index ].active_note = channels[ active_channel ].active_note; - // Issue a set frequency for psg3 - events.push( vec![ - ESF_SET_FREQUENCY | channels[ index ].id, - ( 0x000F & channels[ index ].active_note.ok_or( "internal error: wtf happened here (1)??" )?.frequency ) as u8, - ( ( 0x3F0 & channels[ index ].active_note.ok_or( "internal error: wtf happened here (2)??" )?.frequency ) >> 4 ) as u8 - ] ); } if let Some( noise_generator_setting ) = get_noise_generator_setting( note, dcsg_noise_mode )? { diff --git a/src/reskit/soundtrack/formats/dmf.rs b/src/reskit/soundtrack/formats/dmf.rs index cf30b82..ab4895e 100644 --- a/src/reskit/soundtrack/formats/dmf.rs +++ b/src/reskit/soundtrack/formats/dmf.rs @@ -469,19 +469,19 @@ impl DmfModule { // check: do these octave shifts make sense for all dmf modules? // they were needed on the test dmf but no documentation supports it // test dmf sounds off key otherwise... - 1 => Note::CSharp( if (6..9).contains( &channel ) { octave - 1 } else { octave } ), - 2 => Note::D( if (6..9).contains( &channel ) { octave - 1 } else { octave } ), - 3 => Note::DSharp( if (6..9).contains( &channel ) { octave - 1 } else { octave } ), - 4 => Note::E( if (6..9).contains( &channel ) { octave - 1 } else { octave } ), - 5 => Note::F( if (6..9).contains( &channel ) { octave - 1 } else { octave } ), - 6 => Note::FSharp( if (6..9).contains( &channel ) { octave - 1 } else { octave } ), - 7 => Note::G( if (6..9).contains( &channel ) { octave - 1 } else { octave } ), - 8 => Note::GSharp( if (6..9).contains( &channel ) { octave - 1 } else { octave } ), - 9 => Note::A( if (6..9).contains( &channel ) { octave - 1 } else { octave } ), - 10 => Note::ASharp( if (6..9).contains( &channel ) { octave - 1 } else { octave } ), - 11 => Note::B( if (6..9).contains( &channel ) { octave - 1 } else { octave } ), - 12 => Note::C( if (6..9).contains( &channel ) { octave } else { octave + 1 } ), // deflemask y u shift the octave down 1 for C?? - 0 => Note::C( if (6..9).contains( &channel ) { octave - 1 } else { octave } ), // deflemask y u do this?? 0 is not documented + 1 => Note::CSharp( if (6..=9).contains( &channel ) { octave - 1 } else { octave } ), + 2 => Note::D( if (6..=9).contains( &channel ) { octave - 1 } else { octave } ), + 3 => Note::DSharp( if (6..=9).contains( &channel ) { octave - 1 } else { octave } ), + 4 => Note::E( if (6..=9).contains( &channel ) { octave - 1 } else { octave } ), + 5 => Note::F( if (6..=9).contains( &channel ) { octave - 1 } else { octave } ), + 6 => Note::FSharp( if (6..=9).contains( &channel ) { octave - 1 } else { octave } ), + 7 => Note::G( if (6..=9).contains( &channel ) { octave - 1 } else { octave } ), + 8 => Note::GSharp( if (6..=9).contains( &channel ) { octave - 1 } else { octave } ), + 9 => Note::A( if (6..=9).contains( &channel ) { octave - 1 } else { octave } ), + 10 => Note::ASharp( if (6..=9).contains( &channel ) { octave - 1 } else { octave } ), + 11 => Note::B( if (6..=9).contains( &channel ) { octave - 1 } else { octave } ), + 12 => Note::C( if (6..=9).contains( &channel ) { octave } else { octave + 1 } ), // deflemask y u shift the octave down 1 for C?? + 0 => Note::C( if (6..=9).contains( &channel ) { octave - 1 } else { octave } ), // deflemask y u do this?? 0 is not documented _ => return Err( format!( "invalid file: invalid note id {}", note ) )? } )