コード例 #1
0
 public void SetWasapiParams(int bufferSizeMillisec, int zeroFlushMillisec, WasapiCS.DataFeedMode dfm, WasapiCS.ShareMode sm)
 {
     mBufferSizeMillisec = bufferSizeMillisec;
     mZeroFlushMillisec  = zeroFlushMillisec;
     mDataFeedMode       = dfm;
     mShareMode          = sm;
 }
コード例 #2
0
        private static string DfmToStr(WasapiCS.DataFeedMode dfm)
        {
            switch (dfm)
            {
            case WasapiCS.DataFeedMode.EventDriven:
                return("イベント駆動モード");

            case WasapiCS.DataFeedMode.TimerDriven:
                return("タイマー駆動モード");

            default:
                System.Diagnostics.Debug.Assert(false);
                return("unknown");
            }
        }
コード例 #3
0
        public int Setup(int deviceIdx, WasapiCS.DataFeedMode dfm, int wasapiBufferSize,
                         int sampleRate, WasapiCS.SampleFormatType sampleFormatType,
                         int numChannels, int dwChannelMask)
        {
            int hr = mWasapi.Setup(deviceIdx, WasapiCS.DeviceType.Rec,
                                   WasapiCS.StreamType.PCM, sampleRate, sampleFormatType, numChannels, dwChannelMask,
                                   WasapiCS.MMCSSCallType.Enable, WasapiCS.MMThreadPriorityType.None,
                                   WasapiCS.SchedulerTaskType.ProAudio, WasapiCS.ShareMode.Exclusive, dfm, wasapiBufferSize, 0, 10000, true);

            mSampleFormat = sampleFormatType;
            mSampleRate   = sampleRate;
            mNumChannels  = numChannels;

            mDeviceInUse = true;

            return(hr);
        }
コード例 #4
0
        private bool UpdateTestParamsFromUI()
        {
            if (!Int32.TryParse(textBoxTestFrames.Text, out mNumTestFrames) || mNumTestFrames <= 0) {
                MessageBox.Show(Properties.Resources.msgPcmSizeError);
                return false;
            }
            if (0x7fffffff / 8 / 1024 / 1024 < mNumTestFrames) {
                MessageBox.Show(string.Format(Properties.Resources.msgPcmSizeTooLarge, 0x70000000 / 8 / 1024 / 1024));
                return false;
            }
            mNumTestFrames *= 1024 * 1024;

            if (radioButton44100.IsChecked == true) {
                mSampleRate = 44100;
            }
            if (radioButton48000.IsChecked == true) {
                mSampleRate = 48000;
            }
            if (radioButton88200.IsChecked == true) {
                mSampleRate = 88200;
            }
            if (radioButton96000.IsChecked == true) {
                mSampleRate = 96000;
            }
            if (radioButton176400.IsChecked == true) {
                mSampleRate = 176400;
            }
            if (radioButton192000.IsChecked == true) {
                mSampleRate = 192000;
            }

            if (radioButtonPlayPcm16.IsChecked == true) {
                mPlaySampleFormat = WasapiCS.SampleFormatType.Sint16;
            }
            if (radioButtonPlayPcm24.IsChecked == true) {
                mPlaySampleFormat = WasapiCS.SampleFormatType.Sint24;
            }
            if (radioButtonPlayPcm32v24.IsChecked == true) {
                mPlaySampleFormat = WasapiCS.SampleFormatType.Sint32V24;
            }

            if (radioButtonRecPcm16.IsChecked == true) {
                mRecSampleFormat = WasapiCS.SampleFormatType.Sint16;
            }
            if (radioButtonRecPcm24.IsChecked == true) {
                mRecSampleFormat = WasapiCS.SampleFormatType.Sint24;
            }
            if (radioButtonRecPcm32v24.IsChecked == true) {
                mRecSampleFormat = WasapiCS.SampleFormatType.Sint32V24;
            }

            if (radioButtonPlayEvent.IsChecked == true) {
                mPlayDataFeedMode = WasapiCS.DataFeedMode.EventDriven;
            }
            if (radioButtonPlayTimer.IsChecked == true) {
                mPlayDataFeedMode = WasapiCS.DataFeedMode.TimerDriven;
            }

            if (radioButtonRecEvent.IsChecked == true) {
                mRecDataFeedMode = WasapiCS.DataFeedMode.EventDriven;
            }
            if (radioButtonRecTimer.IsChecked == true) {
                mRecDataFeedMode = WasapiCS.DataFeedMode.TimerDriven;
            }

            if (!Int32.TryParse(textBoxPlayBufferSize.Text, out mPlayBufferMillisec)) {
                MessageBox.Show(Properties.Resources.msgPlayBufferSizeError);
                return false;
            }
            if (mPlayBufferMillisec <= 0 || 1000 <= mPlayBufferMillisec) {
                MessageBox.Show(Properties.Resources.msgPlayBufferSizeTooLarge);

            }
            if (!Int32.TryParse(textBoxRecBufferSize.Text, out mRecBufferMillisec)) {
                MessageBox.Show(Properties.Resources.msgRecBufferSizeError);
                return false;
            }
            if (mRecBufferMillisec <= 0 || 1000 <= mRecBufferMillisec) {
                MessageBox.Show(Properties.Resources.msgRecBufferSizeTooLarge);

            }
            return true;
        }
