-
Notifications
You must be signed in to change notification settings - Fork 437
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
[WiP] Support for I2S microphones like SPH0645 (fixes #70) #118
base: master
Are you sure you want to change the base?
Conversation
Try to imlpement all the platform specific functions correctly for esp8266.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still traveling, so I do apologize for not running the code but I did want to spend some time this morning going over it.
One general question: on the ESP32 can you do multiple i2s setup calls? On the 8266, with the way things are set up, this code can't be used to both record and play at the same time since only the last i2s_rxtx_init() call will take effect. The HW itself is shared on the 8266 (and mostly undocumented) so when the setup function is called it needs to know what DMA engines and i2s state machines to enable.
uint32_t* buff32 = reinterpret_cast<uint32_t*>(buff); | ||
|
||
while (validSamples) { | ||
int32_t sample = buff32[curSample]>>(14+gain_shift); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this code and below doesn't work for 16-bits or stereo mikes. On the ESP8266 I only implemented 16-bit stereo to match the fixed output format on that system (and since my only testing was on a dual-mike setup from the RPI hat from GOOG).
Also, because the stream is a set of fixed-point values from -1 to 0.9999, I think you can get much finer grained amplification simply by integer multiply and shifting, like (for example) is done in the Amplify() method.
virtual bool SetBitsPerSample(int bits); | ||
virtual bool SetGain(float f); | ||
uint32_t GetSample(void); | ||
virtual uint32_t read(void* data, size_t len_bytes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this or GetSample() need to be exposed to the end user at all? If it's an AudioGenerator, then the output stage gets the data fed to it as it becomes available. If you end up doing read() from your app code, it may be simpler just to call the ESP SDK directly, no?
Thanks for the comments. The esp32 has two i2s channels, doing a setup call for each works fine. I've added a 'work in progress' it'll probably take some time for me to work on this and do some more extensive testing. |
@h3ndrik Great work here, any update on if this is usable? |
8efa73c
to
7c7fd13
Compare
This is a new input method to read from I2S devices.
Tested with a SPH0645 on ESP32.