use crate::{AudioSourceBundle, Decodable};
use bevy_asset::Asset;
use bevy_reflect::TypePath;
use rodio::{source::SineWave, source::TakeDuration, Source};
#[derive(Asset, Debug, Clone, TypePath)]
pub struct Pitch {
pub frequency: f32,
pub duration: std::time::Duration,
}
impl Pitch {
pub fn new(frequency: f32, duration: std::time::Duration) -> Self {
Pitch {
frequency,
duration,
}
}
}
impl Decodable for Pitch {
type DecoderItem = <SineWave as Iterator>::Item;
type Decoder = TakeDuration<SineWave>;
fn decoder(&self) -> Self::Decoder {
SineWave::new(self.frequency).take_duration(self.duration)
}
}
pub type PitchBundle = AudioSourceBundle<Pitch>;