«Additive Synthesis Demo with QuNEO - Patch 1» by Bruno Ruviaro

on 22 Sep'13 23:44 in additive synthesisquneo

QuNeo controller additive synthesis demo.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// ************************************
// Additive Synthesis Demo with QuNEO
// Patch 1 - Harmonic Series
// Bruno Ruviaro, 2013-07-22
// ************************************

/*
Use QuNEO SCLOrk Preset #1 for piano-like play
Use QuNEO SCLOrk Preset #2 for toggle-like play

Pads play 16 first partials of the harmonic series:

13 14 15 16
09 10 11 12
05 06 07 08
01 02 03 04

Long Slider controls fundamental frequency

Vertical Sliders control ADSR envelope

*/

s.waitForBoot({

	// Some variables

	var notes = Array.newClear(128);

	~att = 0.01;
	~dec = 0.3;
	~sus = 0.5;
	~rel = 1.0;
	~fundamental = 110;
	~quNeoChannel = 11;

	MIDIIn.connectAll;

	MIDIdef.freeAll;

	MIDIdef.noteOn(
		key: \noteOn,
		func: {arg vel, note;
			var partial = note - 35; // start from 1
			notes[note] = Synth("addsynth", [
				\freq, ~fundamental * partial,
				\amp, vel.linlin(0, 127, 0, 0.5),
				\att, ~att,
				\dec, ~dec,
				\sus, ~sus,
				\rel, ~rel;
		])},
		noteNum: (30..127), // Ignore notes lower than 24 (= 46Hz)
		chan: ~quNeoChannel);

	MIDIdef.noteOff(
		key: \noteOff,
		func: {arg vel, note;
			notes[note].release},
		chan: ~quNeoChannel);

	MIDIdef.cc(
		key: \adsr,
		func: {arg val, ccnum;
			case
			{ccnum==6} {~att = val.linlin(0, 127, 0.01, 4)}
			{ccnum==7} {~dec = val.linlin(0, 127, 0.05, 2)}
			{ccnum==8} {~sus = val.linlin(0, 127, 0.10, 1)}
			{ccnum==9} {~rel = val.linlin(0, 127, 0.05, 4)};
			[~att, ~dec, ~sus, ~rel].round(0.01).postln},
		ccNum: (6..9)); // Vertical Sliders

	MIDIdef.cc(
		key: \fundamental,
		func: {arg val, ccnum;
			~fundamental = val.linexp(0, 127, 55, 220);
			("Fundamental is "++~fundamental.round(0.1)++" Hz").postln},
		ccNum: 10);  // Long Slider

	// A synth

	SynthDef("addsynth", {
		arg freq = 440, amp = 0.1, gate = 1, att = 0.01, dec = 0.3, sus = 0.5, rel = 1;
		var snd, env;
		env = EnvGen.ar(Env.adsr(att, dec, sus, rel), gate, doneAction: 2);
		snd = SinOsc.ar(freq, 0, amp) * env;
		Out.ar(0, snd!2);
	}).add;

});
raw 2071 chars (focus & ctrl+a+c to copy)
reception
comments