Page 1 of 1

Need helping using microphone

Posted: Wed Aug 29, 2018 4:12 pm
by Sir_Silver
Hi there.

So I was interested in trying to use the microphone features added in 11.0 and so I checked out the wiki to see how I could use it.
I figured out how to get my microphone, how to get the data in it, and then to replay it as soon as it is heard. I even have a .love you can check out of it attached at the bottom. My question is, why does the sound quality sound so bad, and what do I need to do to make it sound actually decent (like it would normally anywhere else)

Thanks for checking it out!

Re: Need helping using microphone

Posted: Tue Sep 04, 2018 3:01 pm
by zorg
So, the issue is that you're using a very low sampling rate of 8000 Hz, or sample(point)s/second, and it is only enough to represent frequencies up to 4000 Hz, while human hearing goes up to around 20 000 Hz... hearing damage notwithstanding; try using a sampling rate of at least 44100.

Also, not sure if this is an issue or not, but i'd query the QSource whether its buffer queue is full or not (Source:getFreeBufferCount), and if it is, i wouldn't even call microphone:getData, since chunks may get lost that way.

(A third issue could be that the microphone's circular buffer size is too small, but that wasn't the case here; you could just increase the 1000 to something higher, not sure if a multiple of the sampling rate you pass into it would be preferred or not, like 2205, 4410, 8820, etc.)

Anyway, i implemented the minor changes, and it worked for me this way:

Code: Select all

local devices = love.audio.getRecordingDevices()
local microphone = devices[1]

local success = microphone:start(1000, 44100, 16, 1)
local source = love.audio.newQueueableSource(44100, 16, 1)

function love.update(dt)
	if success then
		if source:getFreeBufferCount() > 0 then
			local data = microphone:getData()
			if data then
				source:queue(data)
				source:play()
			end
		end
	end
end

Re: Need helping using microphone

Posted: Tue Sep 04, 2018 3:17 pm
by Sir_Silver
Thanks so much, Zorg! That totally did it! I could've sworn I've tried increasing the hz but maybe it wasn't high enough or not a proper value.
There still is an audio "flicker" of static that seems to linger though, I'm guessing the way to fix that kinda thing is to use source:setFilter?

:3

Re: Need helping using microphone

Posted: Tue Sep 04, 2018 4:25 pm
by zorg
If it does that in other recording programs as well, then that's your microphone, or your ambient sound floor in the room, but yes, you could filter that out through various means.

If it doesn't, then ¯\_(ツ)_/¯.

Re: Need helping using microphone

Posted: Mon Sep 17, 2018 5:26 pm
by ivan
The code runs, but there are audible clicks (increasing in frequency over time).
After running for 10-15 seconds the script crashes on my machine.
Any tips would be appreciated as there aren't many tutorials on queued sources.

Re: Need helping using microphone

Posted: Mon Sep 17, 2018 10:55 pm
by zorg
ivan wrote: Mon Sep 17, 2018 5:26 pm The code runs, but there are audible clicks (increasing in frequency over time).
After running for 10-15 seconds the script crashes on my machine.
Any tips would be appreciated as there aren't many tutorials on queued sources.
I'd start with it shouldn't crash, but apparently it does for you anyway...
also, do you see a general memory increase during those 10-15 seconds?

Maybe your computer just can't handle buffering the data... but again, the getFreeBufferCount thing should protect you from trying to queue when there are no buffers available... maybe it's an openalsoft implementation issue with the recordingdevice's circular buffer... or some combination of these things... i can only say that it worksforme.