Audio pass thru problem

Took a long time to get this sketch to run reliably on Giga, sometimes would not start or when running audio discontinuities at buffer change.
Sorted by delay before buf.release(); discovered when print statement put at this point. Appreciate not a real world problem but this is the sort of code one uses when building up a sketch.

Still a problem why will the Giga board only run this sketch one working and programed is there is an active serial link attached to the powering USB C cable ?

#include <Arduino_AdvancedAnalog.h>
AdvancedDAC dac1(A12);
AdvancedADC adc(A0);

void setup() {
Serial.begin(115200);
while (!Serial) {}
pinMode(23, OUTPUT); // TP pin 23 PG13
// Resolution, sample rate, number of samples per channel, queue depth.
if (!adc.begin(AN_RESOLUTION_12, 32768, 1024, 32)) {
Serial.println("Failed to start analog acquisition!");
while (1);
}
if (!dac1.begin(AN_RESOLUTION_12, 32768 ,1024, 32)) {
Serial.println("Failed to start DAC1 !");
while (1);
}
}

#define TP (1<<13) //
#define TP_HI() GPIOG->ODR |= TP;
#define TP_LO() GPIOG->ODR &= ~TP;
uint64_t last_millis = 0;

void loop() {
if (adc.available()) {
TP_HI();
SampleBuffer buf = adc.read(); // Process the buffer.
dac1.write(buf);
delayMicroseconds(1);
buf.release(); //Release the buffer to return it to the pool.
Serial.println(millis()-last_millis);
last_millis = millis( );
TP_LO();

}
}

John Knott

Welcome! I suggest reading the forum guidelines and then using code tags repost your code. In its existing format it is hard to follow. What is the problem, the original description does not explain what you are asking?

As @gilshultz mentioned hard to follow the code, in this form:
So cut and pated into IDE 2 window, hit ctrl+t to reformat...

#include <Arduino_AdvancedAnalog.h>
AdvancedDAC dac1(A12);
AdvancedADC adc(A0);

void setup() {
  Serial.begin(115200);
  while (!Serial) {}
  pinMode(23, OUTPUT);  // TP pin 23 PG13
  // Resolution, sample rate, number of samples per channel, queue depth.
  if (!adc.begin(AN_RESOLUTION_12, 32768, 1024, 32)) {
    Serial.println("Failed to start analog acquisition!");
    while (1)
      ;
  }
  if (!dac1.begin(AN_RESOLUTION_12, 32768, 1024, 32)) {
    Serial.println("Failed to start DAC1 !");
    while (1)
      ;
  }
}

#define TP (1 << 13)  //
#define TP_HI() GPIOG->ODR |= TP;
#define TP_LO() GPIOG->ODR &= ~TP;
uint64_t last_millis = 0;

void loop() {
  if (adc.available()) {
    TP_HI();
    SampleBuffer buf = adc.read();  // Process the buffer.
    dac1.write(buf);
    delayMicroseconds(1);
    buf.release();  //Release the buffer to return it to the pool.
    Serial.println(millis() - last_millis);
    last_millis = millis();
    TP_LO();
  }
}

It is now a little easier to read.

Not sure what else you are asking here, but:

But that is due to the line:
while (!Serial) {}

Which says wait forever until I have the USB Serial port connected...

I usually add in timeout, like:
while (!Serial && (millis() < 5000)) {} // wait up to 5 seconds for Serial terminal

1 Like