Add sample offset command support

This commit is contained in:
Gwilym Inzani 2024-08-28 16:32:28 +01:00
parent ea792f4768
commit 559367f607
6 changed files with 26 additions and 0 deletions

View file

@ -93,6 +93,7 @@ pub enum PatternEffect {
/// Increase / decrease the pitch by the specified amount immediately /// Increase / decrease the pitch by the specified amount immediately
PitchBend(Num<u32, 8>), PitchBend(Num<u32, 8>),
Jump(Jump), Jump(Jump),
SampleOffset(u16),
} }
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)] #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
@ -401,6 +402,7 @@ impl quote::ToTokens for PatternEffect {
PatternEffect::Jump(jump) => { PatternEffect::Jump(jump) => {
quote! { Jump(#jump) } quote! { Jump(#jump) }
} }
PatternEffect::SampleOffset(offset) => quote! { SampleOffset(#offset) },
}; };
tokens.append_all(quote! { tokens.append_all(quote! {

View file

@ -126,6 +126,9 @@ struct TrackerChannel {
current_speed: Num<u32, 16>, current_speed: Num<u32, 16>,
current_panning: Num<i32, 8>, current_panning: Num<i32, 8>,
is_playing: bool, is_playing: bool,
// if some, should set the current position to this
current_pos: Option<u16>,
} }
#[derive(Default)] #[derive(Default)]
@ -337,6 +340,10 @@ impl<'track, TChannelId> TrackerInner<'track, TChannelId> {
channel.volume(tracker_channel.current_volume.try_change_base().unwrap()); channel.volume(tracker_channel.current_volume.try_change_base().unwrap());
channel.panning(tracker_channel.current_panning.try_change_base().unwrap()); channel.panning(tracker_channel.current_panning.try_change_base().unwrap());
if let Some(offset) = tracker_channel.current_pos.take() {
channel.set_pos(offset as u32);
}
if tracker_channel.is_playing { if tracker_channel.is_playing {
channel.resume(); channel.resume();
} else { } else {
@ -601,6 +608,11 @@ impl TrackerChannel {
PatternEffect::Jump(jump) => { PatternEffect::Jump(jump) => {
*current_jump = Some(jump.clone()); *current_jump = Some(jump.clone());
} }
PatternEffect::SampleOffset(offset) => {
if tick == 0 {
self.current_pos = Some(*offset);
}
}
} }
} }
@ -677,6 +689,10 @@ impl SoundChannel for agb::sound::mixer::SoundChannel {
fn panning(&mut self, panning: impl Into<Num<i16, 8>>) -> &mut Self { fn panning(&mut self, panning: impl Into<Num<i16, 8>>) -> &mut Self {
self.panning(panning) self.panning(panning)
} }
fn set_pos(&mut self, pos: impl Into<Num<u32, 8>>) -> &mut Self {
self.set_pos(pos)
}
} }
#[cfg(feature = "agb")] #[cfg(feature = "agb")]

View file

@ -17,6 +17,8 @@ pub trait SoundChannel {
fn restart_point(&mut self, value: impl Into<Num<u32, 8>>) -> &mut Self; fn restart_point(&mut self, value: impl Into<Num<u32, 8>>) -> &mut Self;
fn playback(&mut self, playback_speed: impl Into<Num<u32, 8>>) -> &mut Self; fn playback(&mut self, playback_speed: impl Into<Num<u32, 8>>) -> &mut Self;
fn panning(&mut self, panning: impl Into<Num<i16, 8>>) -> &mut Self; fn panning(&mut self, panning: impl Into<Num<i16, 8>>) -> &mut Self;
fn set_pos(&mut self, pos: impl Into<Num<u32, 8>>) -> &mut Self;
} }
pub trait Mixer { pub trait Mixer {

View file

@ -324,6 +324,7 @@ pub fn parse_module(module: &Module) -> agb_tracker_interop::Track {
) )
} }
} }
0x9 => PatternEffect::SampleOffset(effect_parameter as u16 * 256),
0xB => { 0xB => {
let pattern_idx = slot.effect_parameter; let pattern_idx = slot.effect_parameter;

View file

@ -171,6 +171,11 @@ impl agb_tracker::SoundChannel for SoundChannel {
self.panning = panning.into(); self.panning = panning.into();
self self
} }
fn set_pos(&mut self, pos: impl Into<Num<u32, 8>>) -> &mut Self {
self.pos = pos.into();
self
}
} }
impl agb_tracker::Mixer for Mixer { impl agb_tracker::Mixer for Mixer {

Binary file not shown.