Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is AnalogAudioStream supported on ESP32-S3? #1039

Closed
1 task done
uutzinger opened this issue Nov 6, 2023 · 17 comments
Closed
1 task done

Is AnalogAudioStream supported on ESP32-S3? #1039

uutzinger opened this issue Nov 6, 2023 · 17 comments

Comments

@uutzinger
Copy link
Contributor

uutzinger commented Nov 6, 2023

Problem Description

When I open basic-adc-serial and I attempt to compile it I get:
error: 'AnalogAudioStream' does not name a type

My goals is to read with the internal A/D converter.

Device Description

Hardware: Adafruit Feather ESP32-S3 2MB PSRAM
Board Manager: esp32 by Espressif Systems version 2.0.14
Selected Board: ESP32S3 Dev Module (not the Adafruit defined board)

Sketch

The example program base-adc-serial

Other Steps to Reproduce

Not applicable.

What is your development environment

Arduino IDE 2.2.1
Selected Board: ESP32S3 Dev Module (not the Adafruit defined board)

I have checked existing issues, discussions and online documentation

  • I confirm I have checked existing issues, discussions and online documentation
@pschatzmann
Copy link
Owner

pschatzmann commented Nov 6, 2023

The Arduino IDE version is not relevant here.

To use the ADC functionality of the S3 you need to have the new ADC API available from Espressif. This is not the case in the ESP32 core version you are using: you can find the version in the Board Manager.

It is only available starting from ESP32 3.0: Fortunately there is a pre-release available. So I suggest to upgrade 3.0.0 alpha2

The other option is to add a USE_ANALOG_ARDUINO in the AudioConfig.h and you might get away with this if you keep the sampling rates very low.

@uutzinger
Copy link
Contributor Author

Thanks very much for your support.

I tried with alpha2. Using base-adc-serial unfortunately I get
src/AudioAnalog/AnalogConfigESP32V1.h:62:5: error: 'dac_channel_mask_t' does not name a type; did you mean 'adc_channel_t'?

I guess its almost working.

P.S. When I used the new AnalogReadContinous example in 3.x I can measure with ESP32-S3 at about 20Khz but regularly it drops one reading. At 10kHz its about once a second. I am looking forward trying your AudioStream instead.

@pschatzmann
Copy link
Owner

pschatzmann commented Nov 7, 2023

Yes, this error was introduced with one of the last changes to make the dac pin selectable for the S2 and ESP32.
The correction has been committed...

@uutzinger
Copy link
Contributor Author

Thank you very much!
I tried to compile some of your examples on the different board options for Arduino ESP32 Core version 3.0.0 alpha2 before your fix and found that ESP32C3, ESP32S3, ESP32C6 and ESP32H2 had issues.
After the fix C3 and S3 is working, but there are remaining issues with ESP32C6 with 'ADC_CONV_MODE', 'ADC_OUTPUT_TYPE', 'ADC_CHANNELS', 'touchRead', and ESP32H2 with 'i2s_pdm_rx_slot_config_t', 'i2s_pdm_rx_clk_config_t', 'i2s_pdm_rx_config_t', 'pdm_rx_cfg' 'i2s_channel_init_pdm_rx_mode' and 'touchRead'. I don't have those models but I guess sooner or later others will be asking...

@pschatzmann
Copy link
Owner

I added the missing variants to the AudioConfig.h

@uutzinger
Copy link
Contributor Author

Cool.
Unfortunately when I use

uint16_t sample_rate = 100;
uint8_t  channels = 2;
uint8_t  bits_per_sample = 12;
AudioInfo info(sample_rate, channels, bits_per_sample);

I get regardless of sample_rate

E (228) adc_continuous: adc_continuous_config(511): ADC sampling frequency out of range

When I use the stock base-adc-serial example (default config) I get

E (227) adc_continuous: adc_continuous_config(511): ADC sampling frequency out of range
E (238) adc_continuous: adc_continuous_read(414): The driver is already stopped

Almost there.

@pschatzmann
Copy link
Owner

Well 100 does not make any sense.
In audio values start usually with 8000

@uutzinger
Copy link
Contributor Author

uutzinger commented Nov 7, 2023

Yes I started with 44100 and went down with the values. So no value between 100 and 44100 are accepted. The default values of the defaultConfig are also not accepted.

@pschatzmann
Copy link
Owner

pschatzmann commented Nov 8, 2023

You should be ablee to determine the available range for your processor by printing the following values

#define SOC_ADC_SAMPLE_FREQ_THRES_HIGH          (2*1000*1000)
#define SOC_ADC_SAMPLE_FREQ_THRES_LOW           (20*1000)

The values above are for the ESP32, so I expect it to be different for your board

@uutzinger
Copy link
Contributor Author

Phil
I looked into this some further by digging into the source code (yours, Arduino-ESP32 and ESP33 IDL) and when I tried to run your code on an older ESP32 Dev Kit, I realized this is a problem not specific to ESP32S3 but to all version on attempting Arduino ESP32 Core version 3.0.0 alpha. I will create separate ticket explaining what I found so far. For example the numbers above SOC_ADC_SAMPLE_FREQ_THRES_LOW/HIGH actually translate to like 600 something and 80000 somethin when you add a boundary check in AnalogAudioESP32V1.h and print them (e.g. when you set sample frequency to 20000 it states its 633). What puzzles me is that the Example provided by Espressif for Continuous A/DC is able to set the continuous configuration without error while it does not work with your code, although code section under the hood for configuring are similar.

Or in short: At this time your base-adc_serial compiles but fails to set sampling rate with ESP32 Core Version 3.0.0 alpha2.

@pschatzmann
Copy link
Owner

Strange, I used the example from Espressif as starting point for my implementation.
I double check if I can find the difference...

@pschatzmann
Copy link
Owner

pschatzmann commented Nov 9, 2023

Oops, there were some pretty ugly bugs: e.g. I did not set the sampling rate!

I committed a correction and a test case. But there is still something wrong: I am measuring a sampling rate which is much higher in mono and much lower in stereo then requested. But at least it seems that we are getting some data now...
It seems that this is a known open bug with Espressif.

I did not check if the data makes any sense...

@pschatzmann
Copy link
Owner

I committed some more corrections: I removed the shadowed channels and bits_per_sample and all conversions so that we can better understand the provided data.
One last topic: I assume the result will be unsigned, but in audio we prefer to have signed values. So there might be one final conversion necessary...

@pschatzmann pschatzmann reopened this Nov 11, 2023
@pschatzmann
Copy link
Owner

pschatzmann commented Nov 17, 2023

see #1049

@mehran-mohammadi
Copy link

mehran-mohammadi commented Nov 23, 2023

Hi, I have an issue with esp32-s3, more specifically the board I am using is lilygo t-display s3. I installed ESP version 3.0 alpha 2 and this solved the compile issue. however, After uploading the code, I get no sound! (I am using Analog DAC) I have checked all the pins on the board but there is no sound...
Do I need to change anything in the configuration files or the GPIO pins, since ESP32-S3 does not have default pins (25 and 26) on board?

@pschatzmann
Copy link
Owner

I am not really sure what functionality you are talking about, but I have the impression that you try to use the non existing DAC of the ESP32-S3!

If you want to output sound you need to use I2S or PWM on this processor...

@mehran-mohammadi
Copy link

Thank you for your answer. I will try them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants