tags

descriptioncore glitch

 
 
awk
Level 7 Mixist
 
remix
th/24

 
street love 
19th Σ3.571

 
cats 
18th Σ3.997

 
dogs 
19th Σ3.667

 
beardability 
16th Σ4.421

 
shit in pants 
20th Σ3.718

 
My drift
 
  18th/24   Σ19.374   Dec 17th 2007 11:28pm
 
 
// Expects Laurent de Soras' freely available FFT tools in the directory:
// See http://ldesoras.free.fr/src/FFTReal-1.03.zip
#include "FFTReal.cpp"

#define OUTS (89561048*sizeof(short) * 2)

#define CNOTE 523.2511306012
#define BASE (M_PI*2/44100*8.1757989156)
#define SEMITONE (pow(2,1.0/12.0))

typedef float sample;

#define REALFILES 25
#define FILES REALFILES

// perl -e 'for (`ls IN`) {chomp; $a = "IN/$_"; s/(.+?)\.mp3$/OUT\/$1.wav/; `lame --decode -t $a $_`; }'
char *all[REALFILES] = {
"OUT/botb_0479.wav",
"OUT/botb_0481.wav",
"OUT/botb_0482.wav",
"OUT/botb_0483.wav",
"OUT/botb_0486.wav",
"OUT/botb_0487.wav",
"OUT/botb_0490.wav",
"OUT/botb_0491.wav",
"OUT/botb_0493.wav",
"OUT/botb_0496.wav",
"OUT/botb_0499.wav",
"OUT/botb_0500.wav",
"OUT/botb_0501.wav",
"OUT/botb_0502.wav",
"OUT/botb_0503.wav",
"OUT/botb_0508.wav",
"OUT/botb_0511.wav",
"OUT/botb_0512.wav",
"OUT/botb_0514.wav",
"OUT/botb_0516.wav",
"OUT/botb_0519.wav",
"OUT/botb_0521.wav",
"OUT/botb_0522.wav",
"OUT/botb_0525.wav",
"OUT/botb_0533.wav"
};

sample *load(char *file, int &size) {
struct stat sb;
stat(file, &sb);
FILE *in = fopen(file, "r");
size = sb.st_size;
short *out = (short *)malloc(size);
fread(out, size/sizeof(short), sizeof(short), in);
fclose(in);
size /= sizeof(short);
int undersize = size;
//for (size = 1; size < undersize; size *= 2);
sample *vals = (sample *)malloc(size*sizeof(sample));
for(int c = 0; c < undersize; c++)
vals[c] = ((double)out[c])/SHRT_MAX;
for(int c = undersize; c < size; c++)
vals[c] = 0;
//free(out);
return vals;
}

struct clip {
sample *val;
int len;
bool live;
sample weight;
clip() { val = 0; len = 0; live = true; weight = -1; }
};


#define CLIPSMAX 10000

struct clips {
int len;
clip *val[CLIPSMAX];
clips() {len = 0;}
void lives(bool b) {for(int c = 0; c < len;c++)val[c]->live=b;}
};

struct baseSorter {
virtual sample cWeight(clip *c) = 0;
sample weight(clip *c) {
if (c->weight < 0)
c->weight = cWeight(c);
return c->weight;
}
void sort(clip **order, int len) {
int p;
printf("SORTING %d things...\n", len);
for(int c = 0; c < len; c++)
order[c]->weight = -1;
do {
p = 0;
for(int c = 0; c < len-1; c++) {
if (weight(order[c]) > weight(order[c+1])) {
clip* o = order[c];
order[c] = order[c+1];
order[c+1] = o;
p++;
}
}
//printf("%d problems...\n", p);
} while (p > 0);
}
void sort(clips &c) {
sort(c.val, c.len);
}
};

struct sorter : public baseSorter {
virtual sample cWeight(clip *c) {
sample sum = 0;
for(int d = 0; d < c->len; d++)
sum += c->val[d]*c->val[d];
sum /= c->len;
return sum;
}
};

sample staticblah[4096];

char* letters[12] = {"A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"};

