Beispiel #1
0
 public void SetAsyncInputPin(ISoundProvider source)
 {
     if (_syncSoundProvider != null)
     {
         _syncSoundProvider.DiscardSamples();
         _syncSoundProvider = null;
     }
     if (_outputProvider != null)
     {
         _outputProvider.DiscardSamples();
         _outputProvider.BaseSoundProvider = null;
     }
     _asyncSoundProvider         = source;
     _semiSync.BaseSoundProvider = source;
     _semiSync.RecalculateMagic(Global.Emulator.CoreComm.VsyncRate);
 }
Beispiel #2
0
        public void DiscardSamples()
        {
            _buffer.Clear();
            _extraCountHistory.Clear();
            _outputCountHistory.Clear();
            _hardCorrectionHistory.Clear();
            _baseConsecutiveEmptyFrames = 0;
            _baseEmptyFrameCorrectionHistory.Clear();
            _lastAdvertisedSamplesPerFrame = 0.0;
            _baseSamplesPerFrame.Clear();
            _outputBuffer   = new short[0];
            _resampleBuffer = new short[0];
            _resampleLengthRoundingError = 0.0;

            if (BaseSoundProvider != null)
            {
                BaseSoundProvider.DiscardSamples();
            }
        }
Beispiel #3
0
        public void UpdateSound()
        {
            if (Global.Config.SoundEnabled == false || disposed)
            {
                if (asyncsoundProvider != null)
                {
                    asyncsoundProvider.DiscardSamples();
                }
                if (syncsoundProvider != null)
                {
                    syncsoundProvider.DiscardSamples();
                }
                return;
            }

            int samplesNeeded = SNDDXGetAudioSpace() * 2;

            short[] samples;

            int samplesProvided;


            if (Muted)
            {
                if (samplesNeeded == 0)
                {
                    return;
                }
                samples         = new short[samplesNeeded];
                samplesProvided = samplesNeeded;

                if (asyncsoundProvider != null)
                {
                    asyncsoundProvider.DiscardSamples();
                }
                if (syncsoundProvider != null)
                {
                    syncsoundProvider.DiscardSamples();
                }
            }
            else if (syncsoundProvider != null)
            {
                if (DSoundBuffer == null)
                {
                    return;                                       // can cause SNDDXGetAudioSpace() = 0
                }
                int nsampgot;

                syncsoundProvider.GetSamples(out samples, out nsampgot);

                samplesProvided = 2 * nsampgot;

                if (!Global.ForceNoThrottle)
                {
                    while (samplesNeeded < samplesProvided)
                    {
                        System.Threading.Thread.Sleep((samplesProvided - samplesNeeded) / 88);                         // let audio clock control sleep time
                        samplesNeeded = SNDDXGetAudioSpace() * 2;
                    }
                }
            }
            else if (asyncsoundProvider != null)
            {
                if (samplesNeeded == 0)
                {
                    return;
                }
                samples = new short[samplesNeeded];
                //if (asyncsoundProvider != null && Muted == false)
                //{
                semisync.BaseSoundProvider = asyncsoundProvider;
                semisync.GetSamples(samples);
                //}
                //else asyncsoundProvider.DiscardSamples();
                samplesProvided = samplesNeeded;
            }
            else
            {
                return;
            }

            int cursor = soundoffset;

            for (int i = 0; i < samplesProvided; i++)
            {
                short s = samples[i];
                SoundBuffer[cursor++] = (byte)(s & 0xFF);
                SoundBuffer[cursor++] = (byte)(s >> 8);

                if (cursor >= SoundBuffer.Length)
                {
                    cursor = 0;
                }
            }

            DSoundBuffer.Write(SoundBuffer, 0, LockFlags.EntireBuffer);

            soundoffset += samplesProvided * 2;
            soundoffset %= BufferSize;
        }
Beispiel #4
0
 public void DiscardSamples()
 {
     input.DiscardSamples();
     buffer.clear();
 }
Beispiel #5
0
 void ISyncSoundProvider.DiscardSamples()
 {
     syncinput.DiscardSamples();
 }