Skip to content

Fix PDMIn MEMS microphone support #479

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

Merged
merged 5 commits into from
Dec 13, 2017
Merged

Conversation

dhalbert
Copy link
Collaborator

Changes:

  1. New faster filter loop, by @ladyada. New filter coefficients as well.
  2. Turn on microphone clock when PDMIn object is created, and run it all the time, so the user code doesn't have to wait for microphone startup, which can be 10ms or even 100ms.
  3. Wait for microphone startup when PDMIn is first created, based on new optional parameter microphone_startup_msecs.
  4. record() returns number of samples actually recorded, so you can see if it's not keeping up.
  5. Fix buffer overflow errors when buffer size was not a multiple of 16 or something like that.
  6. Tweak a few peripheral settings.
  7. Minimum sampling frequency is now 16kHZ or so, because 8kHz runs microphone at only 0.5MHz, which is too slow for many mics.

Note: I tried 128x oversampling instead of 64x, but the code cannot keep up at 24kHz or above sampling. 128x would reduce the high-frequency noise by 6db.

@dhalbert dhalbert requested a review from tannewt December 13, 2017 03:24
@dhalbert dhalbert closed this Dec 13, 2017
@dhalbert dhalbert reopened this Dec 13, 2017
@dhalbert
Copy link
Collaborator Author

closed by mistake. was going to make a cosmetic change but not worth it.

@ladyada
Copy link
Member

ladyada commented Dec 13, 2017

yaaaaaaaaaaaay@!

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Just a couple minor things.

@@ -146,6 +146,10 @@ endif
CFLAGS += -Os -DNDEBUG -flto $(GCC_INLINE_LIMIT)
endif

# Do extra optimization for speed on a few files.
# e.g.:
#$(BUILD)/xxx/Something.o: CFLAGS += $(CSUPEROPT)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't needed for this PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was basically just documenting how to do this, but I'll take it out.

/* 1788, 1631, 1473, 1315, 1161, 1013, 873, 742, */
/* 622, 514, 418, 334, 262, 201, 150, 108, */
/* 75, 49, 30, 16, 7, 2, 0, 0 */
/* }; */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these still in here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wanted to stash them somewhere, but I can save them elsewhere.

//| :param int bit_depth: Final number of bits per sample. Must be divisible by 8
//| :param bool mono: True when capturing a single channel of audio, captures two channels otherwise
//| :param int oversample: Number of single bit samples to decimate into a final sample. Must be divisible by 8
//| :param int microphone_startup_msecs: milliseconds to wait after starting microphone clock
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about taking taking float seconds to be consistent with time.sleep?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea. I considered this and then for some reason thought float might not be available, which is wrong: we depend on float

@dhalbert
Copy link
Collaborator Author

not done - didn't do float mic time yet

@dhalbert
Copy link
Collaborator Author

Ready to re-review. Squash merge if you like due to multiple commits.

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thank you!

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.

3 participants