struct notesorter : public baseSorter {
int note;
notesorter() : note(-1) {}
notesorter(int _note) : note(_note) {}
virtual sample cWeight(clip *c) {
// printf("TRY LEN: %d\n", out.len-startat);
FFTReal fft (c->len);
// printf("SURVIVED!\n");
fft.do_fft(staticblah, c->val);
int maxat = -1;
sample maxwas = -1;
for(int d = 0; d < c->len/2; d++) {
sample loud = staticblah[d]*d; //fabs(out.val[startat + d]);
if (loud > maxwas) {
maxwas = loud;
maxat = d;
}
}
float hz = maxat/4096.0*44010.0;
float closest = 1000000.0; int closestat = -1;
for(int d = 0; d < 12*16; d++) {
if (note >= 0 && note != (d%12)) continue;
float lhz = 4.4 * pow(pow(2, 1.0/12.0), d);
float dist = lhz-hz;
if (fabs(dist) < fabs(closest)) {
closest = dist; closestat = d;
}
}
// printf("Okay at %d, max %d/4096 (%f hz). Letter %d (%s) + %f\n", c, maxat, hz, closestat, letters[closestat%12], closest);
return fabs(closest);
}
};

#define MINCROSS 2

void load(char *file, clip & into) {
into.val = load(file, into.len);
}

void distribute(clips &out, clip &in, int cliplen, double mincross = MINCROSS) {
int c = 0;
while(c < in.len) {
clip *val = new clip; // Create clip out of next block of in
val->val = &in.val[c];
val->len = cliplen;
while(fabs(val->val[0]) > mincross) { // Move forward start of clip
val->val++;
val->len--;
}
if (val->len <= 0) // Sanity check out
val->len = 1;
if (val->val + val->len > in.val + in.len) // Sanity check in
{ printf("FAILURE ACTUAL OVERFLOW\n"); break; }
while (fabs(val->val[val->len-1]) > mincross) { // Move forward end of clip
if (val->val + val->len >= in.val + in.len)
{ printf("FAILURE NEAR OVERFLOW\n"); break; }
val->len++;
}
if (out.len >= CLIPSMAX) {
printf("FAILURE FAILURE FAILURE %d\n", out.len);
break;
}
c += val->len;
out.val[out.len++] = val;
}
}

void tribute(clip &out, clips &in, int start=0, int end=-1) {
sample lastsample = 0;
if (end < 0)
end = in.len;
if (end > in.len) {
printf("TRIBUTE FAILURE %d > %d\n", end, in.len);
return;
}
for(int c = start; c < end; c++) {
int startat = out.len; // debug
if (!in.val[c]->live)
continue;
bool flip = (in.val[c]->val[0] > 0 ^ (lastsample > 0));
sample offset = lastsample - in.val[c]->val[0]* (flip?-1:1);
// printf("len %d last %f current %f flip? %s offset %f\n", in.val[c]->len, lastsample, in.val[c]->val[0], flip?"Y":"N", offset);
for(int e = 0; e < in.val[c]->len; e++) {
lastsample = in.val[c]->val[e] * (flip?-1:1) + (offset*(in.val[c]->len-(sample)e+1)/in.val[c]->len);
out.val[out.len++] = lastsample;
}
}
}

#define BPM 90
#define POD ((int)(44100*60.0/BPM))

