示例#1
0
        // 1 oct 22.5Hz to approx. 20000Hz ... 10 variations

        public bool Start()
        {
            m_inputChannelNum = listBoxInput.SelectedIndex;

            double startFreq = 22.5;
            double endFreq   = 20000.0;
            int    nSamples  = SAMPLE_RATE;

            System.Diagnostics.Debug.Assert(SAMPLE_RATE <= nSamples);

            int nFreq = 0;

            for (double f = startFreq; f < endFreq; f *= Math.Pow(2, 1.0 / 3.0))
            {
                ++nFreq;
            }
            m_seconds = nFreq;

            int[] outputData = new int[nFreq * nSamples];
            int   pos        = 0;

            for (double f = startFreq; f < endFreq; f *= Math.Pow(2, 1.0 / 3.0))
            {
                for (int i = 0; i < nSamples; ++i)
                {
                    outputData[pos + i] = 0;
                }

                for (int i = 0; i < SAMPLE_RATE * (int)numericUpDownPulseCount.Value / f; ++i)
                {
                    outputData[pos + i] = (int)(System.Int32.MaxValue * Math.Sin(2.0 * Math.PI * (i * f / SAMPLE_RATE)));
                }
                pos += nSamples;
            }
            foreach (int idx in listBoxOutput.SelectedIndices)
            {
                asio.OutputSet(idx, outputData, false);
            }
            asio.InputSet(listBoxInput.SelectedIndex, outputData.Length);

            if (0 <= listBoxClockSources.SelectedIndex)
            {
                asio.ClockSourceSet(listBoxClockSources.SelectedIndex);
            }

            asio.Start();

            progressBar1.Value   = 0;
            progressBar1.Visible = true;

            bw = new BackgroundWorker();
            bw.WorkerReportsProgress = true;
            bw.DoWork             += new DoWorkEventHandler(DoWork);
            bw.ProgressChanged    += new ProgressChangedEventHandler(ProgressChanged);
            bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(RunWorkerCompleted);
            bw.RunWorkerAsync();
            buttonStop.Enabled = true;
            return(true);
        }
示例#2
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            SignalGeneraterWorkerArg sgwa = (SignalGeneraterWorkerArg)e.Argument;
            SignalGenerator          sg   = new SignalGenerator();

            backgroundWorker1.ReportProgress(1, "出力データの準備開始。\r\n");

            WavData wavData;
            SignalGeneratorResult cwdr
                = sg.GenerateSignal(sgwa.sgParams, out wavData);

            switch (cwdr)
            {
            case SignalGeneratorResult.Success:
                backgroundWorker1.ReportProgress(2, "出力データの準備完了。\r\n");
                break;

            case SignalGeneratorResult.LevelOver:
                backgroundWorker1.ReportProgress(2, "レベルオーバー。出力レベルを下げて下さい。\r\n");
                break;

            default:
                System.Diagnostics.Debug.Assert(false);
                break;
            }

            switch (sgwa.outputMode)
            {
            case OutputMode.WavFile:
                if (!WriteWavFile(wavData, sgwa.outputPath))
                {
                    backgroundWorker1.ReportProgress(3, string.Format("書き込み失敗: {0}\r\n", sgwa.outputPath));
                    return;
                }
                backgroundWorker1.ReportProgress(3, string.Format("書き込み成功: {0}\r\n", sgwa.outputPath));
                break;

            case OutputMode.Asio:
            {
                // short → int に拡張
                int[] asioData = new int[wavData.NumSamples];
                for (int i = 0; i < wavData.NumSamples; ++i)
                {
                    asioData[i] = wavData.Sample16Get(0, i) << 16;
                }
                // 出力デバイスに出力データをセット
                foreach (int ch in sgwa.outputChannels)
                {
                    asio.OutputSet(ch, asioData, true);
                }
                // 開始
                asio.Start();

                /* backgroundWorker1.ReportProgress(3,
                 *  string.Format("出力開始。{0}Hz {1} {2}dB\r\n", sgwa.sgParams.freq, sgwa.sgParams.ss, sgwa.sgParams.dB)); */
                while (!asio.Run())
                {
                }
                backgroundWorker1.ReportProgress(3, "出力終了。\r\n");
            }
            break;

            default:
                System.Diagnostics.Debug.Assert(false);
                break;
            }
        }