And here is the end of the stuggle, in recognition to Girth's help. 
Maybe I should have followed drmatt's terse advice, because the result
is kind of a hack, and getting to is was really, really, painful.

Anyways, here is an asound.conf that will allow 2 (or more) programs to
use hw:1,0 (a justboom amp HAT in my case) at the same time, while using
equal and with conversion of stereo to dual mono.
The first program is, of course, the great squeezelite. The next
programs are anything you wish to run, in my case short sounds (Ill's
call that "gongs") played via aplay locally on the PCP client.
In order to make gongs be audible yet not too loud, 2 separate volume
sliders are defined, one for the music sent by squeezelite to the
"equal" device, as defined by PCP 3.2, and one for gongs (played through
the "gong" device). 
PCP runs an adhoc program and when a gong needs to sound, that program
ramps down music, ramps up the gong sound, and conversely.
I think rendering is ok. Don't ask about bit-perfectness or resampling,
I couldn't care less.

When PCP starts with the following file as /etc/asound.conf, music
should sound as long as you've set squeezelite to use the ALSA
equalizer.
Then if you login to PCP, you should be able to send extra audio (in
addition to squeezelite) over the "equal" device, eg "mpg123 -a equal
foo.mp3".
In my case, my interest was to fade-in audio sent to another device
("gong") while fading out music through the speakers, hence the gong
device and musicvol / gongvol controls.

Code:
--------------------
    # default - Generated by piCorePlayer
  # Unused. Disable it?
  pcm.!default {
  type plug
  slave.pcm "hw:0,0"
  }
  
  # PCP3.2: squeezelite gets set to use this device ("-o equal")
  # when equalizer is activated. Same name, new type of device.
  # This softvol allows to ramp down-up music when an application
  # plays another sound.
  pcm.equal {
        type softvol
        slave.pcm equal_real
        control.name musicvol
        control.card 1
  }
  
  # Same story here: ramp up-down sounds sent by applications
  pcm.gong {
        type softvol
        slave.pcm equal_real
        control.name gongvol
        control.card 1
  }
  
  # The original equal device from PCP3.2, with added dual-mono
  pcm.equal_real {
  type plug;
  slave.pcm plugequal
        # Dual mono downmix
        ttable {
                        0.1 1
                        0.0 1
                        1.0 1
                        1.1 1
                }
  }
  
  # Used by equal_real. Why not. This calls a dmixer device
  # that allows concurrent access from squeezelite (equal)
  # and other applications (gong)
  pcm.plugequal {
  type equal;
  slave.pcm "plug:dmixer"
  controls "/home/tc/.alsaequal.bin"
  library "/usr/local/lib/ladspa/caps.so"
  }
                                                                        
  # Shared access to our audio card
  pcm.dmixer {
        type dmix
        ipc_key 1234
        ipc_key_add_uid true # Needed ?
        ipc_perm 0666
        slave.pcm "hw:1,0"
  }
  
  # Whatever ctl magic things below
  ctl.dmixer {
        type hw
        card 1
  }
        
  ctl.equal {
  type equal;
  controls "/home/tc/.alsaequal.bin"
  library "/usr/local/lib/ladspa/caps.so"
  }
--------------------


Caveats :D
A softvol control device is not created until the device that uses it is
opened! (read the 'fine print somewhere here'
(http://alsa.opensrc.org/Softvol)). 
In other news, the combination of devices below creates a funny and
mostly harmful (AFAIK, currently) double-free kernel error linked to
equal being in the processing chain.
In practice, my userland daemon script that plays sounds over music
starts with this:
Code:
--------------------
    #!/bin/bash
  # MAKE SURE to "aplay -D gong" before start or devices and controls are not 
guaranteed to be there.
  # We must do that at OS startup too.
  (aplay -D gong /dev/null >/dev/null 2>&1)&
  FOO_PID=$!
  sleep 1
  kill -9 $FOO_PID
--------------------
 
Yes, that's a kill -9. Excuse my french, but I'm talking to Alsa.

And now I will check how much dmix has harmed audio sync...



3 SB 3 • Libratone Loop, Zipp Mini • iPeng (iPhone + iPad) • LMS 7.9
(linux) with plugins: CD Player, WaveInput, Triode's BBC iPlayer by bpa
• IRBlaster by Gwendesign (Felix) • Server Power Control by Gordon
Harris • Smart Mix, Music Walk With Me, What Was That Tune? by Michael
Herger • PowerSave by Jason Holtzapple • Song Info, Song Lyrics by
Erland Isaksson • AirPlay Bridge by philippe_44 • WeatherTime by Martin
Rehfeld • Auto Dim Display, SaverSwitcher, ContextMenu by Peter Watkins.
------------------------------------------------------------------------
epoch1970's Profile: http://forums.slimdevices.com/member.php?userid=16711
View this thread: http://forums.slimdevices.com/showthread.php?t=107539

_______________________________________________
unix mailing list
unix@lists.slimdevices.com
http://lists.slimdevices.com/mailman/listinfo/unix

Reply via email to