-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
I've been trying to capture audio on a loopback device in Linux. I've enabled a loopback device through:
modprobe snd-aloopThis adds a new virtual card to my environment:
arecord -l
**** List of CAPTURE Hardware Devices ****
card 2: Loopback [Loopback], device 0: Loopback PCM [Loopback PCM]
Subdevices: 8/8
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
Subdevice #4: subdevice #4
Subdevice #5: subdevice #5
Subdevice #6: subdevice #6
Subdevice #7: subdevice #7
card 2: Loopback [Loopback], device 1: Loopback PCM [Loopback PCM]
Subdevices: 8/8
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
Subdevice #4: subdevice #4
Subdevice #5: subdevice #5
Subdevice #6: subdevice #6
Subdevice #7: subdevice #7To test if the loopback device is working a ran the following examples:
1st terminal:
arecord -D hw:2,1,0 -r 44100 -c 2 -f S16_LE record.wav2nd terminal (sample wav):
aplay -D hw:2,0,0 -f S16_LE -c2 play.wavAfterwards I'm able to successfully play the recorded file back:
aplay record.wavNext it was time to try capturing the input through Audify. The below code snippet tries to capture data from Loopback device.
const { RtAudio, RtAudioFormat, RtAudioApi } = require('audify');
const rtAudio = new RtAudio(RtAudioApi.LINUX_ALSA);
const audioDevices = rtAudio.getDevices();
console.log('Device #, Name, # of Channels');
for(let i = 0; i < audioDevices.length; i++){
let device = audioDevices[i];
if(device.inputChannels > 0){
console.log(i, device.name, device.inputChannels);
}
}
rtAudio.openStream(null, { deviceId: 2, nChannels: 2, firstChannel: 0 }, RtAudioFormat.RTAUDIO_FLOAT32, 48000, 48, 'testing', (outputBuffer) => {
console.log(outputBuffer);
});
rtAudio.start();Outputs:
Device #, Name, # of Channels
0 Default ALSA Device 32
1 PulseAudio Sound Server 32
2 Loopback (Loopback PCM) 32
<Buffer 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ... 334 more bytes>
<Buffer 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ... 334 more bytes>
<Buffer 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ... 334 more bytes>
<Buffer 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ... 334 more bytes>
<Buffer 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ... 334 more bytes>
<Buffer 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ... 334 more bytes>
etc..
The empty buffers indicate no audio data is captured.
@almoghamdani Have you by any chance tested loopback devices? Might be I'm doing something wrong tho.
fanjieqi and rafaelhovhannisyan24
Metadata
Metadata
Assignees
Labels
No labels