Example #1
0
        RenderItem ResamplePhonemeAsync(object state)
        {
            RenderItem item = state as RenderItem;

            Log.Verbose($"Sound {item.HashParameters():x} resampling {item.GetResamplerExeArgs()}");
            var output = driver.DoResampler(DriverModels.CreateInputModel(item, 0));

            item.Sound = MemorySampleProvider.FromStream(output);
            output.Dispose();
            item.progress.CompleteOne($"Resampling \"{item.phonemeName}\"");
            return(item);
        }
        private List <RenderItem> RenderAsync(UVoicePart part, UProject project, IResamplerDriver engine, BackgroundWorker worker)
        {
            var renderItems = new List <RenderItem>();
            var watch       = new Stopwatch();

            watch.Start();
            Log.Information("Resampling start.");
            lock (part) {
                var cacheDir = PathManager.Inst.GetCachePath(project.FilePath);
                var cacheFiles = Directory.EnumerateFiles(cacheDir).ToArray();
                int count = 0, i = 0;
                foreach (var note in part.Notes)
                {
                    foreach (var phoneme in note.Phonemes)
                    {
                        count++;
                    }
                }

                foreach (var note in part.Notes)
                {
                    foreach (var phoneme in note.Phonemes)
                    {
                        if (string.IsNullOrEmpty(phoneme.Oto.File))
                        {
                            Log.Warning($"Cannot find phoneme in note {note.Lyric}");
                            continue;
                        }

                        var item = new RenderItem(phoneme, part, project);

                        //System.Diagnostics.Debug.WriteLine("Sound {0:x} resampling {1}", item.HashParameters(), item.GetResamplerExeArgs());
                        var engineArgs = DriverModels.CreateInputModel(item, 0);
                        var output     = engine.DoResampler(engineArgs);
                        item.Sound = MemorySampleProvider.FromStream(output);
                        output.Dispose();
                        renderItems.Add(item);
                        worker.ReportProgress(100 * ++i / count, $"Resampling \"{phoneme.Phoneme}\" {i}/{count}");
                    }
                }
            }
            watch.Stop();
            Log.Information($"Resampling end, total time {watch.Elapsed}");
            return(renderItems);
        }
Example #3
0
        RenderItem ResamplePhonemeAsync(object state)
        {
            RenderItem item = state as RenderItem;
            uint       hash = item.HashParameters();

            byte[] data = cache.Get(hash);
            if (data == null)
            {
                data = driver.DoResampler(DriverModels.CreateInputModel(item, 0));
                cache.Put(hash, data);
                Log.Information($"Sound {hash:x} {item.GetResamplerExeArgs()} resampled.");
            }
            else
            {
                Log.Information($"Sound {hash:x} {item.GetResamplerExeArgs()} cache retrieved.");
            }
            var stream = new MemoryStream(data);

            item.Sound = MemorySampleProvider.FromStream(stream);
            item.progress.CompleteOne($"Resampling \"{item.phonemeName}\"");
            return(item);
        }