示例#1
0
        public SasCore GetSasCore(uint SasCorePointer, bool CreateIfNotExists = false)
        {
            if ((SasCorePointer == 0) || (SasCorePointer % 64 != 0))
            {
                throw (new SceKernelException(SceKernelErrors.ERROR_SAS_INVALID_ADDRESS));
            }

            if (CreateIfNotExists)
            {
                if (!SasCoreList.ContainsKey(SasCorePointer))
                {
                    SasCoreList[SasCorePointer] = new SasCore();
                }
            }

            if (!SasCoreList.ContainsKey(SasCorePointer))
            {
                throw (new SceKernelException(SceKernelErrors.ERROR_SAS_NOT_INIT));
            }

            return(SasCoreList[SasCorePointer]);
        }
示例#2
0
		public SasCore GetSasCore(uint SasCorePointer, bool CreateIfNotExists = false)
		{
			if (SasCorePointer == 0)
			{
				throw (new SceKernelException(SceKernelErrors.ERROR_SAS_INVALID_PARAMETER));
			}

			if (CreateIfNotExists)
			{
				if (!SasCoreList.ContainsKey(SasCorePointer))
				{
					SasCoreList[SasCorePointer] = new SasCore();
				}
			}

			if (!SasCoreList.ContainsKey(SasCorePointer))
			{
				throw (new SceKernelException(SceKernelErrors.ERROR_SAS_NOT_INIT));
			}
	
			return SasCoreList[SasCorePointer];
		}
        /// <summary>
        ///
        /// </summary>
        /// <param name="SasCore"></param>
        /// <param name="SasOut"></param>
        /// <param name="SasIn"></param>
        /// <param name="LeftVolume"></param>
        /// <param name="RightVolume"></param>
        /// <returns></returns>
        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);
        }
示例#4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="SasCore"></param>
        /// <param name="SasOut"></param>
        /// <param name="SasIn"></param>
        /// <param name="LeftVolume"></param>
        /// <param name="RightVolume"></param>
        /// <returns></returns>
        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;
        }