pub(crate) fn fill_audio_buffer(&mut self, buffer: &mut [f32], frames: usize) {
        if !self.system_is_ready {
            return;
        }

        let (sounds, currently_played_sounds) = self.split_loaded_and_playing();
        for frame in 0..frames {
            let (mut left_channel, mut right_channel) = (0., 0.);
            currently_played_sounds.retain(|sound_id, state| {
                match sounds.get(sound_id) {
                    Some(sound_data) => {
                        left_channel += sound_data[state.sample_cursor][0] * 1.;
                        right_channel += sound_data[state.sample_cursor][1] * 1.;
                        state.sample_cursor += 1;
                        if state.sample_cursor >= sound_data.len() {
                            false
                        } else {
                            true
                        }
                    }
                    None => {
                        log::error!(
                            "A sound can't be played because it's not present in the datas"
                        );
                        true
                    }
                }
            });
            buffer[CHANNELS as usize * frame as usize] = left_channel;
            buffer[CHANNELS as usize * frame as usize + 1] = right_channel;
        }
    }
/// Add data to the OS audio buffer according to the frames number
Add data to the OS audio buffer according to the frames number
Add data to the OS audio buffer according to the frames number
pub(crate) fn fill_audio_buffer(&mut self, buffer: &mut [f32], frames: usize) {
        if !self.system_is_ready {
            return;
        }
        let (sounds, currently_played_sounds) = self.split_loaded_and_playing();
        for frame in 0..frames {
            let (mut left_channel, mut right_channel) = (0., 0.);
            currently_played_sounds.retain(|sound_id, state| {
                match sounds.get(sound_id) {
                    Some(sound_data) => {
                        left_channel += sound_data[state.sample_cursor][0] * 1.;
                        right_channel += sound_data[state.sample_cursor][1] * 1.;
                        state.sample_cursor += 1;
                        if state.sample_cursor >= sound_data.len() {
                            false
                        } else {
                            true
                        }
                    }
                    None => {
                        log::error!(
                            "A sound can't be played because it's not present in the datas"
                        );
                        true
                    }
                }
            });
            buffer[CHANNELS as usize * frame as usize] = left_channel;
            buffer[CHANNELS as usize * frame as usize + 1] = right_channel;
        }
    }
pub ( crate ) fn fill_audio_buffer ( & mut self , buffer : & mut [ f32 ] , frames : usize ) { if ! self . system_is_ready { return ; } let ( sounds , currently_played_sounds ) = self . split_loaded_and_playing ( ) ; for frame in 0 .. frames { let ( mut left_channel , mut right_channel ) = ( 0. , 0. ) ; currently_played_sounds . retain ( | sound_id , state | { match sounds . get ( sound_id ) { Some ( sound_data ) => { left_channel += sound_data [ state . sample_cursor ] [ 0 ] * 1. ; right_channel += sound_data [ state . sample_cursor ] [ 1 ] * 1. ; state . sample_cursor += 1 ; if state . sample_cursor >= sound_data . len ( ) { false } else { true } } None => { log :: error ! ( " " ) ; true } } } ) ; buffer [ CHANNELS as usize * frame as usize ] = left_channel ; buffer [ CHANNELS as usize * frame as usize + 1 ] = right_channel ; } }
Add data to the OS audio buffer according to the frames number
Add data to the OS audio buffer according to the frames number
&mut self
buffer
&mut [f32]
frames
usize
&mut self
buffer
&mut [f32]
frames
usize