Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: Audio to UDP

  1. #1
    Junior Member
    Join Date
    Apr 2017

    Audio to UDP

    I write a program to transmit audio USB to UDP with T3.6 but the queue doesn't receive the data from USB . The program is this :

    #include <SPI.h> // needed for Arduino versions later than 0018
    #include <Ethernet2.h>
    #include <EthernetUdp2.h> // UDP library from: 12/30/2008
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>

    // GUItool: begin automatically generated code
    AudioInputUSB usb1; //xy=179,2337
    AudioRecordQueue queue1; //xy=380,2328
    AudioConnection patchCord1(usb1, 0, queue1, 0);
    AudioConnection patchCord2(usb1, 1, queue1, 0);
    // GUItool: end automatically generated code

    // Enter a MAC address and IP address for your controller below.
    // The IP address will be dependent on your local network:
    byte mac[] = {
    0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
    IPAddress ip(192, 168, 1, 177);
    IPAddress ip_dest(192, 168, 1, 178);

    unsigned int localPort = 8888; // local port to listen on

    // buffers for receiving and sending data
    char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
    char ReplyBuffer[] = "acknowledged"; // a string to send back

    // An EthernetUDP instance to let us send and receive packets over UDP
    EthernetUDP Udp;

    void setup() {
    // start the Ethernet and UDP:

    // Audio connections require memory, and the record queue
    // uses this memory to buffer incoming audio.

    Ethernet.begin(mac, ip);

    while (!Serial)
    Serial.println("End setup");

    void loop() {

    if (queue1.available() >= 2) {
    char buffer[512];
    Serial.println("Queue received");
    // Fetch 2 blocks from the audio library and copy
    // into a 512 byte buffer. The Arduino SD library
    // is most efficient when full 512 byte sector size
    // writes are used.
    memcpy(buffer, queue1.readBuffer(), 256);
    memcpy(buffer+256, queue1.readBuffer(), 256);
    // write all 512 bytes to the SD card
    //elapsedMicros usec = 0;

    // send a reply, to the IP address and port that sent us the packet we received
    Udp.beginPacket(ip_dest, localPort);


    Thanks for your help.

  2. #2
    Hi Marcello,
    could it be that you are overrunning the UDP buffer?
    IP6 max is 1500 Bytes. UDP Header is 20 + 8 Bytes, leaves 1472 bytes
    can't find: char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,

    if (queue1.available() >= 2) {
    char buffer[512]; // this would be 3x 512 = 1536 bytes

  3. #3
    Junior Member
    Join Date
    Apr 2017
    The Serial.println("Queue received") not show this message so the program not use the udp because the queue is empty but I send audio from pc by usb, why the queue is empty?

  4. #4
    Any progress on this?

    Please let me know if you succeed!

  5. #5
    Senior Member
    Join Date
    Aug 2016
    Hi Marcello,

    Have you looked at my Teensy Audio Ethernet Library? It provides a ready way to share audio packets over UDP.

  6. #6
    Senior Member
    Join Date
    Jul 2014
    Quote Originally Posted by marcellom66 View Post
    I write a program to transmit audio USB to UDP with T3.6 but the queue doesn't receive the data from USB . The program is this :
    In addition to AudioInputUSB you need a 'real' input or output object, e.g. AudioInputI2S (simply declare object without any connections). Reason: USB is not triggering the audio processing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts