[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[sc-dev] File Processor



Ive come to a stand still, i have been modding this
patch for hours tonight trying to get it to work.  I
got rid of the Buffer.write method because i found out
that there is a delay.  Can anyone take a look?  I
completely dumbfounded.

// Var ***********************************************

var numberOutputs, soundLoad, soundArray,
soundDurationArray;
var group, bus, bufferArray, writeBuffer, dir, path,
shell;
var selectedSize, sizeTemp;
var playStraight, playSynth, mainRoutine;
var effectArray, delay, distorsion, filter, ringMod;

group = Group.new;
bus = Bus.audio;

selectedSize = 0;
sizeTemp = 0;
numberOutputs = 10;

// Disk Out ******************************************

SynthDef("diskout", {
	arg bus, buffer;
	DiskOut.ar(buffer, In.ar(bus, 2));
	ReplaceOut.ar(0, In.ar(bus,2));
}).writeDefFile;
s.sendSynthDef("diskout");

dir = 100000.rand;

shell = SCShell.new;
shell.cd("/Music/Samples/FileProcess");
shell.mkdir(dir);

path = "/Music/Samples/FileProcess/" ++ dir ++ "/";

// Synth Defs ****************************************

SynthDef("SoundFile", {
	arg amp = 1.0, rate = 1.0 , start, length, slope =
0.0, buffer, bus = 0;
	var env, sound;
	env = EnvGen.ar(Env.new([0,1,1,0], 
		[length * (slope / 2), length * (1 - slope), length
* (slope / 2)]));
	sound = PlayBuf.ar(2, buffer, rate, 0.0, start *
44100) * env * amp;
	Out.ar(bus, sound);
}).writeDefFile;
s.sendSynthDef("SoundFile");

SynthDef("Delay", {
	arg mix, time, feedback, bus = 0;
	var sound, delay;
	sound = In.ar(bus, 2);
	delay = CombN.ar(sound, time, time, feedback);
	XOut.ar(bus, mix, delay);
}).writeDefFile;
s.sendSynthDef("Delay");

SynthDef("Distorsion", {
	arg mix, bit, clip, bus = 0;
	var sound, dist;
	sound = In.ar(bus, 2);
	dist = sound.trunc(bit).clip2(clip) * (1/clip);
	XOut.ar(bus, mix, dist);
}).writeDefFile;
s.sendSynthDef("Distorsion");

SynthDef("Filter", {
	arg mix, cuttoff, res, hplp, bus = 0;
	var sound, lowpass, highpass, filter;
	sound = In.ar(bus, 2);
	filter = RLPF.ar(sound,cuttoff,res,hplp) +
		RHPF.ar(sound,cuttoff,res,(1-hplp));
	XOut.ar(bus, mix, filter);
}).writeDefFile;
s.sendSynthDef("Filter");

SynthDef("RingMod", {
	arg mix, freq = 440, bus = 0;
	var sound, ring;
	sound = In.ar(bus, 2);
	ring = sound * SinOsc.ar(freq);
	XOut.ar(bus, mix, ring);
}).writeDefFile;
s.sendSynthDef("RingMod");

// Sound Files ***************************************

soundArray = [
	"/ROCK/Girls On Film_02.wav",
	"/ROCK/Along The Watchtower_05.wav",
	"/ROCK/Tainted Love_02.wav",
	"/ROCK/Bohemian Rhapsody_02.wav",
	"/ROCK/You Really Got Me_01.wav",
	"/ROCK/Tainted Love_05.wav",
	"/ROCK/Rebel Yell_02.wav",
	"/ROCK/Light My Fire_01.wav",
	"/ROCK/Bohemian Rhapsody_06.wav",
	"/ROCK/That'll Be the Day_04.wav"
];	

// Determine Buffer Numbers
bufferArray = Array.fill(soundArray.size, {
	arg i;
	Buffer.read(s, soundArray.at(i));
});

// Load Soundfiles
soundDurationArray = Array.fill(soundArray.size, {
	arg i;
	var soundfile, duration;
	soundfile = SoundFile.new;
	soundfile.openRead(soundArray.at(i));
	duration = soundfile.duration;
	soundfile.close;
	duration;
});

// Play Routine **************************************

playStraight = {
	var file, length, offset;
	"play".postln;
	file = bufferArray.size.rand;
	length = rrand(0.1, 2.0);
	sizeTemp = length;
	offset = (soundDurationArray.at(file) - length).rand;
	playSynth = playSynth.add(Synth.head(group,
"SoundFile", [
		"rate", [1, -1].choose * 2.0.rand,
		"start", offset,
		"length", length,
		"buffer", bufferArray.at(file).id,
		"bus", bus.index]));
	"play".postln;
};

// Effect Routines************************************

delay = {
	"delay".postln;
	playSynth =
playSynth.add(Synth.after(playSynth.at(playSynth.size
- 1),
		"Delay", [ 
		"mix", 1.0.rand,
		"time", rrand(0.01, 2.0),
		"feedback", rrand(0.0, 3.0),
		"bus", bus.index]));
	"delay".postln;

};

distorsion = {
	"distorsion".postln;
	playSynth =
playSynth.add(Synth.after(playSynth.at(playSynth.size
- 1), 
		"Distorsion", [
		"mix", 1.0.rand,
		"bit", rrand(0.0, 1.0),
		"clip", rrand(0.01, 1.0),
		"bus", bus.index]));
	"distorsion".postln;
};

filter = {
	"filter".postln;
	playSynth =
playSynth.add(Synth.after(playSynth.at(playSynth.size
- 1), 		"Filter", [
		"mix", 1.0.rand,
		"cuttoff", 50 + 2000.rand,
		"resonance", 1.0.rand,
		"hplp", [1, 0].choose,
		"bus", bus.index]));
	"filter".postln;
};

ringMod = {
	"ring".postln;
	playSynth =
playSynth.add(Synth.after(playSynth.at(playSynth.size
- 1),		"RingMod", [
		"mix", 1.0.rand,
		"freq", [200.rand, 10000.rand].choose,
		"bus", bus.index]));
	"ring".postln;
};

effectArray = [delay, distorsion, filter, ringMod];

// Main **********************************************

mainRoutine = Routine({
	1.wait;
	numberOutputs.do({
		arg i;
		var numberEffects;
		
		writeBuffer = Buffer.new(s, 65536, 2);
		
		playSynth = Array.new;
		playStraight.value;
		selectedSize = sizeTemp;
		
		numberEffects = 5.rand;
		numberEffects.do({
			effectArray.choose.value;
		});
		
		"write".postln;
		s.sendMsg("/b_write", writeBuffer.id, (path ++
i.asString ++ ".aiff"),
			"aiff", "int16", -1, 0, 1);
		playSynth = playSynth.add( 		
			Synth.after(playSynth.at((playSynth.size -
1).postln), 				"diskout", ["bus", bus.index,
"buffer", writeBuffer.id]));
		"write".postln;
			
		selectedSize.wait;
		
		(playSynth.size).do({
			arg j;
			playSynth.at((playSynth.size - 1) - j).free;
		});
		writeBuffer.close;
		writeBuffer.free;
		"done".postln;
		0.5.wait;
	});
	group.free;
	bus.free;
	bufferArray.size.do({
		arg i;
		bufferArray.at(i).free;
	});
});

SystemClock.play(mainRoutine);


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com