• ### Broken Square Waves?

Hi, I'm looking for someone with a deeper understanding of PD and audio synthesis to help me understand why my patch sounds the way it sounds. I don't know why the audio is generated this way. I don't know if it is because of some expected behavior of square waves and the math behind it, or if it is because of some quirk of PD and the way I'm generating the square wave. If you think you can help, please stay with me, I don't know who to go to or what to study to help me understand this.

I was attempting to make a square wave from scratch, I saw some tutorials and I know there are more "proper" ways of doing this, but the simplest I could think of was -1 and 1 alternating. The osc I built is a metronome with a route alternating between -1 and 1 at a given hertz. But the result doesn't sound like a single square wave, there are some harmonics, almost like having senoidal waves mixed with the square wave.

Experimenting, I noticed a cycle of the resonances going from 1hz to 1378.125hz where it completely stops, like zero hz, or one tick in several, several minutes. Other cycles multiples of this frequency exist, like this:

n=1378.125hz
Cycle0 = 1 to n* 2^0
Cycle1 = n*(2^0) to n*(2^1)
Cycle2 = n*(2^1) to n*(2^2)
Cycle3 = n*(2^2) to n*(2^2)
? Cyclen= n2^(n-1) to n(2^n) ?

C0 and C1 are very similar, with subtle differences, but inside of C2 it seems like 2 times C0 or C1 (I didn't check it, but it sounds like this). Inside C3 there are 3 times, and next, C4, 4 times, and so on, the same cycle but more times and faster in each power of two.

I have made a patch that makes it easy to clone the osc to generate each Cycle. For example, clone 10 times to get audio files from C0 through C9.

Where do the resonances come from? Why these cycles exist? Are they some kind of harmonic series? Why 1378.125hz? Is this expected from the math, or is it a quirk result of some PD object (like inputing very low numbers to the metronome)? Does someone understand why this is happening?

main_oscs_cycles.pd
square-from-scratch-osc.pd used in main
square-from-scratch-osc-lineramp.pd used in main

• Posts 4 | Views 645
• @titi-gal No idea, except that it could be the maths. I guess you are running a sample rate of 44100, and 44100/32 is 1378.125
A google found this about 32-bit precision...... https://dspconcepts.com/forums/audio-weaver-designer/345-sample-rate-matching-problem and it could be relevant but I am not sure.
David.

• you're going from control-rate to signal rate (a somewhat complex topic)
going off david's discovery, the 'resonances' (which are probably actually aliasing components) probably correspond to the fact that control-rate messages interact with signals every 64 samples, and you're probably running pd at 44.1 k samplerate (effectively you're 'sampling' the toggle every 64 samples)
In order to create waveforms using control-rate you have to use `[vline~]` but there are much better ways to do this at signal rate, even without anti-aliasing:
https://mikemorenodsp.github.io/basic-waveforms/

• That's it. Aliasing. I tried at 48khz sample rate, and it changed. I researched a little and I understand in general terms what is happening, it's caused by the periodicity of my generated signal interacting with the periodicity of its sampling to generate the audio. But these are new concepts for me, it opened more questions, I will research a bit more, I quite enjoy the results, but couldn't understand why it was happening, thanks for the clarification.

Posts 4 | Views 645
Internal error.

Oops! Looks like something went wrong!