Home of the Squeezebox™ & Transporter® network music players.
Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1
    Senior Member
    Join Date
    Apr 2008
    Location
    Paris, France
    Posts
    2,075

    PCP3.2 - Need to inject sound from aplay while squeezelite runs

    Hi,
    I use PCP3.2 and a justboom amp HAT, it runs very fine.
    I managed to get it working with both equalizer and mono re-mapping thanks to the PCP GUI and to a poster on this forum.
    I really don't understand how ALSA works and it's been like that for ages.

    I need now to inject sound directly from the OS, with something like aplay, on top of what squeezelite is playing. This comes in addition to the mono/equal setup.
    I don't want to stop squeezelite to be able to play the sound, in fact I would like to change nothing at LMS level (volume, pause...) because the soundbite I need to inject is so short.
    What I would like to do is fade out or reduce the audio volume for squeezelite, play the soundbite a bit louder on top of it, then return the squeezelite audio output to normal volume.

    Is it possible? How?
    Thanks in advance.
    PS: asound.conf
    Code:
    # default - Generated by piCorePlayer
    pcm.!default {
            type plug
            slave.pcm "hw:0,0"
    }
    
    #---ALSA EQ Below--------
    ctl.equal {
            type equal;
            controls "/home/tc/.alsaequal.bin"
            library "/usr/local/lib/ladspa/caps.so"
    }
    
    pcm.plugequal {
            type equal;
            slave.pcm "plughw:1,0";
            controls "/home/tc/.alsaequal.bin"
            library "/usr/local/lib/ladspa/caps.so"
    }
    
    pcm.equal {
            type plug;
            slave.pcm plugequal;
    # Mono downmix + eq
    	ttable {
    		0.1 1
    		0.0 1
    		1.0 1
    		1.1 1
    	}
    }
    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.

  2. #2
    Senior Member
    Join Date
    Apr 2013
    Location
    UK
    Posts
    905
    jackd might be able to do that.


    <i>Transcoded from Matt's brain by Tapatalk</i>
    --
    Hardware: 3x Touch, 1x Radio, 2x Receivers, 1 HP Microserver NAS with Debian+LMS 7.9.0
    Music: ~1300 CDs, as 450 GB of 16/44k FLACs. No less than 3x 24/44k albums..

  3. #3
    Junior Member
    Join Date
    Mar 2014
    Posts
    29
    Put dmix inline in your asound

  4. #4
    Senior Member
    Join Date
    Apr 2008
    Location
    Paris, France
    Posts
    2,075
    I guess dmix is the idea, somehow. However I am puzzled by something more basic right now: if I stop squeezelite and try to play something from the OS, I get a weird "double free or corruption" error when I use the "equal" device as a target, same as squeezelite uses
    Code:
    root@pcp:/home/tc# ps waxu | grep squeezelite
     5619 root     /usr/local/bin/squeezelite -n pcp -o equal -a 80 4  1
     5791 root     grep squeezelite
    root@pcp:/home/tc# kill -9 5619
    root@pcp:/home/tc# mpg123 -a equal speaker-test.mp3 
    ...
    Playing MPEG stream 1 of 1: speaker-test.mp3 ...
    
    MPEG 1.0 L III cbr128 44100 stereo
    ...
    [0:05] Decoding of speaker-test.mp3 finished.
    *** Error in `mpg123': double free or corruption (!prev): 0x01b8e138 ***
    Aborted
    root@pcp:/home/tc#
    When I target the hardware device it works, but it's no longer in mono:
    Code:
    root@pcp:/home/tc# mpg123 -a sysdefault:CARD=sndrpijustboomd speaker-test.mp3 
    ...
    MPEG 1.0 L III cbr128 44100 stereo
    ...
    [0:05] Decoding of speaker-test.mp3 finished.
    The behaviour is the same with aplay so I suppose the message comes from Alsa itself.
    The machine doesn't crash, audio rendering is normal. Shall I disregard that message?

    The machine runs 4.9.21-pcpCore_v7 #1 SMP Thu Apr 13 19:56:59 EDT 2017 armv7l GNU/Linux
    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.

  5. #5
    Junior Member
    Join Date
    Mar 2014
    Posts
    29
    What do you see if you use plug:equal ?

  6. #6
    Senior Member
    Join Date
    Apr 2008
    Location
    Paris, France
    Posts
    2,075
    Quote Originally Posted by Girth View Post
    What do you see if you use plug:equal ?
    I don't know

    I think we have 2 issues. The first one is this strange double-free crash whenever equal is in use. I went back to a fresh PCP 3.2.0 install, and I just get this error consistently when I try to mpg123 or aplay a file. Sound is ok regardless.
    I dropped a message in the PCP3.2 announce thread, either the devs look at it or not, since the machine doesn't crash I'm ready to send the trace to /dev/null and forget about it.

    The second one, overlaying a sound over the music, all converted to mono, begins to get sorted. This is my asound.conf file:
    Code:
    tc@pcp:~$ cat /etc/asound.conf 
    # 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")
    pcm.equal {
            type plug;
            slave.pcm plugequal;
    	# Mono downmix
    	ttable {
    			0.1 0.5
    			0.0 0.5
    			1.0 0.5
    			1.1 0.5
    		}
    }
    
    # Used by equal. Why not.
    pcm.plugequal {
            type equal;
            slave.pcm "plug:dmixer";
            controls "/home/tc/.alsaequal.bin"
            library "/usr/local/lib/ladspa/caps.so"
    }
    
    # Used by plugequal. Allows shared access to device "equal"
    pcm.dmixer {
    	type dmix
    	ipc_key 1234
    	ipc_key_add_uid 1
    	ipc_perm 0666
    	slave {
    		pcm "hw:1,0"
    	}
    }
    
    # Whatever ctl magic things
    ctl.dmixer {
    	type hw
    	card 1
    }
    	
    ctl.equal {
            type equal;
            controls "/home/tc/.alsaequal.bin"
            library "/usr/local/lib/ladspa/caps.so"
    }
    With this, squeezelite plays in mono and equalized, and I can play a soundbite at the same time. squeezelite uses "-o equal" (don't know where PCP sets that), and to overlay a sound I can "sudo aplay -D equal xxx.wav"

    One thing really doesn't cut it: volume control. I need to reduce the volume for squeezelite temporarily while I play my sound. For the moment I would need to reduce Digital volume something like 100% to 50%, boost the player volume setting on LMS so that music remains audible (players are set at 20-30%), and then play the sound.
    That won't work.
    Since I am using mono I "guess" squeezelite could output to the left channel, my program to the right channel, and use different values for left and right Digital volume. In the end however I still need to output the exact same audio on both speakers. I fear a t-table f-fest.

    I will eagerly read your suggestions.
    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.

  7. #7
    Junior Member
    Join Date
    Mar 2014
    Posts
    29
    If you're not getting any troubles from the errors then your call whether you want to chase it. One possible difference maker would be to try the mbeq library instead of caps but on piCore that could be a chore.

    For the volume I'd just use nc (included in piCore) to the server's cli to poll and store the current volume then set the lower volume level then return it once your script has completed.

    The other option would be to add a virtual control through your asound between the eq and dmix then have your script set those but you'd really only be doing what lms does which is using digital attenuation. I'd bet doing it through lms is more efficient.

    Good luck!

  8. #8
    Senior Member
    Join Date
    Apr 2008
    Location
    Paris, France
    Posts
    2,075
    Quote Originally Posted by Girth View Post
    The other option would be to add a virtual control through your asound between the eq and dmix then have your script set those but you'd really only be doing what lms does which is using digital attenuation. I'd bet doing it through lms is more efficient.

    Good luck!
    Thank you, your guidance is much appreciated.
    I never though about it before -I'm audiophile like that- but at least in my case, out-of-the-box PCP3.2 doesn't set squeezelite to use Alsa volume control. So we have indeed 2 digital volume controls in a row, one in LMS (varies) and one in Alsa (fixed to 0 dB for me).
    But, squeezelite can come to the rescue. In PCP 3.2 I can add "-O hw:1,0 -V Digital" to the "Various input" field in tab "Squeezelite Settings" and there we go, one single volume control, still mono and equalized. It doesn't seem to be bidirectional though, ie if you "amixer -c 1 sset Digital 50%" within PCP, the volume slider control on LMS will not move accordingly.

    So now I've got one less volume control, I think I'll add one to differentiate between my 2 sources
    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.

  9. #9
    Senior Member
    Join Date
    Apr 2008
    Location
    Paris, France
    Posts
    2,075
    And here is the end of the struggle, 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 it 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 a daemon playing short sounds (Ill's call that "gongs") 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 musicvol, ramps up gongvol 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
    A softvol control device is not created until the device that uses it is opened! (read the fine print somewhere here).
    In other news, the combination of devices above 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...
    Last edited by epoch1970; 2017-06-22 at 16:33.
    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.

  10. #10
    Senior Member
    Join Date
    Apr 2008
    Location
    Paris, France
    Posts
    2,075
    I don't think audio sync has suffered much, but squeezelite starts to stutter after a few hours playing now, perhaps on some file types?
    I've added some hardware params to dmixer that supposedly match capabilities of the Justboom amp HAT, I'll see how this goes...

    EDIT. Had to add dtparam=audio=off to config.txt in order to disable the internal audio card. They were trading places at boot and my asound.conf couldn't cope with it.
    I think stuttering is now solved by increasing buffer time by quite a lot. Squeezelite uses the same setting (I tried 80, 160, 320, and 640 finally seemed ok).
    Most of my material is CD, so I chose to define dmix as a 16/44.1 device. AFAIK other formats/rates are resampled by Alsa even if the hardware card could support them.
    Code:
    # default - Generated by piCorePlayer
    # Onboard audio disabled in config.txt
    # Otherwise volume sliders that use "control.card X"
    # can attach to the wrong card at boot...
    #
    #pcm.!default {
    #        type plug
    #        slave.pcm "hw:CARD=ALSA,DEV=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 0
    }
    
    # Same story here: ramp up-down the sounds sent by applications
    pcm.gong {
    	type softvol
    	slave.pcm equal_real
    	control.name gongvol
    	control.card 0
    }
    
    # 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:CARD=sndrpijustboomd,DEV=0"
    		format S16_LE
    		rate 44100
    		channels 2
    		buffer_time 640000 # 640 ms as used by squeezelite
    		periods 4
                }
    }
    
    # Whatever ctl magic things below
    ctl.dmixer {
    	type hw
    	card 0
    }
    	
    ctl.equal {
            type equal;
            controls "/home/tc/.alsaequal.bin"
            library "/usr/local/lib/ladspa/caps.so"
    }
    EDIT2. I'll expound on what this is good for. As exposed in the OP, we can merge audio gracefully from 2 sources, imagine a door bell ringing through your speakers.
    We've hacked together bits of script that make use of a multicast address via socat. Socat is available on linux (including PCP: "socat.tcz"), windows, etc.
    There are "sender" scripts installed wherever necessary that send events to the multicast address, and other "receiver" scripts installed in players that listen on the address, and execute some amixer/aplay sauce to merge the requested audio signal ("gong") with what squeezelite is currently playing.
    We have players running with both sender (an EnOcean device listener, FWIW) and receiver colocated, and players running only the receiver task. For what I've seen until now, it doesn't disrupt music sync at all. Load is minimal and gongs also ring in sync (a happy side-effect.) The system works as long as there is one sender and one receiver online, that is completely independently of squeezelite or LMS.

    HTH
    Last edited by epoch1970; 2017-06-27 at 02:24.
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •