Adding Delay Time for Audio Source

Hi,

I want to introduce some delay to audio output in order to synchronize it with a video camera source. Is that possible by changing any parameters on Nano?

Thank you

Hi,
Please share your release version( $ head -1 /etc/nv_tegra_release ) and audio device for reference. Not sure but you run audio/video recording on Jetson Nano? Do you run gstreamer command?

Hi @DaneLLL,

The version is R32, 3.1
I don’t use gstreamer because I want to connect the microphone to the browser for video conferencing, such as Hangouts Meeting.The only thing I need is to stream the auido to the browser with some delay.

Hi,
Does the microphone go through USB or audio codec? Please share arecord -l for information.

Hi @DaneLLL,

It is connected to USB port. Attaching arecord output as below. The device shown in rectangle is what I am trying to adjust for a delay.

Thank you

Hi,
You would need to check if the application supports the function. In arecord, there is an option:

-R, --start-delay=#     delay for automatic PCM start is # microseconds
                        (relative to buffer size if <= 0)

Please set it and try.

Hi @DaneLLL,

Thank you for your help
I applied that but got the following weird result:
I also connected the microphone to the browser application to check if delay introduced, but nothing has changed, it still in real-time

Screenshot from 2020-07-24 13-06-28

Hello!

You should be able to adjust the latency using pavucontrol. To install …

$ sudo apt install pavucontrol

Then open the ‘PulseAudio Volume Control’ desktop application from the ubuntu menu. Under the ‘Output Devices’ tab, if you expand the ‘Advanced’ option for the appropriate sound card, you should be able to increase the ‘latency’ to delay the audio. See the attached screen shot.


Regards
Jon

the pavucontrol doesn’t appear to impact the input device latency;
tested with usb microphone & web meeting app connected from other network computer
despite the latency values for the micrphone , the audio stream will have no latency at web browser


In the latter article they proposed
pactl load-module module-null-sink sink_name=delayed
pactl load-module module-loopback latency_msec=2000 source=delayed.monitor sink=alsa_output.pci-0000_00_1b.0.analog-stereo

Not sure how to adopt it for usb microphone use case though

 pactl load-module module-loopback latency_msec=2000 source=delayed.monitor sink=alsa_output.pci-0000_00_1b.0.analog-stereo
Failure: Module initialization failed

Hello!

I tested audio playback from the web browser and verified that the latency is applied. In other words, I can see that the audio and video becomes out-of-sync when increasing the latency. How do you determine that the latency applied to the input is not taking effect? Are you looping the audio back?

Regards,
Jon

Hello!
Thank you for you rresponse!
were you able to select in the browser the input source as a virtual microphone? virtual microphone with latency? or as a hardware microphone? both? neither of the two?
How did you introduce the latency in the tested scenario? In case that you managed to verify in the web browser?
Could you share steps how to reproduce it, please?
I am still trying to determine how to make sure the hardware microphone is looped to a virtual adudio device microphone.
I was testing with web video chat from Jetson NX using jitsi meet application;
First I would modprobe snd-aloop,
It would create the card3 device

 ls /proc/asound/card3
cable#0  cable#1  id  pcm0c  pcm0p  pcm1c  pcm1p

Also I would try to sink to the virtual device [ card 3 ]

pacmd load-module module-alsa-sink device=hw:3,1

Then I would make the virtual microphone the default source with first listing sources and then setting up the default source:

index: 0
	name: <alsa_output.usb-Logitech_Logitech_USB_Headset-00.analog-stereo.monitor>
		device.string = "2"
  * index: 1
	name: <alsa_input.usb-Logitech_Logitech_USB_Headset-00.analog-mono>
		device.string = "hw:2"
    index: 2
	name: <alsa_output.platform-sound.analog-stereo.monitor>
		device.string = "1"
    index: 3
	name: <alsa_input.platform-sound.analog-stereo>
		device.string = "front:1"
    index: 4
	name: <alsa_output.platform-snd_aloop.0.analog-stereo.monitor>
		device.string = "3"
    index: 5
	name: <alsa_input.platform-snd_aloop.0.analog-stereo>
		device.string = "front:3"
    index: 6
	name: <alsa_output.hw_3_1.monitor>

pacmd "set-default-source alsa_input.platform-snd_aloop.0.analog-stereo"
Then I would try connecting to web browser video web chat application [ this time tested with jitsi], but still it wouldn’t appear to list virtual devices at all, it would still seem top recognize hardware usb microphone input as the only working;
I also tryed doing gsteramer streaming with the default source , then conencted from network computer with VLC to the rtsp gstreamer pipeline, and there wold be silence if it uses the virtual source that I specified in the scenario above.

/test-launch 'videotestsrc ! nvvidconv ! nvv4l2h264enc ! h264parse ! queue ! rtph264pay name=pay0 pt=96 alsasrc buffer-time=32000 latency-time=16000 ! voaacenc ! queue ! rtpmp4apay pt=97 name=pay1'

Initially I used pulse audio volume control -> advanced added maximal delay 2 seconds [2000]. the delay was added to the input source, not to the playing source , then opened a browser and found that the gUI method doesn’t seem to work as the delay wasn;'t introduced. Did you try otherwise?

That is what I am trying to figure out how to add a delay and loop it with a delay to anywhere, e.g. to virtual microphone device. Or otherwise back to where? Back to the hardware microphone?
Probably I missed some factors trying to loop audio and introducing latency.
If you could share your steps that would be helpful, Thanks.

