Some fixes
parent
0714ef5de9
commit
f276051133
|
@ -2,7 +2,7 @@ use std::{collections::HashMap, cmp::{max, min}, error::Error};
|
||||||
use convert_case::{Case, Casing};
|
use convert_case::{Case, Casing};
|
||||||
use samplerate::convert;
|
use samplerate::convert;
|
||||||
use uuid::Uuid;
|
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};
|
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 {
|
for instrument in &self.instruments {
|
||||||
match &instrument.instrument_type {
|
match &instrument.instrument_type {
|
||||||
InstrumentType::Fm2612( settings ) => {
|
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
|
// Create feedback + algorithm byte
|
||||||
let alg_fb: u8 = ( settings.fb << 3 ) | settings.alg;
|
let alg_fb: u8 = ( settings.fb << 3 ) | settings.alg;
|
||||||
|
@ -70,10 +71,11 @@ impl EchoFormat for DmfModule {
|
||||||
eif.extend( rr_sl );
|
eif.extend( rr_sl );
|
||||||
eif.extend( ssg_eg );
|
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 ) => {
|
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
|
// Echo uses volume and arpeggio envelopes
|
||||||
// Noise envelopes are usable but cannot be articulated in an instrument.
|
// Noise envelopes are usable but cannot be articulated in an instrument.
|
||||||
|
@ -202,13 +204,14 @@ impl EchoFormat for DmfModule {
|
||||||
// Echo end loop command
|
// Echo end loop command
|
||||||
envelope.push( 0xFF );
|
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 {
|
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
|
// Amplify data in original sample
|
||||||
let data: Vec<i16> = sample.data
|
let data: Vec<i16> = sample.data
|
||||||
|
@ -259,7 +262,7 @@ impl EchoFormat for DmfModule {
|
||||||
// Terminate stream
|
// Terminate stream
|
||||||
data.push( 0xFF );
|
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
|
// Write Echo ASM file that includes all the instruments
|
||||||
|
@ -270,13 +273,13 @@ impl EchoFormat for DmfModule {
|
||||||
|
|
||||||
echo_asm += &format!( "{}:\n", instr_list_label );
|
echo_asm += &format!( "{}:\n", instr_list_label );
|
||||||
for filename in &instrument_filenames {
|
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" );
|
echo_asm += &format!( "\tEcho_ListEnd\n\n" );
|
||||||
|
|
||||||
for filename in &instrument_filenames {
|
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 );
|
echo_asm += &format!( "\tincbin '{}{}'\n\n", artifact_path, filename );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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??" )?;
|
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
|
// Copy over the active note to psg3
|
||||||
channels[ index ].active_note = channels[ active_channel ].active_note;
|
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 {
|
} else {
|
||||||
return Err( "internal error: wtf happened here (3)??" )?
|
return Err( "internal error: wtf happened here (3)??" )?
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let index = channels.iter().position( | channel | channel.id == ESF_PSG_3 ).ok_or( "internal error: where is psg3??" )?;
|
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;
|
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 )? {
|
if let Some( noise_generator_setting ) = get_noise_generator_setting( note, dcsg_noise_mode )? {
|
||||||
|
|
|
@ -469,19 +469,19 @@ impl DmfModule {
|
||||||
// check: do these octave shifts make sense for all dmf modules?
|
// check: do these octave shifts make sense for all dmf modules?
|
||||||
// they were needed on the test dmf but no documentation supports it
|
// they were needed on the test dmf but no documentation supports it
|
||||||
// test dmf sounds off key otherwise...
|
// test dmf sounds off key otherwise...
|
||||||
1 => Note::CSharp( if (6..9).contains( &channel ) { octave - 1 } else { octave } ),
|
1 => Note::CSharp( if (6..=9).contains( &channel ) { octave - 1 } else { octave } ),
|
||||||
2 => Note::D( 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 } ),
|
3 => Note::DSharp( if (6..=9).contains( &channel ) { octave - 1 } else { octave } ),
|
||||||
4 => Note::E( 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 } ),
|
5 => Note::F( if (6..=9).contains( &channel ) { octave - 1 } else { octave } ),
|
||||||
6 => Note::FSharp( 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 } ),
|
7 => Note::G( if (6..=9).contains( &channel ) { octave - 1 } else { octave } ),
|
||||||
8 => Note::GSharp( 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 } ),
|
9 => Note::A( if (6..=9).contains( &channel ) { octave - 1 } else { octave } ),
|
||||||
10 => Note::ASharp( 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 } ),
|
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??
|
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
|
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 ) )?
|
_ => return Err( format!( "invalid file: invalid note id {}", note ) )?
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue