Stereo audio output using DAC0 & DAC1

I just got a Giga R1 Wifi and have been at a loss finding examples or library code to use both DAC0 and DAC1 to drive a stereo audio signal. Does anyone know if it has been proven or demonstrated to do so, and if so, maybe you could point me to the information. I have searched the Arduino forum and Git APIs, code examples, etc. Maybe unrelated, but my playing with the DAC0 and DAC1 using the AdvancedDAC APIs and examples has given me problems where the signals on the two DACs are sometimes out of sync for reasons I cannot determine. This along with finding a few other forum inquiries about lack of info with Giga stereo signaling makes me wonder if it cannot do it or that no one has been able to write code to make it work. If you can shed light on any of this, I'd appreciate it. Thanks

I assume you are referring to the documentation where the examples only use DAC0: https://docs.arduino.cc/tutorials/giga-r1-wifi/giga-audio/

It's not for the Giga R1 but I know the PJRM Teensy website has some general technical guidance / tutorial for their boards (search forum too. There's also a github page for further info).

Were you trying DMA with this?

Can you expand on this please as it does not make sense.

I modified the Audio_Playback example when testing and could not pick up on any out of sync audio when using DAC0 and DAC1.

In this example there is this chunk of code, which you can change:

    // Process and write samples to the DAC buffer.
    for (size_t i=0; i<N_SAMPLES; i++) {
      // Map the samples to positive range and down scale to 12-bit.
      if (wavreader.channels() == 1) {
        dacbuf[i] = ((unsigned int) ((int16_t) pcmbuf[i] + 32768)) >> 4;
      } else {
        // If the file has two channels set the average.
        dacbuf[i] = ((unsigned int) ((((int16_t) pcmbuf[(i * 2)] + (int16_t) pcmbuf[(i * 2) + 1]) / 2) + 32768)) >> 4;
      }
    }

    // Write the buffer to DAC.
    dac1.write(dacbuf);
    pcmbuf.release();


So if the wav file has 2 audio channels these two channels are merged as one. You simply change this and split it out to two buffers for each dac. I even increased the sample size N_SAMPLES to 1024 and made no difference (assuming larger sample sizes take longer to write to memory).

    if (dac0.available() && dac1.available() && wavreader.available()) {
      // Get a free buffer for writing.
      SampleBuffer dacbuf0 = dac0.dequeue();
      SampleBuffer dacbuf1 = dac1.dequeue();
  
      // Read a samples buffer from the wav file.
      SampleBuffer pcmbuf = wavreader.read();
  
      // Process and write samples to the DAC buffer.
      for (size_t i=0; i<N_SAMPLES; i++) {
        // Map the samples to positive range and down scale to 12-bit.
        dacbuf0[i] = ((unsigned int) (((int16_t) pcmbuf[(i * 2)]) + 32768)) >> 4;
        dacbuf1[i] = ((unsigned int) (((int16_t) pcmbuf[(i * 2) + 1]) + 32768)) >> 4;
      }
  
      // Write the buffer to DAC.
      dac0.write(dacbuf0);
      dac1.write(dacbuf1);
      pcmbuf.release();
    }

Here is demo:

Thank you for the response. It was helpful. My issue before, where I thought I experienced DAC0,1 out of phase, was probably something I was doing wrong.