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

[sc-dev] File Processor



I still haven't been able to get this file process
patch to work, i reworked it last night using synthlib
and the bus and buffer objects.  for some reason the
"/s_new"'s are happening out of order, any one have
any ideas?  Also how can i use the date/time as the
folder names?

RESULTS::

[ 1062, 0, 1 ]
a SynthDef
77
mkdir 89045
a SynthDef
572
a SynthDef
186
a SynthDef
333
a SynthDef
382
a SynthDef
197
SystemClock
RESULT = 0
play
[ 1074, 1062, 0 ]
play
distorsion
[ 1075, 1074, 3 ]
distorsion
ring
[ 1076, 1075, 3 ]
ring
ring
[ 1077, 1076, 3 ]
ring
write
[ 1078, 1077, 3 ]
write
[ /s_new, SoundFile, 1074, 0, 1062, [ rate,
0.24420833587646, start, 1.7365499792552, length,
0.2450...etc...
[ /s_new, Distorsion, 1075, 3, 1074, [ mix,
0.57305133342743, bit, 0.37850308418274, clip,
0.2460529...etc...
[ /s_new, diskout, 1078, 3, 1077 ]
[ /s_new, RingMod, 1077, 3, 1076, [ mix,
0.44178938865662, freq, 1381 ] ]
[ /s_new, RingMod, 1076, 3, 1075, [ mix,
0.44892859458923, freq, 166 ] ]
sndfileFormatInfoFromStrings info->format 00020003
FAILURE /s_new Node not found
FAILURE /s_new Node not found
FAILURE /s_new Node not found
FAILURE /s_new Node not found
1078 node was freed
1077 node was freed
1076 node was freed
1075 node was freed
1074 node was freed
done
FAILURE /n_free Node not found
FAILURE /n_free Node not found
FAILURE /n_free Node not found
FAILURE /n_free Node not found
FAILURE /n_free Node not found


CODE::

// Var
******************************************************************
var numberOutputs, effectArray, soundLoad, soundArray,
soundDurationArray, bufferArray;
var selectedSize, sizeTemp;
var playArray, playStraight, playCut, playGranular,
mainRoutine;
var delay, distorsion, filter, ringMod;
var  writeBuffer, dir, diskID, path, shell;
var group, bus, playSynth;

group = Group.new;
bus = Bus.audio(s, 2);

selectedSize = 0;
sizeTemp = 0;
numberOutputs = 1;

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

writeBuffer = Buffer.new(s, 65536, 2);

SynthDef("diskout", {
	DiskOut.ar(writeBuffer.id, In.ar(bus.index, 2));
}).writeDefFile;
s.sendSynthDef("diskout");

s.sendMsg("/b_alloc", writeBuffer.id, 65536, 2);

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;
	var env, sound;
	env = EnvGen.ar(Env.new([0,1,1,0], 
		[length * (slope / 2), length * (1 - slope), length
* (slope / 2)]),
		doneAction:2);
	sound = PlayBuf.ar(2, buffer, rate, 0.0, start *
44100) * env;
	Out.ar(bus.index, sound);
}).writeDefFile;
s.sendSynthDef("SoundFile");

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

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

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

SynthDef("RingMod", {
	arg mix, freq = 440;
	var sound, ring;
	sound = In.ar(bus.index, 2);
	ring = sound * SinOsc.ar(freq);
	XOut.ar(bus.index, 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 = soundArray.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]));
	"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)]));
	"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)]));
	"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]));
	"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]));
	"ring".postln;
};

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

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

mainRoutine = Routine({
	1.wait;
	numberOutputs.do({
		arg i;
		var numberEffects;
		
		playSynth = Array.new;
		playStraight.value;
		selectedSize = sizeTemp;
		
		numberEffects = 5.rand;
		numberEffects.do({
			effectArray.choose.value;
		});
		
		"write".postln;
		writeBuffer.write((path ++ i.asString ++ ".aiff"));	
playSynth = playSynth.add( 		
			Synth.after(playSynth.at(playSynth.size - 1),
"diskout"));
		"write".postln;
			
		selectedSize.wait;
		
		playSynth.size.do({
			arg j;
			playSynth.at((playSynth.size - 1) - j).free;
		});
		writeBuffer.close; // close the file.
		"done".postln;
		0.5.wait;
	});
	//group.free; // Any Ideas why this doesn't work?
	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