Audio DSP - Csound/Pd/MAX/Octave/C++ etc

Here’s a thread for talking about using computers to make sounds and audio. But in a DIY kind of way, that is designing and coding your own instruments or effects.

I’ll go first.

I’ve had my eye on csound for about 20 years now, but have only dabbled. I took the plunge and set up CsoundQT and have started working through some examples:

I set up cabbage too, so I can create my own VSTs. At least the test run using one of the examples I did seemed to work.

What kind of nerdy audio synthesis stuff do you like to do with computers?

Cheers

6 Likes

Well, I’ll continue working on this in the near future:

3 Likes

A couple of folks (@BenRufenacht, @Krakenpine, @sebastian) mentioned Daisy recently in another thread - maybe they’d like to come and geek out over here.

Here are the things I cobbled together on the Daisy Pod:

jazamatronic/ParametricChorus: A Parametric Chorus based on that presented by Hal Chamberlin in his Musical Applications of Microprocessors (Second Edition). (github.com)

jazamatronic/ModalResonators: BiQuad Resonators (github.com)

I’ve got a Bela Pepper Kit that’s waiting to be put together - and I’m working on getting some Csound waveshaping code ready to go for it to have a VC waveshaping oscillator.

6 Likes

So far, I have just used the Daisy Seed to create the sounds for my Synth Garden project.

(Ben Rufenacht on Instagram: "Synth garden installed at Ward-Meade park for Garden Glow")

Each flower is a capacitive touch based midi controller and the Daisy is a simple polysynth with a sine wave sent through a delay.

6 Likes

Hey, that’s really cool.

3 Likes

I’ve been going through some csound examples and was inspired to extend one to make this morphing waveshaper proof of concept thing:

It’s a nice prototype - I think I should be able to port it fairly easier to Bela which supports Csound natively. Maybe a bit more work to get it onto the Daisy, but having this implementation as a guide sure will be helpful.

Next steps would be to add multiple detuned oscillators, and maybe external envelope control.

Cheers

4 Likes

Added the two extra oscillators with a detune control and some kind of random drift setting.
Put a sub osc on there too.
Then I discovered the Lissajous graph and was instantly mesmerized:

I could stare at that all day…

6 Likes

That is unbelievably cool!

4 Likes

Well, then. While biking to work I pondered about summing signals in polyphonic synth. If one voice has maximum values of ±1 (which in this case is the maximum range of output), and it’s average power is 0.7, with to (uncorrelated) signals its ±2 and 1.4, with three ±3 and 1.7, etc. with ten ±10 and 3.2. We never want digital distortion, so signal must be attenuated to be again in the range of ±1, but then when playing single note it’s peak-to-peak value is ± 0.1.

How is usually handled in polyphonic synths? Add a compressor/limiter/softclipper to make single notes louder and limit the full polyphonic playing without distorting the signal too much?

Also you could have logic to lower the volume of the notes when multiple are played, but you can never know how many will be played. It would sound a bit stupid if you play long notes one by one and the already playing ones would get quieter when new ones are added.

1 Like

I’m not sure what the “right” way to do it is, but here’s how I’ve handled it in a couple of different projects.

On my modal resonator synth thing, I just divide each single notes value by the number of notes. I could maybe get away with the square root of the number of notes or something like that, but this thing can get quite resonant, so I prefer a little more margin.

to_out += notes[j]->Process(to_in) / NUM_NOTES;

After that, I also have the option of putting it through some soft clipping code with different models. Here’s an example:

to_out = tanhf(to_out) * INV_TANH_1;

So that avoids any nasty digital clipping, but no effort is made to ensure the signal is bandlimited, so you can get aliasing happening. But to me, digital clipping or aliasing are somewhat part of the sound of these kinds of things, and if you don’t push it too hard everything seems to sound okay.

One of the benefits of working with floating point is that you have stupid amounts of headroom, so you can sum whatever you like in the signal chain and as long as you ensure that it’s in the right range for the final output stage you’re not going to get any distortion.

