Ejemplo n.º 1
0
 public void UpdatePrecache()
 {
   if (this.nextCuePrecached || this.strayCues.Count != 0 || OggStreamer.Instance.PendingPrecaches != 0)
     return;
   this.nextCue = this.SoundManager.GetCue(this.Loop.Name, true);
   this.nextCuePrecached = true;
 }
Ejemplo n.º 2
0
        internal bool AddStream(OggStream stream)
        {
            OggStreamer.iterationLock.EnterWriteLock();
            bool flag = this.streams.Add(stream);

            OggStreamer.iterationLock.ExitWriteLock();
            return(flag);
        }
Ejemplo n.º 3
0
 public ActiveAmbienceTrack(AmbienceTrack track, bool activeForDayPhase)
 {
   ServiceHelper.InjectServices((object) this);
   this.volume = 0.0f;
   this.ActiveForDayPhase = activeForDayPhase;
   this.OnMuteStateChanged();
   this.Track = track;
   this.cue = this.SoundManager.GetCue(this.Track.Name, false);
   this.cue.Volume = this.volume;
   this.cue.Play();
 }
Ejemplo n.º 4
0
        internal bool RemoveStream(OggStream stream)
        {
            OggStreamer.iterationLock.EnterWriteLock();
            bool flag = this.streams.Remove(stream);

            OggStreamer.iterationLock.ExitWriteLock();
            if (flag && !stream.FirstBufferPrecached)
            {
                Interlocked.Decrement(ref this.PendingPrecaches);
            }
            return(flag);
        }
Ejemplo n.º 5
0
        public bool FillBuffer(OggStream stream, int bufferId)
        {
            int length;

            lock (this.readMutex)
            {
                length = stream.Reader.ReadSamples(this.readSampleBuffer, 0, this.BufferSize);
                OggStreamer.CastBuffer(this.readSampleBuffer, this.castBuffer, length);
            }
            AL.BufferData <short>(bufferId, stream.Reader.Channels == 1 ? ALFormat.Mono16 : ALFormat.Stereo16, this.castBuffer, length * 2, stream.Reader.SampleRate);
            ALHelper.Check();
            return(length != this.BufferSize);
        }
Ejemplo n.º 6
0
 public ActiveLoop(Loop loop, bool muted, bool activeForDayPhase, bool dontStart)
 {
   ServiceHelper.InjectServices((object) this);
   this.Muted = muted;
   this.volume = muted || !activeForDayPhase ? 0.0f : 1f;
   this.ActiveForDayPhase = activeForDayPhase;
   this.OnMuteStateChanged();
   this.Loop = loop;
   this.nextCuePrecached = true;
   this.nextCue = this.SoundManager.GetCue(loop.Name, false);
   this.barsBeforePlay = (float) this.Loop.Delay;
   if (dontStart || this.Loop.Delay != 0)
     return;
   this.FirstPlay();
 }
Ejemplo n.º 7
0
        public bool FillBuffer(OggStream stream, int bufferId)
        {
            int readSamples;

            lock (readMutex) {
                readSamples = stream.Reader.ReadSamples(readSampleBuffer, 0, BufferSize);
                CastBuffer(readSampleBuffer, castBuffer, readSamples);
            }
            AL.BufferData(bufferId, stream.Reader.Channels == 1 ? ALFormat.Mono16 : ALFormat.Stereo16, castBuffer,
                          readSamples * sizeof(short), stream.Reader.SampleRate);
            ALHelper.CheckError("Failed to fill buffer, readSamples = {0}, SampleRate = {1}, buffer.Length = {2}.", readSamples, stream.Reader.SampleRate, castBuffer.Length);


            return(readSamples != BufferSize);
        }
