Record Mix Audio

Discussion in 'Laptop Hardware' started by Duncan_Rowland, Nov 6, 2008.

  1. Duncan_Rowland

    Duncan_Rowland

    Joined:
    Aug 25, 2008
    Messages:
    246
    Likes Received:
    0
    Following on from a discussion in the beginners forum
    viewtopic.php?f=17&t=6357#p42357
    does anyone know if it is possible to record the currently playing audio to a file?
    I've tried various thing (as above) but it seems like the hardware does not support it,
    since there's no "Mix" to record from - Is that right? If so, is there a workround?
    Thanks -Duncan
     
    Duncan_Rowland, Nov 6, 2008
    #1
  2. Duncan_Rowland

    Duncan_Rowland

    Joined:
    Aug 25, 2008
    Messages:
    246
    Likes Received:
    0
    Update, still no joy.
    I've tried compiling alsa with the "aloop" flag set when configurating the driver.
    I've added the loopback device in /etc/modprobe.d/modprobe.conf.dist
    I can now see the loopback device in audacity,
    but I've not managed to record anything as it just comes out silent.
    Any ideas?

    [Duncan@localhost ~]$ arecord -l
    **** List of CAPTURE Hardware Devices ****
    card 0: Intel [HDA Intel], device 0: ALC268 Analog [ALC268 Analog]
    Subdevices: 1/1
    Subdevice #0: subdevice #0
    card 1: Loopback [Loopback], device 0: Loopback PCM [Loopback PCM]
    Subdevices: 8/8
    Subdevice #0: subdevice #0
    Subdevice #1: subdevice #1
    Subdevice #2: subdevice #2
    Subdevice #3: subdevice #3
    Subdevice #4: subdevice #4
    Subdevice #5: subdevice #5
    Subdevice #6: subdevice #6
    Subdevice #7: subdevice #7
    card 1: Loopback [Loopback], device 1: Loopback PCM [Loopback PCM]
    Subdevices: 8/8
    Subdevice #0: subdevice #0
    Subdevice #1: subdevice #1
    Subdevice #2: subdevice #2
    Subdevice #3: subdevice #3
    Subdevice #4: subdevice #4
    Subdevice #5: subdevice #5
    Subdevice #6: subdevice #6
    Subdevice #7: subdevice #7
     
    Duncan_Rowland, Nov 6, 2008
    #2
  3. Duncan_Rowland

    Duncan_Rowland

    Joined:
    Aug 25, 2008
    Messages:
    246
    Likes Received:
    0
    OK, I've had a little success but am continuing to work on it...
    My current (i.e. it might be wrong!) understanding is as follows:

    The reason my initial configuration (as in previous post) did not work is that the loopback device was the second sound card so it never received any audio data (and there is no way of redirecting the data from the physical sound card proper). So, I've put the loopback device as the first sound card as shown here:

    [Duncan@localhost ~]$ arecord -l
    **** List of CAPTURE Hardware Devices ****
    card 0: Loopback [Loopback], device 0: Loopback PCM [Loopback PCM]
    Subdevices: 8/8
    Subdevice #0: subdevice #0
    Subdevice #1: subdevice #1
    Subdevice #2: subdevice #2
    Subdevice #3: subdevice #3
    Subdevice #4: subdevice #4
    Subdevice #5: subdevice #5
    Subdevice #6: subdevice #6
    Subdevice #7: subdevice #7
    card 0: Loopback [Loopback], device 1: Loopback PCM [Loopback PCM]
    Subdevices: 8/8
    Subdevice #0: subdevice #0
    Subdevice #1: subdevice #1
    Subdevice #2: subdevice #2
    Subdevice #3: subdevice #3
    Subdevice #4: subdevice #4
    Subdevice #5: subdevice #5
    Subdevice #6: subdevice #6
    Subdevice #7: subdevice #7
    card 1: Intel [HDA Intel], device 0: ALC268 Analog [ALC268 Analog]
    Subdevices: 1/1
    Subdevice #0: subdevice #0

    The result is the volume control on the gui shows disabled and sound stops working. This is as expected because the loopback device does not have any volume control, and since we are not redirecting the audio data to anything it effectively just disappears before it gets to a speaker.

    So, if you start sending audio now (e.g. open up some flash audio on a web site) it will go to the loopback device and nothing will be heard until you send the audio on to the sound card. This seems to work:
    $arecord -D hw:0,1 -f cd | aplay -D hw:1 -f cd

    You can press ctrl+c to stop this, and instead of sending the data to aplay, direct it to a file...
    $arecord -D hw:0,1 -f cd > sounds
    Also, you can use tee to send the sound data to both aplay and a file
    $arecord -D hw:0,1 -f cd | tee sounds | aplay -D hw:1 -f cd
    And then afterwards you can play the sounds recorded straight to aplay
    $aplay -D hw:1 sounds

    To get the system back to normal you need to reboot so that the sound card proper loads as the first sound card (hw0) and not the loopback device (i.e. "options snd-aloop index=1" in /etc/modprobe.d/modprobe.conf.dist). Obviously there is a lot of tidying up to do here, but at least this works in principle :)
    Best -Duncan.
     
    Duncan_Rowland, Nov 7, 2008
    #3
  4. Duncan_Rowland

    Duncan_Rowland

    Joined:
    Aug 25, 2008
    Messages:
    246
    Likes Received:
    0
    addendum:
    I've has some help from the alsa-users mailing list.
    Apparently you can select which is the default audio device by setting an environment variable.
    This means no more rebooting to switch between devices :)
    So, in my setup (audio card=0, loopback=1), to start an app and send audio to the loopback to record,
    I do:
    $ ALSA_CARD=1 vlc
    or
    $ export ALSA_CARD=1
    $ firefox
    Then to hear the audio I need to do as in the previous post
    arecord -D hw:1,1 -f cd | aplay -D hw:0 -f cd

    Notes: This has failed once for me with vlc (couldn't seem fine a specifc audio format).
    But, I stopped vlc and started arecord first, and then it was fine.
    Afterwards it didn't seem to matter which I started first.
    Also, sometimes when I start it I get some clicking noises (probably processor too slow?)
    But these seem to go away when I restart it (or nice it up).

    Going to leave this now, hope that all helps someone.
    -Duncan.
    p.s.
    Instructions for building the alsa drivers are here, but you need to configure aloop not
    the usb-audio throughout (and I couldn't get the latest release to build, so stick to v17(a) as below)
    viewtopic.php?f=17&t=2463&p=35163&hilit=marathon#p35163
     
    Duncan_Rowland, Nov 7, 2008
    #4
  5. Duncan_Rowland

    Duncan_Rowland

    Joined:
    Aug 25, 2008
    Messages:
    246
    Likes Received:
    0
    For Reference: To allow recording of the audio output
    (e.g. arecord -D p_card1out0 -f cd > filename)
    I think I have this more or less fixed (maybe just need levels setting in audacity?
    - I'm still testing this but it does record something at least).
    Once the loopback driver has been added, the .asoundrc is as follows.
    -Duncan.


    pcm.card0 {
    type hw
    card 0
    }

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

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

    pcm.m_copier {
    type multi
    slaves.a.pcm "card0"
    slaves.a.channels 2
    slaves.b.pcm "p_card1in0"
    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
    }

    pcm.r_copier {
    type route
    slave.pcm "m_copier"
    ttable.0.0 1
    ttable.1.1 1
    ttable.0.2 1
    ttable.1.3 1
    }

    pcm.!default {
    type plug
    slave {
    pcm "r_copier"
    }
    }
     
    Duncan_Rowland, Nov 12, 2008
    #5
  6. Duncan_Rowland

    tcrock

    Joined:
    Apr 16, 2009
    Messages:
    3
    Likes Received:
    0
    Could someone post a newbie to linux friendly howto on this?

    I'd like to be able to record from PCM but obviously its not selectable in my mixer.. I've no idea how to add the loopback or any of that gubbins..

    I'm running crunchbang with the sickboy kernel on an AAO150 if that makes a difference
     
    tcrock, Apr 29, 2009
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.