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(); }
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()); }