Пример #1
0
        private void DoWork(object o, DoWorkEventArgs args)
        {
            Console.WriteLine("DoWork started\n");

            int count = 0;

            while (!asio.Run())
            {
                ++count;
                Console.WriteLine("\nForm1.DoWork() count={0} m_seconds={1}", count, m_seconds);
                int percent = 100 * count / m_seconds;
                if (100 < percent)
                {
                    percent = 100;
                }
            }
            int[] recordedData     = asio.RecordedDataGet(m_inputChannelNum, m_seconds * SAMPLE_RATE);
            PcmSamples1Channel ch0 = new PcmSamples1Channel(m_seconds * SAMPLE_RATE, 16);
            int max = 0;
            int min = 0;

            for (int i = 0; i < recordedData.Length; ++i)
            {
                if (max < recordedData[i])
                {
                    max = recordedData[i];
                }
                if (recordedData[i] < min)
                {
                    min = recordedData[i];
                }
            }
            Console.WriteLine("max={0} min={1}", max, min);

            if (max < -min)
            {
                max = -min;
            }
            double mag = 32767.0 / max;

            Console.WriteLine("mag={0}", mag);

            for (int i = 0; i < recordedData.Length; ++i)
            {
                ch0.Set16(i, (short)(recordedData[i] * mag));
            }

            List <PcmSamples1Channel> chList = new List <PcmSamples1Channel>();

            chList.Add(ch0);

            WavData wd = new WavData();

            wd.Create(SAMPLE_RATE, 16, chList);
            using (BinaryWriter bw = new BinaryWriter(File.Open(m_writeFilePath, FileMode.Create))) {
                wd.Write(bw);
            }

            args.Result = 0;
            Console.WriteLine("DoWork end\n");
        }