How to set up a UDP Audio Stream
8 次查看(过去 30 天)
显示 更早的评论
Hi,
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;
FrameSize=128;
%UDP Sender
global US;
US=dsp.UDPSender('RemoteIPAddress', '192.167.1.103', 'RemoteIPPort', 5050);
%UDP Receiver
global UP;
UR=dsp.UDPReceiver('LocalIPPort', 1112, 'RemoteIPAddress', '192.167.1.103');
%Audio File Reader
global AF;
[AF, Fs]=audioread('TestSound.wav');
%extracting a mono version
AF=AF(:, 1);
FramesToSend=length(AF)/FrameSize;
PacketRate=Fs/FrameSize;
%Audio Player
global AP;
AP=dsp.AudioPlayer('SampleRate',Fs);
global packetCounter;
packetCounter=0;
global payload;
payload=zeros(1, 4*FrameSize+2);
payload(2)=FrameSize;
global dataIn;
dataIn=zeros(1, FrameSize);
%Frames senden
t=timer('ExecutionMode', 'fixedRate', 'TimerFcn', @sendUDPpacket, 'Period', 1/PacketRate, 'TasksToExecute', FramesToSend);
disp('starting transfer')
start(t)
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);
payload(1)=packetCounter;
for(i=0:FrameSize-1)
payload(i*4+3:i*4+6)=float2uint8ByteArray(AF(i+1));
end
step(US, payload);
AF=AF(FrameSize+1:end);
dataReceived=step(UR);
if length(dataReceived)>4*FrameSize
for(i=0:FrameSize-1)
dataIn(i+1)=uint8ByteArray2float(dataReceived(i*4+3:i*4+6));
end
step(AP, dataIn);
end
2 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!