-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathWPFExamplePlugin.cs
106 lines (86 loc) · 3.47 KB
/
WPFExamplePlugin.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.Windows.Controls;
using AudioPlugSharp;
using AudioPlugSharpWPF;
namespace WPFExample
{
public class WPFExamplePlugin : AudioPluginWPF
{
DoubleAudioIOPort monoInput;
DoubleAudioIOPort stereoOutput;
AudioPluginParameter gainParameter = null;
AudioPluginParameter panParameter = null;
public WPFExamplePlugin()
{
Company = "My Company";
Website = "www.mywebsite.com";
Contact = "[email protected]";
PluginName = "WPF Example Plugin";
PluginCategory = "Fx";
PluginVersion = "1.0.0";
// Unique 64bit ID for the plugin
PluginID = 0x1E92758E710B4947;
HasUserInterface = true;
EditorWidth = 200;
EditorHeight = 100;
}
public override void Initialize()
{
base.Initialize();
InputPorts = new AudioIOPort[] { monoInput = new DoubleAudioIOPort("Mono Input", EAudioChannelConfiguration.Mono) };
OutputPorts = new AudioIOPort[] { stereoOutput = new DoubleAudioIOPort("Stereo Output", EAudioChannelConfiguration.Stereo) };
AddParameter(gainParameter = new AudioPluginParameter
{
ID = "gain",
Name = "Gain",
Type = EAudioPluginParameterType.Float,
MinValue = -20,
MaxValue = 20,
DefaultValue = 0,
ValueFormat = "{0:0.0}dB"
});
AddParameter(panParameter = new AudioPluginParameter
{
ID = "pan",
Name = "Pan",
Type = EAudioPluginParameterType.Float,
MinValue = -1,
MaxValue = 1,
DefaultValue = 0,
ValueFormat = "{0:0.0}"
});
}
public override void Process()
{
base.Process();
ReadOnlySpan<double> inSamples = monoInput.GetAudioBuffer(0);
Span<double> outLeftSamples = stereoOutput.GetAudioBuffer(0);
Span<double> outRightSamples = stereoOutput.GetAudioBuffer(1);
int currentSample = 0;
int nextSample = 0;
double linearGain = Math.Pow(10.0, 0.05 * gainParameter.ProcessValue);
double pan = panParameter.ProcessValue;
do
{
nextSample = Host.ProcessEvents(); // Handle sample-accurate parameters - see the SimpleExample plugin for a simpler, per-buffer parameter approach
bool needGainUpdate = gainParameter.NeedInterpolationUpdate;
bool needPanUpdate = panParameter.NeedInterpolationUpdate;
for (int i = currentSample; i < nextSample; i++)
{
if (needGainUpdate)
{
linearGain = Math.Pow(10.0, 0.05 * gainParameter.GetInterpolatedProcessValue(i));
}
if (needPanUpdate)
{
pan = panParameter.GetInterpolatedProcessValue(i);
}
outLeftSamples[i] = inSamples[i] * linearGain * (1 - pan);
outRightSamples[i] = inSamples[i] * linearGain * (1 + pan);
}
currentSample = nextSample;
}
while (nextSample < inSamples.Length); // Continue looping until we hit the end of the buffer
}
}
}