-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathSimpleExamplePlugin.cs
65 lines (53 loc) · 2.04 KB
/
SimpleExamplePlugin.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
using System;
using AudioPlugSharp;
namespace SimpleExample
{
public class SimpleExamplePlugin : AudioPluginBase
{
public SimpleExamplePlugin()
{
Company = "My Company";
Website = "www.mywebsite.com";
Contact = "[email protected]";
PluginName = "Simple Gain Plugin";
PluginCategory = "Fx";
PluginVersion = "1.0.0";
// Unique 64bit ID for the plugin
PluginID = 0xF57703946AFC4EF8;
SampleFormatsSupported = EAudioBitsPerSample.Bits32;
}
FloatAudioIOPort monoInput;
FloatAudioIOPort monoOutput;
public override void Initialize()
{
base.Initialize();
InputPorts = new AudioIOPort[] { monoInput = new FloatAudioIOPort("Mono Input", EAudioChannelConfiguration.Mono) };
OutputPorts = new AudioIOPort[] { monoOutput = new FloatAudioIOPort("Mono Output", EAudioChannelConfiguration.Mono) };
AddParameter(new AudioPluginParameter
{
ID = "gain",
Name = "Gain",
Type = EAudioPluginParameterType.Float,
MinValue = -20,
MaxValue = 20,
DefaultValue = 0,
ValueFormat = "{0:0.0}dB"
});
}
public override void Process()
{
base.Process();
// This will trigger all Midi note events and parameter changes that happend during this process window
// For sample-accurate tracking, see the WPFExample or MidiExample plugins
Host.ProcessAllEvents();
double gain = GetParameter("gain").ProcessValue;
float linearGain = (float)Math.Pow(10.0, 0.05 * gain);
ReadOnlySpan<float> inSamples = monoInput.GetAudioBuffer(0);
Span<float> outSamples = monoOutput.GetAudioBuffer(0);
for (int i = 0; i < inSamples.Length; i++)
{
outSamples[i] = inSamples[i] * linearGain;
}
}
}
}