This post will try to describe what is needed to set up mixing two sound streams, through Pulse Audio, and what set up is required to record the mixed output.
First the Manual method is described ..... but I have also included a script which will do the set up for you.
Even if you use the script rather than the manual method, please read the whole post so you know what PA set up is required to get things working properly.
You must have Pulse Audio installed and working, as well as Pulse Audio Volume Control installed.
You should get familiar with PA Vol Control and its various tabs etc.Tip:
When viewing a tab, enable viewing of ALL
streams, by selecting the option from the drop-down box on the bottom of the tab.Manual Method:
To set up your system for mixing and recording you must first set up the output location for the mixed sound stream.
This is done by loading the 'null-sink' PA module.
Then you set up two loopback sinks, one each for the two sound sources to be mixed ... the song being played, and the MIC for your voice.
Here are the three commands to be input in a terminal as user:
# Set up the mixed sound sink
pactl load-module module-null-sink sink_name=MySink
# Set up the first loopback sink
pactl load-module module-loopback sink=MySink
# Set up the second loopback sink
pactl load-module module-loopback sink=MySink
[If you wish to mix more than two sound streams, just create extra loopbacks using the last command]*Important: Take note of the number returned for each command. They will be needed later.*
As can be seen from the name used in the above commands, they are all related; that is the loopbacks will connect to the null-sink of the same name.
That is it. The system is now set up for mixing two sound sources and recording it.
To record from the correct sound sources, a little set up is needed in PA Vol Control, to specify the correct streams.
This is done on the Recording tab.
With 'All Streams' selected on the bottom of the page, the two Loopback streams become visible.
Using the buttons to the right of the Loopback entries,
select the MIC for one of them, and
select 'Monitor of .. ' the the built in Audio for the other.
You can of course mix different sound streams if you wish by selecting them here.
In general, an entry without 'Monitor' in its name is an input device, such as a MIC.
Those with 'Monitor' in their names are 'taps into' the sound stream going to a sink, such as speakers or headset.
Now launch your preferred recording application. If necessary ensure it uses Pulse Audio and 'default' source.
It too will appear on the Recording tab when a recording is started
It is useful to start a recording and pause it, while the correct settings are applied on the Recording tab.
Set it to record from "Monitor of Null Output" .... that is the mixed sound stream.
The three streams are now set up.
Unpause the recording application ... it starts to record
Play the song with your player application.
Sing into the MIC
You will most likely need to do a few 'dry runs' first to get the balance between the MIC and song to your liking.
To alter the volume of the MIC use the Input Device tab of PA Vol Control.
To alter the volume of the played song, use the Output Devices tab of PA Vol Control.
Alter the sliders on the "Null Input" and "Null Output" devices until you have the required balance.
Hours of fun!
The set up described above is not permanent.
It will be lost on a reboot.
I thought about setting this up permanently, but decided against it, as it seems to cause PA to use an extra couple of % of CPU.
Balanced against that, issuing three commands to do the set up, and three more to dismantle it, is not a difficult task, but is now incorporated into a small script if you prefer to use that.
Should you wish to delete the setup without rebooting the following command will do it. Do the command for each of the three numbers returned when doing the set up commands (you do remember them don't you
pactl unload-module <module number>
About the script ........ this script toggles the set up on and off, in a similar manner to doing it manually.
The script is called PA-Mix.sh
Run it once to set up the mixer, and run it again to delete the set up. Simple!
In this way it can be instantly available and just as quickly deleted when you are finished recording.
Here is a link to the script:-http://dl.dropbox.com/u/5838889/PA-Mix.sh
Copy the script to anyplace you wish. Right click it - Properties - Permissions tab ... and make it executable.
Now clicking on the script will activate it.
You will be able to see the results of the set up immediately, on the Recording tab of PulseAudio Volume Control.
Clicking on the script again at any time will delete the set up, and the virtual devices will disappear from the Recording tab of PA Vol Control immediately.
Hopefully some will find this useful.