daMata
Posts: 3
Joined: Wed Jun 07, 2017 12:10 am

Audio Stream Low Latency

Wed Jun 07, 2017 12:29 am

Hello guy's
I want to stream the audio off my tv(Using a soundCard Input) in my house to my phone and use the headphones on the phone!
I have tried to use IcestCast(http://icecast.org/) + darkIce(https://github.com/rafael2k/darkice) but i have a delay of 8 seconds!
Someone know a better way to stream the audio on RP3 without delays ?
Or if someone have a better ideia on capture and stream the sound, i'am opened to new ideias !

Thanks in Advance ;)

User avatar
flatmax
Posts: 335
Joined: Thu May 26, 2016 10:36 pm

Re: Audio Stream Low Lantency

Wed Jun 07, 2017 1:08 pm

HI there,

One solution for low latency audio streaming is to use the RTP protocol. We have dealt with this problem on the Audio Injector forum in the topic "Streaming from the input".

The solution proposed there is to use avconv to output the RTP protocol. The RTP protocol is a UDP network protocol which means it can be set up to be low latency.

The solution then would be (on the source) :
avconv -f alsa -i plughw -f rtp rtp://destinationHost:port

On your phone (you will have to know its IP unless you work out how to broadcast to all hosts - a little bit of overkill!) :
ffplay rtp://sourceHost:port
However that would be a little tricky without a shell or ssh to the phone ... so perhaps you could install vlc on your phone ? Or a different app (of the many) which can play RTP streams.
The Ultra 2 sound card - Preview now on kickstarter : https://kck.st/2H95YIz
Sound card for the Raspberry Pi with inbuilt microphone : http://www.audioinjector.net
Audio Inector Octo multitrack GPIO sound card : http://www.audioinjector.net

daMata
Posts: 3
Joined: Wed Jun 07, 2017 12:10 am

Re: Audio Stream Low Lantency

Fri Jun 09, 2017 10:32 am

Thanks for the advice, next weak i'm going to implement your idea and then i post the result !

The RTP Protocol is support by the "regular" Routers , the ones that TV suppliers give wen you do a contract ?
Thanks =)

User avatar
flatmax
Posts: 335
Joined: Thu May 26, 2016 10:36 pm

Re: Audio Stream Low Lantency

Fri Jun 09, 2017 1:29 pm

Yes, RTP is based on UDP networking which is very low level and implemented almost everywhere.

Matt
The Ultra 2 sound card - Preview now on kickstarter : https://kck.st/2H95YIz
Sound card for the Raspberry Pi with inbuilt microphone : http://www.audioinjector.net
Audio Inector Octo multitrack GPIO sound card : http://www.audioinjector.net

daMata
Posts: 3
Joined: Wed Jun 07, 2017 12:10 am

Re: Audio Stream Low Lantency

Mon Jun 12, 2017 4:03 pm

Hi
i put your advice working on my house!

Code: Select all

avconv -f alsa -ac 1 -i plughw:1,0 -acodec libmp3lame -b 32k -f rtp rtp://192.168.1.101:8000
But now i have some new problems !
When i start the stream on the first minute i have a lot of "breaks" on the stream, after that time the stream run without problems!
And the delay i have now is somewhere between the 3 seconds and for the objective of these project 3 seconds is too much!

Can some one help with the configuration of avconv for less delay? And have some way so solve the "breaks" on the begin of the stream !

Thanks a lot for the help guys !

Innyve89
Posts: 9
Joined: Wed Jan 10, 2018 12:35 pm

Re: Audio Stream Low Lantency

Thu Mar 01, 2018 5:50 pm

How might someone go about getting this to work on a website using lighttpd?

JakobsenCopenhagen
Posts: 3
Joined: Mon Mar 19, 2018 10:46 pm
Location: Copenhagen Denmark
Contact: Website

Re: Audio Stream Low Lantency

Mon Mar 19, 2018 11:00 pm

