SC as a first language and ... Math

SuperCollider is my first programming language as it’s the only one that produces something interesting enough, quickly enough, to hold my attention and keep me motivated. I find learning a programming language to do something like make a web app, boring. Each to their own.

My questions are: if one was to learn SC fluently as a first language, would one be prepared to learn another language, or is it too different than say JS, Python, Rust, etc? Is it decent to learn as a first language?

And two: If you could only learn one type of math to understand DSP and SC better, is it trigonometry that one should learn, or something else?

Thanks, I know I’ve asked a few questions recently, I’m just really excited about SC.

-Melas

SCLang is a decent language to learn, and it has enough similarities to languages like python and javascript to help you pick those up as well. Obviously it has some quirks (and also possibilities) that you might not find in other languages - but there’s no such thing as an “ideal first language” anyway. My advice in this case would be: “any language is better than no language”. Go with what interests you.

As for one type of math to understand DSP… The foundations of DSP use both a lot of calculus (stuff like Fourier and Laplace transforms) and algebra (stuff like matrix multiplications and decompositions) - and in some types of DSP also statistics. But if your goals is to make music with SC, you don’t really need to know a whole lot about these foundations. Maybe consider browsing a DSP book once and see where it gets you? Here’s a free one: http://www.dspguide.com.

Maybe more interesting, some nice introductory tutorials exist online which focus specifically on sound synthesis, e.g. https://learningsynths.ableton.com/ I think you would learn a lot trying to translate the ideas outlined there into supercollider (and asking questions on the forum when you get stuck).

2 Likes

Thank you so much for your thorough reply. I know synthesis pretty well as I’ve been doing it for a pretty long time, but found myself wanting to understand things like you mention.

I’m hoping that having at least a basic understanding of some math would open up new ideas. Like what I can and cannot do, or just things I can’t imagine yet. I was in the help docs and found myself trying to understand complex numbers last night…From a person that barely has high school algebra under his belt, let’s just say it wasn’t very fruitful.

Just a simple idea to show you where my head is at: the Julia set / fractals, etc. is there a way to apply that formula into synthesis somehow? I have no idea if that is silly to think about or not, because I don’t know what’s really going on. I just know that it seems “cool” from a layperson’s POV.

Thank you for the resources and for taking the time to reply!

-melas

Here’s an example that might be useful inspiration for Julia set synthesis experiments, some interesting stuff going on:

1 Like

I’m in a similar boat to you when it comes to math. And more and more I’ve been looking to up my math skills as I also think it’ll improve my skill in SC and open up many new possibilities compositionally and creatively.

I’m also comfortable with various synthesis techniques, but the underlying math behind them is I think important to knowing and intuiting how to set up controls, modulations, interconnections, etc.

I recently picked up Musimathics by Gareth Loy, and have recently begun going through it. I’m still early stages in the first book, and want to read them in order, but it’s really vol 2 that I’m interested in going through, I think many relevant concepts will be introduced there, but I also think that vol 1 lays the foundation. I haven’t gotten far enough into it yet to see whether it’s a use resource, but it seems like the books were written to speak toward this exactly, so I hope so! There also seem to be a lot of references to Curtis Roads’s Computer Music Tutorial, and various other resources of this sort. I’m not sure if the math is clearly laid out there, but at least the formulas are discussed. Depending on the complexity of the formulas, it may be possible to work backward, maybe not.

Personally I think compositionally, with some foundational algebra under your belt and an understanding of synthesis, you’ve got a lot of tools already inherently there in helping make sense of the math, because you know about how this math is actually implemented. If looking at a formula that describes filter behavior, for instance, you already know what many of those variables represent. Often seeing which variables are used can also be informative for thinking about how to structure a synth compositionally, as the math has helped inform many concepts of common synthesizer controls, layouts, etc.

I think where the math knowledge comes in though are examples like how to set up control structures for say FM synths when you want them to be more harmonically cohesive, versus not.

