Skip to content

Commit cd5205f

Browse files
author
Brian Sorahan
committed
default Env ReleaseNode and LoopNode
1 parent 7d6f0f7 commit cd5205f

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

env.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,18 @@ func (e *Env) defaults() {
6161
}
6262
e.Curvature = C(0)
6363
}
64+
if e.ReleaseNode == nil {
65+
e.ReleaseNode = C(-99)
66+
}
67+
if e.LoopNode == nil {
68+
e.LoopNode = C(-99)
69+
}
6470
}
6571

6672
// Inputs returns the array of inputs that defines the Env.
6773
func (e Env) Inputs() []Input {
74+
(&e).defaults()
75+
6876
// This is how the inputs array is constructed:
6977
// 0, 3, -99, -99, -- starting level, num segments, releaseNode, loopNode
7078
// 1, 0.1, 5, 4, -- first segment: level, time, curve type, curvature
@@ -77,7 +85,6 @@ func (e Env) Inputs() []Input {
7785
if lc != lt {
7886
panic(fmt.Errorf("%d curve types != %d times", lc, lt))
7987
}
80-
(&e).defaults()
8188

8289
var (
8390
numSegments = len(e.Levels) - 1

fixtures/THX.scsyndef

11.8 KB
Binary file not shown.

fixtures/synthdefs.sc

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -326,22 +326,22 @@ SynthDef(\MixTest, {
326326
]));
327327
}).writeDefFile(File.getcwd);
328328

329-
SynthDef(\THX1, {
330-
var numVoices = 10;
331-
332-
// Generate initial random fundamentals.
333-
var fundamentals = {rrand(200.0, 400.0)}!numVoices;
334-
335-
var sig = Mix({ |numTone|
336-
var freq = fundamentals[numTone];
337-
Pan2.ar(
338-
Saw.ar(freq),
339-
rrand(-0.5, 0.5), // stereo placement of voices
340-
numVoices.reciprocal // scale the amplitude of each voice
341-
);
342-
}!numVoices);
343-
344-
Out.ar(0, sig);
329+
SynthDef(\THX, {
330+
var numVoices = 30;
331+
var fundamentals = ({rrand(200.0, 400.0)}!numVoices).sort;
332+
var finalPitches = (numVoices.collect({|nv| (nv/(numVoices/6)).round * 12; }) + 14.5).midicps;
333+
var sweepEnv = EnvGen.kr(Env([0, 1], [13]));
334+
var sig = Mix({ |numTone|
335+
var initRandomFreq = fundamentals[numTone] + LFNoise2.kr(0.5, 3 * (numTone + 1));
336+
var destinationFreq = finalPitches[numTone];
337+
var freq = ((1 - sweepEnv) * initRandomFreq) + (sweepEnv * destinationFreq);
338+
Pan2.ar(
339+
BLowPass.ar(Saw.ar(freq), freq * 5, 0.5),
340+
rrand(-0.5, 0.5),
341+
numVoices.reciprocal //scale the amplitude of each voice
342+
)
343+
}!numVoices);
344+
Out.ar(0, sig);
345345
}).writeDefFile(File.getcwd);
346346

347347
0.exit;

0 commit comments

Comments
 (0)