Skip to content

Commit 62fc79c

Browse files
committed
Update audio implementation to include dead band
1 parent 45fd44d commit 62fc79c

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

sdl_frontend/src/main.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,10 @@ fn update_audio(cpu: &mut CPU, state: &mut EmulatorState) {
10041004
let snd = &mut cpu.bus.audio;
10051005
let audio_sample_size = state.video.audio_sample_size;
10061006

1007+
if audio_sample_size == 0 {
1008+
return;
1009+
}
1010+
10071011
let Some(ref mut stream) = state.audio_stream else {
10081012
return;
10091013
};
@@ -1039,7 +1043,11 @@ fn update_audio(cpu: &mut CPU, state: &mut EmulatorState) {
10391043
// Implement Dynamic Rate Control for audio
10401044
if let Ok(queued_bytes) = stream.queued_bytes() {
10411045
let target_bytes = (audio_sample_size as i32 * 2 * 4) as f32;
1042-
let ratio = 1.0 + (queued_bytes as f32 - target_bytes) / target_bytes * 0.005;
1046+
let error = (queued_bytes as f32 - target_bytes) / target_bytes;
1047+
let deadband = 0.05;
1048+
let adjusted_error = if error.abs() < deadband { 0.0 } else { error };
1049+
let adjust = (adjusted_error * 0.005).clamp(-0.1, 0.1);
1050+
let ratio = 1.0 + adjust;
10431051
let ratio = ratio * SPEED_RATIO[state.speed.speed_index];
10441052
let _ = set_stream_frequency_ratio(stream, ratio);
10451053
let _ = stream.put_data_i16(snd_buffer);

0 commit comments

Comments
 (0)