1

VS 2008 SlimDX 2009 年 3 月

SlimDX を使用して入力オーディオをキャプチャし、プログレス バーに表示しています。バックグラウンドスレッドでキャプチャを行い、進行状況バーを更新するバックグラウンドワーカーがあります。

ただし、プログレスバーを更新する値として何を使用するかという問題に直面しています。

すべてが正常に機能し、キャプチャが開始されます。ただし、進行状況バーを更新しようとすると、アプリケーションは失敗します。

編集 ==== 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;
        }
4

1 に答える 1

0

この例を見てください。多分それはあなたを助けるでしょう.

于 2010-11-24T13:16:26.980 に答える