Ejemplo n.º 1
0
        private int TakeSourceFor(SoundEffect soundEffect, bool filter = false)
        {
            if (this.freeSources.Count == 0)
            {
                this.ExpandSources();
            }
            int source = this.freeSources.Pop();

            if (filter && ALHelper.Efx.IsInitialized)
            {
                ALHelper.Efx.Filter(this.filterId, EfxFilterf.LowpassGainHF, MathHelper.Clamp(this.lowpassGainHf, 0.0f, 1f));
                ALHelper.Efx.BindFilterToSource(source, this.filterId);
                lock (this.filteredSources)
                    this.filteredSources.Add(source);
            }
            OpenALSoundController.BufferAllocation bufferAllocation;
            if (!this.allocatedBuffers.TryGetValue(soundEffect, out bufferAllocation))
            {
                if (this.freeBuffers.Count == 0)
                {
                    this.ExpandBuffers();
                }
                this.allocatedBuffers.Add(soundEffect, bufferAllocation = new OpenALSoundController.BufferAllocation()
                {
                    BufferId = this.freeBuffers.Pop()
                });
                AL.BufferData <byte>(bufferAllocation.BufferId, soundEffect.Format, soundEffect._data, soundEffect.Size, soundEffect.Rate);
                ALHelper.Check();
            }
            ++bufferAllocation.SourceCount;
            AL.BindBufferToSource(source, bufferAllocation.BufferId);
            ALHelper.Check();
            return(source);
        }
Ejemplo n.º 2
0
        private int TakeSourceFor(SoundEffect soundEffect, bool filter = false)
        {
            int result;

            while (!this.freeSources.TryPop(out result))
            {
                this.ExpandSources(32);
            }
            if (filter && ALHelper.Efx.IsInitialized)
            {
                ALHelper.Efx.Filter(this.filterId, EfxFilterf.LowpassGainHF, MathHelper.Clamp(this.lowpassGainHf, 0.0f, 1f));
                ALHelper.Efx.BindFilterToSource(result, this.filterId);
                OpenALSoundController.FilteringLock.EnterWriteLock();
                this.filteredSources.Add(result);
                OpenALSoundController.FilteringLock.ExitWriteLock();
            }
            OpenALSoundController.AllocationsLock.EnterUpgradeableReadLock();
            OpenALSoundController.BufferAllocation bufferAllocation;
            if (!this.allocatedBuffers.TryGetValue(soundEffect, out bufferAllocation))
            {
                bufferAllocation = new OpenALSoundController.BufferAllocation();
                while (!this.freeBuffers.TryPop(out bufferAllocation.BufferId))
                {
                    this.ExpandBuffers(32);
                }
                OpenALSoundController.AllocationsLock.EnterWriteLock();
                this.allocatedBuffers.Add(soundEffect, bufferAllocation);
                OpenALSoundController.AllocationsLock.ExitWriteLock();
                AL.BufferData <byte>(bufferAllocation.BufferId, soundEffect.Format, soundEffect._data, soundEffect.Size, soundEffect.Rate);
            }
            ++bufferAllocation.SourceCount;
            AL.BindBufferToSource(result, bufferAllocation.BufferId);
            OpenALSoundController.AllocationsLock.ExitUpgradeableReadLock();
            return(result);
        }
Ejemplo n.º 3
0
 public void RegisterSoundEffect(SoundEffect soundEffect)
 {
     if (this.allocatedBuffers.ContainsKey(soundEffect))
     {
         return;
     }
     if (this.freeBuffers.Count == 0)
     {
         this.ExpandBuffers();
     }
     Trace.WriteLine("[OpenAL] Pre-allocating buffer for " + soundEffect.Name);
     OpenALSoundController.BufferAllocation bufferAllocation;
     this.allocatedBuffers.Add(soundEffect, bufferAllocation = new OpenALSoundController.BufferAllocation()
     {
         BufferId    = this.freeBuffers.Pop(),
         SinceUnused = -1f
     });
     AL.BufferData <byte>(bufferAllocation.BufferId, soundEffect.Format, soundEffect._data, soundEffect.Size, soundEffect.Rate);
     ALHelper.Check();
 }
