«Sick LinCong» by clicksonnil

on 08 Sep'11 11:57 in noiselinearnonlinearrandom number generator

Use of linear congruence and multiply with carry random number generators for non-realtime signal generation. Very noisy outputs, watch your ears! (you'll need to change the file write path to one valid for your machine)

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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
//Linear congruence random number generator
(
var file,data; 
var sr=44100; 
var last = 0.13154617451; 
var options = Array.rand(80,0.01,0.99); 
var mult= 1.02; 
var changechance = 0.0005; 

file = SoundFile.new.headerFormat_("WAV").sampleFormat_("int16").numChannels_(1).sampleRate_(sr);

file.openWrite("/Users/nickcollins/Desktop/writetest.wav");

data = Signal.fill(sr*10, {|i|  
	
	var next = last; 
	
	if(changechance.coin,{
		
		mult= [1.02, rrand(1.05,1.2),exprand(1.001,1.1), rrand(1.1,3.9)].choose;  

	}); 
	
	last = (last*mult)%1.0; 
	if(abs(last)<0.0000001) {last = options.choose}; 
	
	2*next-1.0
});

file.writeData(data);
file.close;
)






//multiply with carry sequence
//http://en.wikipedia.org/wiki/Multiply-with-carry
(
var file,data; 
var sr=44100; 
var maxr = 200; 
var r = maxr; 
var roptions = Array.rand(8,2,199); 
var xr = Array.rand(maxr,0.01,0.99); 
//var options = Array.rand(500,0.01,0.99); 
var arraypos = 0; 
var a = 1.02;  
var c = rrand(0.0,1.0); 
var changechance = 0.001; 
var changechance2 = 0.0001; 
var changechance3 = 0.00002; 

//defaults to 44100 sample rate
file = SoundFile.new.headerFormat_("WAV").sampleFormat_("int16").numChannels_(1).sampleRate_(sr);

file.openWrite("/Users/nickcollins/Desktop/writetest.wav");

data = Signal.fill(sr*30, {|i|  
	
	var prev = xr[arraypos]; 
	var next = a*prev+c; 
	
	c = floor(next); 
	
	next = next%1.0; 

	//if(abs(next)<0.0000001) {next = options.choose}; 
	
	xr[arraypos] = next; 
	
	arraypos = (arraypos + 1)%r; 
	
	if(changechance.coin,{
		
		a= [1.0001, rrand(1.0001,1.0005),exprand(1.0001,1.005), rrand(1.01,1.05), rrand(1.1,1.99)].wchoose([0.2,0.2,0.2,0.16,0.04]);  
		
	}); 
	
	if(changechance.coin) {
		
		r = [roptions.choose, exprand(2,199).asInteger].wchoose([0.95,0.05]); 
		
	}; 
	
	if(changechance2.coin) {
		
		roptions = Array.rand([exprand(1,100).asInteger,rrand(2,10)].choose,2,199); 
		
	}; 
	
	if(changechance3.coin) {
		
		xr = Array.rand(maxr,0.01,0.99); 
		
	}; 
	
	if(changechance3.coin) {
		
		c = rrand(0.0,1.0); 
		
	}; 
	
	
	if(changechance3.coin,{
		
		changechance = [0.001,exprand(0.0001,0.001)].choose; 
		changechance2 = [0.0001,exprand(0.0001,0.001)].choose;  
		changechance3 = [0.0002,exprand(0.0001,0.001)].choose;    
		
	}); 
	
	
	
	2*next-1.0
});

file.writeData(data);
file.close;
)






//multiply with carry sequence, with interpolation to slow down, and nonlinear powers
(
var file,data; 
var sr=44100; 
var maxr = 200; 
var r = maxr; 
var roptions = Array.rand(8,2,199); 
var powers = Array.fill(maxr,{[1.0,1.0-exprand(0.1,1.0),rrand(0.1,3.0)].choose}); 
var xr = Array.rand(maxr,0.01,0.99); 
//var options = Array.rand(500,0.01,0.99); 
var arraypos = 0; 
var a = 1.02;  
var c = rrand(0.0,1.0); 
var changechance = 0.001; 
var changechance2 = 0.0001; 
var changechance3 = 0.00002; 
var changechance4 = 0.0005; 
var interpsteps = 5; 
var interpmul = 1.0/interpsteps; 
var interp = 0; 
var interpa = 0.0, interpb= 0.0; 
var t; 

//defaults to 44100 sample rate
file = SoundFile.new.headerFormat_("WAV").sampleFormat_("int16").numChannels_(1).sampleRate_(sr);

file.openWrite("/Users/nickcollins/Desktop/writetest.wav");

data = Signal.fill(sr*30, {|i|  
	

	var prev = xr[arraypos]; 
	var next = a*(prev**(powers[arraypos]))+c; 

	if(interp==0) {
	
	c = floor(next); 
	
	next = next%1.0; 

	//if(abs(next)<0.0000001) {next = options.choose}; 
	
	xr[arraypos] = next; 
	
	arraypos = (arraypos + 1)%r; 
	
	if(changechance.coin,{
		
		a= [1.0001, rrand(1.0001,1.0005),exprand(1.0001,1.005), rrand(1.01,1.05), rrand(1.1,1.99)].wchoose([0.2,0.2,0.2,0.12,0.08]);  
		
	}); 
	
	if(changechance.coin) {
		
		r = [roptions.choose, exprand(2,199).asInteger].wchoose([0.95,0.05]); 
		
	}; 
	
	if(changechance2.coin) {
		
		roptions = Array.rand([exprand(1,100).asInteger,rrand(1,10)].choose,2,199); 
		
	}; 
	
	if(changechance3.coin) {
		
		xr = Array.rand(maxr,0.01,0.99); 
		
	}; 
	
	if(changechance3.coin) {
		
		c = rrand(0.0,1.0); 
		
	}; 
	
	
	if(changechance3.coin,{
		
		changechance = [0.001,exprand(0.0001,0.001)].choose; 
		changechance2 = [0.00005,exprand(0.0001,0.001)].choose;  
		changechance3 = [0.00002,exprand(0.0001,0.001)].choose;    
		
	}); 
	
	
	if(changechance4.coin) {

		interpsteps = rrand(1,30); 
		interpmul = 1.0/interpsteps; 
		
		changechance4 = interpsteps*0.001; 
		
	}; 
	
	
	interpa = interpb; 
	interpb = 2*next-1.0; 
	};
	
	
	
	
	t = interp * interpmul; 
	
	next = ((1.0-t)*interpa) + (t*interpb); 
	
	interp = (interp+1)%interpsteps; 
	
	next;
});

file.writeData(data);
file.close;
)
raw 4786 chars (focus & ctrl+a+c to copy)
reception
comments
vividsnow user 08 Sep'11 13:12

alien radio )