/////////////////////////////////////////////////////// ////////////////// ESP32 connections ////////////////// //////////// NRF24L01 ///////////////// //////////// ESP32 NRF PIN //////////// G5 CSN //////////// G4 CE //////////// G23 MOSI //////////// G18 SCK //////////// G19 MISO //////////// NC IRQ ////////////// VS1003 //////////////// //////////// ESP32 VS1003 //////////// G15 XRST //////////// G13 MISO //////////// G12 MOSI //////////// G14 SCLK //////////// G27 DREQ //////////// G26 XCS //////////// G25 XDCS #include #include #include #include // Arduino UNO //VS1003NRF24L01 player(9, 6, 7, 8, 10, 5, 2); // cs_pin, dcs_pin, dreq_pin, reset_pin, sck, mosi, miso //RF24 radio(3, 4); // CE, CSN // Arduino Mega //VS1003NRF24L01 player(3, 2, 4, 5, 11, 9, 10); // cs_pin, dcs_pin, dreq_pin, reset_pin, sck, mosi, miso //RF24 radio(7, 8); // ESP32 NodeMCU VS1003NRF24L01 player(26, 25, 27, 15, 14, 12, 13); // cs_pin, dcs_pin, dreq_pin, reset_pin, sck, mosi, miso RF24 radio(4, 5); uint16_t recWord = 0; const byte address[6] = "00001"; uint8_t text[32] = ""; uint8_t buffer_temp[512]; int buffer_temp_count = 0; int bufferSentCount = 0; int bufferSentCountToBeSent = 10; int bufferSentStart = 0; uint8_t micHeader_temp[512]; uint8_t micHeader1_temp[32], micHeader2_temp[32], micHeader3_temp[32], micHeader4_temp[32], micHeader5_temp[32], micHeader6_temp[32], micHeader7_temp[32], micHeader8_temp[32], micHeader9_temp[32], micHeader10_temp[32], micHeader11_temp[32], micHeader12_temp[32], micHeader13_temp[32], micHeader14_temp[32], micHeader15_temp[32], micHeader16_temp[32]; uint8_t RIFFHeader0fn_temp[52] = { 'R' , 'I' , 'F' , 'F' , // Chunk ID (RIFF) 0xF8, 0x05, 0x00, 0x00, // Chunk payload size (calculate after rec!) 'W' , 'A' , 'V' , 'E' , // RIFF resource format type 'f' , 'm' , 't' , ' ' , // Chunk ID (fmt ) 0x14, 0x00, 0x00, 0x00, // Chunk payload size (0x14 = 20 bytes) 0x11, 0x00, // Format Tag (IMA ADPCM) 0x01, 0x00, // Channels (1) 0x40, 0x1f, 0x00, 0x00, // Sample Rate, 0x1f40 = 8.0kHz 0xd7, 0x0f, 0x00, 0x00, // Average Bytes Per Second 0x00, 0x01, // Data Block Size (256 bytes) 0x04, 0x00, // ADPCM encoded bits per sample (4 bits) 0x02, 0x00, // Extra data (2 bytes) 0xf9, 0x01, // Samples per Block (505 samples) 'f' , 'a' , 'c' , 't' , // Chunk ID (fact) 0xc8, 0x01, 0x00, 0x00, // Chunk payload size (456 bytes (zeropad!)) 0xe4, 0x07, 0x00, 0x00 // Number of Samples (calculate after rec!) }; uint8_t RIFFHeader504fn_temp[8] = { 'd' , 'a' , 't' , 'a' , // Chunk ID (data) 0x00, 0x04, 0x00, 0x00 // Chunk payload size (calculate after rec!) }; int micDataBlocks_temp = 2; int micHeaderBlocks_temp = 1; int bytesPerBlock_temp = 512; QueueHandle_t dataQueue; void setHeader_temp(void) { for(int i=0;i<52;i++) { micHeader_temp[i] = RIFFHeader0fn_temp[i]; } for(int i=52;i<504;i++) { micHeader_temp[i] = 0x00; } int k =0; for(int i=504;i<512;i++) { micHeader_temp[i] = RIFFHeader504fn_temp[k]; k++; } // Size of the audio data should be declared in the header file. Here we are setting the size to 11 * 512 bytes // 11 * 512 = 1 * 512 (header data) + 10 * 512 (audio data) uint32_t paySize1_temp = (micDataBlocks_temp + micHeaderBlocks_temp) * bytesPerBlock_temp - 8; uint32_t numSamp_temp = ((micDataBlocks_temp + micHeaderBlocks_temp) * bytesPerBlock_temp - 512) / 256 * 505; uint32_t paySize2_temp = (micDataBlocks_temp + micHeaderBlocks_temp) * bytesPerBlock_temp - 512; micHeader_temp[7] = paySize1_temp >> 24; micHeader_temp[6] = paySize1_temp >> 16; micHeader_temp[5] = paySize1_temp >> 8; micHeader_temp[4] = paySize1_temp; micHeader_temp[51] = numSamp_temp >> 24; micHeader_temp[50] = numSamp_temp >> 16; micHeader_temp[49] = numSamp_temp >> 8; micHeader_temp[48] = numSamp_temp; micHeader_temp[511] = paySize2_temp >> 24; micHeader_temp[510] = paySize2_temp >> 16; micHeader_temp[509] = paySize2_temp >> 8; micHeader_temp[508] = paySize2_temp; k=0; for(int i=0;i<32;i++) { micHeader1_temp[i] = micHeader_temp[k]; k++; } for(int i=0;i<32;i++) { micHeader2_temp[i] = micHeader_temp[k]; k++; } for(int i=0;i<32;i++) { micHeader3_temp[i] = micHeader_temp[k]; k++; } for(int i=0;i<32;i++) { micHeader4_temp[i] = micHeader_temp[k]; k++; } for(int i=0;i<32;i++) { micHeader5_temp[i] = micHeader_temp[k]; k++; } for(int i=0;i<32;i++) { micHeader6_temp[i] = micHeader_temp[k]; k++; } for(int i=0;i<32;i++) { micHeader7_temp[i] = micHeader_temp[k]; k++; } for(int i=0;i<32;i++) { micHeader8_temp[i] = micHeader_temp[k]; k++; } for(int i=0;i<32;i++) { micHeader9_temp[i] = micHeader_temp[k]; k++; } for(int i=0;i<32;i++) { micHeader10_temp[i] = micHeader_temp[k]; k++; } for(int i=0;i<32;i++) { micHeader11_temp[i] = micHeader_temp[k]; k++; } for(int i=0;i<32;i++) { micHeader12_temp[i] = micHeader_temp[k]; k++; } for(int i=0;i<32;i++) { micHeader13_temp[i] = micHeader_temp[k]; k++; } for(int i=0;i<32;i++) { micHeader14_temp[i] = micHeader_temp[k]; k++; } for(int i=0;i<32;i++) { micHeader15_temp[i] = micHeader_temp[k]; k++; } for(int i=0;i<32;i++) { micHeader16_temp[i] = micHeader_temp[k]; k++; } } void loop2 (void* pvParameters) { uint8_t recValArray[32]; uint8_t inValue; int i=0; int bufferSentCount = 0; int counter = 0; //setHeader_temp(); delay(10); /* player.sdi_send_buffer(micHeader1_temp, 32); player.sdi_send_buffer(micHeader2_temp, 32); player.sdi_send_buffer(micHeader3_temp, 32); player.sdi_send_buffer(micHeader4_temp, 32); player.sdi_send_buffer(micHeader5_temp, 32); player.sdi_send_buffer(micHeader6_temp, 32); player.sdi_send_buffer(micHeader7_temp, 32); player.sdi_send_buffer(micHeader8_temp, 32); player.sdi_send_buffer(micHeader9_temp, 32); player.sdi_send_buffer(micHeader10_temp, 32); player.sdi_send_buffer(micHeader11_temp, 32); player.sdi_send_buffer(micHeader12_temp, 32); player.sdi_send_buffer(micHeader13_temp, 32); player.sdi_send_buffer(micHeader14_temp, 32); player.sdi_send_buffer(micHeader15_temp, 32); player.sdi_send_buffer(micHeader16_temp, 32); */ while (1) { //Serial.print ("Hello"); //delay (500); // wait for half a second //Serial.println (" World"); //delay (500); // wait for half a second xQueueReceive ( dataQueue, &inValue, 5 ); //Serial.println(inValue, HEX); //delayMicroseconds(100); delayMicroseconds(100); recValArray[i] = inValue; i++; if(i>=32) { i = 0; //counter++; //Serial.println(counter); //radio.write(&recValArray, 32); player.sdi_send_buffer(recValArray, sizeof(recValArray)); //delayMicroseconds(100); /* bufferSentCount++; if(bufferSentCount >= 16 * micDataBlocks_temp) { bufferSentCount=0; player.sdi_send_buffer(micHeader1_temp, 32); player.sdi_send_buffer(micHeader2_temp, 32); player.sdi_send_buffer(micHeader3_temp, 32); player.sdi_send_buffer(micHeader4_temp, 32); player.sdi_send_buffer(micHeader5_temp, 32); player.sdi_send_buffer(micHeader6_temp, 32); player.sdi_send_buffer(micHeader7_temp, 32); player.sdi_send_buffer(micHeader8_temp, 32); player.sdi_send_buffer(micHeader9_temp, 32); player.sdi_send_buffer(micHeader10_temp, 32); player.sdi_send_buffer(micHeader11_temp, 32); player.sdi_send_buffer(micHeader12_temp, 32); player.sdi_send_buffer(micHeader13_temp, 32); player.sdi_send_buffer(micHeader14_temp, 32); player.sdi_send_buffer(micHeader15_temp, 32); player.sdi_send_buffer(micHeader16_temp, 32); } */ } } } void setup() { const char clientReadyText[] = "client ready"; Serial.begin(57600); // put your setup code here, to run once: player.begin(); player.initializeVS1003_for_speaker(); player.configureVS1003(); //player.record(); radio.begin(); radio.setPALevel(RF24_PA_MIN); radio.setDataRate(RF24_2MBPS); ///////////// Sender exist check /* while(1) { //Serial.println("Client ready"); radio.openWritingPipe(address); radio.stopListening(); radio.write(&clientReadyText, sizeof(clientReadyText)); radio.openReadingPipe(0, address); radio.startListening(); if (radio.available()) { char text[32] = ""; radio.read(&text, sizeof(text)); Serial.println(text); break; } delay(500); } Serial.println("Ready"); */ ///////////// Reading section radio.openReadingPipe(0, address); radio.startListening(); //player.setHeader(); //player.sendHeader(); setHeader_temp(); dataQueue = xQueueCreate ( 1024, sizeof (uint8_t)) ; xTaskCreatePinnedToCore ( loop2, // Function to implement the task "loop2", // Name of the task 10000, // Stack size in bytes NULL, // Task input parameter 0, // Priority of the task NULL, // Task handle. 0 // Core where the task should run ); } void loop() { //Serial.println("j"); uint8_t tempValue; if (radio.available()) { radio.read(&text, sizeof(text)); for(int i=0;i