-
Notifications
You must be signed in to change notification settings - Fork 16
/
Invertor.cs
69 lines (62 loc) · 1.73 KB
/
Invertor.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
using System;
using System.Collections.Generic;
using System.Text;
// Copyright (c) 2006, 2007 by Hugh Pyle, inguzaudio.com
namespace DSPUtil
{
public class Invertor : SoundObj
{
private bool[] _invert;
public Invertor()
{
}
/// <summary>
/// Get an iterator for samples
/// </summary>
public override IEnumerator<ISample> Samples
{
get
{
if (_input == null)
{
yield break;
}
foreach (ISample sample in Input)
{
yield return _nxt(sample);
}
}
}
internal ISample _nxt(ISample s)
{
if (_invert != null)
{
for (ushort c = 0; c < s.NumChannels; c++)
{
if (_invert[c])
{
s[c] = -s[c];
}
}
}
return s;
}
/// <summary>
/// Time difference, in samples, to apply between left and right channels.
/// Positive values delay the right channel relative to the left channel, and vice versa.
/// </summary>
public void Invert(ushort nChannel, bool doInvert)
{
if (_invert == null)
{
// Lazy lazy. In case input isn't defined yet. Invertor just handles a max 16 channels.
_invert = new bool[16];
}
if (nChannel > _invert.Length)
{
throw new ArgumentOutOfRangeException("nChannel");
}
_invert[nChannel] = doInvert;
}
}
}