OneShotProvider.cs 804 B

1234567891011121314151617181920212223242526
  1. using NAudio.Wave;
  2. namespace Client.MirSounds.Libraries
  3. {
  4. class OneShotProvider : ISampleProvider
  5. {
  6. private readonly CachedSound cachedSound;
  7. private long position;
  8. public OneShotProvider(CachedSound cachedSound)
  9. {
  10. this.cachedSound = cachedSound;
  11. }
  12. public int Read(float[] buffer, int offset, int count)
  13. {
  14. var availableSamples = cachedSound.AudioData.Length - position;
  15. var samplesToCopy = Math.Min(availableSamples, count);
  16. Array.Copy(cachedSound.AudioData, position, buffer, offset, samplesToCopy);
  17. position += samplesToCopy;
  18. return (int)samplesToCopy;
  19. }
  20. public WaveFormat WaveFormat { get { return cachedSound.WaveFormat; } }
  21. }
  22. }