I have this little piece of code here that converts a sawtooth wave signal into a no-alias triangle wave signal that I found elsewhere on the forum.
(mult 2.0 (sum (snd-abs s) -0.5))
My knowledge of Nyquist is very small, but I know this little piece of code changes the harmonics of the fundamental frequency of the tone you are generating which changes the waveform. I know a triangle wave is pretty much a square wave (sets of odd harmonics) with harmonics that roll off faster. Sawtooth waves are sets of even harmonics with each harmonic half the amplitude of the previous one. So what would I change with this piece of code to make it convert a sawtooth signal into a no-alias (bandlimited) sawtooth signal?
I’m making sounds for a video game my friend’s independent software company is creating and aliasing distortion really does get in the way of most of the sounds I’m trying to create. As of now, I have no formal education in any of this but I plan on getting it; my friend already has extensive knowledge of software creation, coding, and game design while I have perfect pitch and extremely creative skills with sound, I just need a little help with this. For a suggestion, an HQ chirp generator would be awesome to go along with the HQ tone generator that already exists, it’d help tremendously for situations like this and I’m sure it wouldn’t take long to make.
Yes, I do plan on learning nyquist, but I’m learning SuperCollider first.
Thank you to whoever helps, the people on this forum are the best.
That code does not do what you think it does.
The Nyquist programming language (based on XLISP which is a dialect of LISP) uses Polish Notation. The “operator” (function) comes before the arguments (operands), so, rather than writing:
3 + 4
in Nyquist / Lisp we would write:
(+ 3 4)
Note that parentheses are always placed around the function and its arguments.
Brief explanation of the functions in that code: mult: multiplies things. It works with both numbers and sounds. This is in effect “amplification”. sum: adds things. It works with both numbers and sounds. This is in effect “mixing”. snd-abs: gives the absolute value of each sample in a sound (the sign is ignored for negative values so that all values are positive). This is in effect “full wave rectifying” the sound. s: is the sound that is passed from the selection in the audio track, to Nyquist.
So the first thing that happens in that code is:
Try this on a saw wave and you will see that all of the negative going samples become positive, turning the saw wave into a triangle wave above the track centre line:
The next thing that happens is that -0.5 is added to the sound (the sound is moved down by 0.5)
(sum <sound> -0.5)
Finally, the track is multiplied (amplified) by 2
(mult 2.0 <sound>)
So the overall effect of (mult 2.0 (sum (snd-abs s) -0.5)) is to convert a saw wave into a triangle wave, but it does nothing to prevent aliasing.
The easiest way to prevent aliasing is to generate the sound without aliasing (for example by additive synthesis).
Trying to “filter out” aliasing after it is there does not really work because the filter sees the alias frequencies as valid data.
Wow, I really do appreciate the detailed explanation AND pictures you added. I decided I’m just going to do additive synthesis. We’re working on a 16 bit Genesis-style game and I want to have the sounds that match. They don’t even have to resemble real sounds, but being made as simplistic as possible is easy with the tone and chirp generators. Thanks, though.