Ejemplo n.º 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));
        }
Ejemplo n.º 2
0
        public void TestInstantiateWithDecoder()
        {
            string decoder = Mpg123.Decoders.ToArray()[0];
            Mpg123 mpg123  = new Mpg123(decoder);

            Assert.That(mpg123.HasValidHandle, Is.True);
        }
Ejemplo n.º 3
0
        public void TestSeekFrameInvalid()
        {
            string decoder = Mpg123.Decoders.ToArray().FirstOrDefault();
            Mpg123 mpg123  = new Mpg123();

            Assert.That(() => mpg123.SeekFrame(5, SeekOrigin.Begin), Throws.TypeOf <Mpg123.ErrorException>());
        }
Ejemplo n.º 4
0
        public void TestResetEqualizerRedLight()
        {
            Mpg123 mpg123 = new Mpg123();

            mpg123.Dispose();
            Assert.That(() => mpg123.ResetEq(), Throws.TypeOf <Mpg123.ErrorException>());
        }
Ejemplo n.º 5
0
        public void TestSetEqualizerRedLight()
        {
            Mpg123 mpg123     = new Mpg123();
            int    ErrorValue = 1000;

            Assert.That(() => mpg123.Eq(Mpg123.Channels.LEFT, ErrorValue, 20), Throws.TypeOf <Mpg123.ErrorException>());
        }
Ejemplo n.º 6
0
        public void TestOpenPathInvalid()
        {
            string path   = "test.mp3";
            Mpg123 mpg123 = new Mpg123();

            Assert.That(() => mpg123.Open(path), Throws.TypeOf <Mpg123.ErrorException>());
        }
Ejemplo n.º 7
0
        public void TestFormatSupportedNoEx()
        {
            Mpg123 handle = new Mpg123();

            //Mpg123.ChannelCount state = handle.IsFormatSupported(100, 20);
            Assert.That(() => handle.IsFormatSupported(100, 20), Throws.Nothing);
        }
Ejemplo n.º 8
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));
        }
        private SoundFile Decode(Stream s)
        {
            IAudioDecoder decoder = new Mpg123();

            if (!decoder.IsAvailable)
            {
                decoder = new MP3AudioDecoder();
            }

            if (!decoder.IsAvailable)
            {
                throw new Exception("No mp3 decoder available!");
            }

            try
            {
                decoder.BeginDecode(s);
                using var data = new MemoryStream();
                var packet = decoder.Decode();
                IAudioConfiguration config = packet;
                while (packet != null)
                {
                    data.Write(packet.Data, 0, packet.Length);
                    packet = decoder.Decode();
                }
                return(new SoundFile(config, data.ToArray()));
            }
            finally
            {
                decoder.Close();
            }
        }
Ejemplo n.º 10
0
        public void TestReadNoOpen()
        {
            Mpg123 mpg123 = new Mpg123();
            uint   done   = 0;

            byte[] buffer = new byte[100];
            Assert.That(() => mpg123.Read(buffer, ref done), Throws.TypeOf <Mpg123.ErrorException>());
        }
Ejemplo n.º 11
0
        public void TestGetFormatOK()   //must fail because there isn't stream loaded
        {
            Mpg123 handle = new Mpg123();
            long   rate = 0;
            int    channels = 0, encoding = 0;

            Assert.That(handle.GetFormat(ref rate, ref channels, ref encoding), Is.Not.EqualTo(Mpg123.Errors.OK));
        }
Ejemplo n.º 12
0
        public void TestTellStreamIsNegative() //without loaded stream
        {
            Mpg123 mpg123 = new Mpg123(Mpg123.Decoders.ToArray().FirstOrDefault());

            long seekPositon = mpg123.TellStream();

            Assert.That(seekPositon, Is.EqualTo(-1));
        }
Ejemplo n.º 13
0
        public void TestTellIsZero() //with no loaded stream
        {
            Mpg123 mpg123 = new Mpg123(Mpg123.Decoders.ToArray().FirstOrDefault());

            long seekPositon = mpg123.Tell();

            Assert.That(seekPositon, Is.Zero);
        }
Ejemplo n.º 14
0
        public void TestOpenPathValid()
        {
            string dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string path    = dirName + "/bensound-epic.mp3";
            Mpg123 mpg123  = new Mpg123();

            Assert.That(() => mpg123.Open(path), Throws.Nothing);
        }
Ejemplo n.º 15
0
        public void TestGetDecoder()
        {
            string decoder = Mpg123.Decoders.ToArray()[0];

            Mpg123 mpg123 = new Mpg123(decoder);

            Assert.That(mpg123.Decoder, Is.EqualTo(decoder));
        }
