Merge branch 'master' of ssh://ssh.paoda.moe:31059/paoda/chip8
This commit is contained in:
		
							
								
								
									
										24
									
								
								src/timer.rs
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								src/timer.rs
									
									
									
									
									
								
							| @@ -1,4 +1,4 @@ | |||||||
| use rodio::{source::SineWave, Sink}; | use rodio::{source::SineWave, Sink, Source}; | ||||||
| use std::sync::atomic::{AtomicU8, Ordering}; | use std::sync::atomic::{AtomicU8, Ordering}; | ||||||
| use std::thread; | use std::thread; | ||||||
| use std::time::{Duration, Instant}; | use std::time::{Duration, Instant}; | ||||||
| @@ -68,23 +68,13 @@ impl Timer { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     fn beep() { |     fn beep() { | ||||||
|         let maybe_device = rodio::default_output_device(); |         const BEEP_FREQ: u32 = 440; // Hz (Middle A) | ||||||
|         let beep = SineWave::new(440); |         const BEEP_LENGTH: u64 = 150; // ms  | ||||||
|  |         let beep = SineWave::new(BEEP_FREQ) | ||||||
|  |             .take_duration(Duration::from_millis(BEEP_LENGTH)); | ||||||
|  |  | ||||||
|         // TODO: Fix Pop when sound ends? |         if let Some(device) = rodio::default_output_device() { | ||||||
|         if let Some(device) = maybe_device { |             rodio::play_raw(&device, beep); | ||||||
|             std::thread::spawn(move || { |  | ||||||
|                 let sink = Sink::new(&device); |  | ||||||
|                 let duration = Duration::from_millis(100); |  | ||||||
|                 let start = Instant::now(); |  | ||||||
|                 sink.append(beep); |  | ||||||
|  |  | ||||||
|                 loop { |  | ||||||
|                     if Instant::now().duration_since(start) > duration { |  | ||||||
|                         break; |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|             }); |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user