Microphone

I am trying to switch this to the amount of loudness it goes then the numbers could switch to yellow and the sound plays. Ex: I want it to be so if you yell then it will trigger the phone so the numbers turn yellow and the sound plays. I guess i am trying to change the frequency . Or the sensitivity, but how ? I also tried changing the threshold but i just couldnt get it to work. This is my code.
[lua]-- 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 – adjust these
threshold.neg = 1 – to change sensitivity

local rawOutput = display.newText( “…”, 0, 0, nil, 22 )
rawOutput:setReferencePoint( display.TopLeftReferencePoint)
rawOutput:setTextColor( 255,255,255, 150 )
rawOutput.x = display.contentWidth/2
rawOutput.y = 0.6*display.contentHeight

function soundDetector:enterFrame( event )
local v = r:getTunerVolume()

rawOutput.text = string.format(“raw %5.3f”, v)

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 )
media.playSound( “sound1.wav”, true )
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: 132369 topic_id: 25997 reply_id: 325997[/import]