MVH/NAudio-2.2.1/NAudio.Extras/CachedSoundSampleProvider.cs

27 lines
800 B
C#
Raw Normal View History

2024-06-07 00:47:07 +02:00
using System;
using NAudio.Wave;
namespace NAudio.Extras
{
class CachedSoundSampleProvider : ISampleProvider
{
private readonly CachedSound cachedSound;
private long position;
public CachedSoundSampleProvider(CachedSound cachedSound)
{
this.cachedSound = cachedSound;
}
public int Read(float[] buffer, int offset, int count)
{
var availableSamples = cachedSound.AudioData.Length - position;
var samplesToCopy = Math.Min(availableSamples, count);
Array.Copy(cachedSound.AudioData, position, buffer, offset, samplesToCopy);
position += samplesToCopy;
return (int)samplesToCopy;
}
public WaveFormat WaveFormat => cachedSound.WaveFormat;
}
}