Example #1
0
        public void TestDecodeFrameNumFrames()
        {
            string dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string path    = Path.Combine(dirName, "bensound-scifi.mp3");

            Mpg123 mpg123 = new Mpg123();

            mpg123.Open(path);

            byte[] buffer = null;
            int    num    = 0;
            uint   bytes  = 0;

            int  b = 0, c = 0;
            long a = 0;

            mpg123.GetFormat(ref a, ref b, ref c);

            Mpg123.Errors error = Mpg123.Errors.OK;
            while (error == Mpg123.Errors.OK)
            {
                error = mpg123.DecodeFrame(ref num, ref buffer, ref bytes);
            }

            Assert.That(num, Is.GreaterThan(0));
        }
Example #2
0
        public void TestDecodeFrameNeedMore()
        {
            string dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string path    = Path.Combine(dirName, "bensound-epic.mp3");

            Mpg123 mpg123 = new Mpg123();

            mpg123.OpenFeed();

            byte[] fileBytes = File.ReadAllBytes(path);
            byte[] buffer    = new byte[8];
            Array.Copy(fileBytes, buffer, 8);

            int  num   = 0;
            uint bytes = 0;

            int  b = 0, c = 0;
            long a = 0;

            mpg123.GetFormat(ref a, ref b, ref c);

            Mpg123.Errors error = Mpg123.Errors.OK;
            Assert.That(() => error = mpg123.DecodeFrame(ref num, ref buffer, ref bytes), Throws.Nothing);

            Assert.That(error, Is.EqualTo(Mpg123.Errors.NEED_MORE));
        }
Example #3
0
        public void TestDecodeFrameNotOpen()
        {
            Mpg123 mpg123 = new Mpg123();

            byte[] buffer = null;
            int    num    = 0;
            uint   bytes  = 0;

            Assert.That(() => mpg123.DecodeFrame(ref num, ref buffer, ref bytes), Throws.TypeOf <Mpg123.ErrorException>());
        }
Example #4
0
        public void TestDecodeFrameNewFormat()
        {
            string dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string path    = Path.Combine(dirName, "bensound-epic.mp3");

            Mpg123 mpg123 = new Mpg123();

            mpg123.Open(path);

            byte[] buffer = null;
            int    num    = 0;
            uint   bytes  = 0;

            Assert.That(mpg123.DecodeFrame(ref num, ref buffer, ref bytes), Is.EqualTo(Mpg123.Errors.NEW_FORMAT));
        }
Example #5
0
        public void TestDecodeFrameBufferLength1()
        {
            string dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string path    = Path.Combine(dirName, "bensound-scifi.mp3");

            Mpg123 mpg123 = new Mpg123();

            mpg123.Open(path);

            byte[] buffer = null;
            int    num    = 0;
            uint   bytes  = 0;

            int  b = 0, c = 0;
            long a = 0;

            mpg123.GetFormat(ref a, ref b, ref c);

            mpg123.DecodeFrame(ref num, ref buffer, ref bytes);
            Assert.That(buffer.Length, Is.EqualTo(188));

            mpg123.DecodeFrame(ref num, ref buffer, ref bytes);
            Assert.That(buffer.Length, Is.EqualTo(4608));
        }
Example #6
0
        public void TestFramePosParsedFrame()
        {
            string dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string path    = Path.Combine(dirName, "bensound-scifi.mp3");

            Mpg123 mpg123 = new Mpg123();

            mpg123.Open(path);

            byte[] buffer = null;
            int    num    = 0;
            uint   bytes  = 0;

            mpg123.DecodeFrame(ref num, ref buffer, ref bytes);

            Assert.That(mpg123.FramePos(), Is.GreaterThan(0));
        }
Example #7
0
        public void TestDecodeFrameBufferLength0()
        {
            string dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string path    = Path.Combine(dirName, "bensound-epic.mp3");

            Mpg123 mpg123 = new Mpg123();

            mpg123.Open(path);

            byte[] buffer = null;
            int    num    = 0;
            uint   bytes  = 0;

            while (mpg123.DecodeFrame(ref num, ref buffer, ref bytes) != Mpg123.Errors.OK)
            {
            }

            Assert.That(buffer.Length, Is.EqualTo(bytes));
        }
Example #8
0
        public void TestDecodeFrameOpen()
        {
            string dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string path    = Path.Combine(dirName, "bensound-epic.mp3");

            Mpg123 mpg123 = new Mpg123();

            mpg123.Open(path);

            byte[] buffer = null;
            int    num    = 0;
            uint   bytes  = 0;

            Mpg123.Errors error = Mpg123.Errors.OK;
            while (error == Mpg123.Errors.OK)
            {
                Assert.That(() => error = mpg123.DecodeFrame(ref num, ref buffer, ref bytes), Throws.Nothing);
            }
        }
Example #9
0
        public void TestDecodeFrameNumFramesTotal()
        {
            string dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string path    = Path.Combine(dirName, "bensound-epic.mp3");

            Mpg123 mpg123 = new Mpg123();

            mpg123.Open(path);

            byte[] buffer = null;
            int    num    = 1;
            uint   bytes  = 0;

            Mpg123.Errors error = Mpg123.Errors.OK;
            while (error != Mpg123.Errors.DONE)
            {
                error = mpg123.DecodeFrame(ref num, ref buffer, ref bytes);
            }

            Assert.That(num, Is.EqualTo(6834));
        }
Example #10
0
        static void Main(string[] args)
        {
            foreach (string decoder in Mpg123.Decoders)
            {
                Console.WriteLine(decoder);
            }

            Out123 out123 = new Out123();

            out123.Open();

            Mpg123 mpg123 = new Mpg123();

            mpg123.Open("Assets/bensound-epic.mp3");

            int offset = 0;

            while (true)
            {
                byte[]        data  = null;
                uint          size  = 0;
                Mpg123.Errors error = mpg123.DecodeFrame(ref offset, ref data, ref size);
                if (error == Mpg123.Errors.NEW_FORMAT)
                {
                    long rate     = 0;
                    int  channels = 0;
                    int  encoding = 0;
                    mpg123.GetFormat(ref rate, ref channels, ref encoding);
                    out123.Start(rate, channels, encoding);
                }
                else if (error == Mpg123.Errors.OK)
                {
                    out123.Play(data);
                }
            }

            Console.ReadLine();
        }