//

        public void Update()
        {
            if (currentSound == null)
            {
                return;
            }

            if ((currentSound.Mode & SoundMode.Mode3D) != 0)
            {
                UpdateVolume2();
            }

            DirectSampleSound currentSampleSound = currentSound as DirectSampleSound;

            if (currentSampleSound != null)
            {
                UpdateSample();
                return;
            }

            DirectDataStreamSound currentDataStreamSound = currentSound as DirectDataStreamSound;

            if (currentDataStreamSound != null)
            {
                UpdateStream();
            }

            if (needStopVirtualChannel)
            {
                CurrentVirtualChannel.Stop();
                needStopVirtualChannel = false;
            }
        }
Пример #2
0
        void UpdateSample()
        {
            int state;

            Al.alGetSourcei(alSource, Al.AL_SOURCE_STATE, out state);
            OpenALSoundWorld.CheckError();
            if (state == Al.AL_STOPPED)
            {
                CurrentVirtualChannel.Stop();
            }
        }
        unsafe void UpdateSample()
        {
            uint status;

            int hr = IDirectSoundBuffer.GetStatus(currentSoundBuffer, out status);

            if (Wrapper.FAILED(hr))
            {
                DirectSoundWorld.Warning("IDirectSoundBuffer.GetStatus", hr);
                return;
            }

            if ((status & DSound.DSBSTATUS_PLAYING) == 0)
            {
                CurrentVirtualChannel.Stop();
            }
        }
Пример #4
0
        public void UpdateFileStreamFromThread()
        {
            if (currentSound == null)
            {
                return;
            }

            //update buffers
            int processed;

            Al.alGetSourcei(alSource, Al.AL_BUFFERS_PROCESSED, out processed);
            OpenALSoundWorld.CheckError();
            while (processed != 0)
            {
                int alStreamBuffer = 0;
                Al.alSourceUnqueueBuffers(alSource, 1, ref alStreamBuffer);

                OpenALSoundWorld.CheckError();
                FileStream(alStreamBuffer);
                if (streamDataAvailable)
                {
                    Al.alSourceQueueBuffers(alSource, 1, ref alStreamBuffer);
                    OpenALSoundWorld.CheckError();
                }

                processed--;
            }

            //play if buffer stopped (from behind internal buffers processed)
            int state;

            Al.alGetSourcei(alSource, Al.AL_SOURCE_STATE, out state);
            OpenALSoundWorld.CheckError();
            bool stoppedNoQueued = false;

            if (state == Al.AL_STOPPED)
            {
                int queued;
                Al.alGetSourcei(alSource, Al.AL_BUFFERS_QUEUED, out queued);
                if (queued != 0)
                {
                    Al.alSourcePlay(alSource);
                }
                else
                {
                    stoppedNoQueued = true;
                }
            }

            //file stream played

            OpenALFileStreamSound fileStreamSound = (OpenALFileStreamSound)currentSound;

            if (!streamDataAvailable && stoppedNoQueued)
            {
                if ((currentSound.Mode & SoundMode.Loop) != 0)
                {
                    //loop play. we need recreate vorbis file

                    //stop and unqueues sources
                    Al.alSourceStop(alSource);
                    Al.alGetSourcei(alSource, Al.AL_BUFFERS_PROCESSED, out processed);
                    OpenALSoundWorld.CheckError();
                    while (processed != 0)
                    {
                        int alStreamBuffer = 0;
                        Al.alSourceUnqueueBuffers(alSource, 1, ref alStreamBuffer);
                        OpenALSoundWorld.CheckError();
                        processed--;
                    }

                    //recreate vorbis file
                    fileStreamSound.Rewind();

                    FileStreamStartPlay();

                    //Pause = false;
                    Al.alSourcePlay(alSource);
                    OpenALSoundWorld.CheckError();
                }
                else
                {
                    CurrentVirtualChannel.Stop();
                }
            }
        }