Hi kernel
Neglecting possibly horrible aliasing in digital domain (not a problem in analog
however), you can derive a 2X freq Sawtooth wave from a Triangle by toggling the
gain between +1 and -1 on slope changes in the triangle wave.
If you have the original Square wave in pretty good phase-alignment with the
Triangle and derived 2X freq Sawtooth, you can get a 1X freq Sawtooth by mixing
the 2X freq Sawtooth with the original Square wave. That can work pretty well in
analog, where you don't have to worry a lot about aliasing. If phase and levels
are well-matched, each half of the Square wave will offset the two cycles of the
2X freq Sawtooth to 'connect the dots' between the two cycles. Each two cycles
of the 2X freq Sawtooth are 'connected together' by the square wave offset, to
draw one cycle of the derived 1X freq Sawtooth.
Anti-aliasing strategies in digital synthesis could mess up the phase
relationship between the Square and derived Triangle, so it might be difficult
to guarantee that the derived waves 'line up' in a sufficiently anti-aliased
digital oscillator, to get a 1X Sawtooth by adding the 2X Sawtooth with the
original Square wave. Dunno, never tried to write a digital synth.
=====
The problem with deriving a Triangle wave from a master Square wave via a leaky
integrator, is that as frequency of the driving Square wave increases, the
amplitude of the derived Triangle wave will diminish. So the derived Triangle
would at least need some kind of frequency-dependent gain adjustment if you
require the Square wave to have a wide frequency range, and you also require a
constant amplitude from the derived Triangle wave.
That is why in many analog synths, the Sawtooth was the first primary wave
generated by the oscillator. The current drive to the oscillator controls the
slope of the Sawtooth, and an amplitude comparator rapidly resets the Sawtooth
to zero when the Sawtooth hits a threshold. That way, the output level of the
Sawtooth stays constant over a wide frequency range, and a higher input current
drive makes a higher frequency output. With amplitude clamped by the comparator,
higher slope == higher frequency.
Once you have the Sawtooth from the primary oscillator stage (in analog), you
can derive the Square (or a variable-width Pulse) by driving the Sawtooth into a
comparator that toggles high above a threshold on the Sawtooth, and then toggles
low below the threshold.
Given a Sawtooth and a Square wave, you can use various tricks to get a
constant-amplitude Triangle wave. For instance, invert the gain of the Sawtooth
depending on the state of the Square wave. Then the easiest way to get a 'fairly
clean' constant-amplitude sine wave, is to drive the Triangle wave into a
multi-stage waveshaper (perhaps using diodes for soft-clippinig).
JCJR
Hmm, just re-read your question, and you didn't require that the Sawtooth be
derived from the Triangle.
If you don't care about aliasing, just add to an acumulator on every sample to
generate the Sawtooth, and reset the accumulator on each positive-to-negative
transition of the Square wave. Simpler than a leaky integrator. But this derived
Sawtooth would also dimish in amplitude as frequency increases, just as with the
leaky-integrator derived Triangle.
Maybe it would work to generate all your waves the simple 'analog way' starting
from a Sawtooth (modulate frequency by changing the accumulator increment, and
reset when Sawtooth amplitude reaches 1.0 or whatever). Derive all the waves as
simple as possible ala analog, but generate them oversampled, and then hope to
quash aliasing when you downsample? But that might be computationally expensive
because each wave would need its own dedicated downsampler, and good
downsamplers can use a fair amount of CPU. The multiple downsamplers could
easily squander more CPU than you save by simple oscillator code. Dunno, never
tried it in digital. Its easy in Analog.
----- Original Message -----
From: "kernel" <***@troniczoo.net>
To: "music DSP music-related DSP" <music-***@music.columbia.edu>
Sent: Monday, August 21, 2006 5:06 PM
Subject: [music-dsp] different waveforms from a single
oscillator. legend has it that a triangle wave can be derived by sending a
square wave thorugh a leaky integrator. this legend is true. i can get a
sinewave by waveshaping the triangle so that's 3 waveforms. anyone know if
sawtooth waves can be achieved somehow from a square/pulse wave oscillator?
pulse > (leaky integrator) > triangle > (waveshaper) > sine
thanks, kernel.
--
dupswapdrop -- the music-dsp mailing list and website: subscription info, FAQ,
source code archive, list archive, book reviews, dsp links
http://music.columbia.edu/cmc/music-dsp
http://music.columbia.edu/mailman/listinfo/music-dsp