Effacer les filtres
Effacer les filtres

How to set up a UDP Audio Stream

13 vues (au cours des 30 derniers jours)
Janos Buttgereit
Janos Buttgereit le 10 Août 2016
I'm working on realtime audio processing algorithm benchmarking on an ARM development board, which is only equipped with a 1000MBit Ethernet port for external communication.
So I want to use this port to stream realtime audio via UDP from my computer to the board and stream the processed data back to my computer to record it in MATLAB and output it through my Computer's soundcard with the help of the dsp toolbox's UDP sender and receiver.
Each UDP Packet should be started with a 16 bit "header" with an 8Bit running packet counter followed by an 8 Bit frame size information and then contain the actual data, encoded in 32Bit floating point values, already sorted in the Byte Order the ARM needs.
I wrote a mex function, receiving one double value and giving back four uint8 values in the right order, representing the bytes of the floating point number to build a vector of integers that will be sent encoded as uint8.
This already works for single transfers.
My approach for streaming was, to schedule the UDP transfer with a timer, however I always get the Error Message
Error while evaluating TimerFcn for timer 'timer-23'
Message too long
So, do I get it right, that MATLAB is just to slow to process the task in the given time? If yes, how could I speed up transmission and get it working the way I want? As this is just a one channel stream, wich should be augmented to a multichannel stream, a performant solution would be really important.
This is the code I currently run:
clear all;
global FrameSize;
%UDP Sender
global US;
US=dsp.UDPSender('RemoteIPAddress', '', 'RemoteIPPort', 5050);
%UDP Receiver
global UP;
UR=dsp.UDPReceiver('LocalIPPort', 1112, 'RemoteIPAddress', '');
%Audio File Reader
global AF;
[AF, Fs]=audioread('TestSound.wav');
%extracting a mono version
AF=AF(:, 1);
%Audio Player
global AP;
global packetCounter;
global payload;
payload=zeros(1, 4*FrameSize+2);
global dataIn;
dataIn=zeros(1, FrameSize);
%Frames senden
t=timer('ExecutionMode', 'fixedRate', 'TimerFcn', @sendUDPpacket, 'Period', 1/PacketRate, 'TasksToExecute', FramesToSend);
disp('starting transfer')
function sendUDPpacket(obj, event, string_arg)
global packetCounter;
global FrameSize;
global payload;
global US;
global AF;
global UR;
global dataIn;
packetCounter=mod((packetCounter+1), 128);
step(US, payload);
if length(dataReceived)>4*FrameSize
step(AP, dataIn);
  2 commentaires
tony le 17 Avr 2020
Modifié(e) : tony le 17 Avr 2020
why do you use the timer function?
if you are working in Real Time
there is a Matlab note:
"The timer object is subject to the limitations of your hardware, operating system, and software. Avoid using timer objects for real-time applications"
Janos Buttgereit
Janos Buttgereit le 17 Avr 2020
Funny to see my four year old post up here. This was for my Bachelor Thesis, in the meantime a lot happened, I'm working as a C++ audio software developer meanwhile and reading my old code from back then makes me laugh a bit – wouldn't try anything like that with my today's knowledge – this is simly a wrong approach in so much dimensions ;) And if I remeber correctly, this didn't work in the end.
While I still like using Matlab for DSP math, it is by no means the correct tool for real-time streaming. What are you trying to achieve?

Connectez-vous pour commenter.

Réponses (0)


En savoir plus sur Audio I/O and Waveform Generation dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by