public Encode(string[] files, IDspTool dllA, IDspTool dllB, Func <IAudioReader> reader) { Files = files; DllA = dllA; DllB = dllB; GetReader = reader; }
private static Result CompareEncodingFine(short[] pcm, IDspTool dllA, IDspTool dllB) { short[] coefsA = dllA.DspCorrelateCoefs(pcm); short[] coefsB = dllB.DspCorrelateCoefs(pcm); int coefsEqual = ArraysEqual(coefsA, coefsB); if (coefsEqual != -1) { return(new Result { Equal = false, CoefsEqual = false, RanFineComparison = true, CoefsA = coefsA, CoefsB = coefsB }); } int sampleCount = pcm.Length; var adpcmA = new byte[SampleCountToByteCount(sampleCount)]; var adpcmB = new byte[SampleCountToByteCount(sampleCount)]; /* Execute encoding-predictor for each frame */ var pcmBufferA = new short[2 + SamplesPerFrame]; var pcmBufferB = new short[2 + SamplesPerFrame]; var adpcmBufferA = new byte[BytesPerFrame]; var adpcmBufferB = new byte[BytesPerFrame]; int frameCount = DivideByRoundUp(sampleCount, SamplesPerFrame); for (int frame = 0; frame < frameCount; frame++) { int samplesToCopy = Math.Min(sampleCount - frame * SamplesPerFrame, SamplesPerFrame); Array.Copy(pcm, frame * SamplesPerFrame, pcmBufferA, 2, samplesToCopy); Array.Copy(pcm, frame * SamplesPerFrame, pcmBufferB, 2, samplesToCopy); Array.Clear(pcmBufferA, 2 + samplesToCopy, SamplesPerFrame - samplesToCopy); Array.Clear(pcmBufferB, 2 + samplesToCopy, SamplesPerFrame - samplesToCopy); dllA.DspEncodeFrame(pcmBufferA, SamplesPerFrame, adpcmBufferA, coefsA); dllB.DspEncodeFrame(pcmBufferB, SamplesPerFrame, adpcmBufferB, coefsB); int encodeEqual = ArraysEqual(adpcmBufferA, adpcmBufferB); if (encodeEqual != -1) { int differentSample = ArraysEqual(pcmBufferA, pcmBufferB) - 2; //Get the input PCM that resulted in different encodings var history = new short[2 + SamplesPerFrame]; Array.Copy(pcm, frame * SamplesPerFrame, history, 2, samplesToCopy); Array.Copy(pcmBufferA, 0, history, 0, 2); var pcmA = new short[SamplesPerFrame]; var pcmB = new short[SamplesPerFrame]; Array.Copy(pcmBufferA, 2, pcmA, 0, samplesToCopy); Array.Copy(pcmBufferB, 2, pcmB, 0, samplesToCopy); return(new Result { Equal = false, CoefsEqual = true, RanFineComparison = true, CoefsA = coefsA, CoefsB = coefsB, Frame = frame, FrameSample = differentSample, Sample = frame * SamplesPerFrame + differentSample, PcmIn = history, PcmOutA = pcmA, PcmOutB = pcmB, AdpcmOutA = adpcmBufferA, AdpcmOutB = adpcmBufferB }); } Array.Copy(adpcmBufferA, 0, adpcmA, frame * BytesPerFrame, SampleCountToByteCount(samplesToCopy)); Array.Copy(adpcmBufferB, 0, adpcmB, frame * BytesPerFrame, SampleCountToByteCount(samplesToCopy)); pcmBufferA[0] = pcmBufferA[14]; pcmBufferA[1] = pcmBufferA[15]; pcmBufferB[0] = pcmBufferB[14]; pcmBufferB[1] = pcmBufferB[15]; } return(new Result { Equal = true, RanFineComparison = true }); }