コード例 #1
0
ファイル: IAudioRenderer.cs プロジェクト: cin619/Ryujinx
        private AdpcmDecoderContext GetAdpcmDecoderContext(long Position, long Size)
        {
            if (Size == 0)
            {
                return(null);
            }

            AdpcmDecoderContext Context = new AdpcmDecoderContext();

            Context.Coefficients = new short[Size >> 1];

            for (int Offset = 0; Offset < Size; Offset += 2)
            {
                Context.Coefficients[Offset >> 1] = Memory.ReadInt16(Position + Offset);
            }

            return(Context);
        }
コード例 #2
0
ファイル: IAudioRenderer.cs プロジェクト: reuniware/Ryujinx
        private AdpcmDecoderContext GetAdpcmDecoderContext(long position, long size)
        {
            if (size == 0)
            {
                return(null);
            }

            AdpcmDecoderContext context = new AdpcmDecoderContext();

            context.Coefficients = new short[size >> 1];

            for (int offset = 0; offset < size; offset += 2)
            {
                context.Coefficients[offset >> 1] = _memory.ReadInt16(position + offset);
            }

            return(context);
        }
コード例 #3
0
ファイル: AdpcmDecoder.cs プロジェクト: zpoo32/Ryujinx
        public static int[] Decode(byte[] Buffer, AdpcmDecoderContext Context)
        {
            int Samples = GetSamplesCountFromSize(Buffer.Length);

            int[] Pcm = new int[Samples * 2];

            short History0 = Context.History0;
            short History1 = Context.History1;

            int InputOffset  = 0;
            int OutputOffset = 0;

            while (InputOffset < Buffer.Length)
            {
                byte Header = Buffer[InputOffset++];

                int Scale = 0x800 << (Header & 0xf);

                int CoeffIndex = (Header >> 4) & 7;

                short Coeff0 = Context.Coefficients[CoeffIndex * 2 + 0];
                short Coeff1 = Context.Coefficients[CoeffIndex * 2 + 1];

                int FrameSamples = SamplesPerFrame;

                if (FrameSamples > Samples)
                {
                    FrameSamples = Samples;
                }

                int Value = 0;

                for (int SampleIndex = 0; SampleIndex < FrameSamples; SampleIndex++)
                {
                    int Sample;

                    if ((SampleIndex & 1) == 0)
                    {
                        Value = Buffer[InputOffset++];

                        Sample = (Value << 24) >> 28;
                    }
                    else
                    {
                        Sample = (Value << 28) >> 28;
                    }

                    int Prediction = Coeff0 * History0 + Coeff1 * History1;

                    Sample = (Sample * Scale + Prediction + 0x400) >> 11;

                    short SaturatedSample = DspUtils.Saturate(Sample);

                    History1 = History0;
                    History0 = SaturatedSample;

                    Pcm[OutputOffset++] = SaturatedSample;
                    Pcm[OutputOffset++] = SaturatedSample;
                }

                Samples -= FrameSamples;
            }

            Context.History0 = History0;
            Context.History1 = History1;

            return(Pcm);
        }