From 35727459682494b1ac2d3421d4f66b490cf00741 Mon Sep 17 00:00:00 2001 From: Grigory Chudov Date: Fri, 19 Sep 2014 01:17:23 -0400 Subject: [PATCH] Backed out changeset: 883e51ca8287 --- CUETools.Codecs.FLACCL/FLACCLWriter.cs | 9 +---- CUETools.Codecs.FLAKE/FlakeWriter.cs | 46 ++++++-------------------- CUETools.Codecs/LPC.cs | 40 ++++++---------------- 3 files changed, 22 insertions(+), 73 deletions(-) diff --git a/CUETools.Codecs.FLACCL/FLACCLWriter.cs b/CUETools.Codecs.FLACCL/FLACCLWriter.cs index ce21b16..0de51f0 100644 --- a/CUETools.Codecs.FLACCL/FLACCLWriter.cs +++ b/CUETools.Codecs.FLACCL/FLACCLWriter.cs @@ -1363,14 +1363,7 @@ namespace CUETools.Codecs.FLACCL fixed (int* coefs = task.frame.subframes[ch].best.coefs) { if (Settings.PCM.BitsPerSample > 16) - { - if (!lpc.encode_residual_long(task.frame.subframes[ch].best.residual, task.frame.subframes[ch].samples, task.frame.blocksize, task.frame.subframes[ch].best.order, coefs, task.frame.subframes[ch].best.shift)) - { - task.frame.subframes[ch].best.type = SubframeType.Verbatim; - task.frame.subframes[ch].best.size = (uint)(task.frame.subframes[ch].obits * task.frame.blocksize); - return; - } - } + lpc.encode_residual_long(task.frame.subframes[ch].best.residual, task.frame.subframes[ch].samples, task.frame.blocksize, task.frame.subframes[ch].best.order, coefs, task.frame.subframes[ch].best.shift); else lpc.encode_residual(task.frame.subframes[ch].best.residual, task.frame.subframes[ch].samples, task.frame.blocksize, task.frame.subframes[ch].best.order, coefs, task.frame.subframes[ch].best.shift); } diff --git a/CUETools.Codecs.FLAKE/FlakeWriter.cs b/CUETools.Codecs.FLAKE/FlakeWriter.cs index 134c9ca..d8d1486 100644 --- a/CUETools.Codecs.FLAKE/FlakeWriter.cs +++ b/CUETools.Codecs.FLAKE/FlakeWriter.cs @@ -1156,10 +1156,7 @@ new int[] { // 30 fixed (int* coefs = frame.current.coefs) { if ((csum << frame.subframes[ch].obits) >= 1UL << 32) - { - if (!lpc.encode_residual_long(frame.current.residual, frame.subframes[ch].samples, frame.blocksize, frame.current.order, coefs, frame.current.shift)) - continue; - } + lpc.encode_residual_long(frame.current.residual, frame.subframes[ch].samples, frame.blocksize, frame.current.order, coefs, frame.current.shift); else lpc.encode_residual(frame.current.residual, frame.subframes[ch].samples, frame.blocksize, frame.current.order, coefs, frame.current.shift); } @@ -1277,10 +1274,7 @@ new int[] { // 30 csum += (ulong)Math.Abs(coefs[i - 1]); if ((csum << frame.subframes[ch].obits) >= 1UL << 32) - { - if (!lpc.encode_residual_long(frame.current.residual, frame.subframes[ch].samples, frame.blocksize, frame.current.order, coefs, frame.current.shift)) - continue; - } + lpc.encode_residual_long(frame.current.residual, frame.subframes[ch].samples, frame.blocksize, frame.current.order, coefs, frame.current.shift); else lpc.encode_residual(frame.current.residual, frame.subframes[ch].samples, frame.blocksize, frame.current.order, coefs, frame.current.shift); @@ -2276,33 +2270,15 @@ new int[] { // 30 if (verify != null) { - try - { - int decoded = verify.DecodeFrame(frame_buffer, 0, fs); - if (decoded != fs || verify.Remaining != bs) - throw new Exception(Properties.Resources.ExceptionValidationFailed); - fixed (int* s = verifyBuffer, r = verify.Samples) - { - for (int ch = 0; ch < channels; ch++) - if (AudioSamples.MemCmp(s + ch * Flake.MAX_BLOCKSIZE, r + ch * Flake.MAX_BLOCKSIZE, bs)) - throw new Exception(Properties.Resources.ExceptionValidationFailed); - } - } - catch (Exception ex) - { - //if (channels == 2) - //{ - // var sw = new WAVWriter("verify.wav", new WAVWriterSettings(this.Settings.PCM)); - // sw.FinalSampleCount = this.frame.blocksize; - // var ab = new AudioBuffer(this.Settings.PCM, this.frame.blocksize); - // ab.Prepare(this.frame.blocksize); - // fixed (int* abs = ab.Samples, s = verifyBuffer) - // AudioSamples.Interlace(abs, s, s + Flake.MAX_BLOCKSIZE, this.frame.blocksize); - // sw.Write(ab); - // sw.Close(); - //} - throw ex; - } + int decoded = verify.DecodeFrame(frame_buffer, 0, fs); + if (decoded != fs || verify.Remaining != bs) + throw new Exception(Properties.Resources.ExceptionValidationFailed); + fixed (int* s = verifyBuffer, r = verify.Samples) + { + for (int ch = 0; ch < channels; ch++) + if (AudioSamples.MemCmp(s + ch * Flake.MAX_BLOCKSIZE, r + ch * Flake.MAX_BLOCKSIZE, bs)) + throw new Exception(Properties.Resources.ExceptionValidationFailed); + } } if (bs < m_blockSize) diff --git a/CUETools.Codecs/LPC.cs b/CUETools.Codecs/LPC.cs index 5724019..d5975b9 100644 --- a/CUETools.Codecs/LPC.cs +++ b/CUETools.Codecs/LPC.cs @@ -693,7 +693,7 @@ namespace CUETools.Codecs } } - public static unsafe bool + public static unsafe void encode_residual_long(int* res, int* smp, int n, int order, int* coefs, int shift) { @@ -704,16 +704,13 @@ namespace CUETools.Codecs int* r = res + order; int c0 = coefs[0]; int c1 = coefs[1]; - long overflows = 0L; switch (order) { case 1: for (int i = n - order; i > 0; i--) { long pred = c0 * (long)*(s++); - pred = *s - (pred >> shift); - overflows += (pred ^ (pred >> 63)) >> 30; - *(r++) = (int)pred; + *(r++) = *s - (int)(pred >> shift); } break; case 2: @@ -721,9 +718,7 @@ namespace CUETools.Codecs { long pred = c1 * (long)*(s++); pred += c0 * (long)*(s++); - pred = *(s--) - (pred >> shift); - overflows += (pred ^ (pred >> 63)) >> 30; - *(r++) = (int)pred; + *(r++) = *(s--) - (int)(pred >> shift); } break; case 3: @@ -732,9 +727,7 @@ namespace CUETools.Codecs long pred = coefs[2] * (long)*(s++); pred += c1 * (long)*(s++); pred += c0 * (long)*(s++); - pred = *s - (pred >> shift); - overflows += (pred ^ (pred >> 63)) >> 30; - *(r++) = (int)pred; + *(r++) = *s - (int)(pred >> shift); s -= 2; } break; @@ -745,9 +738,7 @@ namespace CUETools.Codecs pred += coefs[2] * (long)*(s++); pred += c1 * (long)*(s++); pred += c0 * (long)*(s++); - pred = *s - (pred >> shift); - overflows += (pred ^ (pred >> 63)) >> 30; - *(r++) = (int)pred; + *(r++) = *s - (int)(pred >> shift); s -= 3; } break; @@ -759,9 +750,7 @@ namespace CUETools.Codecs pred += coefs[2] * (long)*(s++); pred += c1 * (long)*(s++); pred += c0 * (long)*(s++); - pred = *s - (pred >> shift); - overflows += (pred ^ (pred >> 63)) >> 30; - *(r++) = (int)pred; + *(r++) = *s - (int)(pred >> shift); s -= 4; } break; @@ -774,9 +763,7 @@ namespace CUETools.Codecs pred += coefs[2] * (long)*(s++); pred += c1 * (long)*(s++); pred += c0 * (long)*(s++); - pred = *s - (pred >> shift); - overflows += (pred ^ (pred >> 63)) >> 30; - *(r++) = (int)pred; + *(r++) = *s - (int)(pred >> shift); s -= 5; } break; @@ -790,9 +777,7 @@ namespace CUETools.Codecs pred += coefs[2] * (long)*(s++); pred += c1 * (long)*(s++); pred += c0 * (long)*(s++); - pred = *s - (pred >> shift); - overflows += (pred ^ (pred >> 63)) >> 30; - *(r++) = (int)pred; + *(r++) = *s - (int)(pred >> shift); s -= 6; } break; @@ -807,9 +792,7 @@ namespace CUETools.Codecs pred += coefs[2] * (long)*(s++); pred += c1 * (long)*(s++); pred += c0 * (long)*(s++); - pred = *s - (pred >> shift); - overflows += (pred ^ (pred >> 63)) >> 30; - *(r++) = (int)pred; + *(r++) = *s - (int)(pred >> shift); s -= 7; } break; @@ -830,13 +813,10 @@ namespace CUETools.Codecs pred += coefs[2] * (long)*(s++); pred += c1 * (long)*(s++); pred += c0 * (long)*(s++); - pred = *s - (pred >> shift); - overflows += (pred ^ (pred >> 63)) >> 30; - *(r++) = (int)pred; + *(r++) = *s - (int)(pred >> shift); } break; } - return overflows == 0; } public static unsafe void