You are not logged in.

#1 2010-05-31 06:37:48

synthead
Member
Registered: 2006-05-09
Posts: 1,344

Adjusting audio output based on an audio input!

Kay so I live in an older apartment where my AC bombards my eardrums every ten minutes.  My stereo master slider on my mixer is my best friend for overcoming this inaudible catastrophe!  Men, I need you to help me link my microphone to my audio output gain so one of my arms doesn't get very strong compared to the other.  I've been working out my other arm on a daily basis, but it's coming to the degree where I can't walk in a straight line.  To prevent the repetitive volume increases and decreases and keep me from walking in circles, is there some software I can use to auto-adjust the gain from my machine?

Offline

#2 2010-05-31 07:07:16

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,464

Re: Adjusting audio output based on an audio input!

It seems you need what is called an audio compressor, there are several ladspa plugins for that, but i think you need to be more specific.


Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !

Offline

#3 2010-05-31 07:29:12

synthead
Member
Registered: 2006-05-09
Posts: 1,344

Re: Adjusting audio output based on an audio input!

I am actually running my mpd server into a hardware compressor atm since my mixer makes that really easy to do.  But I want it to monitor the ambient noise of the room via a microphone, and when it notices a consistant increased db input, it'll turn the audio outputs' gains up smile

Offline

#4 2010-05-31 09:53:14

kazuo
Member
From: São Paulo/Brazil
Registered: 2008-03-18
Posts: 413
Website

Re: Adjusting audio output based on an audio input!

Ok,

Looked simple, but fun, so I did it. Where you go

#!/bin/bash
MAX=20.0
MULT=1.0
TIME=5

function volume(){
  arecord -f S16_LE -r44100 -d $TIME 2>/dev/null|sox -t wav - -t raw  /dev/null \
    stats 2>&1 |awk '/RMS lev dB/ {print $NF}'
}

level=$(volume)
while true; do
  new_level=$(volume)
  diff=$(echo $new_level - $level|bc -l)
  level=$new_level
  adjust=$(echo "
  v=$diff*$MULT;
  if (v < $MAX && v > $MAX*-1){
    if (v > 0) {
      print v,\"%+\"
    } else {
      print -v,\"%-\"
    }
  } else {
    print \"0%+\"
  }"|bc -l)
  echo $diff,$adjust
  amixer set Master -i $adjust >/dev/null
done

Its use arecord and sox to calculate the noise and bc to do some math (because bash is dumb =[). Some parameters MAX is the maximum absolute adjustment that can be made, MULT is a multiplicative factor applicated to the difference of dB measured, and TIME is how much seconds to record in each pass.

TIME can be used to adjuste the reaction time, a small value (like 1) react nearly instantaneous but a bigger value like 6 give some margin for rapid pops in the noise and only adjust if the noise difference existed in much part of TIME window.

When I use pulseaudio MULT=1 works ok, but with alsa I need MULT=5.

About pulseaudio, I started using it this week, and I really think that using pulse audio you have a lot more clear/cool/functional solution, but I need to explore it...

I dont know much about sound theory, so I dont know if I choose the best 'volume' description, but you can look at sox man pages and look for something more adequate (look for stats and stat).

PS. I hate bash... zsh is so much better (but, python is better than all) I only used bash because, uhhh I dont know the reason... masochism?

Last edited by kazuo (2010-05-31 10:31:07)

Offline

#5 2010-05-31 12:35:46

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,464

Re: Adjusting audio output based on an audio input!

Nice!


Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !

Offline

#6 2010-06-01 07:35:07

synthead
Member
Registered: 2006-05-09
Posts: 1,344

Re: Adjusting audio output based on an audio input!

That is so awesome!  I am recording a show right now so I can't mess with the gains atm, but I'm going to try it tomorrow afternoon!

Offline

#7 2010-06-01 12:16:28

bobwad
Member
From: France
Registered: 2010-02-18
Posts: 8

Re: Adjusting audio output based on an audio input!

1. Switch off AC.
2. Open windows. (Glass ones!)

No more ear bombardment.
Fresh air.
Planet (slightly) saved.

Offline

#8 2010-06-01 19:07:05

synthead
Member
Registered: 2006-05-09
Posts: 1,344

Re: Adjusting audio output based on an audio input!

bobwad wrote:

1. Switch off AC.
2. Open windows. (Glass ones!)

No more ear bombardment.
Fresh air.
Planet (slightly) saved.

I live in Atlanta and today is the first of June ... tongue

Offline

Board footer

Powered by FluxBB