forked from hughpyle/inguz-DSPUtil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Source.cs
48 lines (41 loc) · 1.08 KB
/
Source.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
using System;
using System.Collections.Generic;
using System.Text;
namespace DSPUtil
{
public delegate ISample SourceCallback(long n);
/// <summary>
/// Wraps a callback function to become a SoundObj
/// Example: new CallbackSource( 1, 44100, delegate(int j) { ... return sample ... } );
/// </summary>
public class CallbackSource : SoundObj
{
private SourceCallback _fn;
public CallbackSource()
{
}
public CallbackSource(ushort nChannels, uint sampleRate, SourceCallback fn)
{
NumChannels = nChannels;
SampleRate = sampleRate;
_fn = fn;
}
public override IEnumerator<ISample> Samples
{
get
{
int n = 0;
while (true)
{
ISample s = _fn(n);
if (s == null)
{
yield break;
}
yield return s;
n++;
}
}
}
}
}