pub fn play(&mut self, frequency: u16, duration: u16, adsr: bool) {
        let volume = self.volume;
        let samples_duration = duration as u32 * self.sample_rate / 1000;

        let (sustain, samples_attack, samples_decay, samples_release, samples_total, wave);
        if adsr {
            sustain = self.sustain;
            samples_attack = ATTACK[self.attack] * self.sample_rate / 1000;
            samples_decay = DECAY[self.decay] * self.sample_rate / 1000;
            samples_release = RELEASE[self.release] * self.sample_rate / 1000;
            samples_total = samples_attack + samples_decay + max(0, samples_duration as i64 - samples_attack as i64 - samples_decay as i64) as u32 + samples_release;
            wave = self.wave.clone();
        } else {
            sustain = volume;
            samples_attack = 0;
            samples_decay = 0;
            samples_release = 0;
            samples_total = samples_duration;
            wave = Wave::Pulse;
        }

        let mut gen = self.gen.lock().unwrap();
        *gen = Generator {
            volume: volume * self.max_volume,
            sustain: sustain * self.max_volume,
            wave: wave,

            samples_attack: samples_attack as f32,
            samples_decay: samples_decay as f32,
            samples_release: samples_release as f32,

            samples_total: samples_total as f32,
            samples_period: (self.sample_rate / frequency as u32) as f32,

            samples_count: 0.0,
        };

        self.event_loop.play_stream(self.stream_id.clone());
    }
/// Play a sound with a frequency given in hz for a duration given in ms
Play a sound with a frequency given in hz for a duration given in ms
Play a sound with a frequency given in hz for a duration given in ms
pub fn play(&mut self, frequency: u16, duration: u16, adsr: bool) {
        let volume = self.volume;
        let samples_duration = duration as u32 * self.sample_rate / 1000;
        let (sustain, samples_attack, samples_decay, samples_release, samples_total, wave);
        if adsr {
            sustain = self.sustain;
            samples_attack = ATTACK[self.attack] * self.sample_rate / 1000;
            samples_decay = DECAY[self.decay] * self.sample_rate / 1000;
            samples_release = RELEASE[self.release] * self.sample_rate / 1000;
            samples_total = samples_attack + samples_decay + max(0, samples_duration as i64 - samples_attack as i64 - samples_decay as i64) as u32 + samples_release;
            wave = self.wave.clone();
        } else {
            sustain = volume;
            samples_attack = 0;
            samples_decay = 0;
            samples_release = 0;
            samples_total = samples_duration;
            wave = Wave::Pulse;
        }
        let mut gen = self.gen.lock().unwrap();
        *gen = Generator {
            volume: volume * self.max_volume,
            sustain: sustain * self.max_volume,
            wave: wave,
            samples_attack: samples_attack as f32,
            samples_decay: samples_decay as f32,
            samples_release: samples_release as f32,
            samples_total: samples_total as f32,
            samples_period: (self.sample_rate / frequency as u32) as f32,
            samples_count: 0.0,
        };
        self.event_loop.play_stream(self.stream_id.clone());
    }
pub fn play ( & mut self , frequency : u16 , duration : u16 , adsr : bool ) { let volume = self . volume ; let samples_duration = duration as u32 * self . sample_rate / 1000 ; let ( sustain , samples_attack , samples_decay , samples_release , samples_total , wave ) ; if adsr { sustain = self . sustain ; samples_attack = ATTACK [ self . attack ] * self . sample_rate / 1000 ; samples_decay = DECAY [ self . decay ] * self . sample_rate / 1000 ; samples_release = RELEASE [ self . release ] * self . sample_rate / 1000 ; samples_total = samples_attack + samples_decay + max ( 0 , samples_duration as i64 - samples_attack as i64 - samples_decay as i64 ) as u32 + samples_release ; wave = self . wave . clone ( ) ; } else { sustain = volume ; samples_attack = 0 ; samples_decay = 0 ; samples_release = 0 ; samples_total = samples_duration ; wave = Wave :: Pulse ; } let mut gen = self . gen . lock ( ) . unwrap ( ) ; * gen = Generator { volume : volume * self . max_volume , sustain : sustain * self . max_volume , wave : wave , samples_attack : samples_attack as f32 , samples_decay : samples_decay as f32 , samples_release : samples_release as f32 , samples_total : samples_total as f32 , samples_period : ( self . sample_rate / frequency as u32 ) as f32 , samples_count : 0.0 , } ; self . event_loop . play_stream ( self . stream_id . clone ( ) ) ; }
Play a sound with a frequency given in hz for a duration given in ms
Play a sound with a frequency given in hz for a duration given in ms
&mut self
frequency
u16
duration
u16
adsr
bool
&mut self
frequency
u16
duration
u16
adsr
bool