-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShredder2000.js
80 lines (63 loc) · 2.64 KB
/
Shredder2000.js
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
/* ----------------------------------------------------------------------------
Scramble2000.js – Extract the essence of your sound by shredding it into pieces
-------------------------------------------------------------------------------
DESCRIPTION
-----------
This script will displace random parts of the current file, making the sound
shattered and unrecognizable. The idea of this script is to extract the actual
'essence' of the sound. It's a bit related to how granulizers work, but I
wanted to have this functionality as a destructive function in my audio editor.
Note: You may want to perform Correct Errors on the resulting file to soften
up hard cuts a bit. I haven't found a good way to strip silence, otherwise I
would have recommended doing that as well because for some reason, there's
short, occasional micro bits of silence in the resulting audio.
AUTHOR
------
Henrik Cederblad | https://github.com/hced
COMPATIBILITY
-------------
Works in WaveLab Pro 10+. May or may not work in lower WaveLab versions.
VERSION HISTORY
---------------
0.1 - First functional version. Removed commented pseudo-code. There's some
corrections to be made, probably in the selection procedure, because somehow
the audiofile gets slightly longer every time you run the script against it.
0.1a - Initial version
-----------------------------------------------------------------------------*/
const FILELENGTH = activeWave.size(); // Total samples
const SNAPSHOTLENGTH = (FILELENGTH/100)*5; // 5% of total samples
const REPS = 200;
// Debug
logWindow.clear();
var TS = new Date();
function timeStamp() { return TS.toISOString(); }
logWindow.printInfo(timeStamp()); // Log timestamp
logWindow.printInfo("This file has a total of " + FILELENGTH + " samples");
function randomPos(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function Scramble() {
// Set thisEnd to a random location between 0 and FILELENGTH
thisEnd = randomPos(0, FILELENGTH);
logWindow.printInfo(thisEnd); // Debug
// ...but not lower than SNAPSHOTLENGTH.
if (thisEnd < SNAPSHOTLENGTH) {
thisEnd = SNAPSHOTLENGTH;
}
// Make range selection
activeWave.select( (thisEnd - SNAPSHOTLENGTH), SNAPSHOTLENGTH );
// Cut the selected range
activeWave.cut();
// Move cursor to a random location
cursorPos = randomPos(0, FILELENGTH);
activeWave.setCursorPosition(cursorPos); //Todo: round up to prevent 0?
logWindow.printInfo("Moved cursor to position " + cursorPos); // Debug
// Paste the cut-out selection
activeWave.paste();
}
// Repeat the process according to number of times defined in REPS
for (i = 0; i < REPS; i++) {
Scramble();
}