コード例 #1
0
ファイル: VoiceContext.cs プロジェクト: simontime/Ryujinx
        private void UpdateBuffer(AMemory Memory)
        {
            //TODO: Implement conversion for formats other
            //than interleaved stereo (2 channels).
            //As of now, it assumes that HostChannelsCount == 2.
            WaveBuffer Wb = WaveBuffers[BufferIndex];

            if (SampleFormat == SampleFormat.PcmInt16)
            {
                int SamplesCount = (int)(Wb.Size / (sizeof(short) * ChannelsCount));

                Samples = new int[SamplesCount * AudioConsts.HostChannelsCount];

                if (ChannelsCount == 1)
                {
                    for (int Index = 0; Index < SamplesCount; Index++)
                    {
                        short Sample = Memory.ReadInt16(Wb.Position + Index * 2);

                        Samples[Index * 2 + 0] = Sample;
                        Samples[Index * 2 + 1] = Sample;
                    }
                }
                else
                {
                    for (int Index = 0; Index < SamplesCount * 2; Index++)
                    {
                        Samples[Index] = Memory.ReadInt16(Wb.Position + Index * 2);
                    }
                }
            }
            else if (SampleFormat == SampleFormat.Adpcm)
            {
                byte[] Buffer = Memory.ReadBytes(Wb.Position, Wb.Size);

                Samples = AdpcmDecoder.Decode(Buffer, AdpcmCtx);
            }
            else
            {
                throw new InvalidOperationException();
            }

            if (SampleRate != AudioConsts.HostSampleRate)
            {
                //TODO: We should keep the frames being discarded (see the 4 below)
                //on a buffer and include it on the next samples buffer, to allow
                //the resampler to do seamless interpolation between wave buffers.
                int SamplesCount = Samples.Length / AudioConsts.HostChannelsCount;

                SamplesCount = Math.Max(SamplesCount - 4, 0);

                Samples = Resampler.Resample2Ch(
                    Samples,
                    SampleRate,
                    AudioConsts.HostSampleRate,
                    SamplesCount,
                    ref ResamplerFracPart);
            }
        }
コード例 #2
0
        private ElfSym GetSymbol(long Position, long StrTblAddr)
        {
            int  NameIndex = Memory.ReadInt32(Position + 0);
            int  Info      = Memory.ReadByte(Position + 4);
            int  Other     = Memory.ReadByte(Position + 5);
            int  SHIdx     = Memory.ReadInt16(Position + 6);
            long Value     = Memory.ReadInt64(Position + 8);
            long Size      = Memory.ReadInt64(Position + 16);

            string Name = string.Empty;

            for (int Chr; (Chr = Memory.ReadByte(StrTblAddr + NameIndex++)) != 0;)
            {
                Name += (char)Chr;
            }

            return(new ElfSym(Name, Info, Other, SHIdx, Value, Size));
        }
コード例 #3
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);
        }