コード例 #5
0
        private bool UpdateTestParamsFromUI()
        {
            if (!Int32.TryParse(textBoxTestFrames.Text, out mNumTestFrames) || mNumTestFrames <= 0)
            {
                MessageBox.Show(Properties.Resources.msgPcmSizeError);
                return(false);
            }
            if (0x7fffffff / 8 / 1024 / 1024 < mNumTestFrames)
            {
                MessageBox.Show(string.Format(Properties.Resources.msgPcmSizeTooLarge, 0x70000000 / 8 / 1024 / 1024));
                return(false);
            }
            mNumTestFrames *= 1024 * 1024;

            if (radioButton44100.IsChecked == true)
            {
                mSampleRate = 44100;
            }
            if (radioButton48000.IsChecked == true)
            {
                mSampleRate = 48000;
            }
            if (radioButton88200.IsChecked == true)
            {
                mSampleRate = 88200;
            }
            if (radioButton96000.IsChecked == true)
            {
                mSampleRate = 96000;
            }
            if (radioButton176400.IsChecked == true)
            {
                mSampleRate = 176400;
            }
            if (radioButton192000.IsChecked == true)
            {
                mSampleRate = 192000;
            }

            if (radioButtonPlayPcm16.IsChecked == true)
            {
                mPlaySampleFormat = WasapiCS.SampleFormatType.Sint16;
            }
            if (radioButtonPlayPcm24.IsChecked == true)
            {
                mPlaySampleFormat = WasapiCS.SampleFormatType.Sint24;
            }
            if (radioButtonPlayPcm32v24.IsChecked == true)
            {
                mPlaySampleFormat = WasapiCS.SampleFormatType.Sint32V24;
            }

            if (radioButtonRecPcm16.IsChecked == true)
            {
                mRecSampleFormat = WasapiCS.SampleFormatType.Sint16;
            }
            if (radioButtonRecPcm24.IsChecked == true)
            {
                mRecSampleFormat = WasapiCS.SampleFormatType.Sint24;
            }
            if (radioButtonRecPcm32v24.IsChecked == true)
            {
                mRecSampleFormat = WasapiCS.SampleFormatType.Sint32V24;
            }

            if (radioButtonPlayEvent.IsChecked == true)
            {
                mPlayDataFeedMode = WasapiCS.DataFeedMode.EventDriven;
            }
            if (radioButtonPlayTimer.IsChecked == true)
            {
                mPlayDataFeedMode = WasapiCS.DataFeedMode.TimerDriven;
            }

            if (radioButtonRecEvent.IsChecked == true)
            {
                mRecDataFeedMode = WasapiCS.DataFeedMode.EventDriven;
            }
            if (radioButtonRecTimer.IsChecked == true)
            {
                mRecDataFeedMode = WasapiCS.DataFeedMode.TimerDriven;
            }

            if (!Int32.TryParse(textBoxPlayBufferSize.Text, out mPlayBufferMillisec))
            {
                MessageBox.Show(Properties.Resources.msgPlayBufferSizeError);
                return(false);
            }
            if (mPlayBufferMillisec <= 0 || 1000 <= mPlayBufferMillisec)
            {
                MessageBox.Show(Properties.Resources.msgPlayBufferSizeTooLarge);
            }
            if (!Int32.TryParse(textBoxRecBufferSize.Text, out mRecBufferMillisec))
            {
                MessageBox.Show(Properties.Resources.msgRecBufferSizeError);
                return(false);
            }
            if (mRecBufferMillisec <= 0 || 1000 <= mRecBufferMillisec)
            {
                MessageBox.Show(Properties.Resources.msgRecBufferSizeTooLarge);
            }
            return(true);
        }
