using Bmp.Core.Lite.Playback.Inputs; using Bmp.Core.Lite.Playback.Outputs.NAudioASIO.Originals; using NAudio.Wave; namespace Bmp.Core.Lite.Playback.MiddleWare; public class VisualizeDataMiddleWare(WaveStream provider) : IWaveProvider, IHaveBitPerRawSample, IHaveAsioSampleFormat { public event EventHandler? DataTransferred; protected virtual void OnDataTransferred(VisualizeDataEventArgs e) { DataTransferred?.Invoke(this, e); } public int? BitPerRawSample => provider is IHaveBitPerRawSample bpr ? bpr.BitPerRawSample : null; public AsioSampleType? AsioSampleFormat => provider is IHaveAsioSampleFormat asf ? asf.AsioSampleFormat : null; public WaveFormat WaveFormat => provider.WaveFormat; public int Read(byte[] buffer, int offset, int count) { try { var read = provider.Read(buffer, offset, count); OnDataTransferred(new VisualizeDataEventArgs(WaveFormat, new ReadOnlyMemory(buffer, 0, read))); return read; } catch //(Exception e) { if (provider.Position < provider.Length) { //TODO: 消息机制 错误 流读取中断 } return 0; } } }