fixed audio, still needs to do static removal
This commit is contained in:
parent
b6c438ae0f
commit
58aaf78f5a
2 changed files with 12 additions and 5 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
use async_trait::async_trait;
|
||||
use macroquad::color::{BROWN, WHITE};
|
||||
use macroquad::hash;
|
||||
use macroquad::{hash, time};
|
||||
use macroquad::prelude::{clear_background, Vec2, BLACK};
|
||||
use macroquad::rand::ChooseRandom;
|
||||
use macroquad::shapes::draw_rectangle;
|
||||
|
@ -29,7 +29,7 @@ pub struct GuiVec{
|
|||
renderSkip:i32,
|
||||
skipped:i32,
|
||||
lastTouched:Vec<usize>,
|
||||
|
||||
lastPlayed:f64
|
||||
}
|
||||
#[async_trait]
|
||||
pub trait SortingList{
|
||||
|
@ -84,7 +84,8 @@ impl SortingList for GuiVec{
|
|||
done:false,
|
||||
renderSkip:1,
|
||||
skipped:0,
|
||||
lastTouched:Vec::with_capacity(2)
|
||||
lastTouched:Vec::with_capacity(2),
|
||||
lastPlayed:0.,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -163,7 +164,13 @@ impl SortingList for GuiVec{
|
|||
self.writes += 2;
|
||||
self.reads += 2;
|
||||
self.list.swap(index1, index2);
|
||||
self.list[index1].playSound();
|
||||
|
||||
|
||||
if time::get_time() + 0.5 >= self.lastPlayed{
|
||||
self.list[index1].playSound();
|
||||
self.lastPlayed = time::get_time()+0.5;
|
||||
}
|
||||
|
||||
//self.list[index2].playSound();
|
||||
self.lastTouched.clear();
|
||||
self.lastTouched.push(index1);
|
||||
|
|
|
@ -64,7 +64,7 @@ pub async fn generateTone(frequency: f32, duration:f32) -> Sound{
|
|||
|
||||
let mut collect = Vec::new();
|
||||
for i in 0..((SAMPLE_RATE as f32 * duration) as usize){
|
||||
let amplitude = 10000./ SAMPLE_RATE as f32 * MAX_AMPLITUDE as f32;
|
||||
let amplitude = 1500. / SAMPLE_RATE as f32 * MAX_AMPLITUDE as f32;
|
||||
let value = f32::sin((2. * PI * (i as f32) * (frequency as f32)) / SAMPLE_RATE as f32);
|
||||
let channel = (amplitude * value);
|
||||
|
||||
|
|
Loading…
Reference in a new issue