[cln] Code cleanup

Cleanup code
Add a offset delay timer
This commit is contained in:
2024-03-10 14:26:42 +05:30
parent 242919f22a
commit 31fb280fc6
8 changed files with 92 additions and 76 deletions

View File

@@ -16,6 +16,7 @@ pub struct SdlAudioAdapter {
impl SdlAudioAdapter {
/// Number of samples per second
pub const SAMPLING_FREQ:i32 = 15360;
pub const AUDIO_FREQUENCY: f32 = 440.0;
pub const SAMPLES_PER_FRAME: usize = (Self::SAMPLING_FREQ as usize / 60) * 2;
pub fn new_timers(freq: f32,
volume: f32,

View File

@@ -1,15 +1,16 @@
use std::sync::MutexGuard;
use std::time::Duration;
use sdl2::pixels::PixelFormatEnum;
use sdl2::render::{TextureAccess, WindowCanvas};
use crate::device::Device;
use crate::util::EmulatorResult;
#[derive(Debug)]
pub struct SdlGraphicsAdapter {
rgb_frame_buffer: Vec<u8>,
}
impl SdlGraphicsAdapter {
pub const FRAME_RATE_TIMING: Duration = Duration::new(0, 1_000_000_000u32 / 60);
pub const RGB_COMPONENTS: usize = 3;
pub const RGB_FRAMEBUFFER_SIZE: usize = Self::RGB_COMPONENTS * Device::FRAME_BUFFER_SIZE;
pub fn new() -> SdlGraphicsAdapter {
@@ -18,7 +19,7 @@ impl SdlGraphicsAdapter {
rgb_frame_buffer
}
}
pub fn draw_screen(&mut self, frame_buffer: MutexGuard<Box<[bool; Device::FRAME_BUFFER_SIZE]>>, window_canvas: &mut WindowCanvas) ->EmulatorResult<()> {
pub fn draw_screen(&mut self, frame_buffer: MutexGuard<Box<[bool; Device::FRAME_BUFFER_SIZE]>>, window_canvas: &mut WindowCanvas) -> EmulatorResult<()> {
for (i, pixel) in frame_buffer.iter().enumerate() {
let col_component = if *pixel { 0xff } else { 0 };
self.rgb_frame_buffer[3 * i] = col_component;