Ejemplo n.º 8
0
 public bool FillBuffer(OggStream stream, int bufferId)
 {
     OggStreamer.decodeLock.EnterWriteLock();
     if (stream.IsDisposed)
     {
         OggStreamer.decodeLock.ExitWriteLock();
         return(true);
     }
     else
     {
         int num = stream.Reader.ReadSamples(this.readSampleBuffer, 0, this.BufferSize);
         for (int index = 0; index < num; ++index)
         {
             this.castBuffer[index] = (short)((double)short.MaxValue * (double)this.readSampleBuffer[index]);
         }
         AL.BufferData <short>(bufferId, stream.Reader.Channels == 1 ? ALFormat.Mono16 : ALFormat.Stereo16, this.castBuffer, num * 2, stream.Reader.SampleRate);
         OggStreamer.decodeLock.ExitWriteLock();
         return(num != this.BufferSize);
     }
 }
Ejemplo n.º 9
0
 public OggStream GetCue(string name, bool asyncPrecache = false)
 {
   OggStream oggStream = (OggStream) null;
   try
   {
     string str = name.Replace(" ^ ", "\\");
     bool flag = name.Contains("Ambience");
     oggStream = new OggStream(this.MusicAliases[str.ToLower(CultureInfo.InvariantCulture)], 6)
     {
       Category = flag ? "Ambience" : "Music",
       IsLooped = flag
     };
     oggStream.RealName = name;
     oggStream.Prepare(asyncPrecache);
     if (name.Contains("Gomez"))
       oggStream.LowPass = false;
   }
   catch (Exception ex)
   {
     Logger.Log("SoundManager", LogSeverity.Error, ex.Message);
   }
   return oggStream;
 }
Ejemplo n.º 10
0
 public bool FillBuffer(OggStream stream, int bufferId)
 {
   int length;
   lock (this.readMutex)
   {
     length = stream.Reader.ReadSamples(this.readSampleBuffer, 0, this.BufferSize);
     OggStreamer.CastBuffer(this.readSampleBuffer, this.castBuffer, length);
   }
   AL.BufferData<short>(bufferId, stream.Reader.Channels == 1 ? ALFormat.Mono16 : ALFormat.Stereo16, this.castBuffer, length * 2, stream.Reader.SampleRate);
   ALHelper.Check();
   return length != this.BufferSize;
 }
Ejemplo n.º 11
0
 internal bool RemoveStream(OggStream stream)
 {
   lock (this.iterationMutex)
     return this.streams.Remove(stream);
 }
Ejemplo n.º 12
0
 internal bool AddStream(OggStream stream)
 {
   lock (this.iterationMutex)
     return this.streams.Add(stream);
 }
Ejemplo n.º 13
0
 internal bool RemoveStream(OggStream stream)
 {
   OggStreamer.iterationLock.EnterWriteLock();
   bool flag = this.streams.Remove(stream);
   OggStreamer.iterationLock.ExitWriteLock();
   if (flag && !stream.FirstBufferPrecached)
     Interlocked.Decrement(ref this.PendingPrecaches);
   return flag;
 }
