NAudio
NAudio copied to clipboard
Added CachedSound constructor for playing resource wav files
Added CachedSound constructor for playing resource wav files I played the wav file of Properties.Resource using the following source code:
public CachedSound(Stream sound)
{
using (var audioFileReader = new WaveFileReader(sound))
{
WaveFormat = audioFileReader.WaveFormat;
var sp = audioFileReader.ToSampleProvider();
var wholeFile = new List<float>((int)(audioFileReader.Length / 4));
var sourceSamples = (int)(audioFileReader.Length / (audioFileReader.WaveFormat.BitsPerSample / 8));
var sampleData = new float[sourceSamples];
int samplesread;
while ((samplesread = sp.Read(sampleData, 0, sourceSamples)) > 0)
{
wholeFile.AddRange(sampleData.Take(samplesread));
}
AudioData = wholeFile.ToArray();
}
}
"using System.IO;" Is missing. I fixed this error.
I think it's not good write to a list, it's better to write to a buffer(array) with some offset.
I think it's not good write to a list, it's better to write to a buffer(array) with some offset.
I create it based on public CachedSound(string audiofilename) in CachedSound.cs.
Since lists are used in the source code, I also used lists.
Why are arrays better than lists?
I needed this change as well, so I adapted it for the new layout in pull request #963.