예제 #1
0
 /// <summary>
 /// The Microphone.BufferReady event handler.
 /// Gets the audio data from the microphone and stores it in a buffer,
 /// then writes that buffer to a stream for later playback.
 /// Any action in this event handler should be quick!
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void microphone_BufferReady(object sender, EventArgs e)
 {
     double db = 0.0;
     //// Store the audio data in a stream
     //stream.Write(buffer, 0, buffer.Length);
     uint min = FreqAnalyzer.GetLowerPowerOfTwo((uint)this.microphone.GetData(this.buffer));
     double[] input = new double[min / 2];
     short[] numArray2 = new short[min / 2];
     Buffer.BlockCopy(this.buffer, 0, numArray2, 0, (int)(min / 2));
     int num3 = 0;
     short[] numArray3 = numArray2;
     for (int i = 0; i < numArray3.Length; i++)
     {
         float num4 = numArray3[i];
         input[num3++] = num4;
     }
     Complex[] complexArray = FreqAnalyzer.FFT(input, true);
     double num5 = 0.0;
     for (int j = 0; j < complexArray.Length; j++)
     {
         num5 += 20.0 * Math.Log10(Math.Abs(complexArray[j].ToModul()));
     }
     if (num5 >= 0.0)
     {
         db = num5 / ((double)complexArray.Length);
         if (db <= 200.0)
         {
             if (this.dbmax < db)
             {
                 this.dbmax = db;
                 this.txtDB.Text = this.dbmax.ToString("f2");
             }
             if (this.dbmin > db)
             {
                 this.dbmin = db;
                 this.txtDB.Text = this.dbmin.ToString("f2");
             }
             this.txtDB.Text = string.Format("{0} ", db.ToString("f2"));
         }
     }
     App.CurrentDecibel = db;
 }
예제 #2
0
        private void SetupBeepPlayer()
        {
            beepPlayer.FinishedPlaying += (s, e) =>
            {
                beepPlayer.Stop();
                buttonPlay.Text      = "Play";
                labelTitle.ForeColor = titleColor;
                note = 0;
                textBoxSequence.Select(0, 0);
            };

            beepPlayer.NotePlaying += (s, e) =>
            {
                NumberRange  range = FreqAnalyzer.GetFreqRangeFromNotes(beepPlayer.Notes);
                FreqAnalyzer FA    = new FreqAnalyzer(titleColor, e.Frequency, range);
                Color        color = FA.GetNewColor();
                labelTitle.ForeColor = color;
                textBoxSequence.SelectNote(note++);
            };
        }
예제 #3
0
        private void microphone_BufferReady(object sender, EventArgs e)
        {
            uint lowerPowerOfTwo = FreqAnalyzer.GetLowerPowerOfTwo(this.microphone.GetData(this.buffer));

            double[] input     = new double[lowerPowerOfTwo / 2];
            short[]  numArray2 = new short[lowerPowerOfTwo / 2];
            Buffer.BlockCopy(this.buffer, 0, numArray2, 0, lowerPowerOfTwo / 2);
            int num3 = 0;

            short[] numArray3 = numArray2;
            for (int i = 0; i < numArray3.Length; i++)
            {
                float num4 = numArray3[i];
                input[num3++] = num4;
            }
            Complex[] complexArray = FreqAnalyzer.FFT(input, true);
            double    num5         = 0.0;

            for (int j = 0; j < complexArray.Length; j++)
            {
                num5 += 20.0 * Math.Log10(Math.Abs(complexArray[j].ToModul()));
            }
            if (num5 >= 0.0)
            {
                double num7 = num5 / ((double)complexArray.Length);
                if (num7 <= 200.0)
                {
                    if (this.max_DB < num7)
                    {
                        this.max_DB = num7;
                        this.TB_MAXDB.set_Text(this.max_DB.ToString("f1"));
                    }
                    if (this.min_DB > num7)
                    {
                        this.min_DB = num7;
                        this.TB_MINDB.set_Text(this.min_DB.ToString("f1"));
                    }
                    this.TB_DB.set_Text(string.Format("{0} ", num7.ToString("f1")));
                }
            }
        }