예제 #1
0
        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();
        }
예제 #2
0
        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());
        }