How to set up a UDP Audio Stream

15 ビュー (過去 30 日間)
Janos Buttgereit
Janos Buttgereit 2016 年 8 月 10 日
コメント済み: Janos Buttgereit 2020 年 4 月 17 日
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 件のコメント
tony 2020 年 4 月 17 日
編集済み: tony 2020 年 4 月 17 日
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 2020 年 4 月 17 日
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?


回答 (0 件)


Help Center および File ExchangeAudio I/O and Waveform Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by