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,433
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
299
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,433
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)
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • JuanMena @ JuanMena:
    Kissing random dudes choking in celery? Really? Need to study for that?
  • K3N1 @ K3N1:
    Yes it requires a degree
  • K3N1 @ K3N1:
    I could also yank out the rest of my teeth but theirs professionals for that
  • x65943 @ x65943:
    If your throat closes, putting oxygen in your mouth will not solve anything - as you will be introducing oxygen prior to the area of obstruction
  • JuanMena @ JuanMena:
    Just kiss me Kyle.
  • x65943 @ x65943:
    You either need to be intubated to bypass obstruction or create a stoma inferior to the the area of obstruction to survive
  • x65943 @ x65943:
    "Just kiss me Kyle." And I thought all the godreborn gay stuff was a smear campaign
  • JuanMena @ JuanMena:
    If I die, tell my momma I won't be carrying Baby Jesus this christmas :sad::cry:
  • K3N1 @ K3N1:
    Smear campaigns are in The political section now?
  • JuanMena @ JuanMena:
    Chary! Chary! Chary, Chary, Chary!
  • Sonic Angel Knight @ Sonic Angel Knight:
    Pork Provolone :P
  • Psionic Roshambo @ Psionic Roshambo:
    Sounds yummy
  • K3N1 @ K3N1:
    Sweet found my Wii u PSU right after I ordered a new one :tpi:
  • JuanMena @ JuanMena:
    It was waiting for you to order another one.
    Seems like, your PSU was waiting for a partner.
  • JuanMena @ JuanMena:
    Keep them both
    separated or you'll have more PSUs each year.
  • K3N1 @ K3N1:
    Well one you insert one PSU into the other one you get power
  • JuanMena @ JuanMena:
    It literally turns it on.
  • K3N1 @ K3N1:
    Yeah power supplies are filthy perverts
  • K3N1 @ K3N1:
    @Psionic Roshambo has a new friend
    +1
  • JuanMena @ JuanMena:
    It's Kyle, the guy that went to school to be a Certified man Kisser.
  • Psionic Roshambo @ Psionic Roshambo:
    Cartmans hand has taco flavored kisses
  • A @ abraarukuk:
    hi guys
  • Iron_Masuku @ Iron_Masuku:
    Hello
    Skelletonike @ Skelletonike: hmm