예제 #1
0
        internal virtual int synth_1to1_mono <T>(
            MPGLib.mpstr_tag mp,
            float[] bandPtr,
            int bandPos,
            T[] @out,
            MPGLib.ProcessedBytes pnt,
            Factory <T> tFactory)
        {
            //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:

            var samples_tmp = new T[64];
            var tmp1 = 0;
            int i, ret;
            var pnt1 = new MPGLib.ProcessedBytes();

            ret = synth_1to1(mp, bandPtr, bandPos, 0, samples_tmp, pnt1, tFactory);
            var outPos = pnt.pb;

            for (i = 0; i < 32; i++)
            {
                @out[outPos++] = samples_tmp[tmp1];
                tmp1          += 2;
            }

            pnt.pb += 32;

            return(ret);
        }
예제 #2
0
        private int lame_decode_fromfile(FileStream fd, short[] pcm_l, short[] pcm_r, MP3Data mp3data)
        {
            var ret = 0;
            var len = 0;
            var buf = new byte[1024];

            ret = -1;
            ret = mpg.hip_decode1_headers(hip, buf, len, pcm_l, pcm_r, mp3data);
            if (ret != 0)
            {
                return(ret);
            }

            while (true)
            {
                try
                {
                    len = fd.Read(buf, 0, buf.Length);
                }
                catch (IOException e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                    return(-1);
                }

                if (len <= 0)
                {
                    ret = mpg.hip_decode1_headers(hip, buf, 0, pcm_l, pcm_r, mp3data);
                    if (ret <= 0)
                    {
                        mpg.hip_decode_exit(hip);
                        hip = null;
                        return(-1);
                    }

                    break;
                }

                ret = mpg.hip_decode1_headers(hip, buf, len, pcm_l, pcm_r, mp3data);
                if (ret == -1)
                {
                    mpg.hip_decode_exit(hip);
                    hip = null;
                    return(-1);
                }

                if (ret > 0)
                {
                    break;
                }
            }

            return(ret);
        }
예제 #3
0
        private int lame_decode_fromfile(Stream fd, short[] pcm_l, short[] pcm_r, MP3Data mp3data, bool seek)
        {
            var ret = 0;
            var len = 0;
            var buf = new byte[1024];

            ret = -1;
            ret = mpg.hip_decode1_headers(hip, buf, len, pcm_l, pcm_r, mp3data, seek);
            if (ret != 0)
            {
                return(ret);
            }

            while (true)
            {
                try
                {
                    len = fd.Read(buf, 0, buf.Length);
                }
                catch (IOException e)
                {
                    return(-1);
                }

                if (len <= 0)
                {
                    ret = mpg.hip_decode1_headers(hip, buf, 0, pcm_l, pcm_r, mp3data, seek);
                    if (ret <= 0)
                    {
                        mpg.hip_decode_exit(hip);
                        hip = null;
                        return(-1);
                    }

                    break;
                }

                ret = mpg.hip_decode1_headers(hip, buf, len, pcm_l, pcm_r, mp3data, seek);
                if (ret == -1)
                {
                    mpg.hip_decode_exit(hip);
                    hip = null;
                    return(-1);
                }

                if (ret > 0)
                {
                    break;
                }
            }

            return(ret);
        }
