Exemplo n.º 1
0
        /// <summary>
        /// LevelMeterユーザーコントロールの設定がユーザー操作によって変更されたとき呼び出される。
        /// </summary>
        private void LevelMeterUCParamChanged(
            int peakHoldSeconds, int yellowLevelDb, int releaseTimeDbPerSec, bool meterReset)
        {
            mPref.PeakHoldSeconds     = peakHoldSeconds;
            mPref.YellowLevelDb       = yellowLevelDb;
            mPref.ReleaseTimeDbPerSec = releaseTimeDbPerSec;

            lock (mLock) {
                mLevelMeter = new LevelMeter(mPref.RecSampleFormat, mPref.NumOfChannels, mPref.PeakHoldSeconds,
                                             mPref.RecWasapiBufferSizeMS * 0.001, mPref.ReleaseTimeDbPerSec);
            }
        }
Exemplo n.º 2
0
        public MixerMaster(MixerWindow _mixer)
        {
            mixerWindow = _mixer;
            project     = mixerWindow.project;
            InitializeComponent();
            chkLock.Checked = true;
            fadersAreLocked = true;

            leftMeter          = new LevelMeter(this);
            leftMeter.Location = new Point(45, 26);
            this.Controls.Add(leftMeter);
            leftMeter.BringToFront();

            rightMeter          = new LevelMeter(this);
            rightMeter.Location = new Point(80, 26);
            rightMeter.BringToFront();
            this.Controls.Add(rightMeter);
        }
Exemplo n.º 3
0
        private void BwStartTesting_DoWork(object sender, DoWorkEventArgs e)
        {
            //Console.WriteLine("BwStartTesting_DoWork()");
            var args = e.Argument as StartTestingArgs;
            var r    = new StartTestingResult();

            r.result = false;
            r.text   = "StartTesting failed!\n";
            e.Result = r;

            PreparePcmData(args);

            System.GC.Collect();

            lock (mLock) {
                int hr = 0;

                // 録音
                mCapturedBytes = 0;
                mReceivedBytes = 0;

                mLevelMeter = new LevelMeter(mPref.RecSampleFormat, args.numChannels, mPref.PeakHoldSeconds,
                                             mPref.RecWasapiBufferSizeMS * 0.001, mPref.ReleaseTimeDbPerSec);

                hr = mWasapiRec.Setup(mRecDeviceIdx,
                                      WasapiCS.DeviceType.Rec, WasapiCS.StreamType.PCM,
                                      mPref.SampleRate, mPref.RecSampleFormat, args.numChannels, args.recDwChannelMask,
                                      WasapiCS.MMCSSCallType.Enable, WasapiCS.MMThreadPriorityType.None,
                                      WasapiCS.SchedulerTaskType.ProAudio, WasapiCS.ShareMode.Exclusive,
                                      mPref.RecDataFeedMode, mPref.RecWasapiBufferSizeMS, ZERO_FLUSH_MILLISEC, TIME_PERIOD, true);
                if (hr < 0)
                {
                    r.result = false;
                    r.text   = string.Format(Properties.Resources.msgRecSetupError,
                                             mPref.SampleRate, mPref.RecSampleFormat, args.numChannels, mPref.RecDataFeedMode,
                                             mPref.RecWasapiBufferSizeMS, WasapiCS.GetErrorMessage(hr)) + "\n";
                    e.Result = r;
                    StopUnsetup();
                    return;
                }

                // 再生

                hr = mWasapiPlay.Setup(mPlayDeviceIdx,
                                       WasapiCS.DeviceType.Play, WasapiCS.StreamType.PCM,
                                       mPref.SampleRate, mPref.PlaySampleFormat, args.numChannels, args.playDwChannelMask,
                                       WasapiCS.MMCSSCallType.Enable, WasapiCS.MMThreadPriorityType.None,
                                       WasapiCS.SchedulerTaskType.ProAudio, WasapiCS.ShareMode.Exclusive,
                                       mPref.PlayDataFeedMode, mPref.PlayWasapiBufferSizeMS, ZERO_FLUSH_MILLISEC, TIME_PERIOD, true);
                if (hr < 0)
                {
                    mWasapiPlay.Unsetup();
                    r.result = false;
                    r.text   = string.Format(Properties.Resources.msgPlaySetupError,
                                             mPref.SampleRate, mPref.PlaySampleFormat, args.numChannels,
                                             mPref.PlayDataFeedMode, mPref.PlayWasapiBufferSizeMS) + "\n";
                    e.Result = r;
                    return;
                }

                var ss = mWasapiPlay.GetSessionStatus();

                mWasapiPlay.ClearPlayList();
                mWasapiPlay.AddPlayPcmDataStart();
                mWasapiPlay.AddPlayPcmData(0, mPcmPlay.GetSampleLargeArray());
                mWasapiPlay.AddPlayPcmDataEnd();

                mWasapiPlay.SetPlayRepeat(true);

                var playAttr = mWasapiPlay.GetDeviceAttributes(mPlayDeviceIdx);
                var recAttr  = mWasapiRec.GetDeviceAttributes(mRecDeviceIdx);

                r.result = true;
                r.text   = string.Format(Properties.Resources.msgTestStarted, mPref.SampleRate,
                                         mPcmPlay.NumFrames / mPref.SampleRate, mPcmPlay.NumFrames * 0.001 * 0.001);
                r.text += string.Format(Properties.Resources.msgPlaySettings,
                                        mPref.PlaySampleFormat, mPref.PlayWasapiBufferSizeMS,
                                        mPref.PlayDataFeedMode, playAttr.Name);
                r.text += string.Format(Properties.Resources.msgRecSettings,
                                        mPref.RecSampleFormat, mPref.RecWasapiBufferSizeMS,
                                        mPref.RecDataFeedMode, recAttr.Name);
                e.Result = r;
            }
        }
