Exemplo n.º 1
0
        /*
         * same as hip_decode1 (look in lame.h), but returns unclipped raw
         * floating-point samples. It is declared here, not in lame.h, because it
         * returns LAME's internal type sample_t. No more than 1152 samples per
         * channel are allowed.
         */

        internal virtual int hip_decode1_unclipped(
            mpstr_tag hip,
            byte[] buffer,
            int bufferPos,
            int len,
            float[] pcm_l,
            float[] pcm_r)
        {
            var mp3data = new MP3Data();
            var enc     = new Enc();

            if (hip != null)
            {
                IDecoder dec  = new IDecoderAnonymousInnerClass(this, bufferPos);
                var      @out = new float?[OUTSIZE_UNCLIPPED];
                Decode.Factory <float?> tFactory = new FactoryAnonymousInnerClass(this);

                // XXX should we avoid the primitive type version?
                var pcmL = new float?[pcm_l.Length];
                for (var i = 0; i < pcmL.Length; i++)
                {
                    pcmL[i] = Convert.ToSingle(pcm_l[i]);
                }

                var pcmR = new float?[pcm_r.Length];
                for (var i = 0; i < pcmR.Length; i++)
                {
                    pcmR[i] = Convert.ToSingle(pcm_r[i]);
                }

                var decode1_headersB_clipchoice = this.decode1_headersB_clipchoice(
                    hip,
                    buffer,
                    bufferPos,
                    len,
                    pcmL,
                    0,
                    pcmR,
                    0,
                    mp3data,
                    enc,
                    @out,
                    OUTSIZE_UNCLIPPED,
                    dec,
                    tFactory);
                for (var i = 0; i < pcmL.Length; i++)
                {
                    pcm_l[i] = pcmL[i].Value;
                }

                for (var i = 0; i < pcmR.Length; i++)
                {
                    pcm_r[i] = pcmR[i].Value;
                }

                return(decode1_headersB_clipchoice);
            }

            return(0);
        }
Exemplo n.º 2
0
        internal virtual int hip_decode1_headersB(
            mpstr_tag hip,
            byte[] buffer,
            int len,
            short[] pcm_l,
            short[] pcm_r,
            MP3Data mp3data,
            Enc enc)
        {
            if (hip != null)
            {
                IDecoder dec  = new IDecoderAnonymousInnerClass2(this);
                var      @out = new short?[OUTSIZE_CLIPPED];
                Decode.Factory <short?> tFactory = new FactoryAnonymousInnerClass2(this);

                // XXX should we avoid the primitive type version?
                var pcmL = new short?[pcm_l.Length];
                for (var i = 0; i < pcmL.Length; i++)
                {
                    pcmL[i] = Convert.ToInt16(pcm_l[i]);
                }

                var pcmR = new short?[pcm_r.Length];
                for (var i = 0; i < pcmR.Length; i++)
                {
                    pcmR[i] = Convert.ToInt16(pcm_r[i]);
                }

                var decode1_headersB_clipchoice = this.decode1_headersB_clipchoice(
                    hip,
                    buffer,
                    0,
                    len,
                    pcmL,
                    0,
                    pcmR,
                    0,
                    mp3data,
                    enc,
                    @out,
                    OUTSIZE_CLIPPED,
                    dec,
                    tFactory);
                for (var i = 0; i < pcmL.Length; i++)
                {
                    pcm_l[i] = pcmL[i].Value;
                }

                for (var i = 0; i < pcmR.Length; i++)
                {
                    pcm_r[i] = pcmR[i].Value;
                }

                return(decode1_headersB_clipchoice);
            }

            return(-1);
        }
Exemplo n.º 3
0
        /*
         * For lame_decode:  return code
         *  -1     error
         *   0     ok, but need more data before outputing any samples
         *   n     number of samples output.  Will be at most one frame of
         *         MPEG data.
         */
        internal virtual int hip_decode1_headers(
            mpstr_tag hip,
            byte[] buffer,
            int len,
            short[] pcm_l,
            short[] pcm_r,
            MP3Data mp3data)
        {
            var enc = new Enc();

            return(hip_decode1_headersB(hip, buffer, len, pcm_l, pcm_r, mp3data, enc));
        }
Exemplo n.º 4
0
        /*
         * same as hip_decode1 (look in lame.h), but returns unclipped raw
         * floating-point samples. It is declared here, not in lame.h, because it
         * returns LAME's internal type sample_t. No more than 1152 samples per
         * channel are allowed.
         */

        internal virtual int hip_decode1_unclipped(
            mpstr_tag hip,
            byte[] buffer,
            int bufferPos,
            int len,
            float[] pcm_l,
            float[] pcm_r)
        {
            var mp3data = new MP3Data();
            var enc     = new Enc();

            if (hip != null)
            {
                IDecoder dec  = new IDecoderAnonymousInnerClass(this, bufferPos);
                var      @out = new float[OUTSIZE_UNCLIPPED];
                Decode.Factory <float> tFactory = new FactoryAnonymousInnerClass(this);

                var decode1_headersB_clipchoice = this.decode1_headersB_clipchoice(
                    hip,
                    buffer,
                    bufferPos,
                    len,
                    pcm_l,
                    0,
                    pcm_r,
                    0,
                    mp3data,
                    enc,
                    @out,
                    OUTSIZE_UNCLIPPED,
                    dec,
                    tFactory,
                    false);

                return(decode1_headersB_clipchoice);
            }

            return(0);
        }