예제 #4
0
        private int lame_decode_initfile(Stream fd, MP3Data mp3data, Enc enc)
        {
            var buf        = new byte[100];
            var pcm_l      = new short[1152];
            var pcm_r      = new short[1152];
            var freeformat = false;

            if (hip != null)
            {
                mpg.hip_decode_exit(hip);
            }

            hip = mpg.hip_decode_init();
            var len = 4;

            if (fd.Position + len > fd.Length)
            {
                return(-1);
            }

            fd.Read(buf, 0, len);

            if (buf[0] == (sbyte)'I' && buf[1] == (sbyte)'D' && buf[2] == (sbyte)'3')
            {
                len = 6;
                try
                {
                    fd.Read(buf, 0, len);
                }
                catch (IOException e)
                {
                    return(-1);
                }

                buf[2] &= 127;
                buf[3] &= 127;
                buf[4] &= 127;
                buf[5] &= 127;
                len     = (((((buf[2] << 7) + buf[3]) << 7) + buf[4]) << 7) + buf[5];
                try
                {
                    fd.Seek(len, SeekOrigin.Current);
                }
                catch (IOException e)
                {
                    return(-1);
                }

                len = 4;
                try
                {
                    fd.Read(buf, 0, len);
                }
                catch (IOException e)
                {
                    return(-1);
                }
            }

            if (check_aid(buf))
            {
                try
                {
                    fd.Read(buf, 0, 2);
                }
                catch (IOException e)
                {
                    return(-1);
                }

                var aid_header = (buf[0] & 0xff) + 256 * (buf[1] & 0xff);

                try
                {
                    fd.Seek(aid_header - 6, SeekOrigin.Current);
                }
                catch (IOException e)
                {
                    return(-1);
                }

                try
                {
                    fd.Read(buf, 0, len);
                }
                catch (IOException e)
                {
                    return(-1);
                }
            }

            len = 4;
            while (!is_syncword_mp123(buf))
            {
                int i;
                for (i = 0; i < len - 1; i++)
                {
                    buf[i] = buf[i + 1];
                }

                try
                {
                    fd.Read(buf, len - 1, 1);
                }
                catch (IOException e)
                {
                    return(-1);
                }
            }

            if ((buf[2] & 0xf0) == 0)
            {
                freeformat = true;
            }

            var ret = mpg.hip_decode1_headersB(hip, buf, len, pcm_l, pcm_r, mp3data, enc, false);

            if (-1 == ret)
            {
                return(-1);
            }

            while (!mp3data.header_parsed)
            {
                try
                {
                    fd.Read(buf, 0, buf.Length);
                }
                catch (IOException e)
                {
                    return(-1);
                }

                ret = mpg.hip_decode1_headersB(hip, buf, buf.Length, pcm_l, pcm_r, mp3data, enc, false);
                if (-1 == ret)
                {
                    return(-1);
                }
            }

            if (mp3data.bitrate == 0 && !freeformat)
            {
                return(lame_decode_initfile(fd, mp3data, enc));
            }

            if (mp3data.totalframes > 0)
            {
            }
            else
            {
                mp3data.nsamp = -1;
            }

            return(0);
        }