One of Nick Collins’s SC tutorials on synthesis goes into some of the math, and some of the common means of control, and also references a Max/MSP tutorial that references Roads, Chowning, and Moore. Collins sort of hints at it, and the Max tutorial goes into it just a bit more, about the difference in Chowning and Roads’s harmonicity index formula, vs Moore’s and ultimately opting for Moore’s:

In this tutorial we use Moore’s definition because that way whenever the harmonicity ratio is an integer the result will be a harmonic tone with Fc as the fundamental.

I think it does take an appreciable understanding of math, not to understand why they chose one over the other, but just knowing that it’s possible to choose, of knowing thee distinction, of figuring out one versus the other on your own. And the ramifications of choosing Chowning’s versus Moore’s, or if you chose the wrong one, even know that it’s possible to correct and switch to another… My natural inclination would have been some sort of down chain brute strength method, and who knows what that means - that could derail the entire patch, and would certainly take a lot of energy, where actually switching numerator and denominator is a simple thing, with huge ramifications!

As for learning other languages after learning a first one… I personally think that the basic syntactical requirements of a language is the easy part. It’s truly the ability to think through a problem programmatically, and to layout and define functionality in this way which is the hard part and not language specific at all. So ideas such as signal flow, problem solving, etc these are the real concepts that must be understood to learn. Sure every language has its quirks, and the more you learn about each language’s syntactical structure will certainly inform and inspire specific types of use, but I think the underlying principals of how to think in this way are much more difficult and generally universal. Maybe there are larger divides between object oriented languages and non-, but all the languages you listed are, and so will function similarly for the most part.

The higher level the language, or the more domain specific, the more this is the case, “invisible foundations”. I had a problem to solve in Python, the answer was use that function in NumPy. Learned nothing. I use POV-Ray (a ray tracer) for near three decades now. Still could not write a ray tracer. It is very good for learning basic skills and 3D vector math (and you can do sound with it, kind of).

If sound is the targeted “interesting part”, you can pick any language that let’s you write a wav file. It may be slow and certainly not real time. You can write any synthesis or DSP algorithm in Python or Lisp or Nim or …

I think the kind of math you need depends on what you want to do.

I’m mainly interested in generative composition, not as much in sample-level signal processing. While filter design and FFTs (trigonometry of complex numbers) are interesting, for myself, I don’t feel a need to master them. But I do need to be very comfortable with manipulating time and pitch values, and with mapping modulator signals onto real-world ranges.

For a quick example – a common use case is to produce a number of detuned oscillators. Math concepts involved:

  • Frequency is an exponential scale, so detuning would be multiplying by a ratio close to, but not equaling, 1.

  • The ratio should itself follow an exponential scale: not 1 + x and 1 - x, but x and 1/x.

  • So your first thought might be to have a detun parameter (deliberately misspelled so as not to conflict with the Event default \detune value), and ExpRand(detun.reciprocal, detun).

  • But then, what if you want to change detun while the synth is playing? Neither ExpRand nor TExpRand update continuously.

  • Another way to write 1/x is x ** (-1). And x is x ** 1. So you could get exponentially distributed detuning values by producing linear random numbers between -1 and 1, and raising x to that power. As you change x, the range of ratios will shrink closer to 1, or expand farther away from it.

(
a = {
	var n = 10;
	var freq = 400;

	// this is arbitrary, could be a synth control (arg)
	var detun = MouseX.kr(1, 1.2, 1);

	// here we turn 'detun' into randomized ratios
	var detunes = Array.fill(n, { detun ** Rand(-1, 1) });

	var oscs = Saw.ar(freq * detunes);
	var mix = Splay.ar(oscs);
	LPF.ar(mix, 3000) * 0.1
}.play;
)

a.release;

… nothing earthshaking here, but it does depend on algebraically rephrasing the concept of an exponentially distributed set of ratios – boring for real mathematicians, but musicians might need to dust off some of this old stuff from middle school. (Similarly, “how to write a rhythm using this function that occupies a total of ‘n’ beats” is an integration problem from calculus, etc.)

