public void c2demo() { Codec2 c2 = new Codec2(Codec2.Mode.b3200); string filePath = "../../../../audioSamples/speech_orig_16k.raw"; byte[] buf; byte[] bits; buf = new byte[c2.samplesPerFrame * sizeof(short)]; bits = new byte[c2.bytesPerFrame]; FileStream readfile = File.OpenRead(filePath); FileStream writeFile = File.OpenWrite("out3200"); while (readfile.Read(buf, 0, c2.samplesPerFrame * 2) == c2.samplesPerFrame * 2) { c2.encodeFrame(ref bits, buf); c2.decodeFrame(ref buf, bits); writeFile.Write(buf, 0, c2.samplesPerFrame * 2); } // TODO make assert writeFile.Close(); readfile.Close(); }
public void TestMethod1() { TreeNode treeNode = new TreeNode(1); treeNode.left = new TreeNode(2); treeNode.right = new TreeNode(3); treeNode.right.left = new TreeNode(4); treeNode.right.right = new TreeNode(5); Codec2 codec = new Codec2(); var stringCoding = codec.serialize(treeNode); var treeNodeResult = codec.deserialize(stringCoding); Assert.IsTrue(AreEquals(treeNode, treeNodeResult)); }
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 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()); }
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()); }