Play PCM samples in ESF stream

master
Ashley N. 2023-08-24 21:26:07 -04:00
parent 0b86436ff7
commit 00f30dd5c0
1 changed files with 32 additions and 15 deletions

View File

@ -82,6 +82,27 @@ fn get_semitone( note: &Note ) -> Result<u8, Box<dyn Error>> {
} ) } )
} }
/**
* Notes are used to index PCM sample playback. C = 1, etc.
*/
fn get_pcm_index( note: &Note ) -> Result<u8, Box<dyn Error>> {
Ok( match note {
Note::NoteOff => return Err( "internal error: attempted to get pcm index for a Note::NoteOff" )?,
Note::C(_) => 0,
Note::CSharp(_) => 1,
Note::D(_) => 2,
Note::DSharp(_) => 3,
Note::E(_) => 4,
Note::F(_) => 5,
Note::FSharp(_) => 6,
Note::G(_) => 7,
Note::GSharp(_) => 8,
Note::A(_) => 9,
Note::ASharp(_) => 10,
Note::B(_) => 11
} )
}
/** /**
Gets the semitone frequency used by Echo. Gets the semitone frequency used by Echo.
https://github.com/sikthehedgehog/Echo/blob/master/doc/esf.txt#L243 https://github.com/sikthehedgehog/Echo/blob/master/doc/esf.txt#L243
@ -235,23 +256,19 @@ fn get_events_for_channel( channel: &mut Channel, row: &PatternRow ) -> Result<V
// Key on or key off note // Key on or key off note
if let Some( note ) = &row.note { if let Some( note ) = &row.note {
if let Note::NoteOff = note { if let Note::NoteOff = note {
if channel.id == ESF_FM_6_PCM { channel.active_note = None;
// TODO: Completely different scenario required for PCM channel events.push( vec![ ESF_NOTE_OFF | channel.id ] );
} else {
channel.active_note = None;
events.push( vec![ ESF_NOTE_OFF | channel.id ] );
}
} else { } else {
if channel.id == ESF_FM_6_PCM { channel.active_note = Some(
// TODO: Completely different scenario required for PCM channel OctaveFrequency {
} else { octave: note.get_octave()?,
channel.active_note = Some( frequency: get_semitone_frequency( get_semitone( note )? )?
OctaveFrequency { }
octave: note.get_octave()?, );
frequency: get_semitone_frequency( get_semitone( note )? )?
}
);
if channel.id == ESF_FM_6_PCM {
events.push( vec![ ESF_NOTE_ON | channel.id, get_pcm_index( note )? ] );
} else {
let note = get_note( note, channel.id )?; let note = get_note( note, channel.id )?;
events.push( vec![ ESF_NOTE_ON | channel.id, note ] ); events.push( vec![ ESF_NOTE_ON | channel.id, note ] );
} }