int main() {
clip out, tmp;
clips everything;
out.val = (sample *)malloc(OUTS);
short *sout = (short *)malloc(OUTS/2);

/* ------------- */ printf("Loadr.\n");
#if 1
for(int c = 0; c < FILES; c++) {
load(all[c], tmp);
distribute(everything, tmp, 4096);

printf("period %d clips %d clip %s\n", (int)4096, everything.len, all[c]);
}
#else
load("SCRAP/110_220_440_C", tmp);
distribute(everything, tmp, 4096);
#endif

/* ------------- */ printf("Sr:\n");
#if 0
{
sorter sort;
sort.sort(everything);
}
#endif

{
// Alright, so here's what's happening here:
// The goal is this: I take every single sample in the pack and I mush them all
// together. Then I take this mess, chop it up into 1/10 second snippets, and
// rearrange the 1/10 second snippets in order of increasing volume.
// Then I go through and I delete almost all of these snippets-- the reason being,
// I've got this D F D G F C sort of melody, and I want to selectively keep only
// those snippets that come close to shadowing this melody. The hope is to have
// this noisy, rising little symphony of sound bursts, which overall give the
// impression of hovering around the notes I wanted. So, I set this up, I run it,
// and what do I get?
// NOTHING!
// My code doesn't work at all. Basically my code seems to be unable to meaningfully
// tell the difference between any two notes-- I do some thing where I do an FFT and
// then I try to measure where the peak of the FFT is. It doesn't work at all. The top-
// weighted samples for a D sound basically exactly like the top-weighted samples for a
// G. I don't know a better way to do this, I can't fix the bug, and I'm out of time.
// So, my compromise: At the last minute, I throw out my melody, trash half my code,
// and I just create two streams of mashed samples: One the most D-weighted samples
// [via my broken FFT trick], the other the most G-weighted samples. I put one in the
// left channel and the other in the right. That's all. Better luck next time?
// P.S. If you want to hear the full 10-minute mash of all samples sorted by volume:
// http://vote.grumpybumpers.com/full.mp3
#define NOTECOUNT 4
#define NOTELEN 4
int notes[NOTECOUNT] = {
5,600, 10,600};
// 5,3, 8,1, 5,3, 10,1, 8,4, 3,4,
// 5,3, 8,1, 5,3, 10,1, 8,4, 3,4,
// 0,4, 10,4, 8,4, 3,4,
// 5,3, 8,1, 5,3, 10,1, 8,4, 3,4};
everything.lives(true);
clips filter[12];
int pointer[12];
clip blah[2];
blah[0].val = (sample *)malloc(OUTS);
blah[1].val = (sample *)malloc(OUTS);
for(int c = 0; c < 12; c++)
pointer[c] = 0;
for(int c = 0; c < NOTECOUNT*1; c+=2) {
int note = notes[c%NOTECOUNT];
int outlen = notes[c%NOTECOUNT+1]*NOTELEN;
printf("%s for %d beats (start %d)\n", letters[note], outlen, pointer[note]);
if (filter[note].len <= 0) {
printf("\t(Must sort!)\n");
for(int d = 0; d < everything.len; d++) {
filter[note].val[filter[note].len++] = everything.val[d];
}

notesorter sort(note);
sort.sort(filter[note]);
}
tribute(blah[c/2], filter[note], pointer[note], pointer[note] + outlen);
pointer[note] += outlen;
}
for(int c = 0; c < blah[0].len; c++) {
out.val[out.len++] = blah[0].val[c];
out.val[out.len++] = blah[1].val[c];
}
}

// /* ------------- */ printf("DS!\n");

// tribute(out, everything);

/* ------------- */ printf("Don.\n");

sample roof = 0; // Is this really even necessary?
for(int c = 0; c < out.len; c++)
if (fabs(out.val[c]) > roof)
roof = fabs(out.val[c]);
printf("normal %lf\n", roof);
for(int c = 0; c < out.len; c++)
sout[c] = (out.val[c]/roof)*SHRT_MAX;

// ------------------ SAVE ------------------

FILE *fout = fopen("drums.out", "w");
fwrite(sout, out.len, sizeof(short), fout);

return 0;
}
47
2
460
8
19
 


previous entry
triazolam - god of dub


nextious entry
traits - i swear to fuck
 
7757
Level 20 Mixist
aclone
 
 
 
post #7757 :: 2007.12.17 11:35pm
nice;}
 
 
7758
Level 26 Mixist
sc
 
 
 
post #7758 :: 2007.12.18 4:34am
The code that worked, worked! Interesting approach.
 
 
7759
Level 16 Mixist
bleedmaster
 
 
post #7759 :: 2007.12.18 2:49pm
damn, i wish your original idea would have worked out, it was a really good idea!
 
 
7760
Level 17 Mixist
JonBro
 
 
 
post #7760 :: 2007.12.18 4:23pm
AH! open sauce music? I agree whole heartedly with this concept. I think you could have drawn out more of the sections longer and really let the loopability sink in.
 
 
7761
Level 28 Chipist
ui
 
 
 
post #7761 :: 2007.12.19 6:30am
jajaja dam..! you did it again!!... but this time the volume levels are good! :P.... and you have pan in the headphones!!! :)... i like the "concept" of this song... you have to try a code with new stuff the next time!!!! :X.... you have an xtra point comming from me! :)...
 
 
7762
Level 4 Criticist
zekmiyashiro
 
 
post #7762 :: 2007.12.19 7:37am
I have to admit this is one of the most original ideas i've come across in a long time. Congratulations for that =)
 
 
7763
Level 5 Mixist
bgone
 
 
post #7763 :: 2007.12.20 9:03pm
I like the concept...definitely high marks for originality. Hope you are able to work out the bugs...maybe throw a gui on it and make a plugin? :)
 
 
7764
Level 15 Criticist
lilly
 
 
 
post #7764 :: 2007.12.25 6:34am
love the panning \o/
 
 

LOGIN or REGISTER to add your own comments!