コード例 #1
0
        private void copyStereoSamplesToMem(int[] mixedSamples, int addr, int samples, int leftVol, int rightVol, bool writeSamples)
        {
            // Adjust the volume according to the global volume settings
            leftVol  = Audio.getVolume(leftVol);
            rightVol = Audio.getVolume(rightVol);

            if (!writeSamples)
            {
                // If the samples have not been changed and the volume settings
                // would also not adjust the samples, no need to copy them back to memory.
                if (leftVol == MAX_VOLUME && rightVol == MAX_VOLUME)
                {
                    return;
                }
            }

            int           lengthInBytes = mixedSamples.Length << 1;
            IMemoryWriter memoryWriter  = MemoryWriter.getMemoryWriter(addr, lengthInBytes, 4);

            for (int i = 0, j = 0; i < samples; i++, j += 2)
            {
                short sampleLeft  = clampSample(mixedSamples[j]);
                short sampleRight = clampSample(mixedSamples[j + 1]);
                sampleLeft  = SoundChannel.adjustSample(sampleLeft, leftVol);
                sampleRight = SoundChannel.adjustSample(sampleRight, rightVol);
                int sampleStereo = getSampleStereo(sampleLeft, sampleRight);
                memoryWriter.writeNext(sampleStereo);
            }
            memoryWriter.flush();
        }
コード例 #2
0
        private void copyMonoSamplesToMem(int[] mixedSamples, int addr, int samples, int monoVol, bool writeSamples)
        {
            // Adjust the volume according to the global volume settings
            monoVol = Audio.getVolume(monoVol);

            if (!writeSamples)
            {
                // If the samples have not been changed and the volume settings
                // would also not adjust the samples, no need to copy them back to memory.
                if (monoVol == MAX_VOLUME)
                {
                    return;
                }
            }

            int           lengthInBytes = mixedSamples.Length << 1;
            IMemoryWriter memoryWriter  = MemoryWriter.getMemoryWriter(addr, lengthInBytes, 2);

            for (int i = 0, j = 0; i < samples; i++, j++)
            {
                short sampleMono = clampSample(mixedSamples[j]);
                sampleMono = SoundChannel.adjustSample(sampleMono, monoVol);
                memoryWriter.writeNext(sampleMono & 0xFFFF);
            }
            memoryWriter.flush();
        }
コード例 #3
0
        protected internal static int doAudioOutput(SoundChannel channel, int pvoid_buf)
        {
            int ret = -1;

            if (channel.Reserved)
            {
                //if (log.DebugEnabled)
                {
                    Console.WriteLine(string.Format("doAudioOutput({0}, 0x{1:X8})", channel.ToString(), pvoid_buf));
                }
                int     bytesPerSample = channel.FormatStereo ? 4 : 2;
                int     nbytes         = bytesPerSample * channel.SampleLength;
                sbyte[] data           = new sbyte[nbytes];

                IMemoryReader memoryReader = MemoryReader.getMemoryReader(pvoid_buf, nbytes, 2);
                if (channel.FormatMono)
                {
                    int volume = Audio.getVolume(channel.LeftVolume);
                    for (int i = 0; i < nbytes; i += 2)
                    {
                        short sample = (short)memoryReader.readNext();

                        sample = SoundChannel.adjustSample(sample, volume);

                        SoundChannel.storeSample(sample, data, i);
                    }
                }
                else
                {
                    int leftVolume  = Audio.getVolume(channel.LeftVolume);
                    int rightVolume = Audio.getVolume(channel.RightVolume);
                    for (int i = 0; i < nbytes; i += 4)
                    {
                        short lsample = (short)memoryReader.readNext();
                        short rsample = (short)memoryReader.readNext();

                        lsample = SoundChannel.adjustSample(lsample, leftVolume);
                        rsample = SoundChannel.adjustSample(rsample, rightVolume);

                        SoundChannel.storeSample(lsample, data, i);
                        SoundChannel.storeSample(rsample, data, i + 2);
                    }
                }
                Modules.sceAudioModule.audioData = data;
                channel.play(data);
                ret = channel.SampleLength;
            }
            else
            {
                Console.WriteLine("doAudioOutput: channel " + channel.Index + " not reserved");
            }
            return(ret);
        }