Implement whipping
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
Alex Page 2022-01-30 17:06:27 -05:00
parent 2be2b357ad
commit 784e205357
9 changed files with 249 additions and 11 deletions

View file

@ -4,12 +4,13 @@ use cpal::{
traits::{DeviceTrait, HostTrait, StreamTrait},
SampleRate, Stream,
};
use oddio::{Frames, Handle, Mixer};
use oddio::{Frames, FramesSignal, Gain, Handle, Mixer, MonoToStereo, Stop};
use rand::Rng;
use super::sound_effects::{SoundEffect, SoundType};
pub type SoundSamples = Arc<Frames<f32>>;
pub type SoundEffectHandle = Handle<Stop<MonoToStereo<Gain<FramesSignal<f32>>>>>;
pub struct SoundOutput {
mixer_handle: Handle<Mixer<[f32; 2]>>,
@ -114,12 +115,12 @@ impl SoundOutput {
oddio::Frames::from_iter(self.sample_rate.0, effect_buffer.iter().copied())
}
pub fn play_sound(&mut self, samples: SoundSamples) {
pub fn play_sound(&mut self, samples: SoundSamples) -> SoundEffectHandle {
self.mixer_handle
.control::<oddio::Mixer<_>, _>()
.play(oddio::MonoToStereo::new(oddio::Gain::new(
oddio::FramesSignal::from(samples),
0.20,
)));
)))
}
}