 static_assert(buffer.size() % 8 == 0, "Buffer size must be multiple of DAC buffer.");
 
 void initBuffer() {
-    for(size_t i = 0; i < buffer.size(); i += 4) {
-        buffer[i+0] = 0;
-        buffer[i+1] = 1000;
-        buffer[i+2] = 2000;
-        buffer[i+3] = 3000;
+    for(size_t i = 0; i < buffer.size(); i ++) {
+        buffer[i] = (int16_t)(2047 * sinf(6.2831853 * i / buffer.size())) +2048;
     }
 }
 

    PDB0_MOD = mod;

    // The hardware doesn't do what the manual claims. The DAC trigger counter is
    // not reset on PDB counter overflow. Things work correctly, if the PDB mod
    // is used.
    PDB0_DACINT0 = mod;                // trigger DAC once per PDB cycle
    PDB0_DACINTC0 = PDB_DACINTC_TOE;   // enable DAC interval trigger

    PDB0_SC |= PDB_SC_LDOK;            // sync buffered PDB registers

        unsigned dac_out_idx_curr = DAC0_C2 >> 4;
        unsigned dac_val = ((aliased_uint16_vptr) &DAC0_DAT0L)[dac_out_idx_curr];
        interrupts();
        if(/*src_idx_prev == src_idx_curr &&*/ dac_out_idx_prev == dac_out_idx_curr) continue;
        src_idx_prev = src_idx_curr;
        dac_out_idx_prev = dac_out_idx_curr;
        if (!TRACE_VIEW)
          Serial.printf("DMA src idx: %4u   DMA dest idx: %4u   DAC out idx: %4u   DAC value: %4u\n",
                      src_idx_curr, dest_idx, dac_out_idx_curr, dac_val);
        else
          Serial.println(dac_val); // This allows to see the waveform in the tracer
    }
}

