2

I'm trying to make a small music reactive light project with the RPi. I'd like to play music (using whichever software in Raspbian), and to interpret that music as audio input to process while still playing out through the audio jack.

I've achieved it using MacOS and SoundFlower: set soundflower 2ch as both audio input/output, that drives the lights already; and then using soundflowerbed, set soundflower 2ch as built-in output so you recover sound as well.

I've been trying to clone this setup in the RPi using jackd & qjackctl, but i didn't manage.

Any thoughts? Thanks, Alvaro

2

You want to use ALSA for this, and load the snd_loopback module.

pi@raspberrypi ~ $ sudo modprobe snd-aloop pcm_substreams=1

This will create a loopback device on your system. Next you want to set the default ALSA audio output to this substream by editing /etc/asound.conf.

pi@raspberrypi ~ $ sudo nano /etc/asound.conf

Setup your configuration file:

# .asoundrc
pcm.multi {
    type route;
    slave.pcm {
        type multi;
        slaves.a.pcm "output";
        slaves.b.pcm "loopin";
        slaves.a.channels 2;
        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;
    }

    ttable.0.0 1;
    ttable.1.1 1;
    ttable.0.2 1;
    ttable.1.3 1;
}

pcm.!default {
    type plug
    slave.pcm "multi"
} 

pcm.output {
    type hw
    card Headset
}

pcm.loopin {
    type plug
    slave.pcm "hw:Loopback,0,0"
}

pcm.loopout {
    type plug
    slave.pcm "hw:Loopback,1,0"
}

You need to make sure the output pcm points to the speaker/output device you want the audio to go to. You can use aplay -L to get a list of available output devices.

You can know use avconv or ffmpeg to record audio from any application and also routing the audio to an output device.

Here is an example:

pi@raspberrypi ~ $ avconv -f alsa -ac 2 -ar 44100 -i loopout test.wav

SOURCE:
https://trac.ffmpeg.org/wiki/Capture/ALSA

  • Firstly, thanks for the help @linus Secondly, when I run aplay -L I get sysdefault:CARD=ALSA bcm2835 ALSA, bcm2835 ALSA Default Audio Device so I changed pcm.output to type hw and card ALSA. I tried playing a song and then running the avconv command you provided, but it records nothing but low noise, being the song perfectly audible through speakers/headphones. – AlvaroP Jan 14 '15 at 10:36
  • @Peri To begin with you could try follow these instructions and see if you're able to record audio from any application. – Linus Jan 14 '15 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.