Microphone Support for LÖVE!

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Dr. Peeps
Citizen
Posts: 57
Joined: Sat May 28, 2016 12:57 am
Location: British Columbia, Canada

Re: Microphone Support for LÖVE!

Post by Dr. Peeps »

raidho36 wrote:OpenAL internally updates at under 50 frames per second. The amount of samples updated per frame is usually at cyclically repeating irregular intervals, e.g. 342 on odd frames and 558 on even frames.
That's useful information. I did notice the fluctuating sample counts.
raidho36 wrote:Also you're reading the data out wrong. You're waiting on entire buffer to fill up before reading. What you should do is immediately read as soon as there is any input in the buffer. That should produce SoundData at the same rate as AL's internal update rate.
Ah, I see. OK, I just tried simplifying it to:

Code: Select all

if data:getSampleCount ( ) > 0 then
  data = inputs[1]:getData()
end
And that gives the fastest reads (I'm getting about 34 updates per second). However, the buffer is jumping from 412 samples, 345 samples, and sometimes down to 67 samples captured per update. A buffer of only 67 samples is too short for me to analyze waveforms correctly, so I think if I change this instead to a comfortable number like if data:getSampleCount() > 300 I should get the results I'm looking for. Thanks for the help! :awesome:

As for my chosen sample rate of 11025 ... what will OpenAL do when I request a rate that isn't supported by a particular piece of hardware? In Windows, it seems to give me any arbitrary rate I ask for. But on the original iPhone, for example, the sample rate is limited to 8000 (on the built-in mic at least). Would my program generate an error in that case?
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Microphone Support for LÖVE!

Post by raidho36 »

It will fail to start recording, that's pretty simple.
User avatar
Dr. Peeps
Citizen
Posts: 57
Joined: Sat May 28, 2016 12:57 am
Location: British Columbia, Canada

Re: Microphone Support for LÖVE!

Post by Dr. Peeps »

raidho36 wrote:It will fail to start recording, that's pretty simple.
Sure, but I'd like to find out what the problem was and respond to it programmatically.

It looks like "AL lib: (EE) ALCdsoundCapture_open: Device init failed: 0x80070057" gets dumped to output when the call to RecordingDevice:start() fails. Other than that I don't see any errors for "bitrate not supported" or the like ....
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Microphone Support for LÖVE!

Post by raidho36 »

It's impossible to tell, this is why. AL error codes are undescriptive. You get the text in error steam in console and it tells more about the nature of the problem than error code. And besides, is not like you want to crash your game just because your selected format is not supported. Just goes to show that you do not hard-code things that may or may not be supported.
User avatar
Dr. Peeps
Citizen
Posts: 57
Joined: Sat May 28, 2016 12:57 am
Location: British Columbia, Canada

Re: Microphone Support for LÖVE!

Post by Dr. Peeps »

raidho36 wrote:And besides, is not like you want to crash your game just because your selected format is not supported. Just goes to show that you do not hard-code things that may or may not be supported.
Yes, that's my point. :) I don't want to crash the game and I don't want to hardcode a single option; I want to request the option that is optimal for my game, and then switch to plan B (and then C, etc.) if it's not available.

With no error message/code, I don't even know which parameter I need to change to try again. I guess I just have to try all options until one hopefully returns success.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Microphone Support for LÖVE!

Post by raidho36 »

Yes that's how it works. The framework does the same thing when it opens a window.

It will error if you try to use a format not supported by the framework itself, but if the hardware doesn't support it then it will simply fail to do anything, and return false.
Snow(original)
Prole
Posts: 3
Joined: Sat Mar 10, 2018 9:45 pm

Re: Microphone Support for LÖVE!

Post by Snow(original) »

My apologies to bump a year old thread, but I'm having difficulty figuring out how to return a list of frequencies (or even just a single variable continually updated with the latest frequency) from microphone input using FFT. I'm not going to post any of my code yet as that is pointless. I just wonder if this is possible with this microphone library.

What I want the numbers for is a simple visualizer that scrolls across the screen (which consists of 10px wide rects and the height of each rect is determined by the frequency number returned). I have the code for this simple visualizer working (using randomly generated numbers). I just need to figure out how to get samples from the mic which I can then feed through FFT and get those numbers.

Any help on this matter is greatly appreciated and I will reciprocate to the community by contributing my help (on things or problems I understand) and even contributing any libraries that I should code. I do have a nice little text input library that I'm going to post soon. :)

Thank you.

-Snow
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Microphone Support for LÖVE!

Post by zorg »

Snow(original) wrote: Sat Mar 10, 2018 11:03 pm ...
Raidho may give a more expanded answer, but i'd say get 0.11 (latest nightly release of löve) since that already has the microphone support in-built (more or less based on this lib).

In short, you get a buffer (SoundData) of samplepoints recorded by the microphone, and then you run an FFT algorithm on those samplepoints (maybe windowing them before as well, to your liking), and finally, use the returned values in your frequency analyzer.

There's nothing inherently impossible; the fft is just an algorithm that takes 1 set of numbers and transforms them to another set of numbers.

Edit: Dr. Peeps is right, the FFT actually returns frequency bins, which cover more than just individual frequencies.
Last edited by zorg on Sun Mar 11, 2018 4:18 am, edited 1 time in total.
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
Dr. Peeps
Citizen
Posts: 57
Joined: Sat May 28, 2016 12:57 am
Location: British Columbia, Canada

Re: Microphone Support for LÖVE!

Post by Dr. Peeps »

Snow(original) wrote: Sat Mar 10, 2018 11:03 pm I'm having difficulty figuring out how to return a list of frequencies (or even just a single variable continually updated with the latest frequency) from microphone input using FFT. I just wonder if this is possible with this microphone library.
Yes, it's certainly possible. You're more likely going to be looking for the amplitude of each range of frequencies, not "returning a list of frequencies" ... there is a lot of information on using FFTs out there. It's doesn't need to be specific to LÖVE.
Snow(original) wrote: Sat Mar 10, 2018 11:03 pm What I want the numbers for is a simple visualizer that scrolls across the screen (which consists of 10px wide rects and the height of each rect is determined by the frequency number returned). I have the code for this simple visualizer working (using randomly generated numbers). I just need to figure out how to get samples from the mic which I can then feed through FFT and get those numbers.
First of all, are you using LÖVE 0.11? The mic capabilities are not in the current released version (0.10.2).
Snow(original)
Prole
Posts: 3
Joined: Sat Mar 10, 2018 9:45 pm

Re: Microphone Support for LÖVE!

Post by Snow(original) »

Hey guys,

thank you for the replies so far. I feel a bit silly. I just downloaded the nightly build. :/ I'll play around with it and see what I come up with. I'll also post my code if I have problems.
Post Reply

Who is online

Users browsing this forum: No registered users and 43 guests