«oneshot renderer» by LFSaw

on 29 Jan'19 18:38 in nrtmultichannelmonooneshotrenderersamplepackgenerator

render each synthdef in a given dictionary as one-shot sound file.

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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
(
q = ();
q.numChans = 1;
q.sRate = 48000;
q.dur = 2;
q.dirname = thisProcess.nowExecutingPath.dirname;
q.subDirname = q.dirname +/+ "%-%sec-%chan".format(q.sRate, q.dur, q.numChans);
// load a dictionary of SynthDefs
// should be of the form
/*
{|numChans = 2|
(
// name: SynthDef(\name, {})
bdSimple: SynthDef(\bdSimple, {|out = 0, lFreq = 67, sustain = 0.5, attack = 0.01, amp=0.1, startFreq = 1000|

			var osc = SinOsc.ar(XLine.kr(startFreq, lFreq, attack), 0.5pi);
			var env = EnvGen.kr(Env.perc(attack, sustain), doneAction: 2) * amp;

			Out.ar(out, osc * env!numChans);
		}), // ...

)
}
*/
q.synthDefs = (q.dirname +/+ ".." +/+ "oneShots/_oneShotEnv.scd").load.value(q.numChans);

q.renderSound = {|q, nameOrSynthDef, dur = 1, amp = 1, out = 0, params, sRate = 48000, format = "int32", dirname, filename|
	var score;
	var args;
	var name, synthdef;


	nameOrSynthDef.isKindOf(SynthDef).if({
		name = nameOrSynthDef.name;
		synthdef = nameOrSynthDef;
	}, {
		name = nameOrSynthDef.asSymbol;
		synthdef = q.synthDefs[name];
	});


	params = params ? ();
	dirname = dirname ?? q.dirname;
	filename = filename ?? {"%_%_%-%-%%.aiff".format(name, sRate, format, dur, params.asKeyValuePairs.inject("", {|current, next| current ++ "-" ++ next}), Date.getDate.asSortableString)};



	args = [
		\instrument, name,
		\amp, 1,
		\dur, Pseq([dur], 1),
		\sustain, Pseq([dur], 1),
		\legato, 1
	] ++ params.asKeyValuePairs;
	args.postln;
	score = Pbind(*args).asScore(dur);
	score.score.printAll;
	// add synthdef after g_new
	score.score = score.score.insert(1,
		[ 0, [\d_recv, synthdef.asBytes ] ]
	);

	score.recordNRT(
		// oscFilePath: nil,
		outputFilePath: dirname +/+ filename,
		// inputFilePath: nil,
		sampleRate: sRate,
		headerFormat: "AIFF",
		sampleFormat: format,
		options: ServerOptions().numOutputBusChannels_(q.numChans),
		duration: dur.postln,
	);
}
)

/* test rendering
q[\renderSound].(q, \bdCrack, sRate: 44100, dur: 5)
*/

///////////////////// render
(
File.exists(q.subDirname).not.if{
	q.subDirname.mkdir;
};
q.synthDefs.keys.do{|name|
	">>>>>>>>>>>>>> % <<<<<<<<<<<<<<".postf(name);
	q[\renderSound].(q, name, dirname: q.subDirname, format: "float32",sRate: q.sRate, dur: q.dur)
}
)

///////////////////// normalise
( // normalise
var normDirname = q.subDirname +/+ "../%-normalised".format(q.subDirname.basename);

File.exists(normDirname).not.if{
	normDirname.mkdir;
};

(q.subDirname +/+ "*.aiff").pathMatch.do{|file|
	SoundFile.normalize(file, normDirname +/+ file.basename, newSampleFormat: "int32")
}
)


"asd/sad/d.ext".basename.splitext.first
descendants
«Re: oneshot renderer» by Nandor Devai (private)
full graph
raw 2683 chars (focus & ctrl+a+c to copy)
reception
comments