2009-08-29 2 views
1

VS 2008 SlimDX 2009年3月はSlimDX

を使用してマイクからの音声入力をキャプチャ私は、入力された音声をキャプチャし、プログレスバーに表示しSlimDXを使用しています。バックグラウンドスレッドでキャプチャを行い、進行状況バーを更新するバックグラウンドワーカーがいます。

しかし、私はプログレスバーを更新するための値として何を使うべきかの問題に遭遇しています。

すべて正常に動作し、キャプチャが開始されます。ただし、プログレスバーを更新しようとすると、アプリケーションが失敗します。

EDIT ==== DoWorkで自分のコードを編集しました。今回はInt16を使用して丸数字を与えます。しかし、私が直面している問題は、バッファがオーバーランすることです。それはとにかくサーキュラーバッファーを作成すると、それが終わりになると再び開始されます。

提案がありますか?

多くのおかげで、

private DirectSoundCapture soundCapture; 
     private WaveFormat wavFormat; 
     private CaptureBufferDescription captureBufDescription; 
     private CaptureBuffer captureBuff; 

     // stopCapturing - flag to stop capturing 
     bool stopCapturing = false; 

     private void AudioCapture_Load(object sender, EventArgs e) 
     { 
      this.FillProperties(); 
     } 

     // Fill wave format properties 
     private void FillProperties() 
     { 
      // Declare a wave audio format to use in getting the input. 
      soundCapture = new DirectSoundCapture(); 

      // Wave Format 
      wavFormat = new WaveFormat(); 
      // 
      wavFormat.FormatTag = SlimDX.WaveFormatTag.IeeeFloat; 
      wavFormat.BitsPerSample = 32; 
      wavFormat.BlockAlignment = (short)(wavFormat.BitsPerSample/8); 
      wavFormat.Channels = 1; 
      wavFormat.SamplesPerSecond = 44100; 
      wavFormat.AverageBytesPerSecond = 
       wavFormat.SamplesPerSecond * wavFormat.BlockAlignment * wavFormat.Channels; 

      // Capture buffer description 
      captureBufDescription = new CaptureBufferDescription(); 
      // 
      captureBufDescription.ControlEffects = true; 
      captureBufDescription.WaveMapped = true; 
      captureBufDescription.BufferBytes = 8192; 
      captureBufDescription.Format = wavFormat; 

      captureBuff = new CaptureBuffer(soundCapture, captureBufDescription); 
     } 

     // Run capture in background thread to keep the form active 
     private void bgwAudioInput_DoWork(object sender, DoWorkEventArgs e) 
     { 
     Int16[] samples = new Int16[8192/sizeof(Int16)]; 
     Int16 audioValue = 0; 
     int i = 0; 

     captureBuff.Start(true); 

     while (captureAudio) 
     { 
      if (!this.bgwAudioInput.CancellationPending) 
      { 
       captureBuff.Read(samples, 0, true); 
       audioValue = Math.Abs(samples[captureBuff.CurrentReadPosition]); 
       this.bgwAudioInput.ReportProgress(audioValue); 
      } 
     } 
     } 

     // Start capturing the input audio from the microphone 
     private void btnStart_Click(object sender, EventArgs e) 
     { 
      btnStart.Enabled = false; 
      btnStop.Enabled = true; 

      this.bgwAudioInput.RunWorkerAsync(); 
     } 

     private void btnStop_Click(object sender, EventArgs e) 
     { 
      captureBuff.Stop(); 
      // Exit while loop 
      this.bgwAudioInput.CancelAsync(); 
      stopCapturing = false; 

      btnStop.Enabled = false; 
      btnStart.Enabled = true; 
     } 

答えて

0

は、多分あなたを助けるために起こっている、this exampleを見てください。

関連する問題