Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/crates/bevy_audio/src/pitch.rs
6598 views
1
use crate::Decodable;
2
use bevy_asset::Asset;
3
use bevy_reflect::TypePath;
4
use rodio::{
5
source::{SineWave, TakeDuration},
6
Source,
7
};
8
9
/// A source of sine wave sound
10
#[derive(Asset, Debug, Clone, TypePath)]
11
pub struct Pitch {
12
/// Frequency at which sound will be played
13
pub frequency: f32,
14
/// Duration for which sound will be played
15
pub duration: core::time::Duration,
16
}
17
18
impl Pitch {
19
/// Creates a new note
20
pub fn new(frequency: f32, duration: core::time::Duration) -> Self {
21
Pitch {
22
frequency,
23
duration,
24
}
25
}
26
}
27
28
impl 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
}
36
37