Unit testing synths?

Hi, I’m starting to learn Supercollider. I managed to write some classes and test them using UnitTest. However, is it somehow possible to unit test Synths? By inspecting generated UGens, maybe? Or do yoy just test them manually? Thanks.

An opinion, take with a grain of salt:

In unit testing, given specific inputs to an operation, we expect to be able to tell the difference between valid and invalid results. That’s easy if the operation is deterministic: there’s only one valid result for 1+2 over real numbers. Even some nondeterministic operations have clear boundaries: 5.rand should never be < 0 or >= 5.

So the first question you need to decide, to have a synth unit test that is meaningful to you, is: What are you testing for?

“Inspecting generated UGens” would test the behavior of the SynthDef builder but wouldn’t catch signal processing bugs, so this may not be enough.

If all UGens in a synth are deterministic, you could record a bit of output signal and check, sample by sample, whether the test run of the synth produced the same output. If there are noise generators or other randomized values, you could set the RandSeed and probably get the same values out. The test suite already includes tests for a number of UGens, following this model.

The interesting thing about sampled signals is that the numbers can look quite different with no appreciable difference in timbre. There’s a beautiful demonstration in the latter half of xiph’s Digital Show & Tell of the way digital sampling represents sub-sample phase shift in a square wave: the phase shift makes the numbers look like they’re not a perfect square wave, but they do accurately reflect the shape of a bandlimited square.

… which is to say that it’s not hard to detect a numerical difference between two sampled signals, but more difficult to tell whether that numerical difference is audible. So again, it depends what you’re testing for.


Well, I was thinking of recording synth output, FFTing it or some parts of it, and doing fuzzy comparisons in the frequency domain. But all this seems like a lot of work (would be worth it if there was some testing framework for it).

For my use case, just inspecting UGens (eg. checking that multichannel expansion worked as expected, controls are set properly etc.) would be pretty much sufficient. But I don’t know how to do that - I can inspect nodes via OSC, but not UGens. dumpUgens just prints them to the console.

So, there’s currently no conventional way to do this kind of testing?

d = SynthDef(\name, ... your stuff here...);


// or if you didn't save in a variable

Probably should do some spelunking to verify the inputs and outputs of each UGen, not only the order.


Ah, I missed that. Thanks a lot.