public void Rewind()
        {
            if (vorbisFile != null)
            {
                vorbisFile.Dispose();
                vorbisFile = null;
            }

            vorbisFileReader.RewindStreamToBegin();

            vorbisFile = new VorbisFile.File();
            if (!vorbisFileReader.OpenVorbisFile(vorbisFile))
            {
                Log.Warning("OpenALSoundSystem: Creating sound failed \"{0}\".", Name);
                return;
            }
        }
Example #2
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 & SoundModes.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
                    {
                        fileStreamVorbisFile?.Dispose();
                        fileStreamVorbisFile = null;

                        fileStreamVorbisFileReader.RewindStreamToBegin();

                        fileStreamVorbisFile = new VorbisFile.File();
                        if (!fileStreamVorbisFileReader.OpenVorbisFile(fileStreamVorbisFile))
                        {
                            Log.Warning("OpenALSoundSystem: Creating sound failed \"{0}\".", currentSound.Name);
                            return;
                        }
                    }
                    //fileStreamSound.Rewind();

                    FileStreamStartPlay();

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