marcellom66
New member
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: bjoern@cs.stanford.edu 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:
SPI.setMOSI(7);
SPI.setMISO(8);
SPI.setSCK(27);
// Audio connections require memory, and the record queue
// uses this memory to buffer incoming audio.
AudioMemory(128);
Ethernet.init(10);
Ethernet.begin(mac, ip);
Udp.begin(localPort);
Serial.begin(9600);
while (!Serial)
delay(1);
queue1.begin();
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);
queue1.freeBuffer();
memcpy(buffer+256, queue1.readBuffer(), 256);
queue1.freeBuffer();
// 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);
Udp.write(buffer);
Udp.endPacket();
}
}
Thanks for your help.
#include <SPI.h> // needed for Arduino versions later than 0018
#include <Ethernet2.h>
#include <EthernetUdp2.h> // UDP library from: bjoern@cs.stanford.edu 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:
SPI.setMOSI(7);
SPI.setMISO(8);
SPI.setSCK(27);
// Audio connections require memory, and the record queue
// uses this memory to buffer incoming audio.
AudioMemory(128);
Ethernet.init(10);
Ethernet.begin(mac, ip);
Udp.begin(localPort);
Serial.begin(9600);
while (!Serial)
delay(1);
queue1.begin();
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);
queue1.freeBuffer();
memcpy(buffer+256, queue1.readBuffer(), 256);
queue1.freeBuffer();
// 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);
Udp.write(buffer);
Udp.endPacket();
}
}
Thanks for your help.