[music-dsp] Square wave with variable Pulse width algorythm?
earlevel at earlevel.com
Wed Jan 2 21:26:04 EST 2002
Yeah, that's it. Basically, you correct the number of harmonics that you want
to, to match that of a sawtooth, and the rest will drop off faster than a
sawtooth to reduce aliasing. When I looked at this, I remember wishing they
dropped off a little faster though (for aliasing).
Also, the algorithm (implemented for the fixed point 56K) used a tracking filter
to correct the harmonics. The idea (again, from memory, so someone feel free to
correct me if I remember wrong) is to place the corner of the first order
highpass a certain distance up from the oscillator frequency. Say you want to
preserve three octaves of sawtooth harmonics (um, eight harmonics). The filter's
slope will attenuate everything low that its Fc by 6 dB/oct, so the fundamental
will now be down 18dB, so you'd compensate by boosting the filter output by that much.
So... it occurred to me that you could probably dispense with tracking the
filter, and just fix it relative to Nyquist. Then you'd calculate how far down
the oscillator fundamental would be attenuated for a giving oscillator
frequency, and compensate accordingly. This would obviate the need for filter
tracking (but adding amplitude tracking), and give you more corrected harmonics
for lower frequencies. (Good and bad points to this--I like the idea of hearing
all the harmonics I can, but the tracking-filter method would give you less
aliasing for lower pitches, at the expensive of dulling as you point out.) So,
you'd have the whole sawthooth spectrum, up to a point on the high end where it
drops off faster to reduce aliasing. This would be practical only for floating
point, I'm sure. I didn't look at it past that because I calc'd the lowest point
I'd like my full sawtooth correction to end (the filter Fc) versus the aliasing
I'd have for higher tones and the result was just OK (maybe better than some
other methods, I don't know, but it wasn't a grand slam).
I haven't had the motivation to build a software "VCO" yet, so I just think
about ways that I might do it when the need arises. My key "needs" are good s/n
and distortion, as many correct harmonics as I can get (meaning that if I dust
off the old modular analog and listen to a raw 100Hz sawtooth, I want the
digital version to sound the same. Nevermind that in typical use there will be a
filter on it and it wouldn't matter), unnoticeable aliasing, and at least the
usual waveforms, PWM (easy), and sync (not so easy, sans aliasing).
I haven't messed around with much of what's out there, but for comparision, I'd
say the Virus (the Pro Tool pug-in version) oscillators are pretty decent
considering (that is, I'd like better, but they do get the job done pretty well
and are amazing considering everything that's packed into one 56300). I checked
out the Reactor demo a couple of years ago (may be better now), and the naked
oscillators sounded pretty bad, unless you bumped the sample rate up (at least
88kHz, as I recall), where they sounded sweet. Anyway, between these simple
listening tests and doing calculations on various oscillator methods, I have a
nagging feeling I'd have to oversample to get what I want. The whole thing
becomes a lot simpler if you just burn the cycles and oversample.
(but I'm still open to suggestions ;-)
> > I think what he's referring to is using a rectified sine, which
> Yes, I missed the keyword.
> > harmonic series like a sawtooth, except that the harmonics drop
> > off 6dB/oct
> > faster (er, I'm going by memory here, I think that's right). So,
> So there will be aliasing, but it drops off fast enough that you
> probably won't notice, at least if you put the highpass cut-off
> a few octaves down from Nyquist. And the slight dulling of the
> wave won't be noticed, because the only good use of sawtooth
> waves is to feed them into a high-order high-resonance filter
> with a fairly low cut-off anyway :-) :-) Clever.
dupswapdrop -- the music-dsp mailing list and website: subscription info,
FAQ, source code archive, list archive, book reviews, dsp links
More information about the music-dsp