/// <summary> /// Stars loading all sounds in a background thread. /// </summary> protected void LoadThreadSounds() { IEnumerator <KeyValuePair <string, Tuple <IntPtr, uint> > > it = Wavs.GetEnumerator(); Tuple <IntPtr, uint> wavData = null; while (it.MoveNext()) { // load it wavData = Util.LoadFileToUnmanagedMem( Path.Combine(WavFolder, it.Current.Key)); // update Wavs.TryUpdate(it.Current.Key, wavData, null); queueAsyncFilesLoaded.Enqueue(it.Current.Key); } }
/// <summary> /// Stars loading all sounds in a background thread. /// </summary> protected void LoadThreadSounds() { IEnumerator <KeyValuePair <string, string> > it = Wavs.GetEnumerator(); string filename = null; while (it.MoveNext()) { // load it filename = Path.Combine(WavFolder, it.Current.Key); // update Wavs.TryUpdate(it.Current.Key, filename, null); numLoadedWavs++; queueAsyncFilesLoaded.Enqueue(it.Current.Key); } }
/// <summary> /// Preloads all elements in the Wavs dictionary. /// </summary> public void PreloadSounds() { IEnumerator <KeyValuePair <string, Tuple <IntPtr, uint> > > it = Wavs.GetEnumerator(); Tuple <IntPtr, uint> wavData = null; while (it.MoveNext()) { // load it wavData = Util.LoadFileToUnmanagedMem( Path.Combine(Config.WavFolder, it.Current.Key)); // update Wavs.TryUpdate(it.Current.Key, wavData, null); } GC.Collect(2); }
/// <summary> /// Tries to retrieve a WAV file from the Wavs dictionary. /// Will load the file from disk, if not yet loaded. /// </summary> /// <param name="File"></param> /// <returns></returns> public Tuple <IntPtr, uint> GetWavFile(string File) { Tuple <IntPtr, uint> wavData = null; // if the file is known if (Wavs.TryGetValue(File, out wavData)) { // haven't loaded it yet? if (wavData == null) { // load it wavData = Util.LoadFileToUnmanagedMem(WavFolder + "/" + File); // update the registry Wavs.TryUpdate(File, wavData, null); } } return(wavData); }
/// <summary> /// Tries to retrieve a WAV file from the Wavs dictionary. /// Will load the file from disk, if not yet loaded. /// </summary> /// <param name="File"></param> /// <returns></returns> public string GetWavFile(string File) { string filename = null; // if the file is known if (Wavs.TryGetValue(File, out filename)) { // haven't loaded it yet? if (filename == null) { // load it filename = Path.Combine(WavFolder, File); // update the registry if (Wavs.TryUpdate(File, filename, null)) { numLoadedWavs++; } } } return(filename); }