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

[WiP] Support for I2S microphones like SPH0645 (fixes #70) #118

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

h3ndrik
Copy link
Contributor

@h3ndrik h3ndrik commented Aug 20, 2018

This is a new input method to read from I2S devices.

Tested with a SPH0645 on ESP32.

Copy link
Owner

@earlephilhower earlephilhower left a 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);
Copy link
Owner

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);
Copy link
Owner

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?

@h3ndrik h3ndrik changed the title Support for I2S microphones like SPH0645 (fixes #70) [WiP] Support for I2S microphones like SPH0645 (fixes #70) Sep 16, 2018
@h3ndrik
Copy link
Contributor Author

h3ndrik commented Sep 16, 2018

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.

@debsahu
Copy link

debsahu commented Mar 28, 2019

@h3ndrik Great work here, any update on if this is usable?

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

Successfully merging this pull request may close these issues.

None yet

3 participants