void testEncodingIntegrity(Codec2.Mode mode) { string filePathEnc = "../../../../audioSamples/speech_orig_16k." + mode.ToString() + ".enc"; string filePathRaw = "../../../../audioSamples/speech_orig_16k.raw"; byte[] fileContentEnc = File.ReadAllBytes(filePathEnc); byte[] fileContentRaw = File.ReadAllBytes(filePathRaw); Codec2 c2 = new Codec2(mode); byte[] c2Encoded = c2.encodeAll(fileContentRaw); Assert.Equal(fileContentEnc, c2Encoded); }
void testEncodingOverload(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.raw"; byte[] fileContent = File.ReadAllBytes(filePath); // test //encode everything at once byte[] encodeAllByte = c2_1.encodeAll(fileContent); //encode the first frame byte[] encodeFrameBytes = c2_2.encodeFrame(fileContent.Take(c2_2.samplesPerFrame * 2).ToArray()); List <byte> encodeFrameList = 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.samplesPerFrame * 2) == c2_3.samplesPerFrame * 2) { c2_3.encodeFrame(ref bits, buf); encodeFrameList.AddRange(bits); } // assert // the first frame of all the bytes and the single frame should be the same. // TODO b450 and b450PWB sometimes fail Assert.Equal(encodeAllByte.Take(c2_1.bytesPerFrame).ToArray(), encodeFrameBytes); Assert.Equal(encodeFrameList.Take(c2_3.bytesPerFrame).ToArray(), encodeFrameBytes); // all the encodedframes added together and the encodedAll should have the same result. Assert.Equal(encodeAllByte, encodeFrameList.ToArray()); }