main.cpp been adjusted to communicate with the dac

This commit is contained in:
2025-11-25 18:41:10 +01:00
parent 8d66fa86db
commit e2d27cdcff

View File

@ -1,27 +1,24 @@
#include <Arduino.h> #include <Arduino.h>
#include <I2S.h>
#include "Heavy_temp_a2960967.hpp" #include "Heavy_temp_a2960967.hpp"
// Erzeuge eine globale Heavy-Instanz // Erzeuge eine globale Heavy-Instanz
Heavy_temp_a2960967* hv = nullptr; Heavy_temp_a2960967* hv = nullptr;
I2S i2s(OUTPUT);
void setup() { #define SAMPLERATE 44100
Serial.begin(115200); #define BLOCKSIZE 64 // Heavy block size
delay(1000); #define BUFFERSIZE (2 * BLOCKSIZE) // Stereo interleaved
Serial.println("Heavy DSP Test startet..."); int16_t buffer[BUFFERSIZE];
// Heavy-Context initialisieren (44.1 kHz z. B.) inline int16_t float_to_i16(float x) {
hv = new Heavy_temp_a2960967(44100.0); if (x > 1.0f) x = 1.0f;
if (x < -1.0f) x = -1.0f;
if (hv) { return (int16_t)(x * 32767.0f);
Serial.println("Heavy context erfolgreich erstellt!");
} else {
Serial.println("Fehler: Heavy context konnte nicht erstellt werden.");
}
} }
void loop() { void codec_transmit() {
if (!hv) return;
// Testausgabe mit einem leeren Audiobuffer // Testausgabe mit einem leeren Audiobuffer
const int blockSize = 64; const int blockSize = 64;
@ -30,8 +27,52 @@ void loop() {
// DSP verarbeiten // DSP verarbeiten
hv->processInlineInterleaved(nullptr, output, blockSize); hv->processInlineInterleaved(nullptr, output, blockSize);
// Optional: etwas ausgeben (z. B. ein Samplewert) for (int i = 0; i < 2*blockSize; i++) {
Serial.print("Sample L[0]: "); buffer[i] = float_to_i16(output[i]);
Serial.println(output[0]); //buffer[i] = random(-12000, 12000);
}
i2s.write((const uint8_t *)&buffer, BUFFERSIZE * sizeof(int16_t));
}
void setup() {
i2s.setSysClk(SAMPLERATE);
Serial.begin(115200);
while (!Serial) {
// Ausgabe auf USB-Seriell *versuchen* (zeigt sich erst bei Verbindung)
Serial.print(".");
delay(100);
}
Serial.println("\nSerial connected!");
Serial.println("Heavy DSP Test startet...");
// Heavy-Context initialisieren (44.1 kHz z. B.)
hv = new Heavy_temp_a2960967(SAMPLERATE);
if (hv) {
Serial.println("Heavy context erfolgreich erstellt!");
} else {
Serial.println("Fehler: Heavy context konnte nicht erstellt werden.");
}
i2s.onTransmit(codec_transmit);
i2s.setDATA(8); // DAC DIN
i2s.setBCLK(6); // Note: LRCLK = BCLK + 1
i2s.setMCLK(9);
i2s.setMCLKmult(256); // 256 = 12.288.000Hz 512 = 25MHz
// i2s.swapClocks();
i2s.setFrequency(SAMPLERATE);
i2s.setBitsPerSample(16);
i2s.setBuffers(4, BUFFERSIZE * sizeof(int16_t) / sizeof(uint32_t));
if (!i2s.begin(SAMPLERATE)) {
Serial.println("0: I2S error!");
while (100);
}
delay(100); delay(100);
} }
void loop() {
}