Page 1 of 2

How to capture audio output

Posted: Mon 25 Aug 2014, 15:07
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!

very interesting this post

Posted: Sat 15 Nov 2014, 10:35
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

Posted: Sat 15 Nov 2014, 11:49
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?

Posted: Sat 15 Nov 2014, 12:06
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

Posted: Sat 15 Nov 2014, 12:41
by disciple
Why did you want to do that?

Posted: Sat 15 Nov 2014, 14:08
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 !!

Posted: Sat 15 Nov 2014, 14:23
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

Posted: Sat 15 Nov 2014, 15:36
by backi
Sorry i was wrong on Tahrpup .
Did not work !

Posted: Sat 15 Nov 2014, 20:42
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 :)

Posted: Sat 15 Nov 2014, 20:54
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

Posted: Mon 17 Nov 2014, 16:04
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!

Posted: Wed 01 Jun 2016, 03:07
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.

Posted: Wed 01 Jun 2016, 03:27
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.

Posted: Thu 02 Jun 2016, 08:31
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.
.

how to record your tapes to mp3

Posted: Thu 02 Jun 2016, 16:20
by Pelo
how to record your tapes to mp3 with audacity French topic here (English how-to)
For concerned people.

Posted: Fri 03 Jun 2016, 01:29
by greengeek
Added an sfs version to my post above for those than don't want to take a risk with installing pets.

Re: How to capture audio output

Posted: Mon 15 Aug 2016, 08:10
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.

Posted: Mon 15 Aug 2016, 09:35
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!

linked to topic in Multimedia section.

Posted: Tue 16 Aug 2016, 12:51
by Pelo
information linked to Simple screen recorder, topic in Multimedia section.

Debate with our french expert, forum francophone

Posted: Wed 12 Oct 2016, 04:00
by Pelo