Giter Club home page Giter Club logo

Comments (1)

tobiasvl avatar tobiasvl commented on June 21, 2024

Others' code:

      let mut begin_cpu = time::PreciseTime::now();
      let mut begin_display = begin_cpu.clone();
      'running: loop {
            let now = time::PreciseTime::now();

            let delta_cpu = begin_cpu.to(now);
            if delta_cpu.num_milliseconds() >= (1000.0 / CPU_FREQUENCY).round() as i64 {
                  begin_cpu = now.clone();

                  if chip.running {
                        chip.cycle();
                  }
            }

            let delta_display = begin_display.to(now);
            if delta_display.num_milliseconds() >= (1000.0 / DRAW_FREQUENCY).round() as i64 {
                  begin_display = now.clone();

                  display.update(&mut chip);
                  if display.should_close() {
                        break 'running;
                  }
                  display.draw(&chip);
            }
      }




            // Delay & sound timers are decreased by 1 at a rate of 60Hz
            let now = time::precise_time_ns();
            if now - self.clock > 16666000 {
                  self.clock = now;
                  if self.delay_timer != 0 {
                        self.delay_timer -= 1;
                  }
                  if self.sound_timer != 0 {
                        self.sound_timer -= 1;
                  }
            }
extern crate time;

const BEEP_SAMPLE_RATE: u32 = 44100;
const BEEP_FREQUENCY: f32 = 1000.0;
fn generate_beep() -> Vec<i16> {
      const SAMPLES: usize = BEEP_SAMPLE_RATE as usize / 2;
      let mut data: Vec<i16> = Vec::new();
      data.resize(SAMPLES, 0);

      // generate half a second of a sine wave
      for i in 0..SAMPLES {
            let t = i as f32 / BEEP_SAMPLE_RATE as f32;
            data[i] = ((BEEP_FREQUENCY * t * 2.0 * 3.1415).sin() * 32767.0).round() as i16;
      }

      data
}

from deca.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.