added a smoother intro the each sound

This commit is contained in:
Rolf Martin Glomsrud 2023-03-04 23:39:26 +01:00
parent b9c6fd24d7
commit b39a778b2d

View file

@ -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 = 1500. / SAMPLE_RATE as f32 * MAX_AMPLITUDE as f32;
let amplitude = f32::min(i as f32 * 100., 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);