Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (
- s.waitForBoot(
- onComplete: {
- var sf;
- var du;
- var z, y;
- var a,b,h,f,p;
- var factor = 40.0;
- SynthDef(
- name:"pvrec",
- ugenGraphFunc: {
- arg recBuf=1, soundBufnum=2;
- var in, chain, bufnum;
- bufnum = LocalBuf.new(1024);
- Line.kr(
- start:1,
- end:1,
- dur:BufDur.kr(soundBufnum),
- mul:1.0,
- add:0.0,
- doneAction: 2
- );
- in = PlayBuf.ar(
- numChannels: 1,
- bufnum: soundBufnum,
- rate:BufRateScale.kr(soundBufnum),
- trigger:1,
- startPos:0,
- loop: 0,
- doneAction:0
- );
- // note the window type and overlaps... this is important for resynth parameters
- // chain = FFT(buffer:bufnum, in: in, hop: 0.25, wintype:1,active:1,winsize:0);
- chain = FFT(buffer:bufnum, in:in, hop:0.25, wintype:1,active:1,winsize:0);
- // chain = PV_RecordBuf(buffer: chain, recbuf:recBuf, offset:0, run:1, loop:0, hop:0.25, wintype:1);
- chain = PV_RecordBuf(buffer:chain, recbuf:recBuf, offset:0, run:1, loop:0, hop:0.25, wintype:1)
- // no ouput ... simply save the analysis to recBuf
- },
- rates:nil,
- prependArgs:nil,
- variants:nil,
- metadata:nil
- ).send(s);
- SynthDef(
- name: "pvplay",
- ugenGraphFunc: {
- arg out=0, recBuf=1, warpBuf = 2, duration = 10.0;
- var in, chain, bufnum, point, warp;
- bufnum = LocalBuf.new(numFrames:1024,numChannels:1);
- // point = MouseX.kr(minval:0.0, maxval:1.0, warp:0, lag:0.2);
- point = Line.kr(start:0.0, end:1.0, dur: duration * factor,mul:1.0,add:0.0,doneAction:0);
- point = (1.0 + MouseX.kr(minval:0.0,maxval: 0.1,warp:0,lag:0.2) + LFSaw.kr(freq: 1.0/(duration * factor), iphase:0, mul:0.5,add:0.0)).wrap(lo:0, hi:1.0);
- warp = Warp1.ar(numChannels:1, bufnum:warpBuf, pointer:point, freqScale:1, windowSize:0.2, envbufnum:-1, overlaps:8, windowRandRatio:0.25, interp: 4,mul:1.0,add:0.0);
- // warp = Warp1.ar(numChannels:1, bufnum:warpBuf, pointer:point, freqScale:1, windowSize:0.2, envbufnum:-1, overlaps:8, windowRandRatio:0.1,interp:1,mul:1,add:0)
- chain = PV_BufRd(buffer:bufnum, playbuf:recBuf, point:point);
- Out.ar(bus:out, channelsArray: (IFFT(buffer:chain, wintype:1, winsize:0).dup + warp) * 0.5);
- },
- rates:nil,
- prependArgs:nil,
- variants:nil,
- metadata:nil
- ).send(s);
- s.sync;
- // path to a sound file here
- p = "./toto_africa.wav".standardizePath;
- // the frame size for the analysis - experiment with other sizes (powers of 2)
- f = 1024;
- // the hop size
- h = 0.25;
- // get some info about the file
- sf = SoundFile.new(p);
- sf.openRead;
- du = sf.duration;
- sf.close;
- // allocate memory to store FFT data to... SimpleNumber.calcPVRecSize(frameSize, hop) will return
- // the appropriate number of samples needed for the buffer
- y = Buffer.alloc(
- server:s,
- numFrames:sf.duration.calcPVRecSize(
- frameSize: f,
- hop: h,
- sampleRate:nil
- ),
- numChannels:1,
- completionMessage:nil,
- bufnum:nil
- );
- // allocate the soundfile you want to analyze
- // z = Buffer.read(s, p);
- z = Buffer.readChannel(
- server:s,
- path:p,
- startFrame:0,
- numFrames:-1,
- channels: 1,
- action:nil,
- bufnum:nil
- );
- s.sync;
- // this does the analysis and saves it to buffer 1... frees itself when done
- a = Synth(
- defName:"pvrec",
- args:[\recBuf, y, \soundBufnum, z],
- target:nil,
- addAction:'addToHead'
- );
- // you can save your 'analysis' file to disk! I suggest using float32 for the format
- // These can be read back in using Buffer.read
- // y.write(p++".scpv", "wav", "float32");
- // play your analysis back ... see the playback UGens listed above for more examples.
- s.sync;
- b = Synth(
- defName:"pvplay",
- args:[\out, 0, \recBuf, y, \warpBuf, z, \duration, du],
- target:nil,
- addAction:'addToHead'
- );
- },
- limit:100,
- onFailure:"Failure".postln;
- )
- )
- // stop the synth
- b.free;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement