-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSineWaveProvider.cs
More file actions
39 lines (35 loc) · 1.25 KB
/
SineWaveProvider.cs
File metadata and controls
39 lines (35 loc) · 1.25 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LocalisedSoundSources
{
public class SineWaveProvider32 : WaveProvider32
{
int sample;
public SineWaveProvider32()
{
Frequency = 1000;
Amplitude = 0.25f; // let's not hurt our ears
}
public float Frequency { get; set; }
public float Amplitude { get; set; }
public override int Read(float[] buffer, int offset, int sampleCount)
{
int sampleRate = WaveFormat.SampleRate;
for (int n = 0; n < sampleCount; n = n + this.WaveFormat.Channels)
{
//for (int channels = 0; channels < this.WaveFormat.Channels; channels++)
//{
// buffer[n + offset + channels] = (float)(Amplitude * Math.Sin((2 * Math.PI * sample * Frequency) / sampleRate));
//}
buffer[n + offset] = (float)(Amplitude * Math.Sin((2 * Math.PI * sample * Frequency) / sampleRate));
buffer[n + offset + 1] = 0f;
sample++;
if (sample >= sampleRate) sample = 0;
}
return sampleCount;
}
}
}