2011-05-31 48 views
0

我目前正在使用directsound錄製音頻的浮點數組。SlimDX錄製(確定)然後播放(問題!)

現在我想用XAudio2(SlimDX也可以)播放該浮點數組,但我不確定該做什麼,因爲來自SlimDX的示例示例播放了一個.wav文件。

這裏是他們是如何做到這一點:

 XAudio2 device = new XAudio2(); 
     MasteringVoice masteringVoice = new MasteringVoice(device); 

     var s = System.IO.File.OpenRead(fileName); 
     WaveStream stream = new WaveStream(s); 
     s.Close(); 

     AudioBuffer buffer = new AudioBuffer(); 
     buffer.AudioData = stream; 
     buffer.AudioBytes = (int)stream.Length; 
     buffer.Flags = BufferFlags.EndOfStream; 

     SourceVoice sourceVoice = new SourceVoice(device, stream.Format); 
     sourceVoice.SubmitSourceBuffer(buffer); 
     sourceVoice.Start(); 

     // loop until the sound is done playing 
     while (sourceVoice.State.BuffersQueued > 0) 
     { 
      if (GetAsyncKeyState(VK_ESCAPE) != 0) 
       break; 

      Thread.Sleep(10); 
     } 

     // wait until the escape key is released 
     while (GetAsyncKeyState(VK_ESCAPE) != 0) 
      Thread.Sleep(10); 

     // cleanup the voice 
     buffer.Dispose(); 
     sourceVoice.Dispose(); 
     stream.Dispose(); 

基本上,我想知道的是如何發揮使用slimDX float數組?

在此先感謝

回答

0

我不是音頻的東西的專家,但我知道,你可以創建IeeeFloat的WAVEFORMAT。填寫所有其他信息,然後將數據寫入DataStream並將其提供給AudioBuffer。然後,您可以調用正常提交。