コード例 #6
0
        private bool UpdateTestParamsFromUI()
        {
            mPlayDeviceIdx = listBoxPlayDevices.SelectedIndex;
            mRecDeviceIdx  = listBoxRecDevices.SelectedIndex;
            mUseFile       = radioButtonPcmFile.IsChecked == true;

            int testFramesMbytes = -1;

            if (!Int32.TryParse(textBoxTestFrames.Text, out testFramesMbytes) || testFramesMbytes <= 0)
            {
                MessageBox.Show(Properties.Resources.msgPcmSizeError);
                return(false);
            }
            mNumTestFrames = 1000L * 1000L * (long)testFramesMbytes;

            if (radioButton44100.IsChecked == true)
            {
                mSampleRate = 44100;
            }
            if (radioButton48000.IsChecked == true)
            {
                mSampleRate = 48000;
            }
            if (radioButton88200.IsChecked == true)
            {
                mSampleRate = 88200;
            }
            if (radioButton96000.IsChecked == true)
            {
                mSampleRate = 96000;
            }
            if (radioButton176400.IsChecked == true)
            {
                mSampleRate = 176400;
            }
            if (radioButton192000.IsChecked == true)
            {
                mSampleRate = 192000;
            }

            if (radioButtonPlayPcm16.IsChecked == true)
            {
                mPlaySampleFormat = WasapiCS.SampleFormatType.Sint16;
            }
            if (radioButtonPlayPcm24.IsChecked == true)
            {
                mPlaySampleFormat = WasapiCS.SampleFormatType.Sint24;
            }
            if (radioButtonPlayPcm32v24.IsChecked == true)
            {
                mPlaySampleFormat = WasapiCS.SampleFormatType.Sint32V24;
            }

            if (radioButtonRecPcm16.IsChecked == true)
            {
                mRecSampleFormat = WasapiCS.SampleFormatType.Sint16;
            }
            if (radioButtonRecPcm24.IsChecked == true)
            {
                mRecSampleFormat = WasapiCS.SampleFormatType.Sint24;
            }
            if (radioButtonRecPcm32v24.IsChecked == true)
            {
                mRecSampleFormat = WasapiCS.SampleFormatType.Sint32V24;
            }

            if (radioButtonPlayEvent.IsChecked == true)
            {
                mPlayDataFeedMode = WasapiCS.DataFeedMode.EventDriven;
            }
            if (radioButtonPlayTimer.IsChecked == true)
            {
                mPlayDataFeedMode = WasapiCS.DataFeedMode.TimerDriven;
            }

            if (radioButtonRecEvent.IsChecked == true)
            {
                mRecDataFeedMode = WasapiCS.DataFeedMode.EventDriven;
            }
            if (radioButtonRecTimer.IsChecked == true)
            {
                mRecDataFeedMode = WasapiCS.DataFeedMode.TimerDriven;
            }

            if (!Int32.TryParse(textBoxPlayBufferSize.Text, out mPlayBufferMillisec))
            {
                MessageBox.Show(Properties.Resources.msgPlayBufferSizeError);
                return(false);
            }
            if (mPlayBufferMillisec <= 0 || 1000 <= mPlayBufferMillisec)
            {
                MessageBox.Show(Properties.Resources.msgPlayBufferSizeTooLarge);
            }
            if (!Int32.TryParse(textBoxRecBufferSize.Text, out mRecBufferMillisec))
            {
                MessageBox.Show(Properties.Resources.msgRecBufferSizeError);
                return(false);
            }
            if (mRecBufferMillisec <= 0 || 1000 <= mRecBufferMillisec)
            {
                MessageBox.Show(Properties.Resources.msgRecBufferSizeTooLarge);
            }

            mRecDwChannelMask = 0;
            if (checkBoxRecSetDwChannelMask.IsChecked == true)
            {
                mRecDwChannelMask = WasapiCS.GetTypicalChannelMask(NUM_CHANNELS);
            }

            return(true);
        }