hjh

I just wanted to say thank you to all that contributed so much to this thread. It’s a lot for me to chew on and I appreciate it greatly. This community seems great. I suck at SC, but am really passionate about it, so having a community that is nice (yall really could have been snarky instead of engaging on this topic), is truly a blessing.

Have a great day everyone!

-melas

There’s a book called ‘cool math for hot music’ that also seems promising

@thresholdpeople I just got both volumes of Musimathics by Gareth Loy. I like the writing style so far. I got the second book in physical format, so I haven’t looked through it yet but it looks great.

Other than a few books, just being able to go through other people’s code is helping

Thanks again

Another great book on math and music is Dave Benson’s Music: A Mathematical Offering. The pdf is free on his website: https://homepages.abdn.ac.uk/d.j.benson/pages/html/music.pdf

1 Like

IMO that’s perfectly fine. I’m teaching SC in a sound synthesis course and it’s the first programming language for most participants. When going to use it for sound synthesis primarily you might want to do extra exercises with the SC language to train loops, conditionals etc. I think a good way to do this is to start with easy musical problems (rhythms, scales etc.) and write little functions for these.

Sure, to understand FFT the basics of complex numbers (and the relation to trigonometry) are actually necessary. On the other hand, I tend to think that for musical applications basic math skills are sufficient and the practical/artistic value of sophisticated math is sometimes overestimated (saying this as someone having a math background myself). Look at something like the greatest common divisor resp. least common multiple or the Xenakis sieves, these integer applications are easy to understand and you can immediately get a lot of interesting structures and sounds from them.

Here some examples from a recent thread on the list, nudged by Nick Collins

https://www.listarc.bham.ac.uk/lists/sc-users/msg68907.html

I’d recommend starting with easy things first and learn and dive into more complicated math over time.

So…that looks complicated to me. I think my math education is lower than you assume, haha. Thanks for the tips though, I’ll be researching…probably forever.

Yes. This is complicated. But not because the math is particularly difficult. It just takes a minute to wrap the mind around.

Here is a rhythm made from ((5,5,8)U(5,6,8)) INT ((8,2,5)U(8,3,5)U(8,4,5))

At least I think so…I didn’t comment my code:

(
a = Array.fill(40, {0});
b = Array.series(5, 5, 8).addAll(Array.series(5, 6, 8));
b.do{arg item; a.put(item, 1)};
a
)

(
c = Array.fill(40, {0});
d = Array.series(8, 2, 5).addAll(Array.series(8, 3, 5).addAll(Array.series(8, 4, 5)));
d.do{arg item; c.put(item, 1)};
c
)

(
40.do{arg i; if((c[i]==1)&&(a[i]==1),{a.put(i, 1)},{a.put(i, 0)})};
a
)

Yes, the math is simple, but the resulting structures are (phenomenologically) interesting. IMO that’s what makes a generative principle especially attractive for music applications. With sieves the degree of perceived randomness can be controlled with tweaking the prime factors, a clever and versatile concept.

I’ve implemented Sieves and Sieve patterns for different logical operators with several options and analysis tools in miSCellaneous_lib.

E.g.:


x = Sieve.union(5, 6, `40)

-> Sieve(points, List[ 0, 5, 6, 10, 12, 15, 18, 20, 24, 25, 30, 35, 36, 40 ])

x.toIntervals

-> Sieve(intervals, 0, List[ 5, 1, 4, 2, 3, 3, 2, 4, 1, 5, 5, 1, 4 ])


// or

r = PSVunion_i([5, 6], limit: 40)

r.asStream.all

-> [ 5, 1, 4, 2, 3, 3, 2, 4, 1, 5, 5, 1, 4 ]

1 Like

Awesome. That miSCellaneous_lib is a treasure trove!

Sam

Understanding mathematics is an enhancement, but expression is transcendent