forked from rconstanzo/the-party-van
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chopper~.maxpat
1371 lines (1285 loc) · 40 KB
/
chopper~.maxpat
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
"patcher" : {
"fileversion" : 1,
"appversion" : {
"major" : 7,
"minor" : 0,
"revision" : 0,
"architecture" : "x86",
"modernui" : 1
}
,
"rect" : [ 292.0, 82.0, 753.0, 383.0 ],
"bglocked" : 0,
"openinpresentation" : 0,
"default_fontsize" : 12.0,
"default_fontface" : 0,
"default_fontname" : "Arial",
"gridonopen" : 1,
"gridsize" : [ 15.0, 15.0 ],
"gridsnaponopen" : 1,
"objectsnaponopen" : 1,
"statusbarvisible" : 2,
"toolbarvisible" : 1,
"lefttoolbarpinned" : 0,
"toptoolbarpinned" : 0,
"righttoolbarpinned" : 0,
"bottomtoolbarpinned" : 0,
"toolbars_unpinned_last_save" : 0,
"tallnewobj" : 0,
"boxanimatetime" : 200,
"enablehscroll" : 1,
"enablevscroll" : 1,
"devicewidth" : 0.0,
"description" : "",
"digest" : "",
"tags" : "",
"style" : "",
"subpatcher_template" : "",
"boxes" : [ {
"box" : {
"bgcolor" : [ 0.0, 0.0, 0.0, 1.0 ],
"color" : [ 0.0, 0.0, 0.0, 1.0 ],
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-2065",
"maxclass" : "newobj",
"numinlets" : 7,
"numoutlets" : 7,
"outlettype" : [ "", "", "", "", "", "", "" ],
"patching_rect" : [ 181.5, 70.089844, 540.0, 22.0 ],
"style" : "",
"text" : "route rate cross min max mode blend",
"textcolor" : [ 1.0, 1.0, 1.0, 1.0 ]
}
}
, {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-19",
"maxclass" : "newobj",
"numinlets" : 0,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patcher" : {
"fileversion" : 1,
"appversion" : {
"major" : 7,
"minor" : 0,
"revision" : 0,
"architecture" : "x86",
"modernui" : 1
}
,
"rect" : [ 650.0, 302.0, 304.0, 158.0 ],
"bglocked" : 0,
"openinpresentation" : 0,
"default_fontsize" : 12.0,
"default_fontface" : 0,
"default_fontname" : "Arial",
"gridonopen" : 1,
"gridsize" : [ 15.0, 15.0 ],
"gridsnaponopen" : 1,
"objectsnaponopen" : 1,
"statusbarvisible" : 2,
"toolbarvisible" : 1,
"lefttoolbarpinned" : 0,
"toptoolbarpinned" : 0,
"righttoolbarpinned" : 0,
"bottomtoolbarpinned" : 0,
"toolbars_unpinned_last_save" : 0,
"tallnewobj" : 0,
"boxanimatetime" : 200,
"enablehscroll" : 1,
"enablevscroll" : 1,
"devicewidth" : 0.0,
"description" : "",
"digest" : "",
"tags" : "",
"style" : "",
"subpatcher_template" : "",
"boxes" : [ {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-2",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 197.0, 58.5, 64.0, 22.0 ],
"style" : "",
"text" : "repeats 1."
}
}
, {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-16",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 92.0, 58.5, 89.0, 22.0 ],
"style" : "",
"text" : "pitchedmode 0"
}
}
, {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-17",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 18.0, 58.5, 61.0, 22.0 ],
"style" : "",
"text" : "capture 1"
}
}
, {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-15",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 1,
"outlettype" : [ "bang" ],
"patching_rect" : [ 18.0, 15.0, 60.0, 22.0 ],
"style" : "",
"text" : "loadbang"
}
}
, {
"box" : {
"comment" : "",
"id" : "obj-18",
"maxclass" : "outlet",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 18.0, 104.5, 25.0, 25.0 ],
"style" : ""
}
}
],
"lines" : [ {
"patchline" : {
"destination" : [ "obj-16", 0 ],
"disabled" : 0,
"hidden" : 0,
"midpoints" : [ 27.5, 46.75, 101.5, 46.75 ],
"source" : [ "obj-15", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-17", 0 ],
"disabled" : 0,
"hidden" : 0,
"midpoints" : [ 27.5, 46.75, 27.5, 46.75 ],
"source" : [ "obj-15", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-2", 0 ],
"disabled" : 0,
"hidden" : 0,
"midpoints" : [ 27.5, 46.75, 206.5, 46.75 ],
"source" : [ "obj-15", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-18", 0 ],
"disabled" : 0,
"hidden" : 0,
"midpoints" : [ 101.5, 90.5, 27.5, 90.5 ],
"source" : [ "obj-16", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-18", 0 ],
"disabled" : 0,
"hidden" : 0,
"midpoints" : [ 27.5, 90.5, 27.5, 90.5 ],
"source" : [ "obj-17", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-18", 0 ],
"disabled" : 0,
"hidden" : 0,
"midpoints" : [ 206.5, 90.5, 27.5, 90.5 ],
"source" : [ "obj-2", 0 ]
}
}
]
}
,
"patching_rect" : [ 94.5, 105.5, 61.0, 22.0 ],
"saved_object_attributes" : {
"description" : "",
"digest" : "",
"globalpatchername" : "",
"style" : "",
"tags" : ""
}
,
"style" : "",
"text" : "p capture"
}
}
, {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-10",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 528.833313, 105.5, 79.0, 22.0 ],
"style" : "",
"text" : "playmode $1"
}
}
, {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-1",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 1,
"outlettype" : [ "signal" ],
"patcher" : {
"fileversion" : 1,
"appversion" : {
"major" : 7,
"minor" : 0,
"revision" : 0,
"architecture" : "x86",
"modernui" : 1
}
,
"rect" : [ 0.0, 44.0, 874.0, 706.0 ],
"bgcolor" : [ 0.9, 0.9, 0.9, 1.0 ],
"editing_bgcolor" : [ 0.9, 0.9, 0.9, 1.0 ],
"bglocked" : 0,
"openinpresentation" : 0,
"default_fontsize" : 12.0,
"default_fontface" : 0,
"default_fontname" : "Arial",
"gridonopen" : 1,
"gridsize" : [ 15.0, 15.0 ],
"gridsnaponopen" : 1,
"objectsnaponopen" : 1,
"statusbarvisible" : 2,
"toolbarvisible" : 1,
"lefttoolbarpinned" : 0,
"toptoolbarpinned" : 0,
"righttoolbarpinned" : 0,
"bottomtoolbarpinned" : 0,
"toolbars_unpinned_last_save" : 0,
"tallnewobj" : 0,
"boxanimatetime" : 200,
"enablehscroll" : 1,
"enablevscroll" : 1,
"devicewidth" : 0.0,
"description" : "",
"digest" : "",
"tags" : "",
"style" : "",
"subpatcher_template" : "",
"boxes" : [ {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-3",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 13.0, 688.0, 37.0, 20.0 ],
"style" : "",
"text" : "out 1"
}
}
, {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-2",
"maxclass" : "newobj",
"numinlets" : 0,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 13.0, 18.0, 198.0, 20.0 ],
"style" : "",
"text" : "in 1 @comment \"source to sample\""
}
}
, {
"box" : {
"code" : "/*\r\n\tWaveset chopper / repeater\r\n\r\n\tThis program divides the input into segments, and plays these segments back.\r\n\tIt could be seen as a time-domain, granular form of analysis/resynthesis.\r\n\t\r\n\tThe program contains a recording section, \r\n\t\twhich stores grains into a Data object (segment_data)\r\n\tand a playback section,\r\n\t\twhich selects and plays these grains one-by-one\r\n\t\r\n\tThe grains are not enveloped; \r\n\t\tinstead the input is segmented at points where the signal is rising and crosses zero\r\n\t\t\r\n\tA positive zero-crossing means that: \r\n\t\ta: previous sample is less than zero\r\n\t\tb: next sample is greater than zero\r\n\t\r\n\tFor pure sounds a segment corresponds to one or more wavecycles, \r\n\t\tbut for complex sounds it can be somewhat stochastic.\r\n\t\r\n\tRECORDING:\r\n\t\t\r\n\tSince waveforms rarely cross zero at an exact sample location, \r\n\t\tthe actual crossing is somewhere between a and b.\r\n\t\tThe program estimates this sub-sample crossing phase (and stores it in offset_data)\r\n\t\tIt also stores the sub-sample accurate segment length (in length_data)\r\n\t\t\r\n\tThe segment_data recorded includes the sample just before the first crossing,\r\n\t\tand the sample just after the last, in order to contain both actual crossings.\r\n\t\tI.e. each captured segment looks like [a1, b1, ... b2 a2 ... a3, b3]\r\n\t\r\n\tWhen a segment finishes recording, a new segment is chosen to write into (write_segment)\r\n\t\r\n\tPLAYBACK:\r\n\t\r\n\tThe playback section is continuously playing a segment (play_segment)\r\n\t\t\r\n\tPlayback includes additional calculations,\r\n \t\tto ensure the sub-sample phase offset is used and retained between segments\r\n\r\n\tWhen the segment playback is done (possibly after several repeats),\r\n\t\ta new segment is selected according to the current strategy (play_mode)\r\n\t\t\r\n\t\t\r\n\tGraham Wakefield 2012\r\n*/\r\n\r\n\r\n// the segment storage (each segment on its own channel):\r\nData segment_data(10004, 64);\r\n// the length of each segment (in samples):\r\nData length_data(64, 1);\r\n// each segment is also offset slightly (sub-sample phase delay):\r\nData offset_data(64, 1);\r\n// each segment also stores it's average energy (root-mean square):\r\nData rms_data(64, 1);\r\n\r\n// set to zero to disable new segment capture:\r\nParam capture(1, min=0, max=1);\r\n// how many zero crossings per segment:\r\nParam crossings(1, min=1);\r\n// the minimum & maximum length of a segment:\r\nParam max_length(10000, min=16, max=10000);\r\nParam min_length(100, min=16, max=10000);\r\n// how many times a segment is played back:\r\nParam repeats(1, min=1);\r\n// hold the current playback segment:\r\nParam hold(0, min=0, max=1);\r\n// choose the strategy to play back grains:\r\nParam playmode(0, min=0, max=4);\r\n// choose how to select playback rates/pitches:\r\nParam pitchedmode(0, min=0, max=4);\r\n// playback frequency for pitchedmode enabled:\r\nParam freq(220, min=0);\r\n// playback rate for pitchedmode not enabled:\r\nParam rate(1, min=0);\r\n\r\n// the segment currently being written to:\r\nHistory write_segment(1);\r\n// the number of samples since the last capture:\r\nHistory write_index(0);\r\n// the number of rising zero-crossings since the last capture:\r\nHistory crossing_count(0);\r\n\r\n// the segment currently being played:\r\nHistory play_segment(0);\r\n// the sample index of playback:\r\nHistory play_index(0);\r\n// the length of the playing segment:\r\nHistory play_len(0);\r\n// the offset of the playing segment:\r\nHistory play_offset(0);\r\n// the loudness of the playing segment:\r\nHistory play_rms(0.1);\r\n// used to create smooth overlaps\r\nHistory prev_input;\r\n// used to accumulate the segment energy total:\r\nHistory energy_sum;\r\n\r\n// the number of segments:\r\nnum_segments = channels(segment_data);\r\n\r\n\r\n\r\n// RECORDING SECTION:\r\n\r\n// DC blocking filter used to remove bias in the input:\r\nunbiased_input = dcblock(in1); \r\n// accumulate energy:\r\nenergy_sum = energy_sum + unbiased_input*unbiased_input;\r\n\r\n// update write index:\r\nwrite_index = write_index + 1;\r\n// always write input into current segment:\r\npoke(segment_data, unbiased_input, write_index, write_segment);\r\n\r\n// detect rising zero-crossing: \r\nis_crossing = change(unbiased_input > 0) > 0;\r\n// capture behavior is triggered on the rising zero-crossing:\r\nif (is_crossing) {\r\n\t\r\n\t// if the segment is too long, \r\n\tif (write_index > max_length) {\r\n\t\t// reset the counters\t\t\r\n\t\tcrossing_count = 0;\r\n\t\twrite_index = 0;\t\r\n\t\t\r\n\t} else {\r\n\t\t// count rising zero-crossings in this segment:\r\n\t\tcrossing_count = crossing_count + 1;\r\n\t\t\t\r\n\t\t// decide whether the segment is complete:\r\n\t\t// only when capture is enabled\r\n\t\t// only when enough zero-crossings have occurred\r\n\t\t// only when enough samples have elapsed\r\n\t\t// only when not too many samples have elapsed\r\n\t\tis_complete = (capture \r\n\t\t\t&& crossing_count >= crossings\r\n\t\t\t&& write_index >= min_length);\r\n\t\tif (is_complete) {\t\r\n\t\t\t\r\n\t\t\t// at what theoretical sample index did it cross?\r\n\t\t\t// estimate as linear intersection:\r\n\t\t\toffset = prev_input / (prev_input - unbiased_input);\r\n\t\t\t\r\n\t\t\t// compare the previous offset:\r\n\t\t\tprev_offset = peek(offset_data, write_segment, 0);\r\n\t\t\t\r\n\t\t\t// store segment length:\r\n\t\t\t// adjusted for the fractional component\r\n\t\t\t// minus one for the extra wrapping sample (a,b,...b,a,...,a,b)\r\n\t\t\tlen = write_index + offset - prev_offset - 1;\r\n\t\t\tpoke(length_data, len, write_segment, 0);\r\n\t\t\t\r\n\t\t\t// store segment energy:\r\n\t\t\t// (root mean square, over number of samples measured)\r\n\t\t\trms = sqrt(energy_sum / floor(len));\r\n\t\t\tpoke(rms_data, rms, write_segment, 0);\r\n\t\t\t\r\n\t\t\t// reset counters:\r\n\t\t\tcrossing_count = 0;\r\n\t\t\tenergy_sum = 0;\r\n\t\t\t\r\n\t\t\t// switch to a new segment:\r\n\t\t\twrite_segment = wrap(write_segment + 1, 0, num_segments);\r\n\t\t\t// don't write into what is currently playing:\r\n\t\t\tif (write_segment == play_segment) {\r\n\t\t\t\twrite_segment = wrap(write_segment + 1, 0, num_segments);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t// store the new offset:\r\n\t\t\tpoke(offset_data, offset, write_segment, 0);\r\n\t\t\t\r\n\t\t\t// write the previous & current (a,b) into the new segment:\r\n\t\t\tpoke(segment_data, prev_input, 0, write_segment);\r\n\t\t\tpoke(segment_data, unbiased_input, 1, write_segment);\r\n\t\t\twrite_index = 1;\r\n\t\t} \r\n\t}\r\n}\r\n\r\n// remember previous input:\r\nprev_input = unbiased_input;\r\n\r\n\r\n\r\n// PLAYBACK SECTION:\r\n\r\nr = rate;\r\n// update playback index:\r\nif (pitchedmode < 1) {\r\n\t// no change\r\n\t\r\n} else if (pitchedmode < 2) {\t\r\n\t// ascending:\r\n\td = play_index / play_len;\r\n\tr = rate * max(1, d);\r\n\t\r\n} else if (pitchedmode < 3) {\r\n\t// descending:\r\n\td = ceil(play_index / play_len);\r\n\tr = rate / max(1, d*d);\r\n\t\r\n} else {\r\n\t// try to play back at a chosen frequency\r\n\t// (compensating for estimated original sample frequency)\r\n\tr = freq * play_len / (samplerate * crossings);\r\n}\r\n// update playback index:\r\nplay_index = play_index + r;\r\n// actual play index needs to stay within len:\r\n// (can be fun to use wrap, fold or clip here)\r\nactual_play_index = wrap(play_index, 0, play_len);\r\n\r\n// play the current segment waveform:\r\n// (offset by the waveform zero-crossing position)\r\nout1 = peek(segment_data, play_offset + actual_play_index, play_segment, interp=\"linear\");\r\n\r\n// switch to a new segment?\r\nif (play_index >= play_len * floor(repeats)) {\r\n\t\r\n\t// reset to the current actual play position\r\n\tplay_index = actual_play_index;\r\n\t\r\n\tif (!hold) {\r\n\t\t// move to a new segment\r\n\t\t// some alternatives... \r\n\t\tif (playmode < 1) {\r\n\t\t\t\r\n\t\t\t// play in forward sequence\r\n\t\t\tplay_segment = wrap(play_segment + 1, 0, num_segments);\r\n\t\t\t// caveat: don't play what is currently being written:\r\n\t\t\tif (write_segment == play_segment) {\r\n\t\t\t\tplay_segment = wrap(write_segment + 1, 0, num_segments);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t} else if (playmode < 2) {\r\n\t\t\t\r\n\t\t\t// play in reverse sequence\r\n\t\t\tplay_segment = wrap(play_segment - 1, 0, num_segments);\r\n\t\t\t// caveat: don't play what is currently being written:\r\n\t\t\tif (write_segment == play_segment) {\r\n\t\t\t\tplay_segment = wrap(write_segment - 1, 0, num_segments);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t} else if (playmode < 3) {\r\n\t\t\t\r\n\t\t\t// choose direction by random walk:\r\n\t\t\tdirection = sign(noise());\r\n\t\t\tplay_segment = wrap(play_segment + direction, 0, num_segments);\r\n\t\t\t// caveat: don't play what is currently being written:\r\n\t\t\tif (write_segment == play_segment) {\r\n\t\t\t\tplay_segment = wrap(write_segment + direction, 0, num_segments);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t} else if (playmode < 4) {\r\n\t\t\t\r\n\t\t\t// choose randomly:\r\n\t\t\tdirection = 1 + ceil(num_segments * (noise() + 1)/2);\r\n\t\t\tplay_segment = wrap(play_segment + direction, 0, num_segments);\r\n\t\t\t// caveat: don't play what is currently being written:\r\n\t\t\tif (write_segment == play_segment) {\r\n\t\t\t\tplay_segment = wrap(write_segment - 1, 0, num_segments);\r\n\t\t\t}\r\n\t\t\t\r\n\t\t} else {\r\n\t\t\t\r\n\t\t\t// play most recently recorded:\r\n\t\t\tplay_segment = wrap(write_segment - 1, 0, num_segments);\r\n\t\t\t\r\n\t\t} \r\n\t\t\r\n\t\t// get the new playback length\r\n\t\tplay_len = peek(length_data, play_segment, 0);\r\n\t\t// get the new playback offset\r\n\t\tplay_offset = peek(offset_data, play_segment, 0);\r\n\t\t// and the new playback loudness\r\n\t\tplay_rms = peek(rms_data, play_segment, 0);\r\n\t}\t\r\n} \r\n\r\n// show what's actually happening:\r\n//out2 = write_segment;\r\n//out3 = play_segment;\r\n//out4 = play_len;\r\n//out5 = play_index / play_len;\r\n//out6 = play_rms;",
"fontface" : 0,
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-1",
"maxclass" : "codebox",
"numinlets" : 1,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 13.0, 52.0, 668.0, 626.0 ],
"style" : ""
}
}
],
"lines" : [ {
"patchline" : {
"destination" : [ "obj-3", 0 ],
"disabled" : 0,
"hidden" : 0,
"source" : [ "obj-1", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-1", 0 ],
"disabled" : 0,
"hidden" : 0,
"source" : [ "obj-2", 0 ]
}
}
]
}
,
"patching_rect" : [ 77.0, 157.0, 77.0, 22.0 ],
"style" : "",
"text" : "gen~"
}
}
, {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-42",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patcher" : {
"fileversion" : 1,
"appversion" : {
"major" : 7,
"minor" : 0,
"revision" : 0,
"architecture" : "x86",
"modernui" : 1
}
,
"rect" : [ 25.0, 69.0, 159.0, 204.0 ],
"bglocked" : 0,
"openinpresentation" : 0,
"default_fontsize" : 12.0,
"default_fontface" : 0,
"default_fontname" : "Arial",
"gridonopen" : 1,
"gridsize" : [ 15.0, 15.0 ],
"gridsnaponopen" : 1,
"objectsnaponopen" : 1,
"statusbarvisible" : 2,
"toolbarvisible" : 1,
"lefttoolbarpinned" : 0,
"toptoolbarpinned" : 0,
"righttoolbarpinned" : 0,
"bottomtoolbarpinned" : 0,
"toolbars_unpinned_last_save" : 0,
"tallnewobj" : 0,
"boxanimatetime" : 200,
"enablehscroll" : 1,
"enablevscroll" : 1,
"devicewidth" : 0.0,
"description" : "",
"digest" : "",
"tags" : "",
"style" : "",
"subpatcher_template" : "",
"boxes" : [ {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-34",
"maxclass" : "newobj",
"numinlets" : 6,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 18.0, 63.0, 119.0, 20.0 ],
"style" : "",
"text" : "scale 0. 1. 16. 5000."
}
}
, {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-40",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 18.0, 93.0, 89.0, 18.0 ],
"style" : "",
"text" : "max_length $1"
}
}
, {
"box" : {
"comment" : "",
"id" : "obj-10",
"maxclass" : "inlet",
"numinlets" : 0,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 18.0, 17.0, 25.0, 25.0 ],
"style" : ""
}
}
, {
"box" : {
"comment" : "",
"id" : "obj-11",
"maxclass" : "outlet",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 18.0, 136.0, 25.0, 25.0 ],
"style" : ""
}
}
],
"lines" : [ {
"patchline" : {
"destination" : [ "obj-34", 0 ],
"disabled" : 0,
"hidden" : 0,
"source" : [ "obj-10", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-40", 0 ],
"disabled" : 0,
"hidden" : 0,
"source" : [ "obj-34", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-11", 0 ],
"disabled" : 0,
"hidden" : 0,
"source" : [ "obj-40", 0 ]
}
}
]
}
,
"patching_rect" : [ 442.0, 105.5, 43.0, 22.0 ],
"saved_object_attributes" : {
"description" : "",
"digest" : "",
"globalpatchername" : "",
"style" : "",
"tags" : ""
}
,
"style" : "",
"text" : "p max"
}
}
, {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-41",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patcher" : {
"fileversion" : 1,
"appversion" : {
"major" : 7,
"minor" : 0,
"revision" : 0,
"architecture" : "x86",
"modernui" : 1
}
,
"rect" : [ 25.0, 69.0, 159.0, 204.0 ],
"bglocked" : 0,
"openinpresentation" : 0,
"default_fontsize" : 12.0,
"default_fontface" : 0,
"default_fontname" : "Arial",
"gridonopen" : 1,
"gridsize" : [ 15.0, 15.0 ],
"gridsnaponopen" : 1,
"objectsnaponopen" : 1,
"statusbarvisible" : 2,
"toolbarvisible" : 1,
"lefttoolbarpinned" : 0,
"toptoolbarpinned" : 0,
"righttoolbarpinned" : 0,
"bottomtoolbarpinned" : 0,
"toolbars_unpinned_last_save" : 0,
"tallnewobj" : 0,
"boxanimatetime" : 200,
"enablehscroll" : 1,
"enablevscroll" : 1,
"devicewidth" : 0.0,
"description" : "",
"digest" : "",
"tags" : "",
"style" : "",
"subpatcher_template" : "",
"boxes" : [ {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-34",
"maxclass" : "newobj",
"numinlets" : 6,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 18.0, 63.0, 119.0, 20.0 ],
"style" : "",
"text" : "scale 0. 1. 16. 1000."
}
}
, {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-40",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 18.0, 93.0, 86.0, 18.0 ],
"style" : "",
"text" : "min_length $1"
}
}
, {
"box" : {
"comment" : "",
"id" : "obj-10",
"maxclass" : "inlet",
"numinlets" : 0,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 18.0, 17.0, 25.0, 25.0 ],
"style" : ""
}
}
, {
"box" : {
"comment" : "",
"id" : "obj-11",
"maxclass" : "outlet",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 18.0, 136.0, 25.0, 25.0 ],
"style" : ""
}
}
],
"lines" : [ {
"patchline" : {
"destination" : [ "obj-34", 0 ],
"disabled" : 0,
"hidden" : 0,
"source" : [ "obj-10", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-40", 0 ],
"disabled" : 0,
"hidden" : 0,
"source" : [ "obj-34", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-11", 0 ],
"disabled" : 0,
"hidden" : 0,
"source" : [ "obj-40", 0 ]
}
}
]
}
,
"patching_rect" : [ 355.166656, 105.5, 40.0, 22.0 ],
"saved_object_attributes" : {
"description" : "",
"digest" : "",
"globalpatchername" : "",
"style" : "",
"tags" : ""
}
,
"style" : "",
"text" : "p min"
}
}
, {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-40",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patcher" : {
"fileversion" : 1,
"appversion" : {
"major" : 7,
"minor" : 0,
"revision" : 0,
"architecture" : "x86",
"modernui" : 1
}
,
"rect" : [ 25.0, 69.0, 159.0, 204.0 ],
"bglocked" : 0,
"openinpresentation" : 0,
"default_fontsize" : 12.0,
"default_fontface" : 0,
"default_fontname" : "Arial",
"gridonopen" : 1,
"gridsize" : [ 15.0, 15.0 ],
"gridsnaponopen" : 1,
"objectsnaponopen" : 1,
"statusbarvisible" : 2,
"toolbarvisible" : 1,
"lefttoolbarpinned" : 0,
"toptoolbarpinned" : 0,
"righttoolbarpinned" : 0,
"bottomtoolbarpinned" : 0,
"toolbars_unpinned_last_save" : 0,
"tallnewobj" : 0,
"boxanimatetime" : 200,
"enablehscroll" : 1,
"enablevscroll" : 1,
"devicewidth" : 0.0,
"description" : "",
"digest" : "",
"tags" : "",
"style" : "",
"subpatcher_template" : "",
"boxes" : [ {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-34",
"maxclass" : "newobj",
"numinlets" : 6,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 18.0, 63.0, 102.0, 20.0 ],
"style" : "",
"text" : "scale 0. 1. 1. 150"
}
}
, {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-40",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 18.0, 93.0, 78.0, 18.0 ],
"style" : "",
"text" : "crossings $1"
}
}
, {
"box" : {
"comment" : "",
"id" : "obj-10",
"maxclass" : "inlet",
"numinlets" : 0,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 18.0, 17.0, 25.0, 25.0 ],
"style" : ""
}
}
, {
"box" : {
"comment" : "",
"id" : "obj-11",
"maxclass" : "outlet",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 18.0, 136.0, 25.0, 25.0 ],
"style" : ""
}
}
],
"lines" : [ {
"patchline" : {
"destination" : [ "obj-34", 0 ],
"disabled" : 0,
"hidden" : 0,
"source" : [ "obj-10", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-40", 0 ],
"disabled" : 0,
"hidden" : 0,
"source" : [ "obj-34", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-11", 0 ],
"disabled" : 0,
"hidden" : 0,
"source" : [ "obj-40", 0 ]
}
}
],
"styles" : [ {
"name" : "AudioStatus_Menu",
"default" : {
"bgfillcolor" : {
"type" : "color",
"color" : [ 0.294118, 0.313726, 0.337255, 1 ],
"color1" : [ 0.454902, 0.462745, 0.482353, 0.0 ],
"color2" : [ 0.290196, 0.309804, 0.301961, 1.0 ],
"angle" : 270.0,
"proportion" : 0.39,
"autogradient" : 0
}
}
,
"parentstyle" : "",
"multi" : 0
}
]
}
,
"patching_rect" : [ 268.333344, 105.5, 49.0, 22.0 ],
"saved_object_attributes" : {
"description" : "",
"digest" : "",
"globalpatchername" : "",
"style" : "",
"tags" : ""
}
,
"style" : "",
"text" : "p cross"
}
}
, {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-12",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patcher" : {
"fileversion" : 1,
"appversion" : {
"major" : 7,
"minor" : 0,
"revision" : 0,
"architecture" : "x86",
"modernui" : 1
}
,
"rect" : [ 25.0, 69.0, 159.0, 204.0 ],
"bglocked" : 0,
"openinpresentation" : 0,
"default_fontsize" : 12.0,
"default_fontface" : 0,
"default_fontname" : "Arial",
"gridonopen" : 1,
"gridsize" : [ 15.0, 15.0 ],
"gridsnaponopen" : 1,
"objectsnaponopen" : 1,
"statusbarvisible" : 2,
"toolbarvisible" : 1,
"lefttoolbarpinned" : 0,
"toptoolbarpinned" : 0,
"righttoolbarpinned" : 0,
"bottomtoolbarpinned" : 0,
"toolbars_unpinned_last_save" : 0,
"tallnewobj" : 0,
"boxanimatetime" : 200,
"enablehscroll" : 1,
"enablevscroll" : 1,
"devicewidth" : 0.0,
"description" : "",
"digest" : "",
"tags" : "",
"style" : "",
"subpatcher_template" : "",
"boxes" : [ {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-34",
"maxclass" : "newobj",
"numinlets" : 6,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 18.0, 63.0, 99.0, 20.0 ],
"style" : "",
"text" : "scale 0. 1. 1. 30."
}
}
, {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-40",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 18.0, 93.0, 49.0, 18.0 ],
"style" : "",
"text" : "rate $1"
}
}
, {
"box" : {
"comment" : "",
"id" : "obj-10",
"maxclass" : "inlet",
"numinlets" : 0,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 18.0, 17.0, 25.0, 25.0 ],
"style" : ""
}
}
, {
"box" : {
"comment" : "",
"id" : "obj-11",
"maxclass" : "outlet",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 18.0, 136.0, 25.0, 25.0 ],
"style" : ""
}
}
],
"lines" : [ {
"patchline" : {
"destination" : [ "obj-34", 0 ],
"disabled" : 0,
"hidden" : 0,
"source" : [ "obj-10", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-40", 0 ],
"disabled" : 0,
"hidden" : 0,
"source" : [ "obj-34", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-11", 0 ],
"disabled" : 0,
"hidden" : 0,
"source" : [ "obj-40", 0 ]
}
}
]
}
,
"patching_rect" : [ 181.5, 105.5, 41.0, 22.0 ],
"saved_object_attributes" : {
"description" : "",
"digest" : "",
"globalpatchername" : "",
"style" : "",
"tags" : ""
}
,
"style" : "",
"text" : "p rate"
}
}
, {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"id" : "obj-7",
"maxclass" : "comment",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 77.0, 341.0, 60.0, 20.0 ],