How to capture audio output

How to do things, solutions, recipes, tutorials
Message
Author
User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

How to capture audio output

#1 Post by SFR »

This "how-to" describes one of the methods of recording audio output in case of lack of 'mix' capture device.
This is especially true for laptops/netbooks with snd_hda_intel driver.
___________

1. First, we need to load snd-aloop kernel module. Open terminal window and type:

Code: Select all

modprobe snd-aloop
If the above command returns 'FATAL: Module snd-aloop not found.' you're out of luck.
In such a case you could either try to compile the missing module by yourself or consult developer(s) of your distro for additional info/help.

To make this module load at system boot:
Menu -> System -> Boot Manager -> Modules -> Add new module

NOTE: if the module is already loaded it won't be listed in BootManager!
To remove it:

Code: Select all

rmmod snd-aloop
Then add it in BootManager and load back using modprobe.



2. Create (if doesn't exist) /etc/asound.conf and append the following content to it:

Code: Select all

pcm.!default {
  type asym
  playback.pcm "LoopAndReal"
  #capture.pcm "looprec"
  capture.pcm "hw:0,0"
}

pcm.looprec {
    type hw
    card "Loopback"
    device 1
    subdevice 0
}


pcm.LoopAndReal {
  type plug
  slave.pcm mdev
  route_policy "duplicate"
}


pcm.mdev {
  type multi
  slaves.a.pcm pcm.MixReale
  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
}


pcm.MixReale {
  type dmix
  ipc_key 1024
  ipc_perm 0666
  slave {
    pcm "hw:0,0"
    rate 48000
    #rate 44100
    periods 128
    period_time 0
    period_size 1024 # must be power of 2
    buffer_size 8192
  }
}

pcm.MixLoopback {
  type dmix
  ipc_key 1025
  ipc_perm 0666
  slave {
    pcm "hw:Loopback,0,0"
    rate 48000
    #rate 44100
    periods 128
    period_time 0
    period_size 1024 # must be power of 2
    buffer_size 8192
  }
}
This will create a new device named looprec, which is kinda substitute for the absent 'mix' device.

NOTE 1: In some cases sound card's index may be different from 0, e.g. in Acer AO 722 I had to replace all occurences of 'hw:0,0' with 'hw:1,0'.

NOTE 2: Multiple-Sound-Card-Wizard creates its own /etc/asound.conf file, so if you need to use it, do it before setting up looprec. Then you can append the stuff from above to it.



3. Perform a quick test. Turn on some music and type:

Code: Select all

arecord -f dat -D looprec > /root/test.wav
Keep recording for a few seconds, then Ctrl+C and type:

Code: Select all

aplay /root/test.wav
to check if the recording went well.



In order to enable recording in mhWaveEdit:
In 'Edit -> Preferences -> Sound -> (Driver: ALSA) Settings -> Recording device' enter looprec.
Also, sample format ('Play -> Record -> Sample format -> Other format') has to be:
- Channels: Stereo
- Sample type: 16 bit PCM
- Signedness: Signed
- Endianness: Little endian
- Sample rate: 48000


In order to enable recording in Audacity:
In 'Edit -> Preferences -> Devices -> Recording -> Device' choose looprec
In 'Edit -> Preferences -> Quality -> Sampling -> Default Sample Rate' choose 48000



KNOWN ISSUES:
- PCM slider in Alsamixer/Retrovol no longer works
- you can't record from microphone using looprec device
- nor from pMusic (may be not true for older versions though, haven't checked), because it uses its own, custom ~/.asoundrc config file (probably needed by equalizer), but if you delete this file after starting PMusic and restart a track, it becomes recordable
- nor from apps that use OSS, unless they have an option to set output to ALSA (or unless you have alsa-oss installed and you'll use aoss script to launch such an application)
___________

DISCLAIMER: I only tranplanted the info provided by kokoko3k on Archlinux forum into Puppy's ground, taking into account some specific quirks of the latter.
I do not understand why and how the stuff in asound.conf works.

Thanks to all in this thread for the feedback.

Greetings!
Last edited by SFR on Mon 17 Nov 2014, 16:02, edited 1 time in total.
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
mister_electronico
Posts: 969
Joined: Sun 20 Jan 2008, 20:20
Location: Asturias_ España
Contact:

very interesting this post

#2 Post by mister_electronico »

very interesting this post.

If you want to record sound from microphone

cat /dev/audio > sample.au

or

dd bs=8k count=4 < /dev/audio > sample.au

Only make file 8 K


to play it

cat sample.au > /dev/audio

Thanks

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#3 Post by disciple »

- nor from apps that use OSS, unless they have an option to set output to alsa
it would work if you used aoss, wouldn't it?
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#4 Post by mikeb »

I managed to compile an audacity to have the choice of OSS and ALSA.... the compromise is to drop their built in mixer controls since the reason they don't support both is because they never bothered to make the mixer/portaudio work with both...hence version 1.2.x. is OSS only and version 1.3.x./ 2.x.x is ALSA only.

Felt the urge to mention that ..it seemed related...and this recording of audio is an interest of mine.

mike

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#5 Post by disciple »

Why did you want to do that?
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

backi
Posts: 1922
Joined: Sun 27 Feb 2011, 22:00
Location: GERMANY

#6 Post by backi »

Thanks !!!! very much
Helped me a lot ......
could not get Audacity working in Quirky Unicorn and in Tahrpup ....
but now.......problem solved .
Thanks a lot !!

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#7 Post by mikeb »

Why did you want to do that?
If thats directed at me the motivation was audacity 1.3 overhead is 4 times that of 1.2 due to it insisting on rendering the waveform in real time as it records...in gtk2 thats a cpu killer and can result in jerky recordings...not good...but the gtk1/1.2 version had no Alsa support so the problem of sound card hogging. I dug in and found out why and got both working on both versions... for the sheer usefulness of it. (sp/dif option was a bonus on 1.2)


mike

backi
Posts: 1922
Joined: Sun 27 Feb 2011, 22:00
Location: GERMANY

#8 Post by backi »

Sorry i was wrong on Tahrpup .
Did not work !

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#9 Post by disciple »

had no Alsa support so the problem of sound card hogging
Again, aoss would be a good work around in that situation. But well done on solving it proproperly :)
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#10 Post by mikeb »

It was a challenge to myself... IIRC newer releases of portaudio makes it extremely difficult to do it now and the loss of built in level controls would be unpopular anyway.

Sorry if that was a bit of a sidetrack on the topic.... my usual method is arecord anyway which also works nicely with sp/dif input..... that in itself usually requires control outside of such as audacity can provide anyway..or did. eg switching digital in on and so on...

mike

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#11 Post by SFR »

disciple wrote:
- nor from apps that use OSS, unless they have an option to set output to alsa
it would work if you used aoss, wouldn't it?
Hmm, I didn't know about the existence of that "thing" 'till you mentioned it.
Slacko doesn't have alsa-oss installed by default, but just grabbed one from pkgs.org and yes, I can confirm - it does work.
Thanks for the info!

Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

gcmartin

#12 Post by gcmartin »

This solution in this thread or this solution here should be included in PUP distros. Often times we need to record audio over the desktop without having to read for a "redirect" cable for Line-out to line-in use.

Hope this gets to PUP developers.

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#13 Post by disciple »

What sound related wizards are in Puppies these days? And how is the software equaliser that is in them provided?
Since soundcards typically have a "mix" control I think this would be more appropriate as (part of?) a wizard than set up by default. I'd say the same for setting up a software volume control when the sound card doesn't provide one.
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#14 Post by greengeek »

gcmartin wrote:This solution in this thread or this solution here should be included in PUP distros. Often times we need to record audio over the desktop without having to read for a "redirect" cable for Line-out to line-in use.
Thanks SFR for the methodology - seems to work well for me on a Slacko 5.6 derivative.
I have made a pet which adds a default /etc/asound.conf file, loads the snd-aloop module, adds a loopbackrecorder script into /usr/bin, and also adds start and stop scripts into /root.

Just click "startloopback" in /root, then start your audio stream playing, and the test.wav file will be accumulated in /root.

When you have finished playing the audio just click "stoploopback" in /root and the recording phase will stop.

EDIT : if you do not have enough RAM to accumulate the final size of the .wav file you record into /root then it will be necessary to modify the /usr/bin/loopbackrecord file to select a different location that has more space to store the recording. (Roughly speaking it uses around 10MB of RAM per minute of recording)

EDITED : The only problem I have experienced is that after the recording is made pMusic cannot be used to play any music - it gives a "playback error". I guess it can't access some part of the audio subsystem. Turns out this only occurs if I have not yet closed the program that was producing the original audio - eg browser or other music player etc.. However, I find this problem does not occur if I play a music track with pmusic before I make the recording. If I do that it has no trouble playing any track afterwards.

EDIT : Once the recording is done I use mhwaveedit to open the test.wav file for the purpose of trimming unwanted extra stuff from the beginning and end of the track, then save as .mp3 if i want a smaller file.

EDIT : Added an sfs for those who dont want to take the risk of installing a pet. Please remove the false .gz suffix.

CAUTION : Never install any pets unless you have first taken a backup of your savefile. I recommend testing pets first in a "fresh" boot of the generic version of your puppy - so that your savefile is not permanently affected. Use the sfs version instead if you are concerned about this issue.
.
Attachments
loopbackrecorder_gg-0.0.sfs.gz
False gz suffix. REMOVE THE gz SUFFIX
(4 KiB) Downloaded 435 times
loopbackrecorder_gg-0.0.pet
(1.04 KiB) Downloaded 460 times
Last edited by greengeek on Fri 03 Jun 2016, 01:39, edited 7 times in total.

Pelo

how to record your tapes to mp3

#15 Post by Pelo »

how to record your tapes to mp3 with audacity French topic here (English how-to)
For concerned people.

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#16 Post by greengeek »

Added an sfs version to my post above for those than don't want to take a risk with installing pets.

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

Re: How to capture audio output

#17 Post by greengeek »

SFR wrote:KNOWN ISSUES:
- PCM slider in Alsamixer/Retrovol no longer works
I am finding that alsamixer won't start at all. It gives the following error:

Code: Select all

# alsamixer
invalid card index: "
It appears to be having trouble with the "card" definition in this stanza:

Code: Select all

pcm.looprec {
    type hw
    card "Loopback"
    device 1
    subdevice 0
}
Retrovol runs fine though.

Do you think it might be possible to make any change that keeps alsamixer happy and lets it run (despite the loss of PCM slider as you have indicated) or is this just an unavoidable side effect?

EDIT : Strangely - if I enter "alsamixer version" into a terminal then alsamixer does run! (Wrong syntax to tell me which version but hey, it opens the alsamixer gui!)
It seems to look slightly different (fonts harder to read) but at least it runs. Weird.
cheers!

EDIT 2 : Alsamixer is version 1.0.26 and this is on a Slacko 5.6 derivative.

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#18 Post by SFR »

greengeek wrote:Do you think it might be possible to make any change that keeps alsamixer happy and lets it run (despite the loss of PCM slider as you have indicated) or is this just an unavoidable side effect?
Hey Greengeek

Sorry, but I have no slightest idea what and how should be changed, I don't get this syntax at all...
Just tried it in Fatdog and Alsamixer/Retrovol work well (except PCM), but YT in Chrome is mute.

Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

Pelo

linked to topic in Multimedia section.

#19 Post by Pelo »

information linked to Simple screen recorder, topic in Multimedia section.


Post Reply