Rearm the coupling run state when E-AC-3 turns coupling off
Browse files at this commit777214d465562211cb3883ceb1ef79f30b9df064Parent: fa29faa- fix
- rearm the coupling run state when E-AC-3 turns coupling off
1 changed file +23 -2
- crates/ec-ac3/src/eac3.rs +23 -2
crates/ec-ac3/src/eac3.rsmodified+23 -2
| @@ -854,8 +854,14 @@ fn parse_block( | |||
| 854 | core.cplband[sbnd] = core.ncplbnd - 1; | 854 | core.cplband[sbnd] = core.ncplbnd - 1; |
| 855 | } | 855 | } |
| 856 | } else { | 856 | } else { |
| 857 | + // §E1.4, the `!cplinu[blk]` branch: switching coupling off also | ||
| 858 | + // rearms the "first block of the run" state, so a frame that turns | ||
| 859 | + // coupling on again later sends its coordinates and leak values | ||
| 860 | + // unconditionally rather than behind a presence bit. | ||
| 857 | core.chincpl = [false; 5]; | 861 | core.chincpl = [false; 5]; |
| 858 | core.phsflginu = false; | 862 | core.phsflginu = false; |
| 863 | + core.first_cplco = [true; 5]; | ||
| 864 | + core.first_cplleak = true; | ||
| 859 | } | 865 | } |
| 860 | } | 866 | } |
| 861 | core.cplinu = frm.cplinu[blk]; | 867 | core.cplinu = frm.cplinu[blk]; |
| @@ -964,7 +970,15 @@ fn parse_block( | |||
| 964 | let absexp = r.read_bits(4)? as u8; | 970 | let absexp = r.read_bits(4)? as u8; |
| 965 | core.exps[ch][0] = absexp; | 971 | core.exps[ch][0] = absexp; |
| 966 | let ngrps = core.expstr[ch].fbw_groups(core.endmant[ch]); | 972 | let ngrps = core.expstr[ch].fbw_groups(core.endmant[ch]); |
| 967 | - exps::decode(r, core.expstr[ch], ngrps, absexp, 1, &mut core.exps[ch])?; | 973 | + exps::decode(r, core.expstr[ch], ngrps, absexp, 1, &mut core.exps[ch]).map_err( |
| 974 | + |e| match e { | ||
| 975 | + Error::Corrupt { context } => Error::corrupt(format!( | ||
| 976 | + "{context} (block {blk}, channel {ch}, {:?}, endmant {}, spx {}, cpl {})", | ||
| 977 | + core.expstr[ch], core.endmant[ch], core.chinspx[ch], core.chincpl[ch] | ||
| 978 | + )), | ||
| 979 | + other => other, | ||
| 980 | + }, | ||
| 981 | + )?; | ||
| 968 | let _gainrng = r.read_bits(2)?; | 982 | let _gainrng = r.read_bits(2)?; |
| 969 | } | 983 | } |
| 970 | if core.lfeon && core.expstr[LFE] != Strategy::Reuse { | 984 | if core.lfeon && core.expstr[LFE] != Strategy::Reuse { |
| @@ -1182,7 +1196,14 @@ fn spectral_extension(core: &mut Core, ch: usize) { | |||
| 1182 | if spxmant >= COEFFS { | 1196 | if spxmant >= COEFFS { |
| 1183 | break; | 1197 | break; |
| 1184 | } | 1198 | } |
| 1185 | - let noise = core.spx_noise.unit_variance(); | 1199 | + // §E3.6.4.2.4's noise(): a zero-mean unit-variance source the |
| 1200 | + // standard leaves to the implementation, so it is switched by the | ||
| 1201 | + // same option as §7.3.4's dither. | ||
| 1202 | + let noise = if core.dither_on { | ||
| 1203 | + core.spx_noise.unit_variance() | ||
| 1204 | + } else { | ||
| 1205 | + 0.0 | ||
| 1206 | + }; | ||
| 1186 | core.coeffs[ch][spxmant] = (core.coeffs[ch][spxmant] * sscale + noise * nscale) * coord; | 1207 | core.coeffs[ch][spxmant] = (core.coeffs[ch][spxmant] * sscale + noise * nscale) * coord; |
| 1187 | spxmant += 1; | 1208 | spxmant += 1; |
| 1188 | } | 1209 | } |