Re: Microphone Support for LÖVE!
Posted: Thu Oct 29, 2015 1:53 pm
Hello. I'm curious how could I get the microphone audio levels (sorry for my terminology) to use (for example) for a visualizer.
Code: Select all
function peakAmplitude(sounddata)
local peak_amp = -math.huge
for t = 0,sounddata:getSampleCount()-1 do
local amp = math.abs(sounddata:getSample(t)) -- |s(t)|
peak_amp = math.max(peak_amp, amp)
end
return peak_amp
end
Code: Select all
function rmsAmplitude(sounddata)
local amp = 0
for t = 0,sounddata:getSampleCount()-1 do
amp = amp + sounddata:getSample(t)^2 -- (s(t))^2
end
return math.sqrt(amp / sounddata:getSampleCount())
end
Code: Select all
local inputs
local output
function love.load ( )
inputs = love.audio.getRecordingDevices ( )
print ( inputs[ 1 ]:getName ( ) )
inputs[ 1 ]:start ( )
output = love.audio.newQueueableSource ( inputs[ 1 ]:getSampleRate ( ), inputs[ 1 ]:getBitDepth ( ), inputs[ 1 ]:getChannels ( ) )
end
function love.update ( )
if inputs[ 1 ]:getSampleCount ( ) > inputs[ 1 ]:getSampleRate ( ) / 20 then
local data = inputs[ 1 ]:getData ( )
output:queue ( data )
print ( ( "%d samples captured" ):format ( data:getSampleCount ( ) ) )
if output:getDuration ( "samples" ) > data:getSampleCount ( ) then
output:play ( )
end
end
end
Thanks! Seems to work.raidho36 wrote:Code: Select all
inputs = love.audio.getRecordingDevices ( ) inputs[ 1 ]:start ( )
This works well, but .... What is the likelihood of having a variant of getData that doesn't create a new SoundData object with every call, instead "refilling" an existing buffer with new data?LÖVE 0.11 wrote:getData removes currently recorded samples from input and puts them into new SoundData