2025-11-25 16:52:38 +01:00
|
|
|
#include <Arduino.h>
|
2025-11-25 18:41:10 +01:00
|
|
|
#include <I2S.h>
|
2025-11-25 16:52:38 +01:00
|
|
|
#include "Heavy_temp_a2960967.hpp"
|
|
|
|
|
|
|
|
|
|
// Erzeuge eine globale Heavy-Instanz
|
|
|
|
|
Heavy_temp_a2960967* hv = nullptr;
|
2025-11-25 18:41:10 +01:00
|
|
|
I2S i2s(OUTPUT);
|
|
|
|
|
|
|
|
|
|
#define SAMPLERATE 44100
|
|
|
|
|
#define BLOCKSIZE 64 // Heavy block size
|
|
|
|
|
#define BUFFERSIZE (2 * BLOCKSIZE) // Stereo interleaved
|
|
|
|
|
|
|
|
|
|
int16_t buffer[BUFFERSIZE];
|
|
|
|
|
|
|
|
|
|
inline int16_t float_to_i16(float x) {
|
|
|
|
|
if (x > 1.0f) x = 1.0f;
|
|
|
|
|
if (x < -1.0f) x = -1.0f;
|
|
|
|
|
return (int16_t)(x * 32767.0f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void codec_transmit() {
|
|
|
|
|
|
|
|
|
|
// Testausgabe mit einem leeren Audiobuffer
|
|
|
|
|
const int blockSize = 64;
|
|
|
|
|
float output[2 * blockSize]; // 2 Kanäle interleaved
|
|
|
|
|
|
|
|
|
|
// DSP verarbeiten
|
|
|
|
|
hv->processInlineInterleaved(nullptr, output, blockSize);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 2*blockSize; i++) {
|
|
|
|
|
buffer[i] = float_to_i16(output[i]);
|
|
|
|
|
//buffer[i] = random(-12000, 12000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i2s.write((const uint8_t *)&buffer, BUFFERSIZE * sizeof(int16_t));
|
|
|
|
|
}
|
2025-11-25 16:52:38 +01:00
|
|
|
|
|
|
|
|
void setup() {
|
2025-11-25 18:41:10 +01:00
|
|
|
i2s.setSysClk(SAMPLERATE);
|
2025-11-25 16:52:38 +01:00
|
|
|
Serial.begin(115200);
|
2025-11-25 18:41:10 +01:00
|
|
|
while (!Serial) {
|
|
|
|
|
// Ausgabe auf USB-Seriell *versuchen* (zeigt sich erst bei Verbindung)
|
|
|
|
|
Serial.print(".");
|
|
|
|
|
delay(100);
|
|
|
|
|
}
|
|
|
|
|
Serial.println("\nSerial connected!");
|
2025-11-25 16:52:38 +01:00
|
|
|
Serial.println("Heavy DSP Test startet...");
|
|
|
|
|
|
|
|
|
|
// Heavy-Context initialisieren (44.1 kHz z. B.)
|
2025-11-25 18:41:10 +01:00
|
|
|
hv = new Heavy_temp_a2960967(SAMPLERATE);
|
2025-11-25 16:52:38 +01:00
|
|
|
|
|
|
|
|
if (hv) {
|
|
|
|
|
Serial.println("Heavy context erfolgreich erstellt!");
|
|
|
|
|
} else {
|
|
|
|
|
Serial.println("Fehler: Heavy context konnte nicht erstellt werden.");
|
|
|
|
|
}
|
2025-11-25 18:41:10 +01:00
|
|
|
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);
|
2025-11-25 16:52:38 +01:00
|
|
|
|
2025-11-25 18:41:10 +01:00
|
|
|
i2s.setBuffers(4, BUFFERSIZE * sizeof(int16_t) / sizeof(uint32_t));
|
2025-11-25 16:52:38 +01:00
|
|
|
|
2025-11-25 18:41:10 +01:00
|
|
|
if (!i2s.begin(SAMPLERATE)) {
|
|
|
|
|
Serial.println("0: I2S error!");
|
|
|
|
|
while (100);
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-25 16:52:38 +01:00
|
|
|
delay(100);
|
|
|
|
|
}
|
2025-11-25 18:41:10 +01:00
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
|
|
|
|
|
|
}
|