@Jon,
It seems that it fails with error?

sudo modprobe snd-aloop
pulseaudio -D
pacmd list-sources | grep -e 'index:' -e device.string -e 'name:'
 index: 0
	name: <alsa_output.platform-snd_aloop.0.analog-stereo.monitor>
		device.string = "2"
    index: 1
	name: <alsa_input.platform-snd_aloop.0.analog-stereo>
		device.string = "front:2"
    index: 2
	name: <alsa_output.platform-sound.analog-stereo.monitor>
		device.string = "1"
  * index: 3
	name: <alsa_input.platform-sound.analog-stereo>
		device.string = "front:1"
    index: 4
	name: <alsa_output.usb-Logitech_Logitech_USB_Headset-00.analog-stereo.monitor>
		device.string = "3"
 pacmd list-sources | grep -e 'index:' -e device.string -e 'name:'
    index: 0
	name: <alsa_output.platform-snd_aloop.0.analog-stereo.monitor>
		device.string = "2"
  * index: 1
	name: <alsa_input.platform-snd_aloop.0.analog-stereo>
		device.string = "front:2"
    index: 2
	name: <alsa_output.platform-sound.analog-stereo.monitor>
		device.string = "1"
    index: 3
	name: <alsa_input.platform-sound.analog-stereo>
		device.string = "front:1"
    index: 4
	name: <alsa_output.usb-Logitech_Logitech_USB_Headset-00.analog-stereo.monitor>
		device.string = "3"

ls /proc/asound/card2
cable#0  cable#1  id  pcm0c  pcm0p  pcm1c  pcm1p
pactl load-module module-null-sink sink_name=delayed
 pactl load-module module-null-sink sink_name=delayed
25
 pacmd list-sources | grep -e 'index:' -e device.string -e 'name:'
    index: 0
	name: <alsa_output.platform-snd_aloop.0.analog-stereo.monitor>
		device.string = "2"
  * index: 1
	name: <alsa_input.platform-snd_aloop.0.analog-stereo>
		device.string = "front:2"
    index: 2
	name: <alsa_output.platform-sound.analog-stereo.monitor>
		device.string = "1"
    index: 3
	name: <alsa_input.platform-sound.analog-stereo>
		device.string = "front:1"
    index: 4
	name: <alsa_output.usb-Logitech_Logitech_USB_Headset-00.analog-stereo.monitor>
		device.string = "3"
    index: 5
	name: <delayed.monitor>
pacmd list-sources | grep -e 'index:' -e device.string -e 'name:'
    index: 0
	name: <alsa_output.platform-snd_aloop.0.analog-stereo.monitor>
		device.string = "2"
    index: 1
	name: <alsa_input.platform-snd_aloop.0.analog-stereo>
		device.string = "front:2"
    index: 2
	name: <alsa_output.platform-sound.analog-stereo.monitor>
		device.string = "1"
    index: 3
	name: <alsa_input.platform-sound.analog-stereo>
		device.string = "front:1"
    index: 4
	name: <alsa_output.usb-Logitech_Logitech_USB_Headset-00.analog-stereo.monitor>
		device.string = "3"
  * index: 5
	name: <delayed.monitor>


 pactl load-module module-loopback latency_msec=2000 source=delayed.monitor sink=alsa_input.platform-snd_aloop.0.analog-stereo
Failure: Module initialization failed
nvidia@nx:~$ pactl load-module module-loopback latency_msec=2000 source=delayed.monitor sink=alsa_output.platform-snd_aloop.0.analog-stereo.monitor
Failure: Module initialization failed

Upd:
I got something working

pactl load-module module-loopback latency_msec=10000
37

in my current environment due to multiple loopback it plays twice using it: at once and with the specified delay;

ref: https://askubuntu.com/questions/403416/how-to-listen-live-sounds-from-input-from-external-sound-card

pacmd list-sources | grep -e 'index:' -e device.string -e 'name:'
    index: 0
	name: <alsa_input.usb-Logitech_Logitech_USB_Headset-00.analog-mono>
		device.string = "hw:2"
    index: 1
	name: <alsa_output.platform-sound.analog-stereo.monitor>
		device.string = "1"
    index: 2
	name: <alsa_input.platform-sound.analog-stereo>
		device.string = "front:1"
  * index: 3
	name: <delayed.monitor>
    index: 4
	name: <alsa_output.platform-snd_aloop.0.analog-stereo.monitor>
		device.string = "3"
    index: 5
	name: <alsa_input.platform-snd_aloop.0.analog-stereo>
		device.string = "front:3"
    index: 6
	name: <delayed.2.monitor>

$ pactl load-module module-loopback latency_msec=3000 source=0 sink=5
Failure: Module initialization failed

What actually works, but requires manual actions in Graphical interface:

1. ```nx:~$ sudo reboot```
at nx open browser and conenct e.g to https://meet.jit.si/test123321 ; then connect to the same url from another computer to hear audio
open Settings Pulse volume Control- Recordings
pactl load-module module-loopback latency_msec=30000 source=0
pactl load-module module-null-sink sink_name=delayed

select the null device in the recordings list;
upd: proved to work at nx by now if to listen at other computer it will have the delay
further possible optimization - to find out how to manage it from terminal without GUI at all