From: Kostya Shishkov Date: Thu, 2 Dec 2021 15:14:45 +0000 (+0100) Subject: mp3: fix reconstruction X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=dc82a7f32abe0b72bb9091841babdff3b6f353be;p=nihav.git mp3: fix reconstruction --- diff --git a/nihav-mpeg/src/codecs/mpegaudio/mp3code.rs b/nihav-mpeg/src/codecs/mpegaudio/mp3code.rs index 516d687..e43988c 100644 --- a/nihav-mpeg/src/codecs/mpegaudio/mp3code.rs +++ b/nihav-mpeg/src/codecs/mpegaudio/mp3code.rs @@ -611,7 +611,7 @@ impl MP3Data { let coef1 = &mut coef1[0][gr_no * SAMPLES/2..]; let is_mode = &self.is_mode[gr_no * SAMPLES/2..]; let start = band_end[gr_no][bound_band[gr_no]]; - let end = grans[0].zero_part; + let end = grans[0].zero_part.max(start); if self.mpeg1 { let coef0 = &mut coef0[start..end]; @@ -628,11 +628,13 @@ impl MP3Data { let iscale = (grans[1].scalefac_compress & 1) as u8; for band in 0..num_bands[gr_no] { if (band_flags[gr_no][band] & IS_MODE) != 0 { + let start = band_start[gr_no][band]; + let end = band_end[gr_no][band]; apply_istereo(&mut coef0[start..end], &mut coef1[start..end], is_mode[start], iscale, (band_flags[gr_no][band] & MS_MODE) != 0); } } } - end_freq[gr_no][1] = end_freq[gr_no][1].min(end); + end_freq[gr_no][1] = end_freq[gr_no][1].max(end); } } if (mode_ext & MS_MODE) != 0 { @@ -645,7 +647,7 @@ impl MP3Data { if band_start[gr_no][band] >= end { break; } - if (band_flags[gr_no][band] & MS_MODE) != 0 { + if band_flags[gr_no][band] == MS_MODE { let start = band_start[gr_no][band]; let end = band_end[gr_no][band]; super::apply_ms(&mut coef0[start..end], &mut coef1[start..end]);