SOUND!
This commit is contained in:
parent
2df3d0a005
commit
db8debb31a
2 changed files with 8 additions and 5 deletions
|
@ -1,7 +1,7 @@
|
|||
|
||||
|
||||
use async_trait::async_trait;
|
||||
use macroquad::audio::{play_sound_once, Sound};
|
||||
use macroquad::audio::{play_sound_once, Sound, play_sound, PlaySoundParams};
|
||||
use macroquad::color::{BROWN, WHITE};
|
||||
use macroquad::{hash, time};
|
||||
use macroquad::prelude::{clear_background, Vec2, BLACK};
|
||||
|
@ -179,7 +179,10 @@ impl SortingList for GuiVec{
|
|||
|
||||
|
||||
if time::get_time() + 0.05 >= self.lastPlayed{
|
||||
play_sound_once(self.sounds[ (self.list[index1].position * 1000 / self.list.len()) ]);
|
||||
play_sound(self.sounds[ (self.list[index1].position * 1000 / self.list.len()) ], PlaySoundParams{
|
||||
looped:false,
|
||||
volume:0.5
|
||||
});
|
||||
self.lastPlayed = time::get_time()+0.05;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::f32::consts::PI;
|
||||
use std::{f32::consts::PI};
|
||||
|
||||
use macroquad::{audio::{Sound, load_sound_from_bytes}, window::{next_frame, screen_width, screen_height, clear_background}, text::draw_text, prelude::{BLACK, WHITE}};
|
||||
|
||||
|
@ -64,9 +64,9 @@ 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 = f32::min(i as f32 * 100., 1500.)/ SAMPLE_RATE as f32 * MAX_AMPLITUDE as f32;
|
||||
let amplitude = 500. * f32::sin((i as f32 - 300.) / 1200.);
|
||||
let value = f32::sin((2. * PI * (i as f32) * (frequency as f32)) / SAMPLE_RATE as f32);
|
||||
let channel = (amplitude * value);
|
||||
let channel = (amplitude * value);
|
||||
|
||||
collect.push(channel);
|
||||
soundFileBytes.append(&mut (channel as i16).to_le_bytes().to_vec());
|
||||
|
|
Loading…
Reference in a new issue