Need helping using microphone

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Sir_Silver
Party member
Posts: 286
Joined: Mon Aug 22, 2016 2:25 pm
Contact:

Need helping using microphone

Post 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!
Attachments
microphone.love
(314 Bytes) Downloaded 168 times
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Need helping using microphone

Post 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
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Sir_Silver
Party member
Posts: 286
Joined: Mon Aug 22, 2016 2:25 pm
Contact:

Re: Need helping using microphone

Post 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
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Need helping using microphone

Post 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 ¯\_(ツ)_/¯.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
ivan
Party member
Posts: 1915
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Need helping using microphone

Post 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.
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Need helping using microphone

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 3 guests