forge
Explore
Log in

Don't you dare go Hollow

Mask stereo angle coding

Browse files at this commit

78cb5792ec8d8664b3bb471ebb343791cd52ebc5Ahmet Kaan GümüşParent: f096338
  • fix
    • mask stereo angle coding
Show full message
fix(vorbis): mask stereo angle coding
crates/ec-vorbis/src/encode.rsmodified+17 -8
@@ -729,20 +729,29 @@ impl VorbisEncoder {
729729 for &(magnitude, angle) in &self.coupling {
730730 let mut left = std::mem::take(&mut quantised[magnitude]);
731731 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+ };
735737 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,
740740 false => half,
741741 };
742742 for (bin, (l, r)) in left.iter_mut().zip(right.iter_mut()).enumerate() {
743743 let (m, a) = couple(*l, *r);
744744 *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+ };
746755 }
747756 quantised[magnitude] = left;
748757 quantised[angle] = right;