pub fn audio_frame(&mut self) -> &[i16; (44100 / 60) * 2] {
        if self.redshift.is_none() {
            return &self.audio_buffer;
        }

        let sqr0_value = self.redshift.as_ref().unwrap().sqr0.borrow().value;
        let sqr1_value = self.redshift.as_ref().unwrap().sqr1.borrow().value;
        let tri0_value = self.redshift.as_ref().unwrap().tri0.borrow().value;
        let nse0_value = self.redshift.as_ref().unwrap().nse0.borrow().value;

        let mut sqr0_wave = self.redshift.as_ref().unwrap().sqr0_wave.borrow_mut();
        let mut sqr1_wave = self.redshift.as_ref().unwrap().sqr1_wave.borrow_mut();
        let mut tri0_wave = self.redshift.as_ref().unwrap().tri0_wave.borrow_mut();
        let mut nse0_wave = self.redshift.as_ref().unwrap().nse0_wave.borrow_mut();

        sqr0_wave.set_frequency(sqr0_value);
        sqr1_wave.set_frequency(sqr1_value);
        tri0_wave.set_frequency(tri0_value);
        nse0_wave.set_frequency(nse0_value);

        let mut waves: Vec<&[i16]> = vec![];
        if sqr0_value > 0 {
            waves.push(sqr0_wave.sample());
        }

        if sqr1_value > 0 {
            waves.push(sqr1_wave.sample());
        }

        if tri0_value > 0 {
            waves.push(tri0_wave.sample());
        }

        if nse0_value > 0 {
            waves.push(nse0_wave.sample());
        }

        if waves.len() == 0 {
            self.audio_buffer.iter_mut().for_each(|m| *m = 0);
            return &self.audio_buffer;
        }

        for idx in 0..44100 / 60 {
            let mut value = 0;
            for wave in waves.iter() {
                value += wave[idx] / waves.len() as i16;
            }
            self.audio_buffer[idx * 2] = value;
            self.audio_buffer[idx * 2 + 1] = value;
        }

        &self.audio_buffer
    }
/// Return interleaved stereo audio stream for a single
/// 60hz frame of the VM.
Return interleaved stereo audio stream for a single
60hz frame of the VM.
Return interleaved stereo audio stream for a single 60hz frame of the VM .
pub fn audio_frame(&mut self) -> &[i16; (44100 / 60) * 2] {
        if self.redshift.is_none() {
            return &self.audio_buffer;
        }
        let sqr0_value = self.redshift.as_ref().unwrap().sqr0.borrow().value;
        let sqr1_value = self.redshift.as_ref().unwrap().sqr1.borrow().value;
        let tri0_value = self.redshift.as_ref().unwrap().tri0.borrow().value;
        let nse0_value = self.redshift.as_ref().unwrap().nse0.borrow().value;
        let mut sqr0_wave = self.redshift.as_ref().unwrap().sqr0_wave.borrow_mut();
        let mut sqr1_wave = self.redshift.as_ref().unwrap().sqr1_wave.borrow_mut();
        let mut tri0_wave = self.redshift.as_ref().unwrap().tri0_wave.borrow_mut();
        let mut nse0_wave = self.redshift.as_ref().unwrap().nse0_wave.borrow_mut();
        sqr0_wave.set_frequency(sqr0_value);
        sqr1_wave.set_frequency(sqr1_value);
        tri0_wave.set_frequency(tri0_value);
        nse0_wave.set_frequency(nse0_value);
        let mut waves: Vec<&[i16]> = vec![];
        if sqr0_value > 0 {
            waves.push(sqr0_wave.sample());
        }
        if sqr1_value > 0 {
            waves.push(sqr1_wave.sample());
        }
        if tri0_value > 0 {
            waves.push(tri0_wave.sample());
        }
        if nse0_value > 0 {
            waves.push(nse0_wave.sample());
        }
        if waves.len() == 0 {
            self.audio_buffer.iter_mut().for_each(|m| *m = 0);
            return &self.audio_buffer;
        }
        for idx in 0..44100 / 60 {
            let mut value = 0;
            for wave in waves.iter() {
                value += wave[idx] / waves.len() as i16;
            }
            self.audio_buffer[idx * 2] = value;
            self.audio_buffer[idx * 2 + 1] = value;
        }
        &self.audio_buffer
    }
pub fn audio_frame ( & mut self ) -> & [ i16 ; ( 44100 / 60 ) * 2 ] { if self . redshift . is_none ( ) { return & self . audio_buffer ; } let sqr0_value = self . redshift . as_ref ( ) . unwrap ( ) . sqr0 . borrow ( ) . value ; let sqr1_value = self . redshift . as_ref ( ) . unwrap ( ) . sqr1 . borrow ( ) . value ; let tri0_value = self . redshift . as_ref ( ) . unwrap ( ) . tri0 . borrow ( ) . value ; let nse0_value = self . redshift . as_ref ( ) . unwrap ( ) . nse0 . borrow ( ) . value ; let mut sqr0_wave = self . redshift . as_ref ( ) . unwrap ( ) . sqr0_wave . borrow_mut ( ) ; let mut sqr1_wave = self . redshift . as_ref ( ) . unwrap ( ) . sqr1_wave . borrow_mut ( ) ; let mut tri0_wave = self . redshift . as_ref ( ) . unwrap ( ) . tri0_wave . borrow_mut ( ) ; let mut nse0_wave = self . redshift . as_ref ( ) . unwrap ( ) . nse0_wave . borrow_mut ( ) ; sqr0_wave . set_frequency ( sqr0_value ) ; sqr1_wave . set_frequency ( sqr1_value ) ; tri0_wave . set_frequency ( tri0_value ) ; nse0_wave . set_frequency ( nse0_value ) ; let mut waves : Vec < & [ i16 ] > = vec ! [ ] ; if sqr0_value > 0 { waves . push ( sqr0_wave . sample ( ) ) ; } if sqr1_value > 0 { waves . push ( sqr1_wave . sample ( ) ) ; } if tri0_value > 0 { waves . push ( tri0_wave . sample ( ) ) ; } if nse0_value > 0 { waves . push ( nse0_wave . sample ( ) ) ; } if waves . len ( ) == 0 { self . audio_buffer . iter_mut ( ) . for_each ( | m | * m = 0 ) ; return & self . audio_buffer ; } for idx in 0 .. 44100 / 60 { let mut value = 0 ; for wave in waves . iter ( ) { value += wave [ idx ] / waves . len ( ) as i16 ; } self . audio_buffer [ idx * 2 ] = value ; self . audio_buffer [ idx * 2 + 1 ] = value ; } & self . audio_buffer }
Return interleaved stereo audio stream for a single
60hz frame of the VM.
Return interleaved stereo audio stream for a single 60hz frame of the VM .
&mut self
&mut self