public void LoadSound(string name) { if (loadedSounds.ContainsKey(name)) { return; } if (loadedSounds.Count == 64) { var toRemove = soundQueue.Dequeue(); toRemove.Data.Dispose(); loadedSounds.Remove(toRemove.Name); } var loaded = new LoadedSound(); loaded.Entry = data.GetAudioEntry(name); loaded.Name = name; if (loaded.Entry.File.ToLowerInvariant().Replace('\\', '/') == "audio/null.wav") { //HACK: Don't bother with sounds using null.wav, makes awful popping noise loaded.Data = null; } else { var path = data.GetAudioPath(name); var snd = audio.AllocateData(); snd.LoadFile(path); loaded.Data = snd; } soundQueue.Enqueue(loaded); loadedSounds.Add(name, loaded); }
//move up to front void Used(LoadedSound snd) { LoadedSoundPtr ptr = lruTail; while (ptr.Sound != snd) { ptr = ptr.Previous; } if (ptr == lruTail) { return; } if (ptr == lruHead) { lruHead = ptr.Next; ptr.Next.Previous = null; } else { ptr.Next.Previous = ptr.Previous; ptr.Previous.Next = ptr.Next; } ptr.Previous = lruTail; ptr.Next = null; lruTail.Next = ptr; lruTail = ptr; }
public void LoadSound(string name) { if (loadedSounds.ContainsKey(name)) { return; } FLLog.Debug("Sounds", "Loading sound " + name); var loaded = new LoadedSound(); loaded.Entry = data.GetAudioEntry(name); loaded.Name = name; if (loaded.Entry.File.ToLowerInvariant().Replace('\\', '/') == "audio/null.wav") { //HACK: Don't bother with sounds using null.wav, makes awful popping noise loaded.Data = null; } else { var path = data.GetAudioPath(name); var snd = audio.AllocateData(); snd.LoadFile(path); loaded.Data = snd; } AddLoaded(loaded); }
void AddLoaded(LoadedSound snd) { if (lruHead == null) { lruHead = lruTail = new LoadedSoundPtr() { Sound = snd }; loadedSounds[snd.Name] = snd; return; } LoadedSoundPtr ptr; if (loadedSounds.Count == SOUNDS_MAX) { FLLog.Debug("Sounds", "Evicting sound"); //Evict oldest and reuse ptr object var h = lruHead; if (h.Sound.Data != null) { h.Sound.Data.Dispose(); } loadedSounds.Remove(h.Sound.Name); lruHead = h.Next; ptr = h; ptr.Sound = snd; ptr.Next = null; ptr.Previous = lruTail; } else { ptr = new LoadedSoundPtr() { Sound = snd, Previous = lruTail }; } lruTail.Next = ptr; lruTail = ptr; loadedSounds[snd.Name] = snd; }