forked from hughpyle/inguz-DSPUtil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Shuffler.cs
75 lines (65 loc) · 1.72 KB
/
Shuffler.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
using System;
using System.Collections.Generic;
using System.Text;
namespace DSPUtil
{
/// <summary>
/// Channel-shuffle (LR to MS or vice versa)
/// Requires two-channel input.
/// </summary>
public class Shuffler: SoundObj
{
public Shuffler()
{
}
/// <summary>
/// Get an iterator for samples
/// </summary>
public override IEnumerator<ISample> Samples
{
get
{
if (_input == null)
{
yield break;
}
// Return (a+b)/2 and (a-b)/2
foreach (ISample sample in _input)
{
yield return _next(sample);
}
}
}
internal ISample _next(ISample s)
{
if (_nc != 2)
{
// NOP!
}
else
{
double L = s[0];
double R = s[1];
// Set sample values in-place (quicker than newing another sample)
s[0] = (L + R) * _sigmaGain;
s[1] = (L - R) * _deltaGain;
}
return s;
}
private double _deltaGain = MathUtil.SQRT2;
public double DeltaGain
{
get { return _deltaGain; }
set { _deltaGain = value; }
}
private double _sigmaGain = MathUtil.SQRT2;
public double SigmaGain
{
get { return _sigmaGain; }
set { _sigmaGain = value; }
}
}
// This is symmetrical if you shuffle twice,
// L, R --> (L+R)/2, (L-R)/2
// (L+R), (L-R) --> (L/2+R/2+L/2-R/2), (L/2+R/2-L/2+R/2) = L, R
}