Hello,

I tried to make a wireless live mono audio link with a Teensy 3.2 as a transmitter and Teensy 4.0 as a receiver.
Mainly copied a code example I found somewhere in the forum and changed it slightly.. Want to stream audio from a mic + several times a secound data from a Joystick on a different pipe but the same channel.
Everything seems to work fine but there is still a little "popping" sound several times a secound.
Without the joystick data there is no problem. Any Ideas, how to get it working/ make the code faster?
Another strange observation I made is that it only works at specific CPU Speeds: Teensy 3.2@120MHz and Teensy 4.0@24MHz. Anything else, even higher, produces extreme jitter. Logically, a higher speed should bring higher performance, I thought?

Here is the code for the Teensy 3.2 (transmitter):

Code:
//Teensy 3.2 @ 120Mhz - transmitter

#include <Audio.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#define audiobuffersize 128 // one block in audio library has 128 values of 2 byte

#define JoyX_Pin 16
#define JoyY_Pin 17
#define JoySwitch_Pin 18

uint16_t JoyX;
uint16_t JoyY;
bool JoySwitch;
byte ControlBuffer[8];

RF24 radio(20,21); // Teensy 3.6 pin 21=CE, Teensy 3.6 pin 15=CSN

const byte pipeaddress[2][5] = {
    {'1','N','O','D','E'},
    {'2','N','O','D','E'}
};

elapsedMillis millisec;

// GUItool: begin automatically generated code
// defs for audio library
AudioInputI2S i2s1;
AudioOutputI2S i2s2;
AudioRecordQueue queue1;
AudioSynthWaveformSine sine1;
AudioConnection patchCord1(i2s1, queue1);

AudioControlSGTL5000 sgtl5000_1;
// GUItool: end automatically generated code

uint8_t bufr[audiobuffersize * 2]; //buffer to hold 256 byte of audio data

void setup()
{
//Serial.begin(9600);
//Serial.println("Start Transmitter");


AudioMemory(100); //give the Audio Library some memory to work with

Serial.begin(36000);

// use alternate SPI pins for nrf24
SPI.setMOSI(7);
SPI.setMISO(8);
SPI.setSCK(14);
SPI.begin();

// Setup the SGTL5000 AIC
//sgtl5000_1.enable(); //activate AIC

sgtl5000_1.enable(); //Enable the SGTL5000
//sgtl5000_1.volume(0.4);


delay(100);

radio.begin();
//radio.setPayloadSize(32); //this is the maximum payload size for a packet transfer of nrf24
radio.setAutoAck(false); // no Ack
//radio.enableDynamicPayloads();
//radio.setRetries(0,0);
radio.disableCRC(); // no CRC
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_2MBPS);
radio.setChannel(121);
delay(50);

radio.openWritingPipe(pipeaddress[0]);
radio.stopListening(); // switch to transmit mode
delay(100);

queue1.begin();
}

void loop()
{
  
  if(millisec>=100){
  JoyX=analogRead(JoyX_Pin);
Serial.print("Position X: ");
Serial.print(JoyX);

JoyY=analogRead(JoyY_Pin);
Serial.print("          Position Y: ");
Serial.print(JoyY);


Serial.print("    SW: ");
Serial.println(JoySwitch);


if(analogRead(JoySwitch_Pin)<=50){
 JoySwitch=true; 
}
else{
  JoySwitch=false;
}

ControlBuffer[0]=JoyX;
ControlBuffer[4]=JoyY;
ControlBuffer[7]=JoySwitch;

delayMicroseconds(5);
radio.openWritingPipe(pipeaddress[0]);
radio.write(&ControlBuffer,8);
millisec=0;

  }

  
if (queue1.available())
{

memcpy(bufr, queue1.readBuffer(), audiobuffersize*2); // copy 256 byte audio data from audio library buffer to bufr
queue1.freeBuffer();

delayMicroseconds(5);
radio.openWritingPipe(pipeaddress[1]);
// send audio data in 8 packages a 32 byte to the FIFO buffers
for (int i=0; i<8; i++)
{
radio.writeFast(&bufr[i * 32],32);
}
}
}
And here for the Teensy 4.0 (receiver):

Code:
//Teensy 4.0@24 MHz (receiver)

#include <Audio.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#define audiobuffersize 128 // one block in audio library has 128 values of 2 byte

RF24 radio(14,15); // Teensy 3.6 pin 21=CE, Teensy 3.6 pin 15=CSN

const byte pipeaddress[2][5] = {
    {'1','N','O','D','E'},
    {'2','N','O','D','E'}
};

// GUItool: begin automatically generated code
// defs for audio library
AudioPlayQueue queue1;
AudioOutputI2S i2s1;
AudioConnection patchCord1(queue1, 0, i2s1, 0);
AudioConnection patchCord2(queue1, 0, i2s1, 1);
//AudioConnection patchCord(sine1,0,i2s1,0);
AudioControlSGTL5000 sgtl5000_1;
// GUItool: end automatically generated code

uint8_t bufr[audiobuffersize * 2]; //buffer to hold 256 byte of audio data
uint8_t bufcount; //received nrf24l01+ packet counter
byte ControlBuffer[8];
uint8_t ZielPipe;

int i; //Counter
int k; //temp

void setup()
{
//Serial.begin(9600);
bufcount = 0;

AudioMemory(200); //give the Audio Library some memory to work with
/*
// use alternate SPI pins for nrf24
SPI.setMOSI(7);
SPI.setMISO(8);
SPI.setSCK(14);
SPI.begin();
*/
// Setup the SGTL5000 AIC
sgtl5000_1.enable(); //Enable the SGTL5000
sgtl5000_1.volume(0.5); //set the headphone volume
//sgtl5000_1.lineOutLevel(5, 5);
/*
sine1.frequency(500);
sine1.amplitude(0.3);
*/
radio.begin();
//radio.setPayloadSize(32); //this is the maximum payload size for a packet transfer of nrf24
radio.setAutoAck(false); //no Ack
//radio.enableAckPayload();
//radio.setRetries(1,2);
radio.disableCRC(); //no CRC
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_2MBPS);
radio.setChannel(121);
delay(100);

radio.openReadingPipe(1, pipeaddress[0]);
radio.openReadingPipe(2, pipeaddress[1]);
delay(50);

radio.startListening();
}

void loop()
{

if (radio.available(&ZielPipe))
{
  
  if(ZielPipe==1){
    
    radio.read(&ControlBuffer,8);
    
    for(i=0;i<8;i++){
      Serial.print(ControlBuffer[i]);
      
    }
    Serial.println("");
    
  }
// get 8 packets a 32 byte audio data
else if(ZielPipe==2){
if ((bufcount >= 0) && (bufcount < 8))
{
// get 32 byte audio packet data
radio.read(&bufr[bufcount * 32], 32);

// test if all 8 packets received
if (bufcount == 7)
{
bufcount = 0;
int16_t *p = queue1.getBuffer();
memcpy(p, &bufr[0], (audiobuffersize * 2));
queue1.playBuffer();
} else bufcount++;
}
}
else{}
}
}
Any ideas what to change/improve?

Greetings, Chris