Пример #1
0
        public virtual void decode(MemoryStream sampleBuffer, bool playOriginal)
        {
            var iread = gaud.get_audio16(gfp, buffer);

            if (iread >= 0)
            {
                parse.mp3input_data.framenum += iread / parse.mp3input_data.framesize;
                wavsize += iread;

                for (var i = 0; i < iread; i++)
                {
                    if (playOriginal)
                    {
                        // We put mp3 data into the sample buffer here!
                        sampleBuffer.WriteByte(unchecked ((byte)(buffer[0][i] & 0xff)));
                        sampleBuffer.WriteByte(unchecked ((byte)(((buffer[0][i] & 0xffff) >> 8) & 0xff)));
                    }

                    if (gfp.num_channels == 2)
                    {
                        // gaud.write16BitsLowHigh(outf, buffer[1][i] & 0xffff);
                        // TODO two channels?
                    }
                }
            }
        }
Пример #2
0
        public virtual int decode(float[] sampleBuffer, int offset = 0, int offset2 = 0)
        {
            var iread = gaud.get_audio16(gfp, buffer); // TODO: Could I get float directly instead of using 16bit?

            if (iread >= 0)
            {
                parse.mp3input_data.framenum += iread / parse.mp3input_data.framesize;
                WavSize += iread;

                if (gfp.num_channels == 2)
                {
                    var max = iread;
                    if (max * 2 + offset + offset2 > sampleBuffer.Length)
                    {
                        max = (sampleBuffer.Length - offset - offset2) / 2;
                    }

                    var start = 0;
                    if (offset < 0)
                    {
                        start = Math.Abs(offset) / 2;
                    }

                    for (var i = start; i < max; i++)
                    {
                        sampleBuffer[i * 2 + offset + offset2]     = buffer[0][i] / 32768f;
                        sampleBuffer[i * 2 + 1 + offset + offset2] = buffer[1][i] / 32768f;
                    }
                }
                else
                {
                    var max = iread;
                    if (max + offset + offset2 > sampleBuffer.Length)
                    {
                        max = sampleBuffer.Length - offset - offset2;
                    }

                    var start = 0;
                    if (offset < 0)
                    {
                        start = Math.Abs(offset);
                    }

                    for (var i = start; i < max; i++)
                    {
                        sampleBuffer[i + offset + offset2] = buffer[0][i] / 32768f;
                    }
                }

                return(iread * gfp.num_channels);
            }

            return(-1);
        }