Play PCM samples in ESF stream
parent
0b86436ff7
commit
00f30dd5c0
|
@ -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.
|
||||
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
|
||||
if let Some( note ) = &row.note {
|
||||
if let Note::NoteOff = note {
|
||||
if channel.id == ESF_FM_6_PCM {
|
||||
// TODO: Completely different scenario required for PCM channel
|
||||
} else {
|
||||
channel.active_note = None;
|
||||
events.push( vec![ ESF_NOTE_OFF | channel.id ] );
|
||||
}
|
||||
channel.active_note = None;
|
||||
events.push( vec![ ESF_NOTE_OFF | channel.id ] );
|
||||
} else {
|
||||
if channel.id == ESF_FM_6_PCM {
|
||||
// TODO: Completely different scenario required for PCM channel
|
||||
} else {
|
||||
channel.active_note = Some(
|
||||
OctaveFrequency {
|
||||
octave: note.get_octave()?,
|
||||
frequency: get_semitone_frequency( get_semitone( note )? )?
|
||||
}
|
||||
);
|
||||
channel.active_note = Some(
|
||||
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 )?;
|
||||
events.push( vec![ ESF_NOTE_ON | channel.id, note ] );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue