CSPspEmu.Hle.Modules.sc_sascore.sceSasCore.__sceSasCore_Internal C# (CSharp) Метод

__sceSasCore_Internal() публичный Метод

public __sceSasCore_Internal ( SasCore SasCore, short SasOut, short SasIn, int LeftVolume, int RightVolume ) : int
SasCore SasCore
SasOut short
SasIn short
LeftVolume int
RightVolume int
Результат int
        public int __sceSasCore_Internal(SasCore SasCore, short* SasOut, short* SasIn, int LeftVolume, int RightVolume)
        {
            fixed (StereoShortSoundSample* BufferShortPtr = BufferShort)
            fixed (StereoIntSoundSample* BufferTempPtr = BufferTemp)
            {
                if (SasCore.OutputMode != OutputMode.PSP_SAS_OUTPUTMODE_STEREO)
                {
                    Logger.Unimplemented("SasCore.OutputMode != OutputMode.PSP_SAS_OUTPUTMODE_STEREO");
                }

                int NumberOfChannels = (SasCore.OutputMode == OutputMode.PSP_SAS_OUTPUTMODE_STEREO) ? 2 : 1;
                int NumberOfSamples = SasCore.GrainSamples;
                int NumberOfVoicesPlaying = Math.Max(1, SasCore.Voices.Count(Voice => Voice.OnAndPlaying));

                for (int n = 0; n < NumberOfSamples; n++) BufferTempPtr[n] = default(StereoIntSoundSample);

                int PrevPosDiv = -1;
                foreach (var Voice in SasCore.Voices)
                {
                    if (Voice.OnAndPlaying)
                    {
                        //Console.WriteLine("Voice.Pitch: {0}", Voice.Pitch);
                        //for (int n = 0, Pos = 0; n < NumberOfSamples; n++, Pos += Voice.Pitch)
                        int Pos = 0;
                        while (true)
                        {
                            if ((Voice.Vag != null) && (Voice.Vag.HasMore))
                            {
                                int PosDiv = Pos / Voice.Pitch;

                                if (PosDiv >= NumberOfSamples) break;

                                var Sample = Voice.Vag.GetNextSample().ApplyVolumes(Voice.LeftVolume, Voice.RightVolume);

                                for (int m = PrevPosDiv + 1; m <= PosDiv; m++) BufferTempPtr[m] += Sample;

                                PrevPosDiv = PosDiv;
                                Pos += PSP_SAS_PITCH_BASE;
                            }
                            else
                            {
                                Voice.SetPlaying(false);
                                break;
                            }
                        }
                    }
                }

                for (int n = 0; n < NumberOfSamples; n++) BufferShortPtr[n] = BufferTempPtr[n];

                for (int channel = 0; channel < NumberOfChannels; channel++)
                {
                    for (int n = 0; n < NumberOfSamples; n++)
                    {
                        SasOut[n * NumberOfChannels + channel] = BufferShortPtr[n].ApplyVolumes(LeftVolume, RightVolume).GetByIndex(channel);
                    }
                }
            }

            //throw(new NotImplementedException());
            return 0;
        }