6 ms·
Using PWM to play audio is flawed (but usable for many applications), other approaches such a sigma-delta will lead to much better results, but with a lot more
by danhor 3y ago
Using PWM to play audio is flawed (but usable for many applications), other approaches such a sigma-delta will lead to much better results, but with a lot more effort. https://github.com/tierneytim/Pico-USB-audio https://github.com/tierneytim/Pico-USB-audio seems like a reasonable implementation at first glance.
- deleted 3y ago[deleted]
- Kirby64 3y agoWhat do you mean? Class D amps are essentially PWM driven amplifiers. Essentially any speaker in existence offers enough low pass filtering to be directly wired to the amplifier, as well.
- namibj 3y agoThey still do noise shaping.
- Kirby64 3y agoGood ones do all sorts of tricks, including closed loop control and special pwm pulse trains… that doesn’t mean pwm is inherently flawed though.
- deleted 3y ago[deleted]
- squarefoot 3y agoAlso, there's a world of difference between PWM out of a CPU running a non realtime multitasking OS with continuous scheduling and varying timings and the same PWM produced by a dedicated chip that does nothing else.
- lambda 3y agoGenerally they use pulse density modulation, rather than pulse width modulation, which increases the frequency of the noise and makes it easier to filter out. Sigma delta modulation, which the comment you replied to mentioned, is a way of doing pulse density modulation. Imagine if you did dithering to produce grayscale images with a black and white screen by just using different sizes of rectangles; you'd have to have a very high resolution screen before you wouldn't be able to see the individual rectangles. That's what pulse width modulation is like. Whereas pulse density modulation, using a sigma-delta modulator, is more like a proper dithering algorithm, where you spread the pixels out evenly across space, you don't just use different size rectangles to represent different shades of gray.
- eru 3y agoBtw, how well does 'random-dithering' work for sound (compared to sigma-delta modulation)?
- dreamcompiler 3y agoSigma-delta is not difficult. Bresenham's algorithm (which was invented around 1960 to draw straight lines at arbitrary angles on pixellated displays) was groundbreaking because it didn't require any multiply or add operations. Sigma-Delta is basically the same idea as Bresenham's algorithm in a different kind of space.
- dreamcompiler 3y agoEDIT: "Didn't require any multiply or divide operations." Oof. Sorry.
- lttlrck 3y agoIt's been a long time but IIRC Bresenhams needs one divide? I spent hours try to get rid of it...
- dreamcompiler 3y agoYou have to do a shift or two but no divides. That's the beauty of Bresenham's: You can draw the line without ever explicitly computing the slope. In effect, Bresenham ends up performing a division by repeated subtraction. And at every subtraction step, it outputs a pixel.