1use crate::Decodable;
2use bevy_asset::Asset;
3use bevy_reflect::TypePath;
4use rodio::{
5 source::{SineWave, TakeDuration},
6 Source,
7};
8
9#[derive(Asset, Debug, Clone, TypePath)]
11pub struct Pitch {
12 pub frequency: f32,
14 pub duration: core::time::Duration,
16}
17
18impl Pitch {
19 pub fn new(frequency: f32, duration: core::time::Duration) -> Self {
21 Pitch {
22 frequency,
23 duration,
24 }
25 }
26}
27
28impl Decodable for Pitch {
29 type DecoderItem = <SineWave as Iterator>::Item;
30 type Decoder = TakeDuration<SineWave>;
31
32 fn decoder(&self) -> Self::Decoder {
33 SineWave::new(self.frequency).take_duration(self.duration)
34 }
35}