예제 #5
0
        private int lame_decode_initfile(FileStream fd, MP3Data mp3data, Enc enc)
        {
            var buf        = new byte[100];
            var pcm_l      = new short[1152];
            var pcm_r      = new short[1152];
            var freeformat = false;

            if (hip != null)
            {
                mpg.hip_decode_exit(hip);
            }

            hip = mpg.hip_decode_init();
            var len = 4;

            try
            {
                fd.Read(buf, 0, len);
            }
            catch (IOException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
                return(-1);
            }

            if (buf[0] == (sbyte)'I' && buf[1] == (sbyte)'D' && buf[2] == (sbyte)'3')
            {
                if (parse.silent < 10)
                {
                    Console.WriteLine(
                        "ID3v2 found. " + "Be aware that the ID3 tag is currently lost when transcoding.");
                }

                len = 6;
                try
                {
                    fd.Read(buf, 0, len);
                }
                catch (IOException e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                    return(-1);
                }

                buf[2] &= 127;
                buf[3] &= 127;
                buf[4] &= 127;
                buf[5] &= 127;
                len     = (((((buf[2] << 7) + buf[3]) << 7) + buf[4]) << 7) + buf[5];
                try
                {
                    fd.Seek(len, SeekOrigin.Current);
                }
                catch (IOException e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                    return(-1);
                }

                len = 4;
                try
                {
                    fd.Read(buf, 0, len);
                }
                catch (IOException e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                    return(-1);
                }
            }

            if (check_aid(buf))
            {
                try
                {
                    fd.Read(buf, 0, 2);
                }
                catch (IOException e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                    return(-1);
                }

                var aid_header = (buf[0] & 0xff) + 256 * (buf[1] & 0xff);
                if (parse.silent < 10)
                {
                    Console.Write("Album ID found.  length={0:D} \n", aid_header);
                }

                try
                {
                    fd.Seek(aid_header - 6, SeekOrigin.Current);
                }
                catch (IOException e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                    return(-1);
                }

                try
                {
                    fd.Read(buf, 0, len);
                }
                catch (IOException e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                    return(-1);
                }
            }

            len = 4;
            while (!is_syncword_mp123(buf))
            {
                int i;
                for (i = 0; i < len - 1; i++)
                {
                    buf[i] = buf[i + 1];
                }

                try
                {
                    fd.Read(buf, len - 1, 1);
                }
                catch (IOException e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                    return(-1);
                }
            }

            if ((buf[2] & 0xf0) == 0)
            {
                if (parse.silent < 10)
                {
                    Console.WriteLine("Input file is freeformat.");
                }

                freeformat = true;
            }

            var ret = mpg.hip_decode1_headersB(hip, buf, len, pcm_l, pcm_r, mp3data, enc);

            if (-1 == ret)
            {
                return(-1);
            }

            while (!mp3data.header_parsed)
            {
                try
                {
                    fd.Read(buf, 0, 1024);
                }
                catch (IOException e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                    return(-1);
                }

                ret = mpg.hip_decode1_headersB(hip, buf, buf.Length, pcm_l, pcm_r, mp3data, enc);
                if (-1 == ret)
                {
                    return(-1);
                }
            }

            if (mp3data.bitrate == 0 && !freeformat)
            {
                if (parse.silent < 10)
                {
                    Console.Error.WriteLine("fail to sync...");
                }

                return(lame_decode_initfile(fd, mp3data, enc));
            }

            if (mp3data.totalframes > 0)
            {
            }
            else
            {
                mp3data.nsamp = -1;
            }

            return(0);
        }
