Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Aug 3, 2024
2 parents 8b038c5 + a20ca7a commit ae3014d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ if (DEFINED ESP_PLATFORM)

# idf component
idf_component_register(
SRC_DIRS src
# SRC_DIRS src
INCLUDE_DIRS src
REQUIRES bt esp_common freertos hal log nvs_flash driver
)

target_compile_options(${COMPONENT_LIB} PUBLIC -DESP32_CMAKE=1 -Wno-error -Wno-format -fpermissive)
target_compile_options(${COMPONENT_LIB} INTERFACE -DESP32_CMAKE=1 -Wno-error -Wno-format -fpermissive)

else()

Expand Down
19 changes: 10 additions & 9 deletions src/AudioAnalog/AnalogDriverESP32V1.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class AnalogDriverESP32V1 : public AnalogDriverBase {
// LOGI("adc_continuous_read request:%d samples %d bytes requested", samples_requested, (uint32_t)(samples_requested * sizeof(adc_digi_output_data_t)));
if (adc_continuous_read(self->adc_handle, (uint8_t *)result_data, (uint32_t)(samples_requested * sizeof(adc_digi_output_data_t)), &bytes_read, (uint32_t)self->cfg.timeout) == ESP_OK) {
samples_read = bytes_read / sizeof(adc_digi_output_data_t);
LOGD("adc_continuous_read -> %u bytes / %d samples of %d bytes requested", (unsigned)bytes_read, samples_read, (uint32_t)(samples_requested * sizeof(adc_digi_output_data_t)));
LOGD("adc_continuous_read -> %u bytes / %d samples of %d bytes requested", (unsigned)bytes_read, samples_read, (int)(samples_requested * sizeof(adc_digi_output_data_t)));

// Parse and store data in FIFO buffers
for (int i = 0; i < samples_read; i++) {
Expand All @@ -297,10 +297,10 @@ class AnalogDriverESP32V1 : public AnalogDriverBase {
if (self->fifo_buffers[idx]->push(data)) {
LOGD("Sample %d, FIFO %d, ch %u, d %u", i, idx, chan_num, data);
} else {
LOGE("Sample %d, FIFO buffer is full, ch %u, d %u", i, idx, chan_num, data);
LOGE("Sample %d, FIFO buffer is full, ch %u, d %u", i, (unsigned)chan_num, data);
}
} else {
LOGE("Sample %d, ch %u not found in configuration, d: %u", i, chan_num, data);
LOGE("Sample %d, ch %u not found in configuration, d: %u", i, (unsigned)chan_num, data);
for (int k = 0; k < self->cfg.channels; ++k) {
LOGE("Available config ch: %u", self->cfg.adc_channels[k]);
}
Expand Down Expand Up @@ -349,7 +349,7 @@ class AnalogDriverESP32V1 : public AnalogDriverBase {
if (self->fifo_buffers[idx]->push(data)) {
LOGD("Top Off Sample %d, FIFO %d, ch %u, d %u", i, idx, chan_num, data);
} else {
LOGE("Top Off Sample %d, FIFO buffer is full, ch %u, d %u", i, idx, chan_num, data);
LOGE("Top Off Sample %d, FIFO buffer is full, ch %u, d %u", i, chan_num, data);
}
} else {
LOGE("Top Off Sample %d, ch %u not found in configuration, d %u", i, chan_num, data);
Expand Down Expand Up @@ -517,12 +517,13 @@ class AnalogDriverESP32V1 : public AnalogDriverBase {
} else {
LOGI("buffer_size: %u samples, conv_frame_size: %u bytes", cfg.buffer_size, (unsigned)conv_frame_size);
}

// Create adc_continuous handle
adc_continuous_handle_cfg_t adc_config = {
.max_store_buf_size = (uint32_t)conv_frame_size * 2,
.conv_frame_size = (uint32_t) conv_frame_size,
};
adc_continuous_handle_cfg_t adc_config;
adc_config.max_store_buf_size = (uint32_t)conv_frame_size * 2;
adc_config.conv_frame_size = (uint32_t) conv_frame_size;
adc_config.flags.flush_pool = true;

err = adc_continuous_new_handle(&adc_config, &adc_handle);
if (err != ESP_OK) {
LOGE("adc_continuous_new_handle failed with error: %d", err);
Expand Down
6 changes: 4 additions & 2 deletions src/AudioI2S/I2SESP32V1.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,12 @@ class I2SDriverESP32V1 {
result = I2S_STD_MSB_SLOT_DEFAULT_CONFIG(
(i2s_data_bit_width_t)cfg.bits_per_sample,
(i2s_slot_mode_t)cfg.channels);
break;
case I2S_PCM:
result = I2S_STD_PCM_SLOT_DEFAULT_CONFIG(
(i2s_data_bit_width_t)cfg.bits_per_sample,
(i2s_slot_mode_t)cfg.channels);
break;
default:
result = I2S_STD_PHILIPS_SLOT_DEFAULT_CONFIG(
(i2s_data_bit_width_t)cfg.bits_per_sample,
Expand All @@ -178,8 +180,8 @@ class I2SDriverESP32V1 {
case I2SChannelSelect::Right:
result.slot_mask = I2S_STD_SLOT_RIGHT;
break;
case I2SChannelSelect::Stereo:
LOGW("Invalid channel_format: %d", cfg.channel_format);
default:
LOGW("Invalid channel_format: %d", (int)cfg.channel_format);
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/AudioTools/AudioStreams.h
Original file line number Diff line number Diff line change
Expand Up @@ -1649,7 +1649,7 @@ class VolumeMeter : public ModifyingStream {
if (p_out!=nullptr){
result = p_out->write(data, len);
}
return len;
return result;
}

size_t readBytes(uint8_t *data, size_t len){
Expand Down
10 changes: 8 additions & 2 deletions src/AudioTools/BaseConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,10 @@ class ChannelDiffT : public BaseConverter {
T *p_source = (T *)src;

for (int i = 0; i < sample_count; i++) {
*p_result++ = *p_source++ - *p_source++;
// *p_result++ = *p_source++ - *p_source++;
auto tmp = *p_source++;
tmp -= *p_source++;
*p_result++ = tmp;
}

return sizeof(T) * sample_count;
Expand Down Expand Up @@ -936,7 +939,10 @@ class ChannelAvgT : public BaseConverter {
T *p_source = (T *)src;

for (int i = 0; i < sample_count; i++) {
*p_result++ = (*p_source++ + *p_source++) / 2; // Average the pair of channels
// *p_result++ = (*p_source++ + *p_source++) / 2; // Average the pair of channels
auto tmp = *p_source++;
tmp += *p_source++;
*p_result++ = tmp / 2;
}

LOGD("channel average %d samples, %d bytes", sample_count, size);
Expand Down

0 comments on commit ae3014d

Please sign in to comment.