Closed Patresko closed 1 year ago
What you observed is what you should expect to see in this example, yes.
You can see that averagePower(forChannel:) returns values in dBFS, between -160dBFS and 0 (being maximum loudness that can be represented). The formula translates that decibel value back to an amplitude between (0...1)
. See wikipedia or this article for instance which is a less mathematical.
If you'd like different scaling, you may map the dB value to (0...1) in any other way you may prefer, eg by dividing by -160 or similar.
I take this one from an example
1 - pow(10, recorder.averagePower(forChannel: 0) / 20)
But this giving very strange results in real scenarions. I have tried muted mic and I was receiving averagePower -120 and amplitude 0.999999.
When I unmuted mic, my level was between -30 to -50 but difference in amplitude was too small to see any difference in waves.
Few logs from console
Adjusted value is from the function above. Mic power is recorder.averagePower
In my code