SSS operand implemented

This commit is contained in:
dawnDus 2022-01-22 16:45:54 -05:00 committed by alula
parent b880fee8e7
commit 1c7e4c9f65
3 changed files with 30 additions and 8 deletions

View File

@ -1637,11 +1637,10 @@ impl TextScriptVM {
exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32);
}
TSCOpCode::SSS => {
let _freq = read_cur_varint(&mut cursor)?;
let freq = read_cur_varint(&mut cursor)? as f32 / 2205.0;
// todo change freq
state.sound_manager.loop_sfx(40);
state.sound_manager.loop_sfx(41);
state.sound_manager.loop_sfx_freq(40, freq);
state.sound_manager.loop_sfx_freq(41, freq);
exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32);
}

View File

@ -122,6 +122,13 @@ impl SoundManager {
let _ = self.tx.send(PlaybackMessage::LoopSample(id));
}
pub fn loop_sfx_freq(&self, id: u8, freq: f32) {
if self.no_audio {
return;
}
let _ = self.tx.send(PlaybackMessage::LoopSampleFreq(id, freq));
}
pub fn stop_sfx(&self, id: u8) {
if self.no_audio {
return;
@ -394,6 +401,7 @@ pub(in crate::sound) enum PlaybackMessage {
PlayOggSongMultiPart(Box<OggStreamReader<File>>, Box<OggStreamReader<File>>),
PlaySample(u8),
LoopSample(u8),
LoopSampleFreq(u8, f32),
StopSample(u8),
SetSpeed(f32),
SaveState,
@ -520,6 +528,9 @@ where
Ok(PlaybackMessage::LoopSample(id)) => {
pixtone.loop_sfx(id);
}
Ok(PlaybackMessage::LoopSampleFreq(id, freq)) => {
pixtone.loop_sfx_freq(id, freq);
}
Ok(PlaybackMessage::StopSample(id)) => {
pixtone.stop_sfx(id);
}

View File

@ -182,6 +182,7 @@ pub struct PlaybackState {
pos: f32,
tag: u32,
looping: bool,
freq: f32,
}
pub struct PixTonePlayback {
@ -226,7 +227,7 @@ impl PixTonePlayback {
}
}
self.playback_state.push(PlaybackState { id, pos: 0.0, tag: 0, looping: false });
self.playback_state.push(PlaybackState { id, pos: 0.0, tag: 0, looping: false, freq: 1.0 });
}
pub fn loop_sfx(&mut self, id: u8) {
@ -237,7 +238,18 @@ impl PixTonePlayback {
}
}
self.playback_state.push(PlaybackState { id, pos: 0.0, tag: 0, looping: true });
self.playback_state.push(PlaybackState { id, pos: 0.0, tag: 0, looping: true, freq: 1.0 });
}
pub fn loop_sfx_freq(&mut self, id: u8, freq: f32) {
for state in &mut self.playback_state {
if state.id == id && state.tag == 0 {
state.looping = true;
return;
}
}
self.playback_state.push(PlaybackState { id, pos: 0.0, tag: 0, looping: true, freq });
}
pub fn stop_sfx(&mut self, id: u8) {
@ -247,7 +259,7 @@ impl PixTonePlayback {
}
pub fn play_concurrent(&mut self, id: u8, tag: u32) {
self.playback_state.push(PlaybackState { id, pos: 0.0, tag, looping: false });
self.playback_state.push(PlaybackState { id, pos: 0.0, tag, looping: false, freq: 1.0 });
}
pub fn mix(&mut self, dst: &mut [u16], sample_rate: f32) {
@ -285,7 +297,7 @@ impl PixTonePlayback {
let sam = (*result ^ 0x8000) as i16;
*result = sam.saturating_add(s as i16) as u16 ^ 0x8000;
state.pos += delta;
state.pos += delta * state.freq;
}
if remove {