SHARE
TWEET

Untitled

a guest Aug 10th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (
  2. s.waitForBoot(
  3.     onComplete: {
  4.         var sf;
  5.         var du;
  6.         var z, y;
  7.         var a,b,h,f,p;
  8.        
  9.         var factor = 40.0;
  10.        
  11.         SynthDef(
  12.             name:"pvrec",
  13.             ugenGraphFunc: {
  14.                 arg recBuf=1, soundBufnum=2;
  15.                 var in, chain, bufnum;
  16.                 bufnum = LocalBuf.new(1024);
  17.                 Line.kr(
  18.                     start:1,
  19.                     end:1,
  20.                     dur:BufDur.kr(soundBufnum),
  21.                     mul:1.0,
  22.                     add:0.0,
  23.                     doneAction: 2
  24.                 );
  25.                 in = PlayBuf.ar(
  26.                     numChannels: 1,
  27.                     bufnum: soundBufnum,
  28.                     rate:BufRateScale.kr(soundBufnum),
  29.                     trigger:1,
  30.                     startPos:0,
  31.                     loop: 0,
  32.                     doneAction:0
  33.                 );
  34.                 // note the window type and overlaps... this is important for resynth parameters
  35.                 // chain = FFT(buffer:bufnum, in: in, hop: 0.25, wintype:1,active:1,winsize:0);
  36.                 chain = FFT(buffer:bufnum, in:in, hop:0.25, wintype:1,active:1,winsize:0);
  37.                 // chain = PV_RecordBuf(buffer: chain, recbuf:recBuf, offset:0, run:1, loop:0, hop:0.25, wintype:1);
  38.                 chain = PV_RecordBuf(buffer:chain, recbuf:recBuf, offset:0, run:1, loop:0, hop:0.25, wintype:1)
  39.                 // no ouput ... simply save the analysis to recBuf
  40.             },
  41.             rates:nil,
  42.             prependArgs:nil,
  43.             variants:nil,
  44.             metadata:nil
  45.         ).send(s);
  46.        
  47.         SynthDef(
  48.             name: "pvplay",
  49.             ugenGraphFunc: {
  50.                 arg out=0, recBuf=1, warpBuf = 2, duration = 10.0;
  51.                 var in, chain, bufnum, point, warp;
  52.                 bufnum = LocalBuf.new(numFrames:1024,numChannels:1);
  53.                 // point = MouseX.kr(minval:0.0, maxval:1.0, warp:0, lag:0.2);
  54.                 point = Line.kr(start:0.0, end:1.0, dur: duration * factor,mul:1.0,add:0.0,doneAction:0);
  55.                 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);
  56.                 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);
  57.                 // 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)
  58.                 chain = PV_BufRd(buffer:bufnum, playbuf:recBuf, point:point);
  59.                 Out.ar(bus:out, channelsArray: (IFFT(buffer:chain, wintype:1, winsize:0).dup + warp) * 0.5);
  60.             },
  61.             rates:nil,
  62.             prependArgs:nil,
  63.             variants:nil,
  64.             metadata:nil
  65.         ).send(s);
  66.        
  67.         s.sync;
  68.        
  69.         // path to a sound file here
  70.         p = "./toto_africa.wav".standardizePath;
  71.         // the frame size for the analysis - experiment with other sizes (powers of 2)
  72.         f = 1024;
  73.         // the hop size
  74.         h = 0.25;
  75.         // get some info about the file
  76.         sf = SoundFile.new(p);
  77.         sf.openRead;
  78.         du = sf.duration;
  79.         sf.close;
  80.         // allocate memory to store FFT data to... SimpleNumber.calcPVRecSize(frameSize, hop) will return
  81.         // the appropriate number of samples needed for the buffer
  82.         y = Buffer.alloc(
  83.             server:s,
  84.             numFrames:sf.duration.calcPVRecSize(
  85.                 frameSize: f,
  86.                 hop: h,
  87.                 sampleRate:nil
  88.             ),
  89.             numChannels:1,
  90.             completionMessage:nil,
  91.             bufnum:nil
  92.         );
  93.         // allocate the soundfile you want to analyze
  94.         // z = Buffer.read(s, p);
  95.         z = Buffer.readChannel(
  96.             server:s,
  97.             path:p,
  98.             startFrame:0,
  99.             numFrames:-1,
  100.             channels: 1,
  101.             action:nil,
  102.             bufnum:nil
  103.         );
  104.        
  105.         s.sync;
  106.        
  107.         // this does the analysis and saves it to buffer 1... frees itself when done
  108.         a = Synth(
  109.             defName:"pvrec",
  110.             args:[\recBuf, y, \soundBufnum, z],
  111.             target:nil,
  112.             addAction:'addToHead'
  113.         );
  114.         // you can save your 'analysis' file to disk! I suggest using float32 for the format
  115.         // These can be read back in using Buffer.read
  116.         // y.write(p++".scpv", "wav", "float32");
  117.         // play your analysis back ... see the playback UGens listed above for more examples.
  118.         s.sync;
  119.         b = Synth(
  120.             defName:"pvplay",
  121.             args:[\out, 0, \recBuf, y, \warpBuf, z, \duration, du],
  122.             target:nil,
  123.             addAction:'addToHead'
  124.         );
  125.     },
  126.     limit:100,
  127.     onFailure:"Failure".postln;
  128. )
  129. )
  130.  
  131. // stop the synth
  132. b.free;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top