Пример #1
0
        private void MixF32_Stereo_NoLoop(float[] buffer, int numSamples, float leftVol, float rightVol)
        {
            float interStep = _freq * SoundMixer.SampleRateReciprocal;
            int   bufPos    = 0;

            do
            {
                if (CheckPause && IsPaused)
                {
                    return;
                }

                Data.Stream.Position = _offset;
                float sampL = Data.Reader.ReadSingle();
                float sampR = Data.Reader.ReadSingle();

                _interPos += interStep;
                int posDelta = (int)_interPos;
                _interPos -= posDelta;
                posDelta  *= sizeof(float) * 2;
                _offset   += posDelta;

                buffer[bufPos]     += sampL * leftVol;
                buffer[bufPos + 1] += sampR * rightVol;

                if (_offset >= Data.DataEnd)
                {
                    SoundMixer.StopChannel(this);
                    return;
                }

                bufPos += 2;
            } while (--numSamples > 0);
        }
Пример #2
0
        private void MixS16_Mono_NoLoop(float[] buffer, int numSamples, float leftVol, float rightVol)
        {
            float interStep = _freq * SoundMixer.SampleRateReciprocal;
            int   bufPos    = 0;

            do
            {
                if (CheckPause && IsPaused)
                {
                    return;
                }

                Data.Stream.Position = _offset;
                int samp = Data.Reader.ReadInt16();

                _interPos += interStep;
                int posDelta = (int)_interPos;
                _interPos -= posDelta;
                posDelta  *= sizeof(short);
                _offset   += posDelta;

                buffer[bufPos]     += SoundMixer.S16ToF32(samp, leftVol);
                buffer[bufPos + 1] += SoundMixer.S16ToF32(samp, rightVol);

                if (_offset >= Data.DataEnd)
                {
                    SoundMixer.StopChannel(this);
                    return;
                }

                bufPos += 2;
            } while (--numSamples > 0);
        }
Пример #3
0
        private static void Task_FadeBattleBGMToOverworldBGM(BackTask task)
        {
            var data = (TaskData_Fade)task.Data;

            if (!data.Handle.IsFading)
            {
                SoundMixer.StopChannel(_battleBGM.Channel);
                _battleBGM = null;
                if (_overworldBGM is not null)
                {
                    // Create overworld bgm fade
                    _overworldBGM.Channel.BeginFade(1_000, 0f, 1f);
                    _overworldBGM.Channel.IsPaused = false;
                }
                _tasks.Remove(task);
            }
        }
Пример #4
0
        private void MixS16_Stereo_Loop(float[] buffer, int numSamples, float leftVol, float rightVol)
        {
            float interStep = _freq * SoundMixer.SampleRateReciprocal;
            int   bufPos    = 0;

            do
            {
                if (CheckPause && IsPaused)
                {
                    return;
                }

                Data.Stream.Position = _offset;
                int sampL = Data.Reader.ReadInt16();
                int sampR = Data.Reader.ReadInt16();

                _interPos += interStep;
                int posDelta = (int)_interPos;
                _interPos -= posDelta;
                posDelta  *= sizeof(short) * 2;
                _offset   += posDelta;

                // Add trail
                if (_trailOffset < Data.DataEnd)
                {
                    Data.Stream.Position = _trailOffset;
                    sampL        += Data.Reader.ReadInt16();
                    sampR        += Data.Reader.ReadInt16();
                    _trailOffset += posDelta;
                }

                buffer[bufPos]     += SoundMixer.S16ToF32(sampL, leftVol);
                buffer[bufPos + 1] += SoundMixer.S16ToF32(sampR, rightVol);

                if (_offset >= Data.LoopEnd)
                {
                    _offset      = Data.LoopStart;
                    _trailOffset = Data.LoopEnd;
                }

                bufPos += 2;
            } while (--numSamples > 0);
        }
Пример #5
0
        private static void Task_FadeOverworldBGMAndStartNewSong(BackTask task)
        {
            var data = (TaskData_FadeSongToSong)task.Data;

            if (!data.Handle.IsFading)
            {
                SoundMixer.StopChannel(_overworldBGM.Channel);
                if (data.Song == Song.None)
                {
                    _overworldBGM = null;
                }
                else
                {
                    _overworldBGM         = SongToSound(data.Song);
                    _overworldBGM.Channel = new SoundChannel(_overworldBGM.Wav);
                    SoundMixer.AddChannel(_overworldBGM.Channel);
                }
                _tasks.Remove(task);
            }
        }