Using PWM DAC vs. R2R for sound synthesis

I'm planning on building a synthesizer but I can't use R2R, which is the only DAC I've seen used on audio generation instructables, since it takes up so many pins. I've discovered PWM to analog which seems so much simpler but have never seen it be used in DIY arduino synths. Do you guys have any idea if it will work and if so what values do I need to use to have as little delay as possible while still being able to use a wide range of frequencies.

I've attached a quick schematic of the circuit I am talking about.

PWM.png

Yes I have used PWM before. Although not a requirement, it does help to have a low pass filter to make it act more like a DAC as you get a waveform that is not just a high frequency square wave. It does work and I have used it for audio synthesis. One advantage PWM has is that you can just write to an 8-bit register. Also 16-bit pwm is possible although I am not sure how well this would compare against a real 16-bit DAC. The reason why this matters as in the ability to simply write to an 8-bit register is that with r2r DAC you will need to shift the data so that only the pins with the resistors are affected. This means a performance increase. Also you could use a real DAC that uses the SPI protocol if PWM proves to be of less quality than desired although I have had no issues with quality. An SPI dac also has the advantage that you just need to write to an 8-bit register and the write does not stall the AVR in any way so you can calculate the next byte while the previous one is sending time your code so that the previous byte is really done sending. Even at very high samples rates this will not be a concern unless you starting doing around 1MHZ sample rate which would be hard to calculate synthesis at that rate.

For higher quality audio (say playing MP3s, for example), you'd typically buy a DAC chip or an audio shield (which has a DAC) rather than building your own with a resistor network.

Your computer's soundcard, your iPod, CD player, DVD player, etc., all have DAC chips or some kind of integrated audio system-on-a-chip that includes a DAC.

You can get away with PWM for certain "electronic synthesizer" sounds, but for a synth that can sound more like a "real instrument", you'll need something better. ...I'm not saying you'll get bad sound with PWM, I'm just saying that it's more limited and with a real DAC, the sound is only limited by the hardware/software driving it.

Really I never had an issue with the quality of PWM audio. I do think that you may get a small improvement as mentioned in my post you will want an SPI dac as this will be fast for arduino.

I'm not saying you'll get bad sound with PWM

I am, it is absoloutly awful. Think chip tunes like sounds.
The filter does not dealy, it smooths.

Here is a recording of PWM generated with the attached code. Note that I wrote the code a long time ago and did try and quickly clean it up using VIM's auto-indent. It sounds good enough for me. The sample that I used was not the best however.

pwm.wav (2.05 MB)

main.c (44.4 KB)

Here is a recording of PWM generated with the attached code.

So just a waveform. Sorry not very impressed.

Well all I wanted to test is if PWM sounded good or not and it did.