public void Put(uint hash, CachedSound sound, string engine) { if (cache.ContainsKey(hash)) cache.Remove(hash); RenderCacheItem item; item.Engine = engine; item.Sound = sound; cache.Add(hash, item); }
public void Put(uint hash, CachedSound sound, string engine) { if (cache.ContainsKey(hash)) { cache.Remove(hash); } RenderCacheItem item; item.Engine = engine; item.Sound = sound; cache.Add(hash, item); }
private List<RenderItem> RenderAsync(UVoicePart part, UProject project, IResamplerDriver engine, BackgroundWorker worker) { List<RenderItem> renderItems = new List<RenderItem>(); System.Diagnostics.Stopwatch watch = new Stopwatch(); watch.Start(); System.Diagnostics.Debug.WriteLine("Resampling start"); lock (part) { string cacheDir = PathManager.Inst.GetCachePath(project.FilePath); string[] cacheFiles = Directory.EnumerateFiles(cacheDir).ToArray(); int count = 0, i = 0; foreach (UNote note in part.Notes) foreach (UPhoneme phoneme in note.Phonemes) count++; foreach (UNote note in part.Notes) { foreach (UPhoneme phoneme in note.Phonemes) { RenderItem item = BuildRenderItem(phoneme, part, project); var sound = RenderCache.Inst.Get(item.HashParameters()); if (sound == null) { string cachefile = Path.Combine(cacheDir, string.Format("{0:x}.wav", item.HashParameters())); if (!cacheFiles.Contains(cachefile)) { System.Diagnostics.Debug.WriteLine("Sound {0:x} resampling {1}", item.HashParameters(), item.GetResamplerExeArgs()); DriverModels.EngineInput engineArgs = DriverModels.CreateInputModel(item, 0); System.IO.Stream output = engine.DoResampler(engineArgs); sound = new CachedSound(output); } else { System.Diagnostics.Debug.WriteLine("Sound {0:x} found on disk {1}", item.HashParameters(), item.GetResamplerExeArgs()); sound = new CachedSound(cachefile); } RenderCache.Inst.Put(item.HashParameters(), sound, engine.GetInfo().ToString()); } else System.Diagnostics.Debug.WriteLine("Sound {0} found in cache {1}", item.HashParameters(), item.GetResamplerExeArgs()); item.Sound = sound; renderItems.Add(item); worker.ReportProgress(100 * ++i / count, string.Format("Resampling \"{0}\" {1}/{2}", phoneme.Phoneme, i, count)); } } } watch.Stop(); System.Diagnostics.Debug.WriteLine("Resampling end"); System.Diagnostics.Debug.WriteLine("Total cache size {0:n0} bytes", RenderCache.Inst.TotalMemSize); System.Diagnostics.Debug.WriteLine("Total time {0} ms", watch.Elapsed.TotalMilliseconds); return renderItems; }
public CachedSoundSampleProvider(CachedSound cachedSound) { this.cachedSound = cachedSound; }
private List <RenderItem> RenderAsync(UVoicePart part, UProject project, IResamplerDriver engine, BackgroundWorker worker) { List <RenderItem> renderItems = new List <RenderItem>(); System.Diagnostics.Stopwatch watch = new Stopwatch(); watch.Start(); System.Diagnostics.Debug.WriteLine("Resampling start"); lock (part) { string cacheDir = PathManager.Inst.GetCachePath(project.FilePath); string[] cacheFiles = Directory.EnumerateFiles(cacheDir).ToArray(); int count = 0, i = 0; foreach (UNote note in part.Notes) { foreach (UPhoneme phoneme in note.Phonemes) { count++; } } foreach (UNote note in part.Notes) { foreach (UPhoneme phoneme in note.Phonemes) { RenderItem item = BuildRenderItem(phoneme, part, project); var sound = RenderCache.Inst.Get(item.HashParameters()); if (sound == null) { string cachefile = Path.Combine(cacheDir, string.Format("{0:x}.wav", item.HashParameters())); if (!cacheFiles.Contains(cachefile)) { System.Diagnostics.Debug.WriteLine("Sound {0:x} resampling {1}", item.HashParameters(), item.GetResamplerExeArgs()); DriverModels.EngineInput engineArgs = DriverModels.CreateInputModel(item, 0); System.IO.Stream output = engine.DoResampler(engineArgs); sound = new CachedSound(output); } else { System.Diagnostics.Debug.WriteLine("Sound {0:x} found on disk {1}", item.HashParameters(), item.GetResamplerExeArgs()); sound = new CachedSound(cachefile); } RenderCache.Inst.Put(item.HashParameters(), sound, engine.GetInfo().ToString()); } else { System.Diagnostics.Debug.WriteLine("Sound {0} found in cache {1}", item.HashParameters(), item.GetResamplerExeArgs()); } item.Sound = sound; renderItems.Add(item); worker.ReportProgress(100 * ++i / count, string.Format("Resampling \"{0}\" {1}/{2}", phoneme.Phoneme, i, count)); } } } watch.Stop(); System.Diagnostics.Debug.WriteLine("Resampling end"); System.Diagnostics.Debug.WriteLine("Total cache size {0:n0} bytes", RenderCache.Inst.TotalMemSize); System.Diagnostics.Debug.WriteLine("Total time {0} ms", watch.Elapsed.TotalMilliseconds); return(renderItems); }