This project has moved and is read-only. For the latest updates, please go here.

Record audio using microphone

Apr 1, 2015 at 1:32 AM

I would like to create an application to record the sound using a microphone.
In my application, when the microphone receive the sound, the label will show the value of amplitude.
I read the discussion here to get some idea to create my application.

However, I don't understand about some point.
Below are the codes that I got from the link:
private bool ProcessData(WaveInEventArgs e)
    bool result = false;

    bool Tr = false;
    double Sum2 = 0;
    int Count = e.BytesRecorded / 2;
    for (int index = 0; index < e.BytesRecorded; index += 2)
        double Tmp = (short)((e.Buffer[index + 1] << 8) | e.Buffer[index + 0]);
        Tmp /= 32768.0;
        Sum2 += Tmp * Tmp;
        if (Tmp > AudioThresh)
            Tr = true;
    Sum2 /= Count;  
May I know,
  1. Is it true the sample in 16bits?
  2. What is the value of Sum2 refer to? is it the value is refer to the amplitude of the sine wave of the audio?
  3. Why we need to multiply with (Tmp*Tmp)?
I need some advice about this matter.

Thank you.
Apr 13, 2015 at 5:16 PM
  1. Not necessarily, but if you're using WaveIn, 16 bit is the default
  2. It's the sum of squares -
  3. It's a simply way of getting all positive values (because samples can go negative).