Audio Hacking with the esp8266

Wemos Audio

This blog post has moved to the new server at:


6 Responses to “Audio Hacking with the esp8266”

  1. Markus Gritsch Says:

    As already pointed out by a comment on the HaD site, an output bit rate of your PDM of 32 times the sampling frequency effectively yields 5 bit resolution. Feeding 16 bit sample values into your routine which generates the PDM has the potential of bad aliasing. See what happens if you continuously feed 0x0001 as DAC variable value into it: It generates a blip every 65536 output sample values which corresponds to a 21.5 Hz hum at your PDM rate of 44100*32.

    • janostman Says:

      Feeding it a constant 0x0001 generates a 44.1Khz signal with a pulse width of 1/32 or 0.7uS pulses. Not a 21.4Hz hum.

      Feeding it 0x8000 generates a 50/50 stream at 700KHz.

      PDM is not like PWM.

      • Markus Gritsch Says:

        I’m sorry, but you’re wrong. After the first pulse the global err variable gets set to 0xFFFF – 1 and then the function gets called 65534/32 times until the next pulse is generated -> 21.4 Hz. That’s because you are trying to get 16 bit resolution by using 0xFFFF and 16 bit samples. Try it with your code.

      • janostman Says:

        No, 0xFFFE gets added to error.
        And when the error cancels out it changes the bitstream again.
        You have to remember that the err variable loops around so 0xFFFF is actually err-1.
        It will keep toggling around the dac value by 1 LSB generating bits that will cancel the error.

  2. Markus Gritsch Says:

    Initially err is 0. If DAC is 1, one pulse is generated and err is set to 0xFFFE, then each iteration subtracts 1 from err. 65533 times. Then, one DAC >= err again when err reaches 1, another pulse is generated.

    Please run your code and look at the output if you cannot be convinced otherwise.

    • janostman Says:

      You have a point but you are describing an extreme case.

      If DAC is 1000 or 1/60 of the full range the situation has improved a 1000 fold.

      Or if the sample value is 10000 or 1/6 of full scale the pulse sequence is now 200KHz and the dynamic range is still 80dB.

Comments are closed.

%d bloggers like this: