Esempio n. 1
0
        public Mp3Decoder(string mp3File)
        {
            // encoder modules
            lame  = new Lame();
            gaud  = new GetAudio();
            ga    = new GainAnalysis();
            bs    = new BitStream();
            p     = new Presets();
            qupvt = new QuantizePVT();
            qu    = new Quantize();
            vbr   = new VBRTag();
            ver   = new Mp3Version();
            id3   = new ID3Tag();
            rv    = new Reservoir();
            tak   = new Takehiro();
            parse = new Parse();

            mpg    = new MPGLib();
            intf   = new Interface();
            common = new Mpg.Common();

            lame.setModules(ga, bs, p, qupvt, qu, vbr, ver, id3, mpg);
            bs.setModules(ga, mpg, ver, vbr);
            id3.setModules(bs, ver);
            p.Modules = lame;
            qu.setModules(bs, rv, qupvt, tak);
            qupvt.setModules(tak, rv, lame.enc.psy);
            rv.Modules  = bs;
            tak.Modules = qupvt;
            vbr.setModules(lame, bs, ver);
            gaud.setModules(parse, mpg);
            parse.setModules(ver, id3, p);

            // decoder modules
            mpg.setModules(intf, common);
            intf.setModules(vbr, common);

            gfp = lame.lame_init();

            /*
             * turn off automatic writing of ID3 tag data into mp3 stream we have to
             * call it before 'lame_init_params', because that function would spit
             * out ID3v2 tag data.
             */
            gfp.write_id3tag_automatic = false;

            /*
             * Now that all the options are set, lame needs to analyze them and set
             * some more internal options and check for problems
             */
            lame.lame_init_params(gfp);

            parse.input_format = GetAudio.sound_file_format.sf_mp3;

            var inPath = new StringBuilder(mp3File);
            var enc    = new Enc();

            gaud.init_infile(gfp, inPath.ToString(), enc);

            var skip_start = 0;
            var skip_end   = 0;

            if (parse.silent < 10)
            {
                Console.Write(
                    "\rinput:  {0}{1}({2:g} kHz, {3:D} channel{4}, ",
                    inPath,
                    inPath.Length > 26 ? "\n\t" : "  ",
                    gfp.in_samplerate / 1000,
                    gfp.num_channels,
                    gfp.num_channels != 1 ? "s" : "");
            }

            if (enc.enc_delay > -1 || enc.enc_padding > -1)
            {
                if (enc.enc_delay > -1)
                {
                    skip_start = enc.enc_delay + 528 + 1;
                }

                if (enc.enc_padding > -1)
                {
                    skip_end = enc.enc_padding - (528 + 1);
                }
            }
            else
            {
                skip_start = gfp.encoder_delay + 528 + 1;
            }

            Console.Write("MPEG-{0:D}{1} Layer {2}", 2 - gfp.version, gfp.out_samplerate < 16000 ? ".5" : "", "III");

            Console.Write(")\noutput: (16 bit, Microsoft WAVE)\n");

            if (skip_start > 0)
            {
                Console.Write("skipping initial {0:D} samples (encoder+decoder delay)\n", skip_start);
            }

            if (skip_end > 0)
            {
                Console.Write("skipping final {0:D} samples (encoder padding-decoder delay)\n", skip_end);
            }

            wavsize = -(skip_start + skip_end);
            parse.mp3input_data.totalframes = parse.mp3input_data.nsamp / parse.mp3input_data.framesize;

            Debug.Assert(gfp.num_channels >= 1 && gfp.num_channels <= 2);
        }
Esempio n. 2
0
        public Mp3Decoder(Stream mp3Stream)
        {
            // encoder modules
            lame  = new Lame();
            gaud  = new GetAudio();
            ga    = new GainAnalysis();
            bs    = new BitStream();
            p     = new Presets();
            qupvt = new QuantizePVT();
            qu    = new Quantize();
            vbr   = new VBRTag();
            ver   = new Mp3Version();
            id3   = new ID3Tag();
            rv    = new Reservoir();
            tak   = new Takehiro();
            parse = new Parse();

            mpg    = new MPGLib();
            intf   = new Interface();
            common = new Mpg.Common();

            lame.setModules(ga, bs, p, qupvt, qu, vbr, ver, id3, mpg);
            bs.setModules(ga, mpg, ver, vbr);
            id3.setModules(bs, ver);
            p.Modules = lame;
            qu.setModules(bs, rv, qupvt, tak);
            qupvt.setModules(tak, rv, lame.enc.psy);
            rv.Modules  = bs;
            tak.Modules = qupvt;
            vbr.setModules(lame, bs, ver);
            gaud.setModules(parse, mpg);
            parse.setModules(ver, id3, p);

            // decoder modules
            mpg.setModules(intf, common);
            intf.setModules(vbr, common);

            gfp = lame.lame_init();

            /*
             * turn off automatic writing of ID3 tag data into mp3 stream we have to
             * call it before 'lame_init_params', because that function would spit
             * out ID3v2 tag data.
             */
            gfp.write_id3tag_automatic = false;

            /*
             * Now that all the options are set, lame needs to analyze them and set
             * some more internal options and check for problems
             */
            lame.lame_init_params(gfp);

            parse.input_format = GetAudio.sound_file_format.sf_mp3;

            var enc = new Enc();

            gaud.init_infile(gfp, mp3Stream, enc);

            SkipStart = 0;
            SkipEnd   = 0;

            if (enc.enc_delay > -1 || enc.enc_padding > -1)
            {
                if (enc.enc_delay > -1)
                {
                    SkipStart = enc.enc_delay + 528 + 1;
                }

                if (enc.enc_padding > -1)
                {
                    SkipEnd = enc.enc_padding - (528 + 1);
                }
            }
            else
            {
                SkipStart = gfp.encoder_delay + 528 + 1;
            }

            WavSize = -(SkipStart + SkipEnd);
            parse.mp3input_data.totalframes = parse.mp3input_data.nsamp / parse.mp3input_data.framesize;

            Framesize  = parse.mp3input_data.framesize;
            SampleRate = parse.mp3input_data.samplerate;
            Length     = parse.mp3input_data.nsamp;
            Channels   = gfp.num_channels;

            Debug.Assert(gfp.num_channels >= 1 && gfp.num_channels <= 2);
        }