Ejemplo n.º 14
0
 private void EnsureBuffersFilled()
 {
     while (!this.cancelled && !this.cancelled)
     {
         this.threadLocalStreams.Clear();
         OggStreamer.iterationLock.EnterReadLock();
         this.threadLocalStreams.AddRange((IEnumerable <OggStream>) this.streams);
         OggStreamer.iterationLock.ExitReadLock();
         if (this.threadLocalStreams.Count != 0)
         {
             int val1 = int.MaxValue;
             for (int index = this.threadLocalStreams.Count - 1; index >= 0; --index)
             {
                 OggStream oggStream = this.threadLocalStreams[index];
                 OggStreamer.iterationLock.EnterReadLock();
                 bool flag = !this.streams.Contains(oggStream);
                 OggStreamer.iterationLock.ExitReadLock();
                 if (flag)
                 {
                     this.threadLocalStreams.RemoveAt(index);
                 }
                 else
                 {
                     int num1;
                     AL.GetSource(oggStream.alSourceId, ALGetSourcei.BuffersQueued, out num1);
                     oggStream.QueuedBuffers = num1;
                     int num2;
                     AL.GetSource(oggStream.alSourceId, ALGetSourcei.BuffersProcessed, out num2);
                     oggStream.ProcessedBuffers = num2;
                     if (!oggStream.Precaching)
                     {
                         val1 = Math.Min(val1, num1 - num2);
                     }
                 }
             }
             foreach (OggStream stream in this.threadLocalStreams)
             {
                 stream.PreparationLock.EnterReadLock();
                 OggStreamer.iterationLock.EnterReadLock();
                 bool flag1 = !this.streams.Contains(stream);
                 OggStreamer.iterationLock.ExitReadLock();
                 if (flag1)
                 {
                     stream.PreparationLock.ExitReadLock();
                 }
                 else if (stream.ProcessedBuffers == 0 && stream.bufferStack.Count == 0)
                 {
                     stream.PreparationLock.ExitReadLock();
                 }
                 else if (stream.QueuedBuffers - stream.ProcessedBuffers > val1)
                 {
                     stream.PreparationLock.ExitReadLock();
                 }
                 else if (stream.Precaching && val1 <= stream.BufferCount * 2 / 3)
                 {
                     stream.PreparationLock.ExitReadLock();
                 }
                 else
                 {
                     int  num   = stream.ProcessedBuffers <= 0 ? stream.bufferStack.Pop() : AL.SourceUnqueueBuffer(stream.alSourceId);
                     bool flag2 = this.FillBuffer(stream, num);
                     if (flag2)
                     {
                         if (stream.IsLooped)
                         {
                             stream.Reader.DecodedTime = TimeSpan.Zero;
                         }
                         else
                         {
                             OggStreamer.iterationLock.EnterWriteLock();
                             this.streams.Remove(stream);
                             OggStreamer.iterationLock.ExitWriteLock();
                         }
                     }
                     AL.SourceQueueBuffer(stream.alSourceId, num);
                     if (!stream.FirstBufferPrecached)
                     {
                         Interlocked.Decrement(ref this.PendingPrecaches);
                         stream.FirstBufferPrecached = true;
                     }
                     if (flag2 && !stream.IsLooped)
                     {
                         stream.PreparationLock.ExitReadLock();
                     }
                     else
                     {
                         stream.PreparationLock.ExitReadLock();
                         stream.StoppingLock.EnterReadLock();
                         if (stream.Precaching)
                         {
                             stream.StoppingLock.ExitReadLock();
                         }
                         else
                         {
                             OggStreamer.iterationLock.EnterReadLock();
                             bool flag3 = !this.streams.Contains(stream);
                             OggStreamer.iterationLock.ExitReadLock();
                             if (flag3)
                             {
                                 stream.StoppingLock.ExitReadLock();
                             }
                             else
                             {
                                 if (AL.GetSourceState(stream.alSourceId) == ALSourceState.Stopped)
                                 {
                                     ALHelper.Log(string.Concat(new object[4]
                                     {
                                         (object)"Buffer underrun on ",
                                         (object)stream.RealName,
                                         (object)" with source ",
                                         (object)stream.alSourceId
                                     }), "OpenAL");
                                     AL.SourcePlay(stream.alSourceId);
                                 }
                                 stream.StoppingLock.ExitReadLock();
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 15
0
 public bool FillBuffer(OggStream stream, int bufferId)
 {
   OggStreamer.decodeLock.EnterWriteLock();
   if (stream.IsDisposed)
   {
     OggStreamer.decodeLock.ExitWriteLock();
     return true;
   }
   else
   {
     int num = stream.Reader.ReadSamples(this.readSampleBuffer, 0, this.BufferSize);
     for (int index = 0; index < num; ++index)
       this.castBuffer[index] = (short) ((double) short.MaxValue * (double) this.readSampleBuffer[index]);
     AL.BufferData<short>(bufferId, stream.Reader.Channels == 1 ? ALFormat.Mono16 : ALFormat.Stereo16, this.castBuffer, num * 2, stream.Reader.SampleRate);
     OggStreamer.decodeLock.ExitWriteLock();
     return num != this.BufferSize;
   }
 }
Ejemplo n.º 16
0
 internal bool AddStream(OggStream stream)
 {
   OggStreamer.iterationLock.EnterWriteLock();
   bool flag = this.streams.Add(stream);
   OggStreamer.iterationLock.ExitWriteLock();
   return flag;
 }
Ejemplo n.º 17
0
 internal bool AddStream(OggStream stream)
 {
     lock (iterationMutex)
         return(streams.Add(stream));
 }
Ejemplo n.º 18
0
        public OggStream GetCue(string name, bool asyncPrecache = false) {
            bool isAmbience = name.Contains("Ambience");

            string oggFile = ((isAmbience ? "" : "music/") + name.Replace(" ^ ", "\\")).Externalize() + ".ogg";
            if (File.Exists(oggFile)) {
                OggStream oggStream = (OggStream) null;
                try {
                    //TODO use the MusicCache - maybe use the already existing one for FNA
                    #if FNA
                    oggStream = new OggStream(oggFile) {
                    #else
                    oggStream = new OggStream(oggFile, 6) {
                    #endif
                        Category = isAmbience ? "Ambience" : "Music",
                        IsLooped = isAmbience
                    };
                    oggStream.RealName = name;
                    #if !FNA
                    oggStream.Prepare(asyncPrecache);
                    #endif
                    if (name.Contains("Gomez")) {
                        oggStream.LowPass = false;
                    }
                } catch (Exception ex) {
                    ModLogger.Log("FEZMod.SoundManager", ex.Message);
                }
                return oggStream;
            }

            return orig_GetCue(name, asyncPrecache);
        }
Ejemplo n.º 19
0
 private void Play()
 {
   if (!this.nextCuePrecached)
     this.nextCue = this.SoundManager.GetCue(this.Loop.Name, false);
   this.nextCue.Volume = this.volume;
   this.nextCue.Play();
   if (this.currentCue != null)
     this.strayCues.Add(this.currentCue);
   this.currentCue = this.nextCue;
   this.barsToCount = this.Loop.Duration;
   this.nextCuePrecached = false;
 }
Ejemplo n.º 20
0
 public void CutOff()
 {
   if (this.currentCue != null)
   {
     this.currentCue.Stop();
     this.currentCue.Dispose();
   }
   this.currentCue = (OggStream) null;
 }
Ejemplo n.º 21
0
 public void Dispose()
 {
   if (this.currentCue != null)
   {
     this.currentCue.Stop();
     this.currentCue.Dispose();
     this.currentCue = (OggStream) null;
   }
   this.nextCue.Stop();
   this.nextCue.Dispose();
   this.nextCue = (OggStream) null;
   foreach (OggStream oggStream in this.strayCues)
   {
     oggStream.Stop();
     oggStream.Dispose();
   }
   this.strayCues.Clear();
   this.CycleLink = (Action) null;
 }
Ejemplo n.º 22
0
 internal bool RemoveStream(OggStream stream)
 {
     lock (iterationMutex)
         return(streams.Remove(stream));
 }
Ejemplo n.º 23
0
        public bool FillBuffer(OggStream stream, int bufferId)
        {
            int readSamples;
            long readerPosition = 0;
            lock (readMutex)
            {
                readerPosition = stream.Reader.DecodedPosition;
                readSamples = stream.Reader.ReadSamples(readSampleBuffer, 0, BufferSize);
                CastBuffer(readSampleBuffer, castBuffer, readSamples);
            }
            AL.BufferData(bufferId, stream.Reader.Channels == 1 ? ALFormat.Mono16 : ALFormat.Stereo16, castBuffer,
                readSamples * sizeof(short), stream.Reader.SampleRate);
            ALHelper.CheckError("Failed to fill buffer, readSamples = {0}, SampleRate = {1}, buffer.Length = {2}.", readSamples, stream.Reader.SampleRate, castBuffer.Length);

            return readSamples != BufferSize;
        }