CelliesProjects / wm8978-esp32

Arduino IDE library for wm8978 dac on ESP32.
MIT License
22 stars 5 forks source link

add function to enable high pass filter #9

Closed h3ndrik closed 3 years ago

h3ndrik commented 3 years ago

adds a function to write to the enable bit of the high pass filter. this is required for some microphone hardware.

CelliesProjects commented 3 years ago

Hi @h3ndrik Thanks for your time and effort.

Could you explain the code to me?

h3ndrik commented 3 years ago

yes: you can find more details in the datasheet under "Selectable High Pass Filter". It has 2 modes: audio and application mode. This is about audio mode.

In audio mode the high pass filter removes any frequencies below 3.7 Hz. Effectively removing any DC offset. To enable this, you need to set HPFEN=1 (and HPFAPP=0). HPFEN is bit 8 of R14

The code

I tried to write it similar to the existing functions.

Motivation: I got a board with an elecret microphone. I had problems and noticed the captured waveform has quite a noticable offset. The high pass filter fixes this.

As frequences at below 3.7 Hz are inaudible, you might as well turn the HPF on by default, for example when writing to R14 the Init function: Write_Reg(14, 1 << 3 | 1 << 8); //R14,ADC 128x采样率 and high pass filter

CelliesProjects commented 3 years ago

I get it. The one-complement operator was a new one for me.

As frequences at below 3.7 Hz are inaudible, you might as well turn the HPF on by default, for example when writing to R14 the Init function: Write_Reg(14, 1 << 3 | 1 << 8); //R14,ADC 128x采样率 and high pass filter

If you could add that to this PR please.

h3ndrik commented 3 years ago

alright. i've added that to the init function. thank you.

CelliesProjects commented 3 years ago

Merged. @h3ndrik Thanks!

h3ndrik commented 3 years ago

great. could you please also add a new tag / release a new version, so this will become available on platformio etc? thanks!

CelliesProjects commented 3 years ago

Version 1.0.4 is just released and should be picked up by the arduino library bot within 24-48 hours.