Page 3 of 4
Re: How to record what the PC is playing?
Posted: Sun Jun 05, 2022 8:06 am
by fredx181
mikewalsh wrote:Mm......dropouts, not so much, Fred. What I do get is LOTS of clipping..!
I've tried addressing this by lowering the PCM level - this is normally set at 100%, as is the 'Front' slider (without which I get no audio at all!)
It reduces the clipping, yes....
Strange... for me adjusting any sliders in the mixer do NOT have any effect on the volume level in the recording (for monitoring it does, btw).
It seems that the volume level is just duplicated from the audio source. Tried with 2 different soundcards (built-in and USB), both the same.
@Bill how is that for you ?
@number77 the alsaloop command in the context we discussed is just for monitoring, not for recording.
Re: How to record what the PC is playing?
Posted: Sun Jun 05, 2022 9:54 am
by rcrsn51
fredx181 wrote: Sun Jun 05, 2022 8:06 am@Bill how is that for you ?
The same. Because the Loopback card does not have any mixer controls, I cannot change its volume while recording. So it depends on the source.
I can only adjust the volume when playing the recorded file. I wonder if that's what Mike is doing.
BTW, I tested downloading the audio track from a Youtube clip, then capturing the same audio and comparing them. To my untrained ears, there wasn't much difference and the files were almost the same size. But it's a lot faster to just download the clip!
Re: How to record what the PC is playing?
Posted: Sun Jun 05, 2022 11:47 am
by fredx181
rcrsn51 wrote:BTW, I tested downloading the audio track from a Youtube clip, then capturing the same audio and comparing them. To my untrained ears, there wasn't much difference and the files were almost the same size.
Best comparison IMO is when you capture to .wav or .flac. alsa-capture does compress to @128 mp3, youtube sound is always lossy AFAIK, so you get lossy > lossy, which results in major quality loss (but probably most people won't hear that, depends also on what type of music, I guess).
Re: How to record what the PC is playing?
Posted: Sun Jun 05, 2022 12:05 pm
by rcrsn51
Are you suggesting that you could get better results by piping arecord into flac instead of lame? Like:
Code: Select all
| flac - -s -f -o /root/alsa-capture.flac
I tried it but couldn't tell the difference.
Re: How to record what the PC is playing?
Posted: Sun Jun 05, 2022 1:04 pm
by mikewalsh
@rcrsn51 / @fredx181 :-
rcrsn51 wrote: Sun Jun 05, 2022 9:54 am
fredx181 wrote: Sun Jun 05, 2022 8:06 am@Bill how is that for you ?
The same. Because the Loopback card does not have any mixer controls, I cannot change its volume while recording. So it depends on the source.
I can only adjust the volume when playing the recorded file. I wonder if that's what Mike is doing.
Mm. TBH, I'm not entirely sure what I am doing - something of a "suck-it-and-see" approach, really. Possibly I'm only modifying what I can actually hear, though I did notice that by reducing DeaDBeeF's pre-amp level, the VU meter reached noticeably lower 'peaks' during the actual recording......since I was using DeaDBeeF's output AS the source, and the pre-amp modifies that output..?
Previously, it was topping-out at around 98%; judicious adjustment of the pre-amp control brought this down to a much more reasonable 70-75%, so.....I dunno.
Might just be my imagination!!
Mike.
Re: How to record what the PC is playing?
Posted: Sun Jun 05, 2022 1:20 pm
by rcrsn51
mikewalsh wrote: Sun Jun 05, 2022 1:04 pmMight just be my imagination!!
I looked at this again with Youtube videos. If I adjust the Youtube player's own volume slider, I can definitely change the volume in the final mp3 file.
But if the source has no volume control, like a radio stream, I cannot change it.
Re: How to record what the PC is playing?
Posted: Sun Jun 05, 2022 2:02 pm
by mikewalsh
rcrsn51 wrote: Sun Jun 05, 2022 1:20 pm
mikewalsh wrote: Sun Jun 05, 2022 1:04 pmMight just be my imagination!!
I looked at this again with Youtube videos. If I adjust the Youtube player's own volume slider, I can definitely change the volume in the final mp3 file.
But if the source has no volume control, like a radio stream, I cannot change it.
This is one reason why I prefer to use DeaDBeeF for .pls streams. Even if the *original* source has no adjustment, I have a certain degree of control over it with DeeDBeeF's pre-amp. Perhaps my hearing is rubbish now, though audio playback has always been one area I've been somewhat 'fussy' about, most of my life.
I know it's supposed to be possible to create an ALSA pre-amp. I don't know if one could be 'added' to the loopback device.....perhaps this could be looked-into, by those that understand this stuff a bit better than me?
(This was one of the things I tried in the past which led to 'borking' a Puppy install, followed by a complete re-build of the save from scratch. I'm not keen to try it again, especially since I don't know where I went wrong; the source ./asoundrc file was again on the Arch wiki, which I generally regard as a pretty reliable source of information. I probably just implemented it wrong, though if I understood ALSA signalling'n'stuff better than I do, I might not have made the mistake...!)
Mike.
Re: How to record what the PC is playing?
Posted: Sun Jun 05, 2022 2:23 pm
by fredx181
rcrsn51 wrote: Sun Jun 05, 2022 12:05 pm
Are you suggesting that you could get better results by piping arecord into flac instead of lame? Like:
Code: Select all
| flac - -s -f -o /root/alsa-capture.flac
I tried it but couldn't tell the difference.
Well, in theory, yes, as it's lossless encoding, but my ears aren't as good as when I was 18 , so I probably won't tell the difference too.
EDIT: Btw, I tried similar as you (piping to flac) but the resulting file is not seekable, did a websearch for that but couldn't solve it, any idea ?
Re: How to record what the PC is playing?
Posted: Sun Jun 05, 2022 2:54 pm
by rcrsn51
As a wild guess, I wonder if it's because the input data comes through a pipe instead of a file. So certain metadata about the source is not known. That prevents a player from being able to jump through the file during playback.
Edit: I can confirm this issue with flac. I tested it with a .pls file for a radio stream and Deadbeef. After recording to an mp3, the resulting file was seekable in Deadbeef. But after recording to a flac, it was not.
Re: How to record what the PC is playing?
Posted: Sun Jun 05, 2022 5:51 pm
by fredx181
rcrsn51 wrote:Edit: I can confirm this issue with flac. I tested it with a .pls file for a radio stream and Deadbeef. After recording to an mp3, the resulting file was seekable in Deadbeef. But after recording to a flac, it was not.
Yes, after long time searching and trying I gave up, probably not possible with arecord > flac, however with ffmpeg it's OK, e.g. :
ffmpeg -f alsa -i Loop capture.flac
Re: How to record what the PC is playing?
Posted: Sun Jun 05, 2022 7:01 pm
by williams2
Does -ss
make it seekable? Like
ffmpeg -f alsa -ss -i Loop capture.flac
or maybe
ffmpeg -ss -f alsa -i Loop capture.flac
(I have not tried this.)
Re: How to record what the PC is playing?
Posted: Sun Jun 05, 2022 7:56 pm
by fredx181
williams2 wrote: Sun Jun 05, 2022 7:01 pm
Does -ss
make it seekable? Like
ffmpeg -f alsa -ss -i Loop capture.flac
or maybe
ffmpeg -ss -f alsa -i Loop capture.flac
(I have not tried this.)
With ffmpeg it's OK already, seekable flac, it's about this approach with arecord that results in a not seekable flac file, e.g.:
arecord -V mono -f cd -D Loop | flac - -f -o capture.flac
Re: How to record what the PC is playing?
Posted: Sun Jun 05, 2022 9:38 pm
by williams2
I remembered something when I read that post.
Something about ALFF being seekable, but streaming to wav files is not.
from arecord --help
-t, --file-type TYPE file type (voc, wav, raw or au)
I seem to remember that if the output file is an .au
file, it will be seekable, but a wav or raw won't.
And I seem to remember that the .au type can be piped through flac, and the flac file will also be seekable.
It was a long time ago, but I think I remember piping to the .au type to make the output seekable.
From flac --help
-S, --seekpoint={#|X|#x|#s} Add seek point(s)
maybe flac -S
would make the flac file seekable? Again, I didn't try it.
Re: How to record what the PC is playing?
Posted: Mon Jun 06, 2022 7:53 am
by fredx181
Thanks for the suggestions @williams2 anyway, but didn't work either.
I give up on arecord > flac and use ffmpeg if I want capturing to flac.
Re: How to record what the PC is playing?
Posted: Mon Jun 06, 2022 1:01 pm
by rcrsn51
fredx181 wrote: Sun Jun 05, 2022 5:51 pm
ffmpeg -f alsa -i Loop capture.flac
Nice. I am constantly amazed at what ffmpeg can do.
How did you figure out that "-i Loop" worked? It's not a legal syntax as described in the ffmpeg documentation.
Which .asoundrc.capture are you using these days - mine or yours? Are you seeing advantages to one over the other?
Re: How to record what the PC is playing?
Posted: Mon Jun 06, 2022 3:32 pm
by fredx181
rcrsn51 wrote:How did you figure out that "-i Loop" worked? It's not a legal syntax as described in the ffmpeg documentation.
Well, simply by trying.
Which .asoundrc.capture are you using these days - mine or yours? Are you seeing advantages to one over the other?
Testing both.
One of my goals is to record from Spotify (the program, not the web-player) and, if I use mine, found that Spotify refuses to play when first press Enter in alsa-capture and then start a song in Spotify, if I start playing a song first it's OK. By using your program it's how I would like it (can first press Enter in alsa-capture and then play a song).
As I mentioned I had a case of dropouts with yours, but found it can be fixed by changing the pcm.loopout function to:
Code: Select all
# output device
pcm.loopout {
type dmix
ipc_key 328211
slave {
pcm "hw:Loopback,0,0"
rate 48000
format S16_LE
channels 2
period_size 256
buffer_size 8192
}
}
EDIT: The "rate 48000" doesn't seem to matter for me, it outputs as 44100
Re: How to record what the PC is playing?
Posted: Mon Jun 06, 2022 3:37 pm
by jamesbond
How to do it:
1. Buy a soundcard that has a hardware mix-out support (most soundcards made before year 2000 have this feature).
2. Run pulseaudio and configure it to "record what you hear".
If option (1) and (2) don't appeal to you, then read here.
EDIT: post moved to its own HOW-TO to make it more prominent and useful to other people, instead of getting buried here in page 8 of a long thread.
Re: How to record what the PC is playing?
Posted: Mon Jun 06, 2022 3:58 pm
by rcrsn51
fredx181 wrote: Mon Jun 06, 2022 3:32 pm
EDIT: The "rate 48000" doesn't seem to matter for me, it outputs as 44100
If you are using arecord, that may be because you have "-f cd". So it's automatically converting to 44100.
I wonder if all you need to add to loopout is the larger buffer_size.
[Edit] It looks like you need period_size and buffer_size.
Re: How to record what the PC is playing?
Posted: Mon Jun 06, 2022 4:55 pm
by fredx181
rcrsn51 wrote:[Edit] It looks like you need period_size and buffer_size.
Right, tested with these added only and works ok.
Re: How to record what the PC is playing?
Posted: Mon Jun 06, 2022 5:06 pm
by rcrsn51
fredx181 wrote: Mon Jun 06, 2022 4:55 pm
rcrsn51 wrote:[Edit] It looks like you need period_size and buffer_size.
Right, tested with these added only and works ok.
Excellent. I am going to add those lines to my .asoundrc.capture but commented out. If someone has dropouts, they just need to uncomment them.
I am also adding a simple way to switch the alsaloop playback device from hw:0,0 to something like hw:1,3.
Re: How to record what the PC is playing?
Posted: Mon Jun 06, 2022 6:20 pm
by number77
fredx181 wrote: Mon Jun 06, 2022 3:32 pm
EDIT: The "rate 48000" doesn't seem to matter for me, it outputs as 44100
Hello
I got totally lost a few posts back so when it is finalised could you try and explain in simplish terms.
Thanks.
Re: How to record what the PC is playing?
Posted: Mon Jun 06, 2022 6:31 pm
by fredx181
number77 wrote: Mon Jun 06, 2022 6:20 pm
fredx181 wrote: Mon Jun 06, 2022 3:32 pm
EDIT: The "rate 48000" doesn't seem to matter for me, it outputs as 44100
Hello
I got totally lost a few posts back so when it is finalised could you try and explain in simplish terms.
Thanks.
Not sure what possibly to explain and what you mean with "when it is finalised".
It's about the application "alsa-capture" from rcrsn51 that will output a 44100 Hz file, even if ~/.asoundrc would contain "rate 48000", rcrsn51 explained why above.
Don't know if you are still interested in this "capture from soundcard" thing, though.
Re: How to record what the PC is playing?
Posted: Mon Jun 06, 2022 7:00 pm
by number77
fredx181 wrote: Mon Jun 06, 2022 6:31 pm
number77 wrote: Mon Jun 06, 2022 6:20 pm
fredx181 wrote: Mon Jun 06, 2022 3:32 pm
EDIT: The "rate 48000" doesn't seem to matter for me, it outputs as 44100
Hello
I got totally lost a few posts back so when it is finalised could you try and explain in simplish terms.
Thanks.
Not sure what possibly to explain and what you mean with "when it is finalised".
It's about the application "alsa-capture" from rcrsn51 that will output a 44100 Hz file, even if ~/.asoundrc would contain "rate 48000", rcrsn51 explained why above.
Don't know if you are still interested in this "capture from soundcard" thing, though.
Yes I would still like to do that.
Re: How to record what the PC is playing?
Posted: Mon Jun 06, 2022 7:28 pm
by Dingo
I was able to record audio while playing youtube videos, with this script
https://forum.puppylinux.com/viewtopic. ... 764#p58764
but I tried to record audio output from a text to speech program working thanks to wine and ended up only with a silent track
Re: How to record what the PC is playing?
Posted: Mon Jun 06, 2022 8:06 pm
by rcrsn51
number77 wrote: Mon Jun 06, 2022 7:00 pmYes I would still like to do that.
I have posted alsa-capture v1.2 here. Read the Notes section.
I would recommend that you run this on a temporary clean install of Puppy. At this point, it's hard to know what you might have done with your ALSA system.
Re: How to record what the PC is playing?
Posted: Tue Jun 07, 2022 2:51 am
by mikewalsh
Now then:-
Using Bill's v1.2 as a starting-point, I've made a few mods.
I created a directory called "AudioRecord" on an external partition, which contains 2 scripts; "RECORD.sh" and "PLAYBACK.sh". This is then sym-linked into /root.....the idea being that this can all be shared between multiple Puppies, OK? Install the alsa-capture.deb package into each one, and sym-link the "AudioRecord" directory into each one as I go...
I then made up a wee YAD-powered GUI to call these two scripts:-
Borrowing from some of the code I used in DriveSpeed!, "RECORD.sh" reads thus:-
Code: Select all
#!/bin/sh
#
HERE="$(dirname "$(readlink -f "$0")")"
#
if [ -f "$HERE/audio.mp3" ]
then
rm -f $HERE/audio.mp3
fi
#
sleep 1
# Start audio recording...
modprobe snd-aloop
#
rxvt -title ' ~ Ffmpeg audio recording.......' -background '#ffff80' -geometry '80x10' rxvt -hold ls -e alsa-capture
It brings up a small rxvt window with alsa-capture already started. Following through the instructions, I also don't need to press the final 'Enter'.....it seems to auto-run this as soon as Ctrl+C is pressed. (Which is neat.)
I've also modified 'alsa-capture' for stereo input, as opposed to mono:-
Once recording is finished with, I can use the GUI to play back the just-recorded file, to check it's OK. "PLAYBACK.sh" reads like this:-
Code: Select all
#!/bin/sh
#
# Play back recorded audio file...
#
HERE="$(dirname "$(readlink -f "$0")")"
#
mplayer $HERE/audio.mp3
I discovered that the "woolliness" I described further back in the thread was all due to playing the file back in DeaDBeeF. Using mplayer gives much cleaner reproduction, and sounds far more like the original as recorded...
"Pause/Break" has been key-bound to let me stop mplayer with the "killall" command.....useful if it's a long track, and I don't want to listen to it all the way through.
-------------------------------------------------------------
Untidy by some people's standards, I daresay. But I'm more than happy with it, especially with the modification Bill made to allow monitoring of what you're recording.
Great effort all round, guys! Well done, all. Nice one.
Mike.
Re: How to record what the PC is playing?
Posted: Tue Jun 07, 2022 11:00 am
by rcrsn51
Nice work.
Fred has discovered that recording though arecord and piping into an encoder like lame does not always work well. As an alternative, you can record with ffmpeg by changing line 34 like this:
Code: Select all
ffmpeg -y -hide_banner -f alsa -i Loop /root/alsa-capture.flac
You can select the output format just by changing the filename extension.
FFmpeg doesn't show the vumeter, but it shows the file transfer in progress.
Re: How to record what the PC is playing?
Posted: Tue Jun 07, 2022 11:30 am
by fredx181
rcrsn51 wrote:Fred has discovered that recording though arecord and piping into an encoder like lame does not always work well. As an alternative, you can record with ffmpeg by changing line 35 like this:
Piping into lame is OK AFAIK, the problem for me was with arecord > flac (file not seekable), btw tested piping into ogg and works OK too.
Re: How to record what the PC is playing?
Posted: Tue Jun 07, 2022 1:20 pm
by mikewalsh
Just a wee note, guys:-
If you want to be able to set the file bitrate with the ffmpeg command, then
- For video, it's
- For audio, it's
Code: Select all
-b:a 192k (or whatever rate you want)
I left the video bitrate unfilled, since I didn't look into those.
Thus, the above ffmpeg command would become (just as an example):-
Code: Select all
ffmpeg -y -hide_banner -f alsa -i Loop -b:a 192k /root/alsa-capture.flac
It's always inserted just prior to the output file name, apparently. Works for me like that.
Mike.
Re: How to record what the PC is playing?
Posted: Tue Jun 07, 2022 3:36 pm
by fredx181
mikewalsh wrote:Thus, the above ffmpeg command would become (just as an example):-
ffmpeg -y -hide_banner -f alsa -i Loop -b:a 192k /root/alsa-capture.flac
It's always inserted just prior to the output file name, apparently. Works for me like that.
That works (setting bitrate) for lots of formats probably, but not for flac AFAIK.
However, you can set the compression level for flac with ffmpeg, doesn't influence the quality, but a high compression level gives a smaller fille, highest is 12 (lowest = 0), so then e.g.:
ffmpeg -y -hide_banner -f alsa -i Loop -c:a flac -compression_level 12 /root/alsa-capture.flac