-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWhisperAudioEffectProcessor.cs
59 lines (47 loc) · 1.7 KB
/
WhisperAudioEffectProcessor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using YukkuriMovieMaker.Player.Audio;
using YukkuriMovieMaker.Player.Audio.Effects;
using ToWhisperNet;
using NAudio.Wave;
namespace WhisperAudioEffect
{
internal class WhisperAudioEffectProcessor : AudioEffectProcessorBase
{
readonly WhisperAudioEffect item;
readonly TimeSpan duration;
private Whisper whisper;
public override int Hz => Input?.Hz ?? 0;
public override long Duration => (long)(duration.TotalSeconds * Input?.Hz ?? 0) * 2;
public WhisperAudioEffectProcessor(WhisperAudioEffect item, TimeSpan duration)
{
this.item = item;
this.duration = duration;
this.whisper = new Whisper();
}
protected override void seek(long position)
{
Input?.Seek(position);
}
protected override int read(float[] destBuffer, int offset, int count)
{
int samplesRead = Input?.Read(destBuffer, offset, count) ?? 0;
if (samplesRead > 0)
{
double[] inputData = new double[samplesRead];
for (int i = 0; i < samplesRead; i++)
{
inputData[i] = destBuffer[offset + i];
}
Wave wave = new Wave(inputData, new WaveFormat(Hz, 16, 1));
var hpf = item.Hpf;
var order = item.Order;
whisper.Convert(wave);
for (int i = 0; i < samplesRead; i++)
{
destBuffer[offset + i] = (float)wave.Data[i];
}
}
return samplesRead;
}
}
}