Mask stereo angle coding
Browse files at this commit78cb5792ec8d8664b3bb471ebb343791cd52ebc5Parent: f096338- fix
- mask stereo angle coding
1 changed file +17 -8
crates/ec-vorbis/src/encode.rsmodified+17 -8
| @@ -729,20 +729,29 @@ impl VorbisEncoder { | ||
| 729 | 729 | for &(magnitude, angle) in &self.coupling { |
| 730 | 730 | let mut left = std::mem::take(&mut quantised[magnitude]); |
| 731 | 731 | let mut right = std::mem::take(&mut quantised[angle]); |
| 732 | - // Only while bits are scarce: headroom at the range is the | |
| 733 | - // rate loop saying the step cannot get finer, so the budget | |
| 734 | - // is better spent stating the angle than left unspent. | |
| 732 | + let cutoff = if self.config.bitrate_bps >= 128_000 { | |
| 733 | + 6_000.0 | |
| 734 | + } else { | |
| 735 | + POINT_STEREO_HZ | |
| 736 | + }; | |
| 735 | 737 | let point = match self.headroom < bc.range { |
| 736 | - true => { | |
| 737 | - (POINT_STEREO_HZ / (f64::from(self.config.sample_rate) * 0.5) * half as f64) | |
| 738 | - as usize | |
| 739 | - } | |
| 738 | + true => (cutoff / (f64::from(self.config.sample_rate) * 0.5) * half as f64) | |
| 739 | + as usize, | |
| 740 | 740 | false => half, |
| 741 | 741 | }; |
| 742 | 742 | for (bin, (l, r)) in left.iter_mut().zip(right.iter_mut()).enumerate() { |
| 743 | 743 | let (m, a) = couple(*l, *r); |
| 744 | 744 | *l = m; |
| 745 | - *r = if bin >= point { 0 } else { a }; | |
| 745 | + *r = if bin < point { | |
| 746 | + a | |
| 747 | + } else { | |
| 748 | + let delta = (spectra[magnitude][bin] - spectra[angle][bin]).abs(); | |
| 749 | + if delta > curves[magnitude][bin].max(curves[angle][bin]) { | |
| 750 | + a.signum() | |
| 751 | + } else { | |
| 752 | + 0 | |
| 753 | + } | |
| 754 | + }; | |
| 746 | 755 | } |
| 747 | 756 | quantised[magnitude] = left; |
| 748 | 757 | quantised[angle] = right; |