コード例 #7
0
        private void buttonDeviceSelect_Click(object sender, RoutedEventArgs e)
        {
            int latencyMillisec = -1;

            try {
                latencyMillisec = Int32.Parse(textBoxLatency.Text);
            } catch (Exception ex) {
                textBoxLog.Text += string.Format("{0}\r\n", ex);
            }
            if (latencyMillisec <= 0)
            {
                latencyMillisec     = DEFAULT_OUTPUT_LATENCY_MS;
                textBoxLatency.Text = string.Format("{0}", DEFAULT_OUTPUT_LATENCY_MS);
            }

            try {
                var bytes = Int32.Parse(textBoxRecMaxMB.Text) * 1024L * 1024L;
                if (0x7fffffff < bytes)
                {
                    string s = string.Format("E: 録音バッファーサイズを2047MB以下に減らして下さい。\r\n");
                    textBoxLog.Text += s;
                    MessageBox.Show(s);
                    return;
                }
                m_bufferBytes = (int)bytes;
            } catch (Exception ex) {
                textBoxLog.Text += string.Format("{0}\r\n", ex);
            }
            if (m_bufferBytes < 0)
            {
                m_bufferBytes        = DEFAULT_BUFFER_SIZE_MB * 1024 * 1024;
                textBoxRecMaxMB.Text = string.Format("{0}", DEFAULT_BUFFER_SIZE_MB);
            }
            try {
                mCapturedPcmData = null;
                mCapturedPcmData = new byte[m_bufferBytes];
            } catch (Exception ex) {
                textBoxLog.Text += string.Format("{0}\r\n", ex);
                MessageBox.Show(string.Format("E: おそらくメモリ不足ですので、録音バッファーサイズを減らして下さい。\r\n{0}", ex));
                return;
            }

            int hr = wasapi.ChooseDevice(listBoxDevices.SelectedIndex);

            textBoxLog.Text += string.Format("wasapi.ChooseDevice({0}) {1:X8}\r\n",
                                             listBoxDevices.SelectedItem.ToString(), hr);
            if (hr < 0)
            {
                return;
            }

            WasapiCS.DataFeedMode dfm = WasapiCS.DataFeedMode.EventDriven;
            if (true == radioButtonTimerDriven.IsChecked)
            {
                dfm = WasapiCS.DataFeedMode.TimerDriven;
            }

            wasapi.SetDataFeedMode(dfm);
            wasapi.SetLatencyMillisec(latencyMillisec);
            hr = wasapi.Setup(mSamplingFrequency, mSampleFormat, mNumChannels);
            textBoxLog.Text += string.Format("wasapi.Setup({0}, {1}, {2}, {3}) {4:X8}\r\n",
                                             mSamplingFrequency, mSampleFormat, latencyMillisec, dfm, hr);
            if (hr < 0)
            {
                wasapi.Unsetup();
                textBoxLog.Text += string.Format("wasapi.Unsetup()\r\n");
                CreateDeviceList();
                string sDfm = DfmToStr(dfm);
                string s    = string.Format("E: wasapi.Setup({0}, {1}, {2}, {3})失敗。{4:X8}\nこのプログラムのバグか、オーディオデバイスが{0}Hz {1} レイテンシー{2}ms {3}に対応していないのか、どちらかです。\r\n",
                                            mSamplingFrequency, mSampleFormat,
                                            latencyMillisec, sDfm, hr);
                textBoxLog.Text += s;
                MessageBox.Show(s);
                return;
            }

            buttonDeviceSelect.IsEnabled     = false;
            buttonDeselect.IsEnabled         = true;
            buttonRec.IsEnabled              = true;
            buttonInspectDevice.IsEnabled    = false;
            groupBoxWasapiSettings.IsEnabled = false;
        }