-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheyeballsun_061024.sc
147 lines (114 loc) · 4.6 KB
/
eyeballsun_061024.sc
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Let's try it this way
//
Server.default = s = Server.internal.boot;
(
~analysis_bus = Bus.control( s, 4 );
b = Buffer.read(s, "/Users/mike/Documents/recordings/samples/harold_bigorlittle.aiff");
// allocate a disk i/o buffer
c = Buffer.alloc(s, 65536, 4);
~playgroup = Group.head( s );
~recordgroup = Group.tail( s );
)
(
SynthDef( 'MachineSample', {
arg outbus = 0, analysis_bus = 0, bufnum = 0, unityFreq = 440,
attackdb = 6, minVelocity = 0.1;
var freq, hasFreq, attack, amplitude, velocity, interval, out;
#freq, hasFreq, amplitude, attack = In.kr( analysis_bus, 4 );
attack = attack - attackdb;
velocity = RunningMax.kr( amplitude, attack * hasFreq ) min: 1;
velocity = LinLin.kr( velocity, 0, 1, minVelocity, 1 );
interval = ( freq / unityFreq ).ratiomidi.wrap2( 24 );
out = PlayBuf.ar(
1,
bufnum,
rate: interval.midiratio * BufRateScale.kr( bufnum ),
trigger: attack,
loop:0
);
Out.ar( outbus, out * velocity );
}).send( s );
// MachineRes
//
// minFreq, minPitch, and range can't be modulated
// because some parameters for CombL and Wrap can't be modulated.
SynthDef( 'MachineRes', {
arg outbus = 1, analysis_bus = 0, minPitch = 220, minFreq = 55, range = 24, attackdb = 12,
leftLevel = 0.5, rightLevel = 0.5, sampleLevel = 0.5,
decayTime = 0.38, maxVelocity = 8;
var in, pitch, hasFreq, amplitude, attack, velocity,
minMidi, transpose, halfRange, centerMidi,
freq, period, maxperiod, out;
in = Mix( ( AudioIn.ar([1,2]) ++ In.ar(0) ) * [ leftLevel, rightLevel, sampleLevel ] );
#pitch, hasFreq, amplitude, attack = In.kr( analysis_bus, 4 );
attack = attack - attackdb;
//velocity = Latch.kr( amplitude, attack ).lag(0.05) min: 1;
// try this:
velocity = amplitude / ( Amplitude.kr( in ) + maxVelocity.reciprocal );
minMidi = minFreq.cpsmidi;
transpose = minMidi - minPitch.cpsmidi;
freq = ( pitch.cpsmidi + transpose ).wrap( minMidi, minMidi + range ).midicps;
period = freq.reciprocal;
maxperiod = minMidi.midicps.reciprocal;
out = CombL.ar( in * velocity, maxperiod, period, decayTime );
Out.ar( outbus, ( out ).softclip );
}).send(s);
SynthDef( 'Analysis', {
arg koutbus = 0, samplebus = 0, resbus = 1,
leftLevel = 0.5, rightLevel = 0.5, sampleLevel = 0.5, resLevel = 0.5;
var mix, freq, hasFreq, amplitude, attack;
mix = Mix.ar(
AudioIn.ar( [1,2] ) ++ InFeedback.ar( [samplebus] ) *
[ leftLevel, rightLevel, sampleLevel ]
);
#freq, hasFreq = Pitch.kr( mix, downSample: 2, median: 7 );
amplitude = Amplitude.kr( mix, add: 0.0001 ); // avoid division by zero
attack = Slope.kr( amplitude.ampdb, ControlRate.ir.reciprocal );
Out.kr( koutbus, [ freq, hasFreq, amplitude, attack ] );
}).send( s );
// this will record to the disk
SynthDef("4chan-Diskout", {arg bufnum;
DiskOut.ar(bufnum, AudioIn.ar([1,2]) ++ In.ar(0,2));
}).send(s);
)
create an output file for the buffer, leave it open
// can you actually have a 4 channel aiff? Yes!!
// can we create unique filenames somehow?
c.write("recordings/machine.aiff", "aiff", "int16", 0, 0, true);
// start a recording:
(
~analysis = Synth( 'Analysis', [ \koutbus, ~analysis_bus.index, \sampleLevel, 4 ], ~playgroup );
~analysis.set( \leftLevel, 0.5, \rightLevel, 0.0, \sampleLevel, 1, \resLevel, 0.0 );
~sample = Synth.after( ~analysis, 'MachineSample', [ \analysis_bus, ~analysis_bus.index, \bufnum, b.bufnum ] );
~res = Synth.after( ~sample, 'MachineRes', [ \analysis_bus, ~analysis_bus.index, \minFreq, 55,
\leftLevel, 1, \rightLevel, 0.25, \sampleLevel, 0.5, \maxVelocity, 27.dbamp ] );
// create the diskout node; making sure it comes after the source
d = Synth("4chan-Diskout", ["bufnum", c.bufnum], ~recordgroup );
)
// stop the music:
(
~analysis.set( \leftLevel, 0, \rightLevel, 0, \sampleLevel, 0, \resLevel, 0 );
// hope that works!
)
// when it all stops, end recording:
d.free;
// close the buffer and the soundfile
c.close;
// experiment with settings:
~analysis.free;
~analysis = Synth( 'Analysis', [ \koutbus, ~analysis_bus.index ], ~playgroup );
~analysis.set( \leftLevel, 0.5, \rightLevel, 0.0, \sampleLevel, 1, \resLevel, 0.0 );
~analysis.set( \leftLevel, 0, \rightLevel, 0);
~analysis.set( \sampleLevel, 0.01 );
~sample.free;
~sample = Synth.after( ~analysis, 'MachineSample', [ \analysis_bus, ~analysis_bus.index, \bufnum, b.bufnum ] );
~res.free;
~res = Synth.after( ~sample, 'MachineRes', [ \analysis_bus, ~analysis_bus.index, \minFreq, 55 ] );
~res.set( \leftLevel, 1, \rightLevel, 0.25, \sampleLevel, 0.5 );
~res.set( \attackdb, 12 );
~res.set( \decayTime, 0.38 );
~res.set( \maxVelocity, 24.dbamp );
~sample.set( \attackdb, 1 );
~sample.set( \unityFreq, 880 );
s.scope(2, rate: \audio)
s.scope(4, rate: \control)