getTunerVolume() Not Returning Expected Values

I’ve seen some other threads about getTunerVolume() but I wanted to start a new one because I hope the information here is new and useful to Ansca and to other developers.

I have a VU meter on my app that always seems pegged at the top with any amount of sustained sound. I decided to set up a test app that records the values from getTunerVolume() and play into the mic white noise that starts silent and gets gradually louder. Here is the code for the test app.[code]local displayGroup = display.newGroup()

local r = media.newRecording()

local decibelText = display.newText( displayGroup, “00.000”, 180, 100, native.systemFontBold, 56 )
local updateStatus = function()

local v = r:getTunerVolume()
local t = system.getTimer()

local vdb = 10 * math.log( v )

decibelText.text = tostring( vdb )

local listFilePath = system.pathForFile( “volume.csv”, system.DocumentsDirectory )
local listFile = io.open( listFilePath, “a+” )
if listFile then
listFile:write( v … “,” )
io.close( listFile )
end

local listFilePath = system.pathForFile( “time.csv”, system.DocumentsDirectory )
local listFile = io.open( listFilePath, “a+” )
if listFile then
listFile:write( t … “,” )
io.close( listFile )
end

end
– Main function
local function main()

r:startTuner()
r:startRecording()

Runtime:addEventListener( “enterFrame”, updateStatus )

return true

end
–Get things moving
main()[/code]

I put the saved volume info into excel and created a scatter plot. Here’s what I got.

Photobucket

Now, to me, that doesn’t look like what I expected to come from a gradual rise in volume. The documentation on getTunerVolume() says it returns the mean squared value scaled to be in the range [-1…1], yet it doesn’t look like it is full range. It looks like it slams up to 0.58 and stays there.

What’s going on?

[import]uid: 55576 topic_id: 13385 reply_id: 313385[/import]

I’ve tried using getTunerVolume many times but I’ve never figured out how to use it (I read the docs, I know what it’s doing, squared value and so on… ).

One thing I noticed: on simulator it seems to work correctlly -or at least definitely better- than on device.

Duff333, have you tried running your test on both device and simulator? Have you noticed any differences?

Ruben [import]uid: 9158 topic_id: 13385 reply_id: 49131[/import]

Here is a pic of the sound file I’ve been using for testing, 30 seconds of white noise that fades in: Photobucket

Here is the data from an iOS device using above sound: Photobucket
I’m working under the assumption that the documentation really means RMS in which case the function is just wrong. A graph of the RMS value of this sample sound should be a line gradually rising from left to right.

In the grand scheme of things this is probably not a high priority fix for the Ansca team but it sure is annoying.
[import]uid: 55576 topic_id: 13385 reply_id: 49542[/import]

I’ve just tried your code on simulator and device.
It looks like getTunerVolume cap the values to a little less than 0.6, and this happens when the audio source volume is still low.

By the way, there are some other posts about getTunerVolume not working properly:
http://developer.anscamobile.com/forum/2010/12/27/detect-microphone-volume-blowing-microphone

http://developer.anscamobile.com/forum/2010/11/28/gettunervolume-values [import]uid: 9158 topic_id: 13385 reply_id: 49616[/import]

@ duff333 thanks a lot for this excellent analysis. I just posted another message in my original thread at:
https://developer.anscamobile.com/forum/2010/12/27/detect-microphone-volume-blowing-microphone#comment-50348

I really hope Ansca will either fix this or at least officially admit that it is broken. I think your data shows very well that there is a problem. Did you file anything on http://bugs.anscamobile.com?

Thomas [import]uid: 8111 topic_id: 13385 reply_id: 50350[/import]

fiy: I filed a bug report many months ago, and just recently I sent an email to Carlos asking Corona devs to look into this post for a better explanation of the getTunerVolume problem…

@duff333, do you have any news on this subject?
[import]uid: 9158 topic_id: 13385 reply_id: 50351[/import]

@shedder, please keep us updated if you hear anything from Carlos. But frankly I do not expect it will have any priority for them :-(.

Thomas [import]uid: 8111 topic_id: 13385 reply_id: 50352[/import]

I haven’t heard anything. I’m glad to see there are some renewed discussions about this problem. That’s all we can do, keep these threads alive, and submit bug reports. [import]uid: 55576 topic_id: 13385 reply_id: 50362[/import]

Wow, cool graphs. There’s definitely some saturation going on but the question is where? It may or may not be in the Corona world. Will look into these when we get a chance. Thanks.

@duf333 BTW you misquoted the docs, they say “The mean squared value of the samples in the current audio buffer using sample values scaled to be in the range [-1…1]” . It matters because the audio buffer values range from -1…1, but the squares of these values range from 0…1. Not the same thing. [import]uid: 6787 topic_id: 13385 reply_id: 50366[/import]

“wow, cool graphs”… [import]uid: 9158 topic_id: 13385 reply_id: 50370[/import]

@Snarla, I’m not sure if he meant that there are no negative values (as the square implies) but rather that the values never seem to get higher than 0.58.

The highest value I’ve ever seen was around 0.6, and believe me I have tried everything from shouting into the mic to testing it on a heavy metal concert.

Thomas [import]uid: 8111 topic_id: 13385 reply_id: 50375[/import]

Checking out the daily build (649) using my test and this is what I get:

Photobucket

Looking good. [import]uid: 55576 topic_id: 13385 reply_id: 63644[/import]

How could they fix something that wasn’t broken? :wink:

To be serious, I’m very glad they finally seem to have addressed this issue. Do you happen do know if it is still not possible on iOS to play and record sound at the same time? Hope I will find the time in the next days to do some testing as well. Please keep us posted about your findings :-).

Thomas [import]uid: 8111 topic_id: 13385 reply_id: 63685[/import]