Force MOC to fade down if another application is playing sound

I have the following setup:

Ubuntu 12.04 Server, MOC running with alsa and a custom ruby app which is playing soundfiles occasionally (e.g. an advertisement mp3 every 20 minutes, or a happy_hour mp3 if some event happens and so on)

The ruby app is event or scheduled drived with his internal logic and the server is connected to the sound system of our store.

Now i want to use the same server (and the already established connection to the sound system of the store) to play mp3s out of a playlist.

this works fine by now but one thing i really have to change:

when MOC is playing a song and the ruby app wants to play an advertisment, they are all on the same sound level and advertisment get drowned out by the music playing. Is there a way i can:

a) set up moc to run on a virtual sound line, so i can seperate the ruby and moc daemons from one another and separately adjust the sound levels of each applications

and the importan one

b) can i tell MOC, alsa or what every application, that as long as a sound is played from the ruby app (or from a specific sound line), fade down MOC (or the MOC-virtual-sound-line/device) by 90% and, as soon as the other application stops playing readjust the soundlevel of moc back to it's origin?

thanks for your help

The easiest way would be to use SoftMixer in moc, but from what I can see, moc doesn't allow command line access to softmixer value.

There are some possibilities of creating special "devices" in alsa .asound file but I was never able to fully understand it. There are also other possible solutions, like jack sound daemon.

Having thought about this overnight, I came to the same conclusion as "tomaszg" did.

Assuming you're using ALSA, I believe it's possible to set up two ALSA "devices" (one each for MOC and the adverts) then use a plug-in to attenuate one in favour of the other. However, I don't know enough about ALSA to be sure, especially about the plug-in part. You should probably address the question to the ALSA mailing list and report back to us.

It is not possible from within MOC, but if it were then "tomaszg" would be correct that it would have to be done via the softmixer. If MOC adjusted the device volume (as it normally would) then that would affect both MOC and advert audio.

well, i talked to the developer of the ruby app. he told me he can fade down the input line and fade it back as the advertise stopped.

he will implement this on monday, so the only thing i have to do is pipe the output of moc to the physical input of the box

so, short question: how can i configure moc, to output the music to the input line with alsa?

... and what about this:

"The name of option 'OSSMixerChannel' has changed to 'OSSMixerChannel1';
please update your configuration file accordingly.
The name of option 'AlsaMixer' has changed to 'ALSAMixer1';
please update your configuration file accordingly.
Segment fault"

Have a look at these posts to see if they match your problem. If not, start a new topic for your problem with enough information to actually allow us to start working on it.