January 2018
Beginner to intermediate
454 pages
10h 8m
English
The only remaining feature needed for our MP3 decoder is to be able to iterate over the samples. We'll first write a function to get the next sample:
fn next_sample<R: Read>(decoder: &mut Mp3Decoder<R>) -> Option<i16> { if decoder.current_frame.samples[0].len() == 0 { return None; } // getting the sample and converting it from fixed step to i16 let sample = decoder.current_frame.samples[decoder.current_frame_channel] [decoder.current_frame_sample_pos]; let sample = sample.to_i32() + (1 << (28 - 16)); let sample = if sample >= 0x10000000 { 0x10000000 - 1 } else if sample <= -0x10000000 { -0x10000000 } else { sample }; let sample = sample >> (28 + 1 - 16); let sample = sample as i16; decoder.current_frame_channel ...
Read now
Unlock full access