12345678910111213141516171819202122232425262728293031323334353637383940 |
- 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<VisualizeDataEventArgs>? 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<byte>(buffer, 0, read)));
- return read;
- }
- catch //(Exception e)
- {
- if (provider.Position < provider.Length)
- {
- //TODO: 消息机制 错误 流读取中断
- }
- return 0;
- }
- }
- }
|