Test if mic is sending any input? (Linux/OSX)

Monado_III

Well-Known Member
OP
Member
Joined
Feb 8, 2015
Messages
722
Trophies
0
Location
/dev/null
XP
1,443
Country
Canada
I'm writing a program that will, when I hook up my electronic drum into my microphone jack, count how many times I've hit a drum and print it to the screen, replacing the previous number. I have hopefully most of the code done, but I need help figuring out a way to test if any input is being sent in from the mic or if it's all blank. A bash script would be preferable but any way would work as long as it returns either 1 or 0 and can be launched from inside the program (using system() etc.). Anyone know of a way of going about this? I can post what I currently have if it's of any interest to you.

edit: 400th post!
 
Last edited by Monado_III,

spoonm

Can count to 3.
Member
Joined
May 20, 2015
Messages
192
Trophies
0
Website
spoonm.org
XP
317
Country
Brazil
Quick google search brought me this: http://stackoverflow.com/questions/13606537/current-level-of-microphone-input
You can try it. You'll end up with something like this:
Code:
arecord -d 1 /tmp/inprec.wav
sox /tmp/inprec.wav -n stat

You might have to install sox, and I don't know how to help you if the target system doesn't run alsa.
To get the boolean return you want from a bash script, you can check of a null mean amplitude. I'm not sure if you want to limit how long a drumbeat can last, so this is certainly not the right approach. Might still help, though. Here's a scrot with what I tested:

UNBzmP.png

You can use the mean amplitude to tell if any input was given during the recording. Compare that to 0, if true yay, else... something's there!

Note that I don't think ALSA is what's used in OSX and though your default shell is bash, other people could be using fish, zsh, etc.
And go on, post it, I'm interested. :3
 
  • Like
Reactions: Monado_III

Monado_III

Well-Known Member
OP
Member
Joined
Feb 8, 2015
Messages
722
Trophies
0
Location
/dev/null
XP
1,443
Country
Canada
Quick google search brought me this: http://stackoverflow.com/questions/13606537/current-level-of-microphone-input
You can try it. You'll end up with something like this:
Code:
arecord -d 1 /tmp/inprec.wav
sox /tmp/inprec.wav -n stat

You might have to install sox, and I don't know how to help you if the target system doesn't run alsa.
To get the boolean return you want from a bash script, you can check of a null mean amplitude. I'm not sure if you want to limit how long a drumbeat can last, so this is certainly not the right approach. Might still help, though. Here's a scrot with what I tested:

UNBzmP.png

You can use the mean amplitude to tell if any input was given during the recording. Compare that to 0, if true yay, else... something's there!

Note that I don't think ALSA is what's used in OSX and though your default shell is bash, other people could be using fish, zsh, etc.
And go on, post it, I'm interested. :3
thanks, I have no clue how I didn't find that page. And ALSA isn't used in OSX (ALSA=Advanced Linux Sound Architecture)
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    K3Nv2 @ K3Nv2: I really don't want to buy this fap tab...