Hi everyone, I'm using ESP32, and I've issue with my output signal. In some place on my signal, the top of the signal is shifted at the bottom or the bottom at the top as on the attached file.
As I'm printing samples[n], when changing the type of samples to uint32_t or int32_t, I've an insufficient memoryGuru Meditation Error
When using uint16_t all the negative values are shifted to the top and some top value are shifted to the bottom. I don't want the bottom and the top of the signal to be shifted. How can I solve this issue, you can see my code below.
Thanks in advance.
#include <SPI.h>
#define SS 5
int16_t* samples;
uint32_t n = 0;
int count = 0;
unsigned long start_time;
unsigned long end_time;
const unsigned long event = 10000;
const uint32_t max_samples=50000;
void setup() {
Serial.begin(115200); /* initialization of serial communication */
SPI.begin(); /* initialization of SPI port */
SPI.setDataMode(SPI_MODE0); /* configuration of SPI communication in mode 0 */
SPI.setClockDivider(SPI_CLOCK_DIV64); /* configuration of clock at 1MHz */
pinMode(SS, OUTPUT);
Serial.println("Start");
samples = (int16_t*)malloc(sizeof(int16_t)*max_samples);
if(samples == NULL){
Serial.print("insufficient memory");
}
else{
Serial.print("malloc ok.");
}
}
void loop() {
start_time = millis();
for (n=0; n<max_samples; n++)
{
samples[n] = Sound();
}
end_time = millis();
// Serial.print("Dauer [ms]: ");
// Serial.print((end_time-start_time));
// Serial.print(" ||| ");
// Serial.print("Beats: ");
// Serial.print(n);
// Serial.println(" ||| ");
for (n = 0; n < max_samples; n++)
{
Serial.print(samples[n]);
//Serial.print(",-32768,32767");
Serial.println();
}
}
int16_t Sound(void) {
digitalWrite(SS, LOW); //activate chip select
int sound = SPI.transfer(0) | (SPI.transfer(0) << 8); //reconstruct 12-bit data
digitalWrite(SS, HIGH); //deactivate chip select
return sound;
}
