-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathact4mini.php
200 lines (161 loc) · 4.07 KB
/
act4mini.php
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
/*
flags:
-w writes to file
Vorspiel - Scene 1 (00:00)
Scene 2 (26:45)
Scene 3 (1:11:31)
Scene 4 (1:40:42)
Applause (2:30:10)
*/
// --------------------- cryptographically secure seeding ----------------------
$iseed1 = random_int(1,2147483562);
$iseed2 = random_int(1,2147483398);
stats_rand_setall($iseed1,$iseed2);
// --------------------- orc ---------------------------------------------------
$orchestra = '
sr = 44100
kr = 4410
ksmps = 10
nchnls = 2
galeft init 0
garight init 0
instr 1
idur = p3
iamp = ampdbfs(p4)
ifreq = p5 ; 1x - negative backwards
iat = p6
irel = p7
ipanStart = p8
ipanEnd = p9
iskiptime = p10
irevSend = p11
kpan linseg ipanStart, idur, ipanEnd
aAmpEnv expsega 0.01, iat, iamp, irel, 0.01
aIn diskin2 "../WAV/rtm.wav", ifreq, iskiptime, 1
aLeft = aIn * kpan * aAmpEnv
aRight = aIn * (1 - kpan) * aAmpEnv
outs aLeft, aRight
galeft = galeft + aIn * kpan * irevSend
garight = garight + aIn * (1 - kpan) * irevSend
endin
instr 99 ; global reverb ----------------------------
irvbtime = p4
aleft, aleft reverbsc galeft, galeft, irvbtime, 18000, sr, 0.8, 1
aright, aright reverbsc garight, garight,irvbtime, 18000, sr, 0.8, 1
outs aright, aleft
galeft = 0
garight = 0
endin
';
// --------------------- init vars ---------------------------------------------
$startT = 60*100+42;
$endT = 60*150+10;
$TT = 60*6+25-20;
$Events = intval($TT*13.33); // 800 events per min = 13.3 per second
// --------------------------- sco head ----------------------------------------
$scoreHeader = '; Reverb
i99 0 '.($TT+20).' 0.9 '.PHP_EOL.PHP_EOL;
// --------------------------- main p1-px fields -------------------------------
function p2() {
Global $TT;
return stats_rand_gen_iuniform(1,$TT);
}
$TDur = 1;
function idur() {
Global $TDur;
$TDur = round(14.4-stats_rand_gen_beta(5,1)*14,1);
//$TDur = round(stats_rand_gen_funiform(0.4,3),1);
return $TDur;
}
function iamp() {
return stats_rand_gen_iuniform(-127,-87);
}
function ifreq() {
// 1/4 tone
// if(rand(0,1)) { return 1; } else { return 1.02; }
return round(stats_rand_gen_funiform(.8,1.1),3);
//return 1;
}
function iat() {
Global $TDur;
return round($TDur*0.25,2);
}
function irel() {
Global $TDur;
return round($TDur*0.75,2);
}
function ipanStart() {
return round(stats_rand_gen_funiform(0,1),2);
}
function ipanEnd() {
return round(stats_rand_gen_funiform(0,1),2);
}
function iskiptime() {
Global $startT;
Global $endT;
return round(stats_rand_gen_funiform($startT,$endT),2);
}
function irevSend() {
return round(stats_rand_gen_funiform(0,0.3),2);
//return 0;
}
// ---------------------------------- generate data ----------------------------
$scoreData = '';
function gen_scoreData($Events){
if($Events == 0) exit;
Global $scoreData;
$P=5;
for($i=0;$i<$Events;$i++) {
$scoreData = $scoreData.
"i1 ".
str_pad(p2(),$P) ." ".
str_pad(idur(),$P) ." ".
str_pad(iamp(),$P+1) ." ".
str_pad(ifreq(),$P) ." ".
str_pad(iat(),$P) ." ".
str_pad(irel(),$P) ." ".
str_pad(ipanStart(),$P) ." ".
str_pad(ipanEnd(),$P) ." ".
str_pad(iskiptime(),$P+2) ." ".
str_pad(irevSend(),$P) ." ".
PHP_EOL
;
}
}
// ----------------------------------------------------------------------------
gen_scoreData($Events);
// ----------------------------------------------------------------------------
$csd = "<CsoundSynthesizer>
<CsOptions>
</CsOptions>
<CsInstruments>"
.$orchestra.
"</CsInstruments>
<CsScore>"
.$scoreHeader
.$scoreData."
e
</CsScore>
</CsoundSynthesizer>";
// ----------------------------------- exit options ---------------------------
function write_to_file() {
global $csd;
$Now = New DateTime();
$filename = $Now->Format('YmdHis').'.csd';
$myfile = fopen("CSD/".$filename, "w") or die("Unable to open file!");
fwrite($myfile, $csd);
fclose($myfile);
}
function display() {
global $csd;
echo $csd;
}
if (isset($argv[1])) {
foreach($argv as $arg) {
if($arg == "-w") {
write_to_file(); }
}
} else {
display(); }
?>