void testDecodingIntegrity(Codec2.Mode mode) { string filePathDec = "../../../../audioSamples/speech_orig_16k." + mode.ToString() + ".dec"; string filePathEnc = "../../../../audioSamples/speech_orig_16k." + mode.ToString() + ".enc"; byte[] fileContentDec = File.ReadAllBytes(filePathDec); byte[] fileContentEnc = File.ReadAllBytes(filePathEnc); Codec2 c2 = new Codec2(mode); byte[] c2Decoded = c2.decodeAll(fileContentEnc); // TODO decoded data is diffrent everytime. Assert.Equal(fileContentDec, c2Decoded); }
void testDecodingOverload(Codec2.Mode mode) { // Assemble Codec2 c2_1 = new Codec2(mode); Codec2 c2_2 = new Codec2(mode); Codec2 c2_3 = new Codec2(mode); string filePath = "../../../../audioSamples/speech_orig_16k." + mode.ToString() + ".enc"; byte[] fileContent = File.ReadAllBytes(filePath); // test //encode everything at once byte[] decodeAllBytes = c2_1.decodeAll(fileContent); byte[] decodeAllBytes2 = c2_2.decodeAll(fileContent); Assert.Equal(decodeAllBytes, decodeAllBytes2); //encode the first frame byte[] decodeFrameBytes = c2_2.decodeFrame(fileContent.Take(c2_2.bytesPerFrame).ToArray()); List <byte> decodeFrameList = new List <byte>(); byte[] buf = new byte[c2_3.samplesPerFrame * sizeof(short)]; byte[] bits = new byte[c2_3.bytesPerFrame]; FileStream readfile = File.OpenRead(filePath); // read all content of the file. while (readfile.Read(buf, 0, c2_3.bytesPerFrame) == c2_3.bytesPerFrame) { c2_3.decodeFrame(ref buf, bits); decodeFrameList.AddRange(buf); } // assert // TODO all tests fail, decoding seems have a random function somewhere // the first frame of all the bytes and the single frame should be the same. Assert.Equal(decodeAllBytes.Take(c2_1.samplesPerFrame * 2).ToArray(), decodeFrameBytes); Assert.Equal(decodeFrameList.Take(c2_3.samplesPerFrame * 2).ToArray(), decodeFrameBytes); // all the encodedframes added together and the encodedAll should have the same result. Assert.Equal(decodeAllBytes, decodeFrameList.ToArray()); }