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

Build error in esp32/audio.c : "sample rate too low" #1287

Closed
stc1988 opened this issue Jan 6, 2024 · 5 comments
Closed

Build error in esp32/audio.c : "sample rate too low" #1287

stc1988 opened this issue Jan 6, 2024 · 5 comments

Comments

@stc1988
Copy link
Contributor

stc1988 commented Jan 6, 2024

Build environment: macOS,
Moddable SDK version: 4.3.8(ESP-IDF v5.1.2 )
Target device: M5StackCore2, M5Stick-c

Steps to Reproduce
Build app examples/pins/audioin/wavserver using this build command: mcconfig -d -m -p esp32/m5stick_c ssid="MY_SSID" password="MY_PASS"

# cc digital.c.o
# cc audioin.c.o
# cc xs6wifi.c.o
/Users/satoshi/Projects/moddable/modules/pins/audioin/esp32/audioin.c:66:18: error: #error "sample rate too low"
   66 |                 #error "sample rate too low"
      |                  ^~~~~
make: *** [/Users/Satoshi/Projects/moddable/build/tmp/esp32/m5stick_c/debug/wavserver/audioin.c.o] Error 1
make: *** Waiting for unfinished jobs....
@phoddie
Copy link
Collaborator

phoddie commented Jan 7, 2024

Under ESP-IDF 5.x, the minimum sample rate on the original ESP32 is now 20000. Here's the relevant defines from $IDF_PATH/components/soc/esp32/include/soc/soc_caps.h:

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

This example uses 8000 in its manifest. This was fine with IDF v4. If you change the sample rate to 20000, does it work for you?

N.B. For other members of the ESP32 family, the minimum sample rate appears to be 611 so this is only an issue on the original ESP32.

@phoddie
Copy link
Collaborator

phoddie commented Jan 7, 2024

Actually, the two devices you cite use PDM, not the ADC, for audio input. So, the check for the sample rate being in bounds for the ADC is unnecessary. Try replacing this....

#if MODDEF_AUDIOIN_SAMPLERATE < SOC_ADC_SAMPLE_FREQ_THRES_LOW
#error "sample rate too low"
#elif MODDEF_AUDIOIN_SAMPLERATE > SOC_ADC_SAMPLE_FREQ_THRES_HIGH
#error "sample rate too high"
#endif

....with this...

	#if MODDEF_AUDIOIN_I2S_ADC
		#if MODDEF_AUDIOIN_SAMPLERATE < SOC_ADC_SAMPLE_FREQ_THRES_LOW
			#warning "SOC reqires higher audioin sample rate. automatically increasing."
			#undef MODDEF_AUDIOIN_SAMPLERATE
			#define MODDEF_AUDIOIN_SAMPLERATE SOC_ADC_SAMPLE_FREQ_THRES_LOW
		#elif MODDEF_AUDIOIN_SAMPLERATE > SOC_ADC_SAMPLE_FREQ_THRES_HIGH
			#warning "SOC requires lower audioin sample rate. automatically decreasing."
			#undef MODDEF_AUDIOIN_SAMPLERATE
			#define MODDEF_AUDIOIN_SAMPLERATE SOC_ADC_SAMPLE_FREQ_THRES_HIGH
		#endif
	#endif

This does two things:

  1. Doesn't check the ADC sample rates for non-ADC devices
  2. If the requested sample rate is out of bounds for the target device, it is pinned to the closest available value

@stc1988
Copy link
Contributor Author

stc1988 commented Jan 7, 2024

Thanks for confirming.
This replacing make build succeed and wavsever app has no problem.

@phoddie
Copy link
Collaborator

phoddie commented Jan 7, 2024

Cool. Thank you. I'll commit the change. It seems like an improvement.

@phoddie
Copy link
Collaborator

phoddie commented Jan 10, 2024

Commit now available. Closing.

@phoddie phoddie closed this as completed Jan 10, 2024
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

2 participants