Ejemplo n.º 16
0
        public void TestDecodeNoOpen()
        {
            Mpg123 mpg123 = new Mpg123();

            uint done = 0;

            Assert.That(() => mpg123.Decode(null, 0, null, 0, ref done), Throws.TypeOf <Mpg123.ErrorException>());
        }
Ejemplo n.º 17
0
        public void TestTellFrameIsZero()
        {
            Mpg123 mpg123 = new Mpg123(Mpg123.Decoders.ToArray().FirstOrDefault());

            long seekPositon = mpg123.TellFrame();

            Assert.That(seekPositon, Is.Zero);
        }
Ejemplo n.º 18
0
        public void TestGetDecoderFalse()
        {
            string decoder    = Mpg123.Decoders.ToArray()[0];
            string notDecoder = Mpg123.Decoders.ToArray()[1];

            Mpg123 mpg123 = new Mpg123(decoder);

            Assert.That(mpg123.Decoder, Is.Not.EqualTo(notDecoder));
        }
Ejemplo n.º 19
0
        public void TestGetEqualizerRedLight()
        {
            Mpg123 mpg123 = new Mpg123();

            mpg123.Eq(Mpg123.Channels.LR, 20, 30);
            double value = 20;

            Assert.That(mpg123.GetEq(Mpg123.Channels.LR, 20), Is.Not.EqualTo(value));
        }
Ejemplo n.º 20
0
        public void TestTellStreamIsNegative()
        {
            string decoder = Mpg123.Decoders.ToArray().FirstOrDefault();
            Mpg123 mpg123  = new Mpg123();

            long seekPositon = mpg123.TellStream();

            Assert.That(seekPositon, Is.EqualTo(-1));
        }
Ejemplo n.º 21
0
        public void TestTellIsZero()
        {
            string decoder = Mpg123.Decoders.ToArray().FirstOrDefault();
            Mpg123 mpg123  = new Mpg123();

            long seekPositon = mpg123.Tell();

            Assert.That(seekPositon, Is.Zero);
        }
Ejemplo n.º 22
0
        public void TestGetEqualizer()
        {
            Mpg123 mpg123 = new Mpg123();

            mpg123.Eq(Mpg123.Channels.LR, 20, 20);
            double aspectedValue = 20;

            Assert.That(mpg123.GetEq(Mpg123.Channels.LR, 20), Is.EqualTo(aspectedValue));
        }
Ejemplo n.º 23
0
        public void TestFeed()
        {
            Mpg123 mpg123 = new Mpg123();

            mpg123.OpenFeed();

            byte[] buffer = new byte[8];

            Assert.That(() => mpg123.Feed(buffer), Throws.Nothing);
        }
Ejemplo n.º 24
0
        public void TestSetDecoder()
        {
            Mpg123 mpg123 = new Mpg123();

            string decoder = Mpg123.Decoders.ToArray()[0];

            mpg123.Decoder = decoder;

            Assert.That(mpg123.Decoder, Is.EqualTo(decoder));
        }
Ejemplo n.º 25
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>());
        }
Ejemplo n.º 26
0
        public void TestDecodeNullInputAndOutput()
        {
            Mpg123 mpg123 = new Mpg123();

            mpg123.OpenFeed();

            uint done = 0;

            Assert.That(() => mpg123.Decode(null, 0, null, 0, ref done), Throws.Nothing);
        }
Ejemplo n.º 27
0
        public void TestOpenFeedOpen()
        {
            Mpg123 mpg123  = new Mpg123();
            string dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string path    = Path.Combine(dirName, "bensound-epic.mp3");

            mpg123.Open(path);

            Assert.That(() => mpg123.OpenFeed(), Throws.Nothing);
        }
Ejemplo n.º 28
0
        public void TestDecodeInconsistentOutputSizeMinor()
        {
            Mpg123 mpg123 = new Mpg123();

            mpg123.OpenFeed();

            byte[] outBuffer = new byte[100];
            uint   done      = 0;

            Assert.That(() => mpg123.Decode(null, 0, outBuffer, 50, ref done), Throws.Nothing);
        }
Ejemplo n.º 29
0
        public void TestDecodeInconsistentOutputSizeMajor()
        {
            Mpg123 mpg123 = new Mpg123();

            mpg123.OpenFeed();

            byte[] outBuffer = new byte[100];
            uint   done      = 0;

            Assert.That(() => mpg123.Decode(null, 0, outBuffer, 300, ref done), Throws.TypeOf <ArgumentOutOfRangeException>());
        }
Ejemplo n.º 30
0
        public void TestFeature()
        {
            string dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string path    = dirName + "/bensound-epic.mp3";

            Mpg123 mpg123 = new Mpg123();

            mpg123.Open(path);

            Assert.That(() => mpg123.Feature(Mpg123.Mpg123FeatureSet.MPG123_FEATURE_EQUALIZER), Throws.Nothing);
        }