Example #1
0
 void Resample(RenderItem item)
 {
     byte[] data = null;
     try {
         uint hash = item.HashParameters();
         data = cache.Get(hash);
         if (data == null)
         {
             CopySourceTemp(item);
             if (!resamplers.TryGetValue(item.ResamplerName, out var driver))
             {
                 driver = this.driver;
             }
             data = driver.DoResampler(DriverModels.CreateInputModel(item, 0), Log.Logger);
             if (data == null || data.Length == 0)
             {
                 throw new Exception("Empty render result.");
             }
             cache.Put(hash, data);
             Log.Information($"Sound {hash:x} {item.Oto.Alias} {item.GetResamplerExeArgs()} resampled.");
             CopyBackMetaFiles(item);
         }
     } catch (Exception e) {
         Log.Error(e, $"Failed to render item {item.SourceFile} {item.Oto.Alias} {item.GetResamplerExeArgs()}.");
     } finally {
         item.Data = data ?? new byte[0];
         item.OnComplete?.Invoke(item.Data);
         item.progress?.CompleteOne($"Resampling \"{item.phonemeName}\"");
     }
 }
Example #2
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);
        }