-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathSequencer.cs
80 lines (72 loc) · 2.03 KB
/
Sequencer.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
using System;
using System.Collections.Generic;
using System.Text;
// Copyright (c) 2006, 2007 by Hugh Pyle, inguzaudio.com
namespace DSPUtil
{
/// <summary>
/// Sequencer: join inputs together sequentially.
/// Create a Sequencer object, then add as many inputs as necessary...
/// </summary>
[Serializable]
public class Sequencer : SoundObj
{
List<ISoundObj> _inputs = new List<ISoundObj>();
List<List<double>> _channelGains = new List<List<double>>();
public Sequencer()
{
}
// Add another source
public void Add(ISoundObj input)
{
Add(input, new List<double>());
}
public void Add(ISoundObj input, List<double> channelGains)
{
if (_inputs.Count == 0)
{
// Treat this as 'Input'...
Input = input;
}
_inputs.Add(input);
_channelGains.Add(channelGains);
}
public override int Iterations
{
get
{
int i = 0;
foreach (ISoundObj input in _inputs)
{
i += input.Iterations;
}
return i;
}
}
/// <summary>
/// Get an iterator for samples
/// </summary>
public override IEnumerator<ISample> Samples
{
get
{
int nIn = 0;
foreach (ISoundObj input in _inputs)
{
foreach (ISample s in input)
{
if (_channelGains[nIn].Count > 0)
{
for(int c=0; c<_channelGains[nIn].Count; c++)
{
s[c] *= _channelGains[nIn][c];
}
}
yield return s;
}
nIn++;
}
}
}
}
}