mirror of
https://github.com/tsulej/GenerateMe.git
synced 2026-06-16 04:25:42 +02:00
granular resynthesis
This commit is contained in:
@@ -41,6 +41,8 @@ List:
|
||||
* fm - frequency modulation and demodulation
|
||||
* composite_video_simulator - very precise VHS/Composite Video/Tape simulation, based on: https://github.com/joncampbell123/composite-video-simulator
|
||||
* Obj2Raw - convert OBJ vertex data to RAW 8 bit signed (for sonification purposes)
|
||||
* granularresynth - Granular (re)synthesis of any RAW using other RAWs for visual/audio
|
||||
* -> sonification - image sonification
|
||||
* TEMPLATE - clean template sketch with some predefined functions
|
||||
|
||||
## Processing 3
|
||||
|
||||
Executable
BIN
Binary file not shown.
Executable
+81
@@ -0,0 +1,81 @@
|
||||
// Granular resynthesis
|
||||
// Recreate target file using samples from source files
|
||||
// generateme @ 2017
|
||||
|
||||
// Prepare source files as RAW (audio/images etc. any type) and set filenames
|
||||
String[] sources = {
|
||||
"test_img.raw", "test_wav.raw"
|
||||
};
|
||||
// Prepare target file and set filename below
|
||||
String target_fn = "test_wav.raw";
|
||||
// Save to filename
|
||||
String save_to = "result.raw";
|
||||
// Number of grains (10-10000), give low number for SELF to get more glitch
|
||||
final static int gnum = 10;
|
||||
// Size of grain in bytes (100-10000)
|
||||
final static int gsize = 3000;
|
||||
// How far search for grains (only for SELF) in number of grain sizes
|
||||
final static int gspread = 25;
|
||||
// How to gather grains:
|
||||
// - SELF - use target as a source and take grains from neighborhood
|
||||
// - ALL - use all files as sources
|
||||
int type = SELF;
|
||||
|
||||
// do not touch below
|
||||
|
||||
// list of types
|
||||
final static int SELF = 0;
|
||||
final static int ALL = 1;
|
||||
|
||||
void setup() {
|
||||
byte[] target = loadBytes(target_fn);
|
||||
ArrayList source = new ArrayList();
|
||||
|
||||
if (type == ALL) {
|
||||
for (String s : sources) {
|
||||
source.add( loadBytes(s) );
|
||||
}
|
||||
}
|
||||
|
||||
byte[] result = new byte[target.length];
|
||||
|
||||
for (int i=0; i<target.length/gsize; i++) {
|
||||
int pos = i*gsize;
|
||||
println( (int)(100*(pos / (float)target.length)) + "%");
|
||||
|
||||
int currmatch = -1;
|
||||
byte[] currsource = null;
|
||||
long currval = Long.MAX_VALUE;
|
||||
|
||||
for (int g=0; g<gnum; g++) {
|
||||
long val = 0;
|
||||
byte[] mysource;
|
||||
int pos2;
|
||||
if (type == SELF) {
|
||||
mysource = target;
|
||||
pos2 = constrain((int)((random(1)<0.5?1:-1)*random(gsize, gsize*gspread)+pos), 0, mysource.length-gsize-1);
|
||||
} else {
|
||||
mysource = (byte[])source.get( (int)random(source.size()) );
|
||||
pos2 = (int)random(mysource.length-gsize-1);
|
||||
}
|
||||
|
||||
for (int p=0; p<gsize; p++) {
|
||||
val += sq( target[pos+p]-mysource[pos2+p] );
|
||||
}
|
||||
val = (long)Math.sqrt((double)val);
|
||||
|
||||
if (val<currval) {
|
||||
currmatch = pos2;
|
||||
currsource = mysource;
|
||||
currval = val;
|
||||
}
|
||||
}
|
||||
|
||||
arrayCopy( currsource, currmatch, result, pos, gsize);
|
||||
}
|
||||
|
||||
saveBytes(save_to, result);
|
||||
println("done");
|
||||
exit();
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 328 KiB |
Reference in New Issue
Block a user