如何使用NAudio同时播放来自麦克风和WAV的实时声音?

时间:2018-07-22 16:37:36

标签: c# naudio asio

我在C#项目中使用NAudio。我正在尝试使用ASIO驱动程序同时播放WAV和现场麦克风声音。问题在于,它不会一起播放,只能是麦克风回送或WAV。

这是我的代码:

asioOut = new AsioOut();
List<ISampleProvider> sampleProviders = new List<ISampleProvider>();
foreach(Track track in tracks)
  {
    OffsetSampleProvider OffsetProvider;
    if (track.MinusTrack) {
      var mono = new StereoToMonoSampleProvider(new AudioFileReader(track.pathToFile));
      mono.LeftVolume = 0.5f;
      OffsetProvider = new OffsetSampleProvider(mono);
    } else {
      AudioFileReader waveFileReader = new AudioFileReader(track.pathToFile);
      OffsetProvider = new OffsetSampleProvider(waveFileReader);
    }
    double delayTo = startValue + track.startLength;
    if (delayTo < 0) {
      OffsetProvider.SkipOver = TimeSpan.FromMilliseconds(-10 * delayTo);
    } else {
      OffsetProvider.DelayBy = TimeSpan.FromMilliseconds(10 * delayTo);
    }
    sampleProviders.Add(OffsetProvider);
 }         
 int inputChannels = asioOut.DriverInputChannelCount;
 inputPatcher = new AsioInputPatcher(44100, inputChannels, 1);

 msp = new MixingSampleProvider(sampleProviders);
 msp.ReadFully = true;

 asioOut.InitRecordAndPlayback(msp.ToWaveProvider(),1, 0);

 asioOut.AudioAvailable += OnAsioOutAudioAvailable;

我做错了什么?还是不可能同时播放WAV和现场声音?

0 个答案:

没有答案