/// Copies all audio data from a source `AudioBuffer` that is of a different sample format type
/// than that of the `RawSampleBuffer` in interleaved channel order. The two buffers must be
/// equivalent.
Copies all audio data from a source `AudioBuffer` that is of a different sample format type
than that of the `RawSampleBuffer` in interleaved channel order. The two buffers must be
equivalent.
Copies all audio data from a source ` AudioBuffer ` that is of a different sample format type than that of the ` RawSampleBuffer ` in interleaved channel order . The two buffers must be equivalent .
pub fn copy_interleaved_typed<F>(&mut self, src: &AudioBuffer<F>)
    where
        F: Sample + IntoSample<S>,
    {
        let n_frames = src.n_frames;
        let n_channels = src.spec.channels.count();
        let n_samples = n_frames * n_channels;
        // Ensure that the capacity of the sample buffer is greater than or equal to the number
        // of samples that will be copied from the source buffer.
        assert!(self.capacity() >= n_samples);
        let mut writer = SampleWriter::from_buf(n_samples, self);
        // Provide slightly optimized interleave algorithms for Mono and Stereo buffers.
        match n_channels {
            // No channels, do nothing.
            0 => (),
            // Mono
            1=> {
                for m in &src.buf[0..n_frames] {
                    S::write((*m).into_sample(), &mut writer);
                }
            },
            // Stereo
            2 => {
                let l_buf = &src.buf[0..n_frames];
                let r_buf = &src.buf[src.n_capacity..(src.n_capacity + n_frames)];
                for (l, r) in l_buf.iter().zip(r_buf) {
                    S::write((*l).into_sample(), &mut writer);
                    S::write((*r).into_sample(), &mut writer);
                }
            },
            // 3+ channels
            _ => {
                let stride = src.n_capacity;
                for i in 0..n_frames {
                    //TODO: possibly replace by Slice::chunks() and Iterator::step_by()
                    for ch in 0..n_channels {
                        let s = src.buf[ch * stride + i];
                        S::write(s.into_sample(), &mut writer);
                    }
                }
            },
        }
    }
pub fn copy_interleaved_typed < F > ( & mut self , src : & AudioBuffer < F > ) where F : Sample + IntoSample < S > , { let n_frames = src . n_frames ; let n_channels = src . spec . channels . count ( ) ; let n_samples = n_frames * n_channels ; // Ensure that the capacity of the sample buffer is greater than or equal to the number // of samples that will be copied from the source buffer. assert ! ( self capacity ( ) n_samples ) ; let mut writer = SampleWriter :: from_buf ( n_samples , self ) ; // Provide slightly optimized interleave algorithms for Mono and Stereo buffers. match n_channels { // No channels, do nothing. 0 => ( ) , // Mono 1 => { for m in & src . buf [ 0 .. n_frames ] { S :: write ( ( * m ) . into_sample ( ) , & mut writer ) ; } } , // Stereo 2 => { let l_buf = & src . buf [ 0 .. n_frames ] ; let r_buf = & src . buf [ src . n_capacity .. ( src . n_capacity + n_frames ) ] ; for ( l , r ) in l_buf . iter ( ) . zip ( r_buf ) { S :: write ( ( * l ) . into_sample ( ) , & mut writer ) ; S :: write ( ( * r ) . into_sample ( ) , & mut writer ) ; } } , // 3+ channels _ => { let stride = src . n_capacity ; for i in 0 .. n_frames { //TODO: possibly replace by Slice::chunks() and Iterator::step_by() for ch in 0 .. n_channels { let s = src . buf [ ch * stride + i ] ; S :: write ( s . into_sample ( ) , & mut writer ) ; } } } , } }
Copies all audio data from a source `AudioBuffer` that is of a different sample format type
than that of the `RawSampleBuffer` in interleaved channel order.
Copies all audio data from a source ` AudioBuffer ` that is of a different sample format type than that of the ` RawSampleBuffer ` in interleaved channel order .
&mut self
src
&AudioBuffer<F>