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

            Assert.That(mpg123.HasValidHandle, Is.True);
        }
Esempio 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>());
        }
Esempio n. 4
0
        public void TestResetEqualizerRedLight()
        {
            Mpg123 mpg123 = new Mpg123();

            mpg123.Dispose();
            Assert.That(() => mpg123.ResetEq(), Throws.TypeOf <Mpg123.ErrorException>());
        }
Esempio 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>());
        }
Esempio n. 6
0
        public void TestOpenPathInvalid()
        {
            string path   = "test.mp3";
            Mpg123 mpg123 = new Mpg123();

            Assert.That(() => mpg123.Open(path), Throws.TypeOf <Mpg123.ErrorException>());
        }
Esempio 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);
        }
Esempio 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();
            }
        }
Esempio 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>());
        }
Esempio 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));
        }
Esempio 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));
        }
Esempio 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);
        }
Esempio 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);
        }
Esempio n. 15
0
        public void TestGetDecoder()
        {
            string decoder = Mpg123.Decoders.ToArray()[0];

            Mpg123 mpg123 = new Mpg123(decoder);

            Assert.That(mpg123.Decoder, Is.EqualTo(decoder));
        }
Esempio 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>());
        }
Esempio n. 17
0
        public void TestTellFrameIsZero()
        {
            Mpg123 mpg123 = new Mpg123(Mpg123.Decoders.ToArray().FirstOrDefault());

            long seekPositon = mpg123.TellFrame();

            Assert.That(seekPositon, Is.Zero);
        }
Esempio 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));
        }
Esempio 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));
        }
Esempio 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));
        }
Esempio 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);
        }
Esempio 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));
        }
Esempio n. 23
0
        public void TestFeed()
        {
            Mpg123 mpg123 = new Mpg123();

            mpg123.OpenFeed();

            byte[] buffer = new byte[8];

            Assert.That(() => mpg123.Feed(buffer), Throws.Nothing);
        }
Esempio 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));
        }
Esempio 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>());
        }
Esempio 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);
        }
Esempio 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);
        }
Esempio 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);
        }
Esempio 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>());
        }
Esempio 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);
        }