Hi All
I did a setup for at performance running 24/7 30 days streaming pi to pi using trx.
Some old very simple stuff based on trx http://www.pogo.org.uk/~mark/trx/
It uses the open source Opus coder/decoder and your are down to a few ms latency.
Code is very old and needs som tweeing to get going. I was very happy with the result and will sure use it for my next project out in low latency audio streaming.
Hit me up for details
/Jorgen
Denmark

rivervaladez
Posts: 1
Joined: Wed Mar 21, 2018 5:41 pm

Re: Audio Stream Low Lantency

Wed Mar 21, 2018 5:45 pm

Hi JakobsenCopenhagen

I am doing some sound art with raspberry pi's.

How did you tweek the TRX to get it to work.

River
US

JakobsenCopenhagen
Posts: 3
Joined: Mon Mar 19, 2018 10:46 pm
Location: Copenhagen Denmark
Contact: Website

Re: Audio Stream Low Latency

Thu May 03, 2018 1:05 pm

Hi
Yes I recall that was a bit clean up to get it rolling. Very old code base and some odd dependent to other old stuff.
I will try to dig up the code at let you know what needs to be done.

By the way I design Class D amps daytime job and do very low power stuff for portable marked in the 10W - 200W segment. Let me know if have needs in that direction - check out www.merus-audio.com

Regards JakobsenCopenhagen

JakobsenCopenhagen
Posts: 3
Joined: Mon Mar 19, 2018 10:46 pm
Location: Copenhagen Denmark
Contact: Website

Re: Audio Stream Low Latency

Thu May 03, 2018 8:41 pm

Try this
Regards Jakobsen

1. Make sure you compile against this implementation / version of ortp
ortp-0.22.0.tar.gz
Get it from here : http://download.savannah.nongnu.org/rel ... p/sources/


2. I changed the opus encoder / decoder to int16 from float - due to my audio devices was simple
16 bit cheep stuf.
changes to tx.c rx.c and device.c


jakobsen@w520:~/work/trx/trx-0.3$ diff rx.c /home/jakobsen/work/friaudio/pi_node/src/trx/rx.c
73c73,74
< float *pcm;
---
> //float *pcm;
> opus_int16 *pcm;
79c80,81
< r = opus_decode_float(decoder, NULL, 0, pcm, samples, 1);
---
> r = opus_decode(decoder, NULL, 0, pcm, samples, 1);
> // r = opus_decode_float(decoder, NULL, 0, pcm, samples, 1);
81c83,84
< r = opus_decode_float(decoder, packet, len, pcm, samples, 0);
---
> r = opus_decode(decoder, packet, len, pcm, samples, 0);
> // r = opus_decode_float(decoder, packet, len, pcm, samples, 0);
241c244,245
<
---
>
>
268a273
>

jakobsen@w520:~/work/trx/trx-0.3$ diff tx.c /home/jakobsen/work/friaudio/pi_node/src/trx/tx.c
63c63,64
< float *pcm;
---
> //float *pcm;
> opus_int16 *pcm;
91c92,93
< z = opus_encode_float(encoder, pcm, samples, packet, bytes_per_frame);
---
> z = opus_encode(encoder, pcm, samples, packet, bytes_per_frame);
> //z = opus_encode_float(encoder, pcm, samples, packet, bytes_per_frame);
245,246c247,248

jakobsen@w520:~/work/trx/trx-0.3$ diff device.c /home/jakobsen/work/friaudio/pi_node/src/trx/device.c
56c56
< r = snd_pcm_hw_params_set_format(pcm, hw, SND_PCM_FORMAT_FLOAT);
---
> r = snd_pcm_hw_params_set_format(pcm, hw, SND_PCM_FORMAT_S16_LE); //SND_PCM_FORMAT_FLOAT);

sporex
Posts: 14
Joined: Thu Jan 23, 2014 3:25 pm

