-
-
Notifications
You must be signed in to change notification settings - Fork 117
Description
Hello,
I have reduced your example to a minimum to investigate in details.
I changed output to Serial and observe the signals via SerialPlot SW.
Input signal was Sine 1kHz, 2V Amp, 1.7V offset.
#include "ADCSampler.h"
#define SAMPLE_RATE 32000 //16000
#define SAMPLES 16384
#define TPIN 2
#define t1 digitalWrite(TPIN, HIGH);
#define t0 digitalWrite(TPIN, LOW);
#define t digitalWrite(TPIN, !digitalRead(TPIN));
ADCSampler *adcSampler = NULL;
I2SSampler *i2sSampler = NULL;
// i2s config for using the internal ADC
i2s_config_t adcI2SConfig = {
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_ADC_BUILT_IN),
.sample_rate = SAMPLE_RATE, //16000,
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, // I2S_BITS_PER_SAMPLE_16BIT,
.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
.communication_format = I2S_COMM_FORMAT_I2S_LSB,
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
.dma_buf_count = 4,
.dma_buf_len = 1024,
.use_apll = false,
.tx_desc_auto_clear = false,
.fixed_mclk = 0
};
void adcWriterTask(void *param)
{
I2SSampler *sampler = (I2SSampler *)param;
const TickType_t xMaxBlockTime = pdMS_TO_TICKS(100);
while (true)
{
uint32_t ulNotificationValue = ulTaskNotifyTake(pdTRUE, xMaxBlockTime);
if (ulNotificationValue > 0){
int8_t buffptr = (int8_t)sampler->getCapturedAudioBuffer();
// for (int i = 0; i < sampler->getBufferSizeInBytes(); i=i+2) {
// Serial.printf("%d\n\r", buffptr[i] + buffptr[i+1]*256);
// }
Serial.write((char *) sampler->getCapturedAudioBuffer(), sampler->getBufferSizeInBytes());
}
}
}
void setup()
{
Serial.begin(115200);
pinMode(TPIN, OUTPUT);
while (!Serial);
adcSampler = new ADCSampler(ADC_UNIT_1, ADC1_CHANNEL_7);
TaskHandle_t adcWriterTaskHandle;
xTaskCreatePinnedToCore(adcWriterTask, "ADC Writer Task", 4096, adcSampler, 1, &adcWriterTaskHandle, 1);
adcSampler->start(I2S_NUM_0, adcI2SConfig, SAMPLES, adcWriterTaskHandle);
}
void loop()
{
}
Below are screenshorts of the various I2S settings.
Please, note how awful they looks. They should be smooth but they did not.
Only at 32Bit 100kHz it looks acceptable.
First time I met the problem on PDM example for M5 Core2.
Note, also, that signals aquired from analogRead function are ideal.
This sawtooth distortion leave no way to use FFT because they produce a lot of harmonics. Also, the same thing occured in you original code(Audacity picture).


)