Ejemplo n.º 4
0
 private int TakeSourceFor(SoundEffect soundEffect, bool filter = false)
 {
   if (this.freeSources.Count == 0)
     this.ExpandSources();
   int source = this.freeSources.Pop();
   if (filter && ALHelper.Efx.IsInitialized)
   {
     ALHelper.Efx.Filter(this.filterId, EfxFilterf.LowpassGainHF, MathHelper.Clamp(this.lowpassGainHf, 0.0f, 1f));
     ALHelper.Efx.BindFilterToSource(source, this.filterId);
     lock (this.filteredSources)
       this.filteredSources.Add(source);
   }
   OpenALSoundController.BufferAllocation bufferAllocation;
   if (!this.allocatedBuffers.TryGetValue(soundEffect, out bufferAllocation))
   {
     if (this.freeBuffers.Count == 0)
       this.ExpandBuffers();
     this.allocatedBuffers.Add(soundEffect, bufferAllocation = new OpenALSoundController.BufferAllocation()
     {
       BufferId = this.freeBuffers.Pop()
     });
     AL.BufferData<byte>(bufferAllocation.BufferId, soundEffect.Format, soundEffect._data, soundEffect.Size, soundEffect.Rate);
     ALHelper.Check();
   }
   ++bufferAllocation.SourceCount;
   AL.BindBufferToSource(source, bufferAllocation.BufferId);
   ALHelper.Check();
   return source;
 }
Ejemplo n.º 5
0
 public void RegisterSoundEffect(SoundEffect soundEffect)
 {
   if (this.allocatedBuffers.ContainsKey(soundEffect))
     return;
   if (this.freeBuffers.Count == 0)
     this.ExpandBuffers();
   Trace.WriteLine("[OpenAL] Pre-allocating buffer for " + soundEffect.Name);
   OpenALSoundController.BufferAllocation bufferAllocation;
   this.allocatedBuffers.Add(soundEffect, bufferAllocation = new OpenALSoundController.BufferAllocation()
   {
     BufferId = this.freeBuffers.Pop(),
     SinceUnused = -1f
   });
   AL.BufferData<byte>(bufferAllocation.BufferId, soundEffect.Format, soundEffect._data, soundEffect.Size, soundEffect.Rate);
   ALHelper.Check();
 }
Ejemplo n.º 6
0
 private int TakeSourceFor(SoundEffect soundEffect, bool filter = false)
 {
   int result;
   while (!this.freeSources.TryPop(out result))
     this.ExpandSources(32);
   if (filter && ALHelper.Efx.IsInitialized)
   {
     ALHelper.Efx.Filter(this.filterId, EfxFilterf.LowpassGainHF, MathHelper.Clamp(this.lowpassGainHf, 0.0f, 1f));
     ALHelper.Efx.BindFilterToSource(result, this.filterId);
     OpenALSoundController.FilteringLock.EnterWriteLock();
     this.filteredSources.Add(result);
     OpenALSoundController.FilteringLock.ExitWriteLock();
   }
   OpenALSoundController.AllocationsLock.EnterUpgradeableReadLock();
   OpenALSoundController.BufferAllocation bufferAllocation;
   if (!this.allocatedBuffers.TryGetValue(soundEffect, out bufferAllocation))
   {
     bufferAllocation = new OpenALSoundController.BufferAllocation();
     while (!this.freeBuffers.TryPop(out bufferAllocation.BufferId))
       this.ExpandBuffers(32);
     OpenALSoundController.AllocationsLock.EnterWriteLock();
     this.allocatedBuffers.Add(soundEffect, bufferAllocation);
     OpenALSoundController.AllocationsLock.ExitWriteLock();
     AL.BufferData<byte>(bufferAllocation.BufferId, soundEffect.Format, soundEffect._data, soundEffect.Size, soundEffect.Rate);
   }
   ++bufferAllocation.SourceCount;
   AL.BindBufferToSource(result, bufferAllocation.BufferId);
   OpenALSoundController.AllocationsLock.ExitUpgradeableReadLock();
   return result;
 }