Function encode_adpcm_ima_ms

Source
pub fn encode_adpcm_ima_ms(
    samples: &[i16],
    states: &mut [AdpcmImaState],
    out_buf: &mut [u8],
) -> Result<(), Error>
Expand description

Encodes 16-bit signed integer samples to a MS / WAV IMA ADPCM (wav format 0x0011) compressed block.

Only 1 or 2 channel audio data is supported. For 1 channel audio, there must be an odd number of samples (1, 3, 5, ..) and for 2 channel audio, samples length must be divisible by 16 after subtracting 2 from it (2, 18, 34, 50, 66, ..). Samples must be interleaved for 2 channel audio.

states must contain channel number of AdpcmImaState items (1 or 2). The state objects should be initialized to zero for the first call and subsequent calls should pass in the state values from the previous call.

This function outputs encoded bytes to out_buf. The out_buf length must be ((samples.len() - states.len()) / 2) + states.len()*4 and less than 65536.

Usually, for 1 channel (mono) audio, the out_buf length is 1024 and the samples length is 2041. For 2 channel (stereo) audio, the out_buf length is 2048 and the samples length is 4082.

An error is returned if states has an invalid number of state objects or if the samples or out_buf length isn’t correct. If an error is returned, out_buf is left unmodified.