Re: Audio Stream Low Latency

Mon Jun 25, 2018 1:16 pm

JakobsenCopenhagen wrote:
Thu May 03, 2018 8:41 pm
Try this
Regards Jakobsen

1. Make sure you compile against this implementation / version of ortp
ortp-0.22.0.tar.gz
Get it from here : http://download.savannah.nongnu.org/rel ... p/sources/


2. I changed the opus encoder / decoder to int16 from float - due to my audio devices was simple
16 bit cheep stuf.
changes to tx.c rx.c and device.c


jakobsen@w520:~/work/trx/trx-0.3$ diff rx.c /home/jakobsen/work/friaudio/pi_node/src/trx/rx.c
73c73,74
< float *pcm;
---
> //float *pcm;
> opus_int16 *pcm;
79c80,81
< r = opus_decode_float(decoder, NULL, 0, pcm, samples, 1);
---
> r = opus_decode(decoder, NULL, 0, pcm, samples, 1);
> // r = opus_decode_float(decoder, NULL, 0, pcm, samples, 1);
81c83,84
< r = opus_decode_float(decoder, packet, len, pcm, samples, 0);
---
> r = opus_decode(decoder, packet, len, pcm, samples, 0);
> // r = opus_decode_float(decoder, packet, len, pcm, samples, 0);
241c244,245
<
---
>
>
268a273
>

jakobsen@w520:~/work/trx/trx-0.3$ diff tx.c /home/jakobsen/work/friaudio/pi_node/src/trx/tx.c
63c63,64
< float *pcm;
---
> //float *pcm;
> opus_int16 *pcm;
91c92,93
< z = opus_encode_float(encoder, pcm, samples, packet, bytes_per_frame);
---
> z = opus_encode(encoder, pcm, samples, packet, bytes_per_frame);
> //z = opus_encode_float(encoder, pcm, samples, packet, bytes_per_frame);
245,246c247,248

jakobsen@w520:~/work/trx/trx-0.3$ diff device.c /home/jakobsen/work/friaudio/pi_node/src/trx/device.c
56c56
< r = snd_pcm_hw_params_set_format(pcm, hw, SND_PCM_FORMAT_FLOAT);
---
> r = snd_pcm_hw_params_set_format(pcm, hw, SND_PCM_FORMAT_S16_LE); //SND_PCM_FORMAT_FLOAT);
Your instructions helped me a lot, thank you very much.
Formerly the rx produced serious distortion after roughly one hour.
With the above modifications the problem is solved.

If someone who is less familiar with Debian, like myself, needs more details how to go through the different steps of installation, let me know.

Regards sporex

Simple
Posts: 12
Joined: Tue Aug 01, 2017 6:51 am

Re: Audio Stream Low Latency

Sun Jul 08, 2018 3:38 pm

Thanks for all the posts..

I am looking for something similar, however, my setup I want to use spotify on my Ubuntu laptop and stream audio to a raspberry pi over a direct ethernet connection between the two that I share the internet with from the laptop. I have attempted to get various methods working and not had good results, if any. I am looking for something simple and the best sound quality possible. I am using Raspian lite on the Pi, alsa is installed by default. On the laptop side of things, pulseaudio is installed, but I have no particular care in which way or system is used. When everything is up and running correctly, I intend to use the script that sets up the Pi into a read-only state..

Suggestions?
Thanks tons
S

Man in a van
Posts: 96
Joined: Sat Dec 27, 2014 2:41 pm
Location: Staffordshire, UK.

Re: Audio Stream Low Latency

Tue Jul 10, 2018 9:33 am

@Simple

I don't know if this would work with your Ubuntu setup, but it will cost nothing to try.

It does require that you are a Spotify Premium User.

Install this

https://github.com/dtcooper/raspotify


On the pi and it should show in the Spotify Desktop as a Spotify-Connect Device.

Ronnie

Return to “Graphics, sound and multimedia”