Exemplo n.º 4
0
        private void buttonSelectDevice_Click(object sender, RoutedEventArgs e)
        {
            if (DeviceSetup() < 0)
            {
                return;
            }

            mLevelMeter = new LevelMeter(mPref.SampleFormat, mPref.NumOfChannels, mPref.PeakHoldSeconds,
                                         mPref.WasapiBufferSizeMS * 0.001, mPref.ReleaseTimeDbPerSec);
            mWasapiCtrl.SetCaptureCallback(ControlCaptureCallback);
            mWasapiCtrl.StorePcm(false);

            int hr = mWasapiCtrl.StartRecording();

            if (hr < 0)
            {
                MessageBox.Show(string.Format("Select device failed! 0x{0:X8}", hr));
                return;
            }

            buttonSelectDevice.IsEnabled     = false;
            buttonDeselectDevice.IsEnabled   = true;
            buttonRec.IsEnabled              = true;
            buttonStop.IsEnabled             = false;
            buttonInspectDevice.IsEnabled    = false;
            groupBoxWasapiSettings.IsEnabled = false;

            var volumeParams = mWasapiCtrl.GetVolumeParams();

            sliderMasterVolume.Minimum = volumeParams.levelMinDB;
            sliderMasterVolume.Maximum = volumeParams.levelMaxDB;
            var tickMarks = new DoubleCollection();

            for (int i = 0; i < (volumeParams.levelMaxDB - volumeParams.levelMinDB) / volumeParams.volumeIncrementDB; ++i)
            {
                tickMarks.Add(volumeParams.levelMinDB + (double)i * volumeParams.volumeIncrementDB);
            }
            sliderMasterVolume.Ticks = tickMarks;
            sliderMasterVolume.IsSnapToTickEnabled = true;
            sliderMasterVolume.Value     = volumeParams.defaultLevel;
            sliderMasterVolume.IsEnabled = true;
            labelRecordingVolume.Content = string.Format("{0} dB", sliderMasterVolume.Value);
            mWasapiCtrl.SetEndpointMasterVolume((float)sliderMasterVolume.Value);

            if ((volumeParams.hardwareSupport & 1) == 1)
            {
                AddLog("This device supports hardware volume control.\r\n");
            }
            else
            {
                AddLog("This device does not support hardware volume control.\r\n");
            }

            mLevelMeterUC.UpdateNumOfChannels(mPref.NumOfChannels);

            mBW = new BackgroundWorker();
            mBW.WorkerReportsProgress = true;
            mBW.DoWork             += new DoWorkEventHandler(DoWork);
            mBW.ProgressChanged    += new ProgressChangedEventHandler(ProgressChanged);
            mBW.RunWorkerCompleted += new RunWorkerCompletedEventHandler(RunWorkerCompleted);
            mBW.RunWorkerAsync();
        }