Hi,
We are creating a blow game for iOS. We are using getTunerVolume() but it seems that the value is always at around .56 to .57. The change happens even with just the background sound. Even if I shout or blow directly to the mic, the value still remains at .56 to .57. My mic is working fine because I can record sounds using the Sound Recorder built in app.
We used the code below.
Regards,
erwin
– Create an object to access audio input features
local r = media.newRecording()
r:startRecording()
r:startTuner()
– Create an object to hold display items
local g = display.newGroup()
– Simple sound detector
– This just changes the color of a text label in response to a detected sound.
– There are two threshold quantities here that could be used to adjust the sensitivity,
– one is the amount of change that detects sound onset, the other is for sound offset.
– You could connect these to a UI element to allow the user to adjust the sensitivity.
local soundDetector = display.newText( “…”, 0, 0, nil, 22 )
soundDetector:setReferencePoint( display.TopLeftReferencePoint)
soundDetector:setTextColor( 255,255,255, 150 )
soundDetector.x = display.contentWidth/2
soundDetector.y = 0.8*display.contentHeight
local lastV = 0
local threshold = {}
threshold.pos = 2.5 – adjust these
threshold.neg = 1 – to change sensitivity
function soundDetector:enterFrame( event )
local v = r:getTunerVolume()
if v == 0 then
return
end
– Convert RMS power to dB scale
v = 20 * 0.301 * math.log(v)
soundDetector.text = string.format("%4.2f", v - lastV )
if v > lastV + threshold.pos then
– Detected a level increase
soundDetector:setTextColor( 255,255,100, 255 )
lastV = v
else
if v < lastV - threshold.neg then
– Detected a level drop
soundDetector:setTextColor( 255,255,255, 150 )
lastV = v
else
– Adapt the background level
– Simple running average
lastV = 0.5 * v + 0.5 * lastV
end
end
end
Runtime:addEventListener( “enterFrame”, soundDetector );
g:insert(soundDetector) [import]uid: 75358 topic_id: 13589 reply_id: 313589[/import]
[import]uid: 52491 topic_id: 13589 reply_id: 49882[/import]
will get back to you
[import]uid: 75358 topic_id: 13589 reply_id: 50148[/import]