Exemplo n.º 5
0
        internal virtual int hip_decode1_headersB(
            mpstr_tag hip,
            byte[] buffer,
            int len,
            short[] pcm_l,
            short[] pcm_r,
            MP3Data mp3data,
            Enc enc,
            bool seek)
        {
            if (hip != null)
            {
                IDecoder dec  = new IDecoderAnonymousInnerClass2(this);
                var      @out = seek ? null : new short[OUTSIZE_CLIPPED];
                Decode.Factory <short> tFactory = new FactoryAnonymousInnerClass2(this);

                var decode1_headersB_clipchoice = this.decode1_headersB_clipchoice(
                    hip,
                    buffer,
                    0,
                    len,
                    pcm_l,
                    0,
                    pcm_r,
                    0,
                    mp3data,
                    enc,
                    @out,
                    OUTSIZE_CLIPPED,
                    dec,
                    tFactory,
                    seek);

                return(decode1_headersB_clipchoice);
            }

            return(-1);
        }
Exemplo n.º 6
0
        /*
         * For lame_decode:  return code
         * -1     error
         *  0     ok, but need more data before outputing any samples
         *  n     number of samples output.  either 576 or 1152 depending on MP3 file.
         */

        private int decode1_headersB_clipchoice <T>(
            mpstr_tag pmp,
            byte[] buffer,
            int bufferPos,
            int len,
            T[] pcm_l,
            int pcm_lPos,
            T[] pcm_r,
            int pcm_rPos,
            MP3Data mp3data,
            Enc enc,
            T[] p,
            int psize,
            IDecoder decodeMP3_ptr,
            Decode.Factory <T> tFactory)
        {
            int processed_samples; // processed samples per channel
            int ret;

            mp3data.header_parsed = false;

            var pb = new ProcessedBytes();

            ret = decodeMP3_ptr.decode(pmp, buffer, bufferPos, len, p, psize, pb, tFactory);
            processed_samples = pb.pb;

            /* three cases:
             * 1. headers parsed, but data not complete
             *       pmp.header_parsed==1
             *       pmp.framesize=0
             *       pmp.fsizeold=size of last frame, or 0 if this is first frame
             *
             * 2. headers, data parsed, but ancillary data not complete
             *       pmp.header_parsed==1
             *       pmp.framesize=size of frame
             *       pmp.fsizeold=size of last frame, or 0 if this is first frame
             *
             * 3. frame fully decoded:
             *       pmp.header_parsed==0
             *       pmp.framesize=0
             *       pmp.fsizeold=size of frame (which is now the last frame)
             *
             */
            if (pmp.header_parsed || pmp.fsizeold > 0 || pmp.framesize > 0)
            {
                mp3data.header_parsed = true;
                mp3data.stereo        = pmp.fr.stereo;
                mp3data.samplerate    = Common.freqs[pmp.fr.sampling_frequency];
                mp3data.mode          = pmp.fr.mode;
                mp3data.mode_ext      = pmp.fr.mode_ext;
                mp3data.framesize     = smpls[pmp.fr.lsf][pmp.fr.lay];

                /* free format, we need the entire frame before we can determine
                 * the bitrate.  If we haven't gotten the entire frame, bitrate=0 */
                if (pmp.fsizeold > 0) // works for free format and fixed, no overrun, temporal results are < 400.e6
                {
                    mp3data.bitrate =
                        (int)(8 * (4 + pmp.fsizeold) * mp3data.samplerate / (1000 * mp3data.framesize) + 0.5);
                }
                else if (pmp.framesize > 0)
                {
                    mp3data.bitrate =
                        (int)(8 * (4 + pmp.framesize) * mp3data.samplerate / (1000 * mp3data.framesize) + 0.5);
                }
                else
                {
                    mp3data.bitrate = Common.tabsel_123[pmp.fr.lsf][pmp.fr.lay - 1][pmp.fr.bitrate_index];
                }

                if (pmp.num_frames > 0)
                {
                    /* Xing VBR header found and num_frames was set */
                    mp3data.totalframes = pmp.num_frames;
                    mp3data.nsamp       = mp3data.framesize * pmp.num_frames;
                    enc.enc_delay       = pmp.enc_delay;
                    enc.enc_padding     = pmp.enc_padding;
                }
            }

            switch (ret)
            {
            case MP3_OK:
                switch (pmp.fr.stereo)
                {
                case 1:
                    COPY_MONO(pcm_l, pcm_lPos, processed_samples, p);
                    break;

                case 2:
                    processed_samples = processed_samples >> 1;
                    COPY_STEREO(pcm_l, pcm_lPos, pcm_r, pcm_rPos, processed_samples, p);
                    break;

                default:
                    processed_samples = -1;
                    Debug.Assert(false);
                    break;
                }

                break;

            case MP3_NEED_MORE:
                processed_samples = 0;
                break;

            case MP3_ERR:
                processed_samples = -1;
                break;

            default:
                processed_samples = -1;
                Debug.Assert(false);
                break;
            }

            /*fprintf(stderr,"ok, more, err:  %i %i %i\n", MP3_OK, MP3_NEED_MORE, MP3_ERR ); */
            /*fprintf(stderr,"ret = %i out=%i\n", ret, processed_samples ); */
            return(processed_samples);
        }