コード例 #1
0
ファイル: ActiveLoop.cs プロジェクト: Zeludon/FEZ
 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;
 }
コード例 #2
0
        internal bool AddStream(OggStream stream)
        {
            OggStreamer.iterationLock.EnterWriteLock();
            bool flag = this.streams.Add(stream);

            OggStreamer.iterationLock.ExitWriteLock();
            return(flag);
        }
コード例 #3
0
ファイル: ActiveAmbienceTrack.cs プロジェクト: tanis2000/FEZ
 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();
 }
コード例 #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);
        }
コード例 #5
0
ファイル: OggStreamer.cs プロジェクト: conankzhang/fez
        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);
        }
コード例 #6
0
ファイル: ActiveLoop.cs プロジェクト: Zeludon/FEZ
 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();
 }
コード例 #7
0
ファイル: OggStream.cs プロジェクト: Uyhuydgfae/Skitspel
        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);
        }
コード例 #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);
     }
 }
コード例 #9
0
ファイル: SoundManager.cs プロジェクト: tanis2000/FEZ
 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;
 }
コード例 #10
0
ファイル: OggStreamer.cs プロジェクト: tanis2000/FEZ
 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;
 }
コード例 #11
0
ファイル: OggStreamer.cs プロジェクト: tanis2000/FEZ
 internal bool RemoveStream(OggStream stream)
 {
   lock (this.iterationMutex)
     return this.streams.Remove(stream);
 }
コード例 #12
0
ファイル: OggStreamer.cs プロジェクト: tanis2000/FEZ
 internal bool AddStream(OggStream stream)
 {
   lock (this.iterationMutex)
     return this.streams.Add(stream);
 }
コード例 #13
0
ファイル: OggStreamer.cs プロジェクト: Zeludon/FEZ
 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;
 }
コード例 #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();
                             }
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #15
0
ファイル: OggStreamer.cs プロジェクト: Zeludon/FEZ
 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;
   }
 }
コード例 #16
0
ファイル: OggStreamer.cs プロジェクト: Zeludon/FEZ
 internal bool AddStream(OggStream stream)
 {
   OggStreamer.iterationLock.EnterWriteLock();
   bool flag = this.streams.Add(stream);
   OggStreamer.iterationLock.ExitWriteLock();
   return flag;
 }
コード例 #17
0
 internal bool AddStream(OggStream stream)
 {
     lock (iterationMutex)
         return(streams.Add(stream));
 }
コード例 #18
0
ファイル: SoundManager.cs プロジェクト: Gyoo/FEZMod
        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);
        }
コード例 #19
0
ファイル: ActiveLoop.cs プロジェクト: Zeludon/FEZ
 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;
 }
コード例 #20
0
ファイル: ActiveLoop.cs プロジェクト: Zeludon/FEZ
 public void CutOff()
 {
   if (this.currentCue != null)
   {
     this.currentCue.Stop();
     this.currentCue.Dispose();
   }
   this.currentCue = (OggStream) null;
 }
コード例 #21
0
ファイル: ActiveLoop.cs プロジェクト: Zeludon/FEZ
 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;
 }
コード例 #22
0
 internal bool RemoveStream(OggStream stream)
 {
     lock (iterationMutex)
         return(streams.Remove(stream));
 }
コード例 #23
0
ファイル: OggStream.cs プロジェクト: Zodge/MonoGame
        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;
        }