3

I have been searching for answers for a long time now but every solution I get seems too complex for what I want to do or perhaps there is no "easier" way of doing it..

What I want to do is simply use my system microphone to get the volume or loudness (or whatever it is called) in the room. Then according to that volume, I want to adjust my system volume so that the sound from my system always "sounds the same" (the same loudness), no matter if a train passes by or an airplane flies over.

How do I get this loudness or volume in my room into a C# application to use that to change my system volume?

I am using C# and a laptop with a built in microphone.

Kelper
  • 31
  • 5

1 Answers1

1
  1. It is better to use library to read the input from microphone. NAudio is probably the best one.

  2. Calibrate input with determining microphone gain. [@MSalters Comment used]

  3. Every second iterate over the waveform recorded in memory, then: square the amplitude (to get an energy), average the squared values and take the square root of that. (Or the log, to convert to dB) [@MSalters Comment used]

  4. Depending on it, set system volume with WinAPI.

Community
  • 1
  • 1
Ilya Tereschuk
  • 1,204
  • 1
  • 9
  • 21
  • 2
    You're missing one critical step; determine the microphone gain. Just like speakers, microphones have a gain factor too. Also, calculating the "average amplitude" is numerically incorrect. You need to square the amplitude (to get an energy), average the squared values and take the square root of that. (Or the log, to convert to dB) – MSalters Jan 06 '14 at 09:02
  • @MSalters Thanks, I'm quite not familiar with calculating these dependencies. I'll edit my answer with your comment. – Ilya Tereschuk Jan 06 '14 at 09:04
  • Sorry for the necromancy :) But could someone explain exactly how to do the calibration and calculation? See my question here : https://stackoverflow.com/questions/63299441/how-to-calibrate-a-tablet-microphone-for-displaying-actual-db-according-to-db-me – Tim Bijnens Aug 14 '20 at 10:33