1

I'm working on a simple Supercollider patch (my first), designed to swap samples in a file to get a stuttering, granular synthesis sort of sound.

What I'm trying to do is make a new audio file that's the length of the input file. It should run a loop that will swap the place of samples in a file with the sample at the scrambled indexes.

I haven't been able to find a way to get it to compile and write an audio file.

var indexa, indexb, frames, count, j, aa, ab;
j = 0;

s.boot;

b = Buffer.read(s, "/Users/admin/Desktop/10counter.aiff"); //my test file

"Frames: " + b.numFrames.postln;
"Channels: " + b.numChannels.postln;

count = b.numFrames * b.numChannels;

"Count: " + count.postln;

b.write("/Users/admin/Desktop/rbs.aiff", "aiff", "int16", 0, 0, true);

opCount.do ({

    temp1 = Buffer.alloc(s, 1, 2);
    temp2 = Buffer.alloc(s, 1, 2);

    aa = Array.fill(frames, {arg i; i});
    ab = a1.scramble;
})

//do the swaps
{j < count}.while ({

    indexa = aa[j];
    indexb = ab[j];

    temp1 = b.get(indexa);
    temp2 = b.get(indexb);

    b.set(indexb, temp1);
    b.set(indexa, temp2);

    j.increment;
})

//write to file here?

b.close;
TurtleOrRodeo
  • 63
  • 1
  • 11

1 Answers1

1

You really just need the Buffer.write method. Put it at the bottom of the code, like you suggest. I'm not sure what the existing b.write is supposed to be doing - you've presumably copied it from somewhere but it's not needed, you don't want to write the file before you've modified it, and also you don't want the leaveOpen argument to be true (because you're doing a single write, not continuously streaming to disk).

Dan Stowell
  • 4,618
  • 2
  • 20
  • 30
  • I get this message when I insert Buffer.write(////): `ERROR: Command line parse failed nil ERROR: syntax error, unexpected CLASSNAME, expecting $end in file 'selected text' line 44 char 6: Buffer.write("/Users/admin/Desktop/rbs.aiff", "aiff", "int16", -1, 0, false); ^^^^^^` and this message when I use the declared buffer, b: `ERROR: Command line parse failed nil ERROR: syntax error, unexpected NAME, expecting $end in file 'selected text' line 44 char 1: b.write("/Users/admin/Desktop/rbs.aiff", "aiff", "int16", -1, 0, false); ^` – TurtleOrRodeo Mar 03 '16 at 19:32
  • 1
    (1) indeed you do need to execute `b.write(...)` where `b` is the `Buffer` you created earlier on. (2) you've got a syntax error, and it's probably because you forgot a semicolon on the line before the line you tried. If you see the phrase "syntax error" then you have a syntax error, i.e. you've made a typing mistake which is preventing the code from even running – Dan Stowell Mar 04 '16 at 19:51