Пример #1
0
        private ALOutput.BufferCache GetBuffer(string file)
        {
            ALOutput.BufferCache bufferCache1;
            if (this._cache.TryGetValue(file, out bufferCache1))
            {
                ++bufferCache1.RefCount;
                bufferCache1.LastUse = DateTime.Now;
                Debug.WriteLine("Using " + file + " from cache");
                return(bufferCache1);
            }
            SoundInstance soundInstance = SoundInstance.Create(file, this._source.Open(file));
            int           bid           = AL.GenBuffer();

            float[]  numArray = soundInstance.ReadFully();
            short[]  buffer   = new short[numArray.Length];
            ALFormat format   = soundInstance is SoundInstanceMono ? ALFormat.Mono16 : ALFormat.Stereo16;

            for (int index = 0; index < numArray.Length; ++index)
            {
                buffer[index] = (short)((double)numArray[index] * (double)short.MaxValue);
            }
            AL.BufferData <short>(bid, format, buffer, buffer.Length * 2, soundInstance.WaveFormat.SampleRate);
            ALOutput.BufferCache bufferCache2 = new ALOutput.BufferCache()
            {
                Buffer   = bid,
                File     = file,
                RefCount = 1,
                LastUse  = DateTime.Now
            };
            this._cache.Add(file, bufferCache2);
            return(bufferCache2);
        }
Пример #2
0
 private void ReleaseBuffer(ALOutput.BufferCache b)
 {
     --b.RefCount;
     foreach (string key in this._cache.Keys.ToArray <string>())
     {
         ALOutput.BufferCache bufferCache = this._cache[key];
         if (bufferCache.RefCount == 0 && bufferCache.LastUse < DateTime.Now.AddSeconds(-30.0))
         {
             AL.DeleteBuffer(bufferCache.Buffer);
             Debug.WriteLine("Removing " + key + " from cache");
             this._cache.Remove(key);
         }
     }
 }