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 {
729 for &(magnitude, angle) in &self.coupling {729 for &(magnitude, angle) in &self.coupling {
730 let mut left = std::mem::take(&mut quantised[magnitude]);730 let mut left = std::mem::take(&mut quantised[magnitude]);
731 let mut right = std::mem::take(&mut quantised[angle]);731 let mut right = std::mem::take(&mut quantised[angle]);
732- // Only while bits are scarce: headroom at the range is the732+ let cutoff = if self.config.bitrate_bps >= 128_000 {
733- // rate loop saying the step cannot get finer, so the budget733+ 6_000.0
734- // is better spent stating the angle than left unspent.734+ } else {
735+ POINT_STEREO_HZ
736+ };
735 let point = match self.headroom < bc.range {737 let point = match self.headroom < bc.range {
736- true => {738+ true => (cutoff / (f64::from(self.config.sample_rate) * 0.5) * half as f64)
737- (POINT_STEREO_HZ / (f64::from(self.config.sample_rate) * 0.5) * half as f64)739+ as usize,
738- as usize
739- }
740 false => half,740 false => half,
741 };741 };
742 for (bin, (l, r)) in left.iter_mut().zip(right.iter_mut()).enumerate() {742 for (bin, (l, r)) in left.iter_mut().zip(right.iter_mut()).enumerate() {
743 let (m, a) = couple(*l, *r);743 let (m, a) = couple(*l, *r);
744 *l = m;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 quantised[magnitude] = left;756 quantised[magnitude] = left;
748 quantised[angle] = right;757 quantised[angle] = right;