UDP streaming example (OP-AN-021)

From openPicus Wiki
Jump to: navigation, search

MUSIC NEST can be used with both FLYPORT Wi-Fi or FLYPORT Ethernet modules. It integrates a multiple audio decoder (MP3, WMA, Ogg Vorbis, etc...), and a micro SD socket for FAT file system storage (both FAT16/32 can be used).



Application Note PDF

Source Code


This application note uses the MUSIC NEST expansion board hardware to provide the following services:

  • UDP Socket (FLYPORT is the UDP Server)
  • VS1053 with SPI interface to decode compressed music data
  • Micro SD card slot is NOT USED, since music data comes from the network

FLYPORT Module acts as UDP Server, any Client can connect to its socket and stream audio content to its output.
Pay attention that only one client at time can access to UDP Server.
User can customize UDP port value (default is 4000), and turn up / down volume using cgi requests via Flyport web server.

User can take advance of provided templates that are just configured to set the right size of UDP Socket buffer, or configure e new project following this Tutorial: Configure Firmware for UDP streaming with this settings:

  • TCP Socket configuration
    • GENERIC_TCP_CLIENT TX: 125 RX: 1500
    • GENERIC_TCP_SERVER TX: 200 RX: 200
    • HTTP_SERVER count:2 TX 1000 RX:1000
    • DEFAULT TX:100 RX:100
    • FTP_COMMAND count:0
    • FTP_DATA count:0
  • UDP sockets configuration as:
    • Socket n.1 Buffer size: 5760
    • Other Sockets not enabled
  • For Hardware configuration leave default settings (UART port: 1 Buffer size: 256) and finish wizard

Required Hardware

Required Software and Libreries


  • OpenPicus Free IDE 2.2+


  • VLSICodec


The simplest way to try the Music Nest demo firmware is to receive music data from a PC or MAC that uses VLC as UDP streaming Client.
Flyport module is the UDP Server, so inside the code it can be seen the command to open an UDP socket:

UDPSocketServer = UDPServerOpen(StreamPort);

Inside a while loop Flyport receives mp3 data and sends it to VLSI Codec via SPI Bus:

while( ((CurrentPacketSize >= 32) && (AudioBuffSize >= CacheSize)) ||
((CurrentPacketSize == 0) && (AudioBuffSize > 0)) )
if (AudioBuffSize >= 32)
wri = 32;
wri = AudioBuffSize;
UDPRead(UDPSocketServer, AudioBuffUDP, wri);
wri2 = VlsiWriteDataN(AudioBuffUDP, wri); //audio pointer
if ( wri == wri2 )
CurrentPacketSize -= wri2;
AudioBuffSize -= wri2;
#if (DEBUG > 1)
UARTWrite(1, "Busy\n\r");
}while((wri2 == 0) && (AudioBuffSize > 0));
AudioBuffSize = CurrentPacketSize;

In addiction to audio streaming, also volume can be controlled at run-time. To change volume settings just open a browser and write the following CGI request:


To test the application note, it is needed to download and install VLC (VideoLAN Client) on a PC (it is available for both Windows and Linux) or on a MAC.
Please, download the software from the VLC home page.
Once correctly installed, and before open VLC, please make sure both PC (or MAC) and Flyport are connected to the same network.
To correctly start to stream music data to UDP Server Socket of Flyport module, open VLC and follow the following steps:

  • Select a music file with Ctrl+S or using the “Media → Stream...” menu:
Testing OP-AN-021 1.png
  • Add the desired file and press “Stream” button:
Testing OP-AN-021 2.png
  • Skip all the windows using the “next” button until it is shown the following window:
Testing OP-AN-021 3.png

The string provides to VLC all the compression and connection parameters to VLC, like IP_FLYPORT and PORT that user should customize at his needs.

  • Now Click on “Stream” button and enjoy your favorite music through Music Nest stereo output!


Thanks to serra82@gmail.com

Personal tools