How to record what you hear from your speaker

Moderator: Forum moderators

Post Reply
jamesbond
Posts: 717
Joined: Tue Aug 11, 2020 3:02 pm
Location: The Pale Blue Dot
Has thanked: 124 times
Been thanked: 402 times

How to record what you hear from your speaker

Post by jamesbond »

Server-less way to record what you hear

Preamble

This is an instruction on how to record the sound that you hear from your own speaker, using ALSA, without using any audio server.

If you already run a audio-server (pulseaudio, pipewire, jack, aloopd, alsa-loop, etc), leave now and read the documentation of your audio server. The information you see here will not help you.

Before you begin

ALSA is a very sophisticated sound system, found in Linux.

Most if end-user components can be configured using ALSA configuration files, located either in /etc/asound.conf and/or $HOME/.asoundrc (that would be /root/.asoundrc if you're running as root, as most puppies are).

The file $HOME/.asoundrc takes precedence over what you put in /etc/asound.conf, so if you edit /etc/asound.conf and it doesn't seem to take any effect, please check that if you have $HOME/.asoundrc that overrides it. Most Puppy utilities works by editing /etc/asound.conf but please be aware that the same instructions works as well if you work with $HOME/.asoundrc instead.

Principle of operation

It's very simple actually. You configure ALSA to do the followig:

1. Configure ALSA to split the sound data into two streams.
2. Configure one of the streams to go into the actual soundcard, so you hear the sound.
3. Configure the other one to go into a virtual loopback device.
4. The virtual loopback device has two ends - whatever comes into one end, goes out from the other.
5. You record from the other end of this virtual loopback.

Code: Select all

              |---> soundcard
Sound data -->|
              |---> virtual loopback ---> RECORDER program.

Requirement

1. The virtual loopback device comes from the kernel module called snd-aloop. To be able to use this, your kernel must support this module, and this module must be loaded. To do this, open terminal and run modprobe snd-aloop; if you don't get an error, you're good to go. It is good to notice that most kernels supports snd-aloop out of the box.

2. That's it. You don't need any other binary or program. You don't even need "alsa-loop" program.

The configuration files

Here is the working configuration file that output sounds to hw:0,0 (the first soundcard in your system), and allows you to record from a "mixout" PCM device.

Code: Select all

pcm.!default fdplug
ctl.!default { type hw card 0 }
pcm.fdplug {
	type plug
	slave {
		pcm fdasym
	}
}
pcm.fdasym { 
		type asym 
		playback.pcm {
			@func getenv
			vars [ ALSA_PCMOUT ]
			default fdmixout
		}
		capture.pcm {
			@func getenv
			vars [ ALSA_PCMIN ]
			default fdhw
		}
}
pcm.fdmixoutdmix {
	type dmix 
	ipc_key    11793603
	ipc_gid audio
	ipc_perm 0660 
	slave {
		pcm "hw:Loopback,0,7"
		period_time 0
		period_size 2048
		buffer_size 32768
	}
}
pcm.fdmixout {
	type plug
	route_policy "duplicate"
	slave.pcm {
		type multi
		slaves.a.pcm fddmix
		slaves.a.channels 2
		slaves.b.pcm "fdmixoutdmix"
		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.mixout "plughw:Loopback,1,7"
pcm.fddmix { 
	type dmix 
	ipc_key     9957191
	ipc_gid audio
	ipc_perm 0660 
	slave {
		pcm fdhw
		period_time 0
		period_size 2048
		buffer_size 32768
	}
}
pcm.fdhw { type hw card 0 device 0  }

If you need to change the output (not to hw:0,0 but for example, to hw:3,0), you only need to edit and change the above configuration in two places:

a) Change pcm.fdhw { type hw card 0 device 0 } to pcm.fdhw { type hw card 3 device 0 } and
b) Change ctl.!default { type hw card 0 } to ctl.!default { type hw card 3 }

How to use this?

Copy and paste the above configuration file to a text editor, and save the file into either /etc/asound.conf or $HOME/.asoundrc (edit as necessary if you're not outputting to hw:0,0).

That's it!

After you have done that:
1. Start playing whatever sound source you want to play (live audio stream, youtube, etc), and
2. Activate your recorded program and tell it to record from "mixout" device.

To clarify step (2), here are some examples.

A. Use "arecord" program to display the sound-level input from the "mixout" device. If the "mixout" device records that you hear, you should see a level-meter which roughly correspond to the music/audio that you hear.

To do this:
- open terminal
- run arecord -vvv -D mixout > /dev/null
- when done, press Ctrl-C to stop it.

B. Use "ffmpeg" to record the sound to an MP3 file

To do this:
- open terminal
- run ffmpeg -f alsa -i mixout /tmp/test.mp3
- when done, press Ctrl-C to stop it.

C. Use "mhhwaveedit" to record the sound to the editor

To do this:
- Launch mhwaveedit.
- Choose "Edit" menu entry, then "Preferences", the click the "Sound" tab, and click the "Settings" button next to ALSA, and change the "recording device" from "default" to "mixout". Then close the preference window.
- Click the "record" button. A VU meter should show up, and the meters should move corresponding to the music/audio that you hear.
- Click "Start recording" once you want to record it.

D. Other programs

All other bonafide recording programs would have some sort of settings to do this to the specify the recording source. Specify "mixout" in this case.

That's it!

Limitations and restrictions, and Q&A

1. The above configuration only works for stereo output. For any other formats (mono, 5.1 surround, 7.1. surround), the principle is the same, but you will need to edit the "bindings" section of the "duplicate" section of the block to bind the appropriate number of streams.

2. There can only be one recorder program in use. You cannot record using mhwaveedit and ffmpeg at the same time (or any other programs for that matter).

3. The configuration file can be left as is and it will continue to work (without any appreciable overhead) even if you are not recording.

What does it mean? It means, if you leave the configuration as it is, you can listen to your favourite radio; and if you want to record it, you can just launch your favorite recording program and click "record". There is no need to start/stop/re-start your radio program. The "mixout" function is always available and on-standby for when you need it; but it will not have any side effects if you are not recording anything - you will still continue to hear the audio.

This settings persists across reboots until you modify the configuration file again.

4. Q: I tried this and it doesn't work! Now I hear nothing at all!
A: Easy. Just delete the configuration file, and things should go back to normal.

5. Q: This is a bit difficult for me, is there a program that automate all this stuff?
A: Yes, the ALSA configuration snippet you see comes from Fatdog's "Set Default Soundcard" program (which is the equivalent / outgrowth of what Puppy's MSCW). With it you can configure this stuff and a lot more. Can this program be used in Puppy, or is it specific to Fatdog? Yes, it can be used in Puppy too. Bother your favorite puppy developer to get it included. Don't bother me, please.

Finally

Good luck and enjoy.

emil
Posts: 10
Joined: Wed Aug 03, 2022 3:30 pm

Re: How to record what you hear

Post by emil »

all this about why and where the sound comes from - it is played allready! just save it to a file.Why make that so difficult?

emil
Posts: 10
Joined: Wed Aug 03, 2022 3:30 pm

Re: How to record what you hear

Post by emil »

the sound coming out of your PC "as is" is recordable without all this on this board, why is that so hard in puppy?

User avatar
rcrsn51
Posts: 1390
Joined: Sun Aug 23, 2020 4:26 pm
Been thanked: 357 times

Re: How to record what you hear

Post by rcrsn51 »

emil wrote: Wed Aug 03, 2022 3:46 pm

just save it to a file.Why make that so difficult?

Details, please.

emil
Posts: 10
Joined: Wed Aug 03, 2022 3:30 pm

Re: How to record what you hear

Post by emil »

I installed Listener - "it listens for sound. If detected it starts recording". NO it does not! The PC confirms that it is installed - than the software is nowhere to be found! This one and a lot of other software tell that you they work and and what they are doing. :thumbdown: Even other recording software tell that they have listened and not "heard" anything. Than they did NOT listen - sound is playing loud and clear! Not much of all this software does what it claims. Sorry folks.

User avatar
rcrsn51
Posts: 1390
Joined: Sun Aug 23, 2020 4:26 pm
Been thanked: 357 times

Re: How to record what you hear

Post by rcrsn51 »

emil wrote: Wed Aug 03, 2022 4:26 pm

I installed Listener

What is Listener? Where did you get it?

Now you seem to be complaining about something different. The point of the instructions at the top of this thread is to capture sound WITHOUT needing third-party software.

emil
Posts: 10
Joined: Wed Aug 03, 2022 3:30 pm

Re: How to record what you hear

Post by emil »

In the Package manager - write listener and it should pop up 2 be installed

User avatar
rcrsn51
Posts: 1390
Joined: Sun Aug 23, 2020 4:26 pm
Been thanked: 357 times

Re: How to record what you hear

Post by rcrsn51 »

emil wrote: Wed Aug 03, 2022 5:04 pm

In the Package manager

What Puppy are you using?

emil
Posts: 10
Joined: Wed Aug 03, 2022 3:30 pm

Re: How to record what you hear

Post by emil »

Puppy Linux 7 just does only play sounds - perfectly - that is, even when recording creates a wave or mp3 file, sound players later show that they are playing it, there is no sound. Other PCs also play those mp3 and wave files - still no sound however. I use Slacko 7

emil
Posts: 10
Joined: Wed Aug 03, 2022 3:30 pm

Re: How to record what you hear

Post by emil »

I started another PC with the same Puppy, that also produced wave and mp3 files. All players play them and recognise them as perfect audio files, tell about rate, quality and so on - still the files are quiet.

emil
Posts: 10
Joined: Wed Aug 03, 2022 3:30 pm

Re: How to record what you hear

Post by emil »

an exifreader didnt tell something unusual ether.

User avatar
rcrsn51
Posts: 1390
Joined: Sun Aug 23, 2020 4:26 pm
Been thanked: 357 times

Re: How to record what you hear

Post by rcrsn51 »

At the top of the forum, there is a section just for Slacko. Post your complaint there so a member of the Slacko team can help you.

emil
Posts: 10
Joined: Wed Aug 03, 2022 3:30 pm

Re: How to record what you hear

Post by emil »

we did it with a little soundrecording USBmemory. Thought that a PC with a slacko were able to do that, but no.

climac
Posts: 1
Joined: Mon Oct 16, 2023 2:23 pm
Has thanked: 1 time
Been thanked: 2 times

Re: How to record what you hear

Post by climac »

I'm not a Puppy user, just a crux nerd. I registered on this forum just so I could thank you. I've been trying to figure out how to record audio from Battlezone on xmame for days and could find very little useful documentation on snd-aloop usage. Your solution works perfectly.

Thanks very much for posting it!

User avatar
mikewalsh
Moderator
Posts: 6158
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 795 times
Been thanked: 1981 times

Re: How to record what you hear

Post by mikewalsh »

Necro-posting, I know, but I felt this needed to be added:-

emil's statements hold true for PCs where the 'loopback' device works as it should. However...

I got this 'new' HP Pavilion desktop rig in Jan 2020, shortly before the onset of the pandemic. I had no issues with recording sound in the previous Compaq rig, because 'loopback' showed up in Retrovol - and worked - as it was meant to. On the Pavilion, however, regardless of the Puppy in use, there was no sign of the standard 'loopback' device. It was nowhere to be found.

Subsequent research unearthed the interesting fact that the 'loopback' device was present & correct for this machine, with this audio chip, under Windows. But no end of other folk had the same complaint as myself when it came to Linux.......turns out HP had carefully written an audio 'adapter' program for this chip exclusively for Windows. BUT....

....HP do NOT support Linux (so they will tell you very plainly & clearly on their support forums). Bummer!!!

------------------------------------------------

I posted about this in @number77 's thread:-

viewtopic.php?t=6083

....specifically, here:-

viewtopic.php?p=58660#p58660

I don't know who came up with the ideas first; whether it was Fred, Bill (rcrsn51) or jamesbond. But whoever it was, the information generated by those initial exchanges eventually resulted in not one, but TWO apps that will allow me to not only capture internally-generated audio, but to monitor it at the same time. One is my own SimpleAudioRecorder - built around ideas/concepts generated during the course of that above-linked discussion - in self-contained, 'portable' format, and basically using simple ALSA-based arecord. The other is Fred's more elaborate concept, ALSA-Capture GUI, which works along similar lines, but is ffmpeg-based instead.

Both work very well for me, so.......big thanks due to all involved.

Mike. ;)

Post Reply

Return to “Sounds”