After lots of searching I've found the answer to my question. You need to appropriately configure ALSA and it will provide a new device which duplicates sound sent to it to two or more devices like soundcards and the loopback device.
Here the .asoundrc file I use:
# If you want this to be the default, then you
# need to override the default device and provide
# a playback path to the CardAndLoop and a capture
# path to whatever soundcard you have (here the 1st card)
#pcm.!default {
# type asym
# playback.pcm "CardAndLoop"
# capture.pcm "hw:0,0"
#}
# This is the interface you use for sound output
# It will send the output to the soundcard and loopback device
pcm.CardAndLoop {
type plug
slave.pcm MultiCh
route_policy "duplicate"
}
# Virtual multichannel device with four channels
# two the for the soundcard, two for the loopback
pcm.MultiCh {
type multi
slaves.a.pcm pcm.MixCard
slaves.a.channels 2
slaves.b.pcm pcm.MixLoopback
slaves.b.channels 2
bindings.0.slave a
bindings.0.channel 0
bindings.1.slave a
bindings.1.channel 1
bindings.2.slave b
bindings.2.channel 0
bindings.3.slave b
bindings.3.channel 1
}
# Mixer for the soundcard
pcm.MixCard {
type dmix
ipc_key 1024
slave {
# pcm "hw:Conectiv,0"
pcm "hw:PCH,0"
# rate 48000
rate 44100
periods 128
period_time 0
period_size 1024 # must be power of 2
buffer_size 8192
}
}
# Mixer for the loopback
pcm.MixLoopback {
type dmix
ipc_key 1025
slave {
pcm "hw:Loopback,0"
# rate 48000
rate 44100
periods 128
period_time 0
period_size 1024 # must be power of 2
buffer_size 8192
}
}
This file will provide a new ALSA sound device 'CardAndLoop'. If you choose this device in your sound application the sound will be sent to the 'PCH' sound card and the loopback device. You can start a second application and use the loopback device as input and it will obtain the sound played by the 1st application.
I used names to denominate the sound devices. These names can be taken from the /proc/asound/cards file:
$ cat /proc/asound/cards
0 [PCH ]: HDA-Intel - HDA Intel PCH
HDA Intel PCH at 0xf5330000 irq 44
2 [Loopback ]: Loopback - Loopback
Loopback 1
Have fun !