In the Csound waveshaper above, when I added two extra oscillators I did much the same thing, divide each oscillator’s output by three before summing the signal. One of the things Csound will do is tell you how many samples are out of range, so I just plugged everything in, wiggled all the knobs and ensured that nothing was reported out of range and called it a day.

Cheers

2 Likes

Maybe I’ll just start doing stuff with more modern things, but this Arduino Nano is also a “fun” challenge.
I try to unroll some loops to save processing power, and suddenly:

Sketch uses 45596 bytes (148%) of program storage space. Maximum is 30720 bytes.

And when I manage to find a solution that just takes lots of memory, the midi library crashes from lack of free ram…

4 Likes

Optimisation is a specialist skill now, though when I learned programming it was still considered to be the most important thing. Unrolling loops is great if your project is compute-bound, but do check to see if input or output is part of the problem. Using interrupt routines enables even the simplest processors to proceed with computation while waiting for slow data input or output to complete. A few bytes of RAM deployed as a buffer can make a big difference to execution, particularly speed of response.

And of course, try rolling the outermost loops back. If you have an outer loop that only executes, say, 10 times per second, the tiny amount of loop overhead time you’d save by unrolling it isn’t worth the excessive use of program memory.

Yeah, problem is in a data I need to recalculate basically in real time with the sample rate of the synth output. I’m trying to make additive oscillator that sums eight sine waves and is also polyphonic. The Hagiwo version of that has just barely enough processing power to multiply (and normalize back) all harmonics for one voice, and it loses lots of precision in different stages. I’m recalculating the whole wavetable in control frequency so the output samplerate can process four voices through their adsr-envelopes. Still, that’s not enough, so I do the wavetable-calculation in four parts in four different control frequency ticks. And I don’t have enough ram to save the whole table for original sinewave, so I save just first quarter of it and mathify rest of it from that.
Also, oscillators in the Mozzi library I’m using actually don’t support changing wavetables, they are always constants, so I actully run a 256 sample long saw wave in an oscillator and use output of that to read sinewave-sample from my own array in ram…
If it’s stupid and it works, it’s not stupid. Except when it is.
For my professional programming life, I’ve mostly been writing JavaScript for cloud computing where you can just throw money and buy more processing power. This is bit different.

3 Likes

@Krakenpine it’s definitely not stupid. It sounds rather ingenious. If you don’t already have an Arduino Mega2560 I would encourage you to procure one. At least this would give you space in which to explore the possibilities in search of a solution that can be scaled down to the Nano.

Alternatively, there seem to be a number of ARM chips that compete well against AVR and are being adopted by the Arduino software platform. I can’t advise on that, but I feel I need to point out that migration to ARM may be beneficial.

1 Like

If you’re willing to share your code we could take a look and maybe spot some opportunities to make it fit?

3 Likes

Arduino Nano Additive Oscillator Polyphonic test by Krakenpine (soundcloud.com)

Well, I got something harmonics-based and polyphonic done. Sometimes very buzzy, distorted, glitchy (I mean, there’s some proper bugs there) and aliasing, but technically close to what I was aiming. So that’s a midi keyboard to Arduino Nano with filter-circuit in its PWM-output and that’s recorded straight from that.
I used whole fifteen minutes to midi note-assignment and -stealing logic, that’s quite crude sometimes.

5 Likes

Sounds pretty good, I would say!

1 Like

I like where it goes nuts around 1:20

Edit: Oh - hang on, that was the Soundcloud player going to your Additive Harmoniqs track…

2 Likes

The soundcloud player is irritating. But yeah, basically monophonic version has much better sound quality. Maybe I’ll just remake this with Teensy or Daisy and have one potentiometer as a pseudo-bitcrusher, as I like the crunchiness of this 8-bittery, but I would like to have it without that aliasing and other artifacts that come from way too short wavetables.

1 Like

So I got this Bela Pepper thing built.

I even managed to get a Csound patch running on it:

Imgur

A quick demo of the wavefolder:

Patching it in and playing it:

I forgot to get the working code off the device before I turned everything off, but once I have it I’ll share it somehow.

Cheers

3 Likes