Implement whipping
This commit is contained in:
parent
2be2b357ad
commit
784e205357
9 changed files with 249 additions and 11 deletions
|
|
@ -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,
|
||||
)));
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue