-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWaveProvider32.cs
More file actions
44 lines (37 loc) · 1.13 KB
/
WaveProvider32.cs
File metadata and controls
44 lines (37 loc) · 1.13 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
40
41
42
43
44
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NAudio.Wave;
namespace LocalisedSoundSources
{
public abstract class WaveProvider32 : IWaveProvider
{
protected WaveFormat waveFormat;
public WaveProvider32()
: this(44100, 1)
{
}
public WaveProvider32(int sampleRate, int channels)
{
SetWaveFormat(sampleRate, channels);
}
public void SetWaveFormat(int sampleRate, int channels)
{
this.waveFormat = WaveFormat.CreateIeeeFloatWaveFormat(sampleRate, channels);
}
public int Read(byte[] buffer, int offset, int count)
{
WaveBuffer waveBuffer = new WaveBuffer(buffer);
int samplesRequired = count / 4;
int samplesRead = Read(waveBuffer.FloatBuffer, offset / 4, samplesRequired);
return samplesRead * 4;
}
public abstract int Read(float[] buffer, int offset, int sampleCount);
public WaveFormat WaveFormat
{
get { return waveFormat; }
}
}
}