예제 #6
0
        internal virtual int synth_1to1_unclipped <T>(
            MPGLib.mpstr_tag mp,
            float[] bandPtr,
            int bandPos,
            int channel,
            T[] @out,
            MPGLib.ProcessedBytes pnt,
            Factory <T> tFactory)
        {
            int bo;
            var samples = pnt.pb;

            float[] b0;
            int     b0Pos;

            float[][] buf;
            var       clip = 0;
            int       bo1;

            bo = mp.synth_bo;

            if (0 == channel)
            {
                bo--;
                bo &= 0xf;
                buf = mp.synth_buffs[0];
            }
            else
            {
                samples++;
                buf = mp.synth_buffs[1];
            }

            if ((bo & 0x1) != 0)
            {
                b0    = buf[0];
                b0Pos = 0;
                bo1   = bo;
                dct64.dct64(buf[1], (bo + 1) & 0xf, buf[0], bo, bandPtr, bandPos);
            }
            else
            {
                b0    = buf[1];
                b0Pos = 0;
                bo1   = bo + 1;
                dct64.dct64(buf[0], bo, buf[1], bo + 1, bandPtr, bandPos);
            }

            mp.synth_bo = bo;

            {
                int j;
                var window = 16 - bo1;

                for (j = 16; j != 0; j--, b0Pos += 0x10, window += 0x20, samples += step)
                {
                    float sum;
                    sum  = tab.decwin[window + 0x0] * b0[b0Pos + 0x0];
                    sum -= tab.decwin[window + 0x1] * b0[b0Pos + 0x1];
                    sum += tab.decwin[window + 0x2] * b0[b0Pos + 0x2];
                    sum -= tab.decwin[window + 0x3] * b0[b0Pos + 0x3];
                    sum += tab.decwin[window + 0x4] * b0[b0Pos + 0x4];
                    sum -= tab.decwin[window + 0x5] * b0[b0Pos + 0x5];
                    sum += tab.decwin[window + 0x6] * b0[b0Pos + 0x6];
                    sum -= tab.decwin[window + 0x7] * b0[b0Pos + 0x7];
                    sum += tab.decwin[window + 0x8] * b0[b0Pos + 0x8];
                    sum -= tab.decwin[window + 0x9] * b0[b0Pos + 0x9];
                    sum += tab.decwin[window + 0xA] * b0[b0Pos + 0xA];
                    sum -= tab.decwin[window + 0xB] * b0[b0Pos + 0xB];
                    sum += tab.decwin[window + 0xC] * b0[b0Pos + 0xC];
                    sum -= tab.decwin[window + 0xD] * b0[b0Pos + 0xD];
                    sum += tab.decwin[window + 0xE] * b0[b0Pos + 0xE];
                    sum -= tab.decwin[window + 0xF] * b0[b0Pos + 0xF];
                    WRITE_SAMPLE_UNCLIPPED(samples, sum, clip, @out, tFactory);
                }

                {
                    float sum;
                    sum  = tab.decwin[window + 0x0] * b0[b0Pos + 0x0];
                    sum += tab.decwin[window + 0x2] * b0[b0Pos + 0x2];
                    sum += tab.decwin[window + 0x4] * b0[b0Pos + 0x4];
                    sum += tab.decwin[window + 0x6] * b0[b0Pos + 0x6];
                    sum += tab.decwin[window + 0x8] * b0[b0Pos + 0x8];
                    sum += tab.decwin[window + 0xA] * b0[b0Pos + 0xA];
                    sum += tab.decwin[window + 0xC] * b0[b0Pos + 0xC];
                    sum += tab.decwin[window + 0xE] * b0[b0Pos + 0xE];
                    WRITE_SAMPLE_UNCLIPPED(samples, sum, clip, @out, tFactory);
                    b0Pos   -= 0x10;
                    window  -= 0x20;
                    samples += step;
                }
                window += bo1 << 1;

                for (j = 15; j != 0; j--, b0Pos -= 0x10, window -= 0x20, samples += step)
                {
                    float sum;
                    sum  = -tab.decwin[window + -0x1] * b0[b0Pos + 0x0];
                    sum -= tab.decwin[window + -0x2] * b0[b0Pos + 0x1];
                    sum -= tab.decwin[window + -0x3] * b0[b0Pos + 0x2];
                    sum -= tab.decwin[window + -0x4] * b0[b0Pos + 0x3];
                    sum -= tab.decwin[window + -0x5] * b0[b0Pos + 0x4];
                    sum -= tab.decwin[window + -0x6] * b0[b0Pos + 0x5];
                    sum -= tab.decwin[window + -0x7] * b0[b0Pos + 0x6];
                    sum -= tab.decwin[window + -0x8] * b0[b0Pos + 0x7];
                    sum -= tab.decwin[window + -0x9] * b0[b0Pos + 0x8];
                    sum -= tab.decwin[window + -0xA] * b0[b0Pos + 0x9];
                    sum -= tab.decwin[window + -0xB] * b0[b0Pos + 0xA];
                    sum -= tab.decwin[window + -0xC] * b0[b0Pos + 0xB];
                    sum -= tab.decwin[window + -0xD] * b0[b0Pos + 0xC];
                    sum -= tab.decwin[window + -0xE] * b0[b0Pos + 0xD];
                    sum -= tab.decwin[window + -0xF] * b0[b0Pos + 0xE];
                    sum -= tab.decwin[window + -0x0] * b0[b0Pos + 0xF];

                    WRITE_SAMPLE_UNCLIPPED(samples, sum, clip, @out, tFactory);
                }
            }
            pnt.pb += 64;

            return(clip);
        }