Last active
November 27, 2025 12:16
-
-
Save 44kwm20/5471871 to your computer and use it in GitHub Desktop.
1つ、もしくは2つ以上のサンプルをテンポによって切り分け、それっぽく分解したりエフェクトをかけたりして再生します。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ////////// | |
| // 説明 | |
| // 1のカッコを実行 > 2にてサンプルのパス、ビートの長さ、音量、確率を入力 > | |
| // 2のカッコを実行 > 3のbpmを設定 > 3のカッコを実行 | |
| // | |
| // - 2について - | |
| //・ループさせたいサンプルについて、ビートの長さは4分音符分を"1"とし計算。4/4一小節分は"4"になります。 | |
| //・ワンショットで鳴らしたいサンプルについて、ビートの長さを"0"にしてください。 | |
| //・確率の部分は「合計して100にする」と言った事は必要ありません。単純に他のサンプルとの比率を記入して下さい。 | |
| // | |
| // ※) 44100Hzでの動作を前提としています。 <- 直したっぽい(2025/11/24) | |
| // SuperCollider 3.14.0(Mac)にて動作確認。 | |
| // | |
| // でもなんでか"Start Recording"でSC内で録音しようとすると、正常に動作しません(謎) | |
| // | |
| ////////// | |
| ( //1 | |
| ( | |
| SynthDef(\pbuf001,{ | |
| arg trg=0,outBus=20,lev=1,pos=0,bnum,rate,sPos,pSftD=0,sel,sLoop; | |
| var mix,buf01,env01,env02,pSft,select,bnumOf; | |
| buf01 = [PlayBuf.ar(1,bnum * 2,rate,trg ,sPos,sLoop) , | |
| PlayBuf.ar(1,(bnum * 2) + 1 ,rate,trg ,sPos,sLoop)]; | |
| pSft = PitchShift.ar(buf01,0.01,pSftD,0,0.004); | |
| select = Select.ar(sel,[buf01,pSft]); | |
| mix = select * lev; | |
| Out.ar(outBus, mix ) | |
| },[\tr]).add | |
| ); | |
| //////////////////////////////////////////// | |
| //////////////////////////////////////////// | |
| ( | |
| SynthDef(\fft01,{ | |
| arg tg,sel=1,wipe,inBus=20,outBuf=30,mFq; | |
| var in,dly,chain,ifft,lfo1,lfo2,dA,freq,selAry,bufsiz,mod01,mod02,in2,seldly; | |
| bufsiz = 2048; | |
| chain = Array.newClear(2); | |
| in = In.ar(inBus,2); | |
| lfo1 = LFTri.kr(0.097, 0, 0.4, 0.5); | |
| lfo2 = LFTri.kr(0.24, 0, -0.5, 0.5); | |
| 2.do({ |i| | |
| chain[i] = FFT(LocalBuf(bufsiz),in[i]); | |
| chain[i] = PV_RandComb(chain[i],wipe, tg); | |
| }); | |
| ifft = IFFT(chain); | |
| ifft = Compander.ar(ifft,ifft,0.6,0.7,1,0.1,0.1); | |
| in2 = DelayN.ar(in,1, bufsiz/s.sampleRate); | |
| mod01 = in2 * SinOsc.ar(mFq).range(0,1); | |
| // mod01 = Compander.ar(mod01,mod01,0.2,0.9,1,0.01,0.01); | |
| mod02 = Latch.ar(in2,Impulse.ar(mFq * 20)); | |
| seldly = DelayN.ar(sel,1, bufsiz/s.sampleRate); | |
| selAry = Select.ar(seldly,[in2,ifft,mod01,mod02]); | |
| Out.ar(outBuf,selAry) | |
| },[\tr]).add | |
| ); | |
| //////////////////////////////////////////// | |
| //////////////////////////////////////////// | |
| ( | |
| SynthDef(\fltbypass,{ | |
| arg inBus = 30,outBus1,outBus2=32; | |
| var in; | |
| in = In.ar(inBus,2); | |
| // Out.ar(outBus1,in); | |
| Out.ar(outBus2,in); | |
| }).add; | |
| SynthDef(\pflt,{ | |
| arg trg=0,inBus=30,outBus=32,sel,envD,fStr,fEnd,gate,sign; | |
| var in,flt,selLst,env; | |
| env = EnvGen.ar( Env([fStr,fStr,fEnd],[0,envD],3 * sign), trg, doneAction:2); | |
| in = In.ar(inBus,2); | |
| flt = Resonz.ar(in, env, 0.7, 0.5); | |
| flt = Compander.ar(flt,flt,0.3,1.0,0.2,0.01,0.01,8).softclip; | |
| // selLst = Select.ar(sel,[in,flt]); | |
| ReplaceOut.ar(outBus,flt) | |
| },[\tr]).add | |
| ); | |
| //////////////////////////////////////////// | |
| //////////////////////////////////////////// | |
| ( | |
| SynthDef(\loopbypass,{ | |
| arg inBus = 32,outBus1=24,outBus2=26; | |
| var in; | |
| in = In.ar(inBus,2); | |
| // Out.ar(outBus1,in); | |
| Out.ar(outBus2,in); | |
| }).add; | |
| SynthDef(\plooper,{ | |
| arg rTg,pTg,gate=1,inBus=32,outBus=26,plsRt; | |
| var in,lBuf,ply,pls,env; | |
| env = EnvGen.ar(Env.adsr(0,0,1,0),gate,doneAction:2); | |
| lBuf = LocalBuf(s.sampleRate*5, 2); lBuf.clear; | |
| in = In.ar(inBus,2); | |
| pls = Impulse.ar(plsRt); | |
| RecordBuf.ar(in, lBuf, 0, 1, 0, 1, 0); | |
| ply = PlayBuf.ar(2,lBuf,1,pls,0,0,0); | |
| ReplaceOut.ar(outBus,ply) | |
| },[\tr,\tr]).add | |
| ); | |
| //////////////////////////////////////////// | |
| //////////////////////////////////////////// | |
| ( | |
| SynthDef(\bballbypass,{ | |
| arg inBus = 26,outBus=28; | |
| var in; | |
| in = In.ar(inBus,2); | |
| // Out.ar(outBus,in); | |
| Out.ar(0,in); | |
| }).add; | |
| SynthDef(\bball,{ | |
| arg gate,dT,dF,dSrt,dEnd,inBus=26,cutDcy,crv; | |
| var in,dly,cut,tig,lBuf; | |
| lBuf = LocalBuf(s.sampleRate ,2);lBuf.clear; | |
| cut = EnvGen.ar( Env.perc(0,cutDcy),doneAction:0); | |
| in = In.ar(inBus,2) * cut; | |
| RecordBuf.ar(in, lBuf, 0, 1, 0, 1, 0); | |
| tig = Impulse.ar( EnvGen.ar( Env([dSrt*dF,dEnd*dF],[dT],crv), doneAction:2) ); | |
| dly = PlayBuf.ar(2, lBuf, 1.0, tig, 0, 0); | |
| // dly = Compander.ar(dly,dly,0.3,0.5,0.7,0.01,0.01); | |
| ReplaceOut.ar (0,dly) | |
| }).add; | |
| ); | |
| //////////////////////////////////////////// | |
| //////////////////////////////////////////// | |
| ( | |
| SynthDef(\rvs01,{ | |
| arg trg,sPos,bTime,inBus = 26,outBus = 26,sel; | |
| var in,ply,selAry; | |
| in = In.ar(inBus,2); | |
| RecordBuf.ar(in,1002,0,loop:1,trigger:trg); | |
| ply = PlayBuf.ar(2,1002,-1,1,sPos,trg); | |
| selAry = Select.ar(sel,[in,ply]); | |
| ReplaceOut.ar(outBus, selAry) | |
| },[\tr]).add | |
| ); | |
| //////////////////////////////////////////// | |
| //////////////////////////////////////////// | |
| ( | |
| ~bStr = Array.newClear(3); | |
| ~bStr[0] = Buffer.alloc(s,s.sampleRate * 10,1,bufnum:1000); | |
| ~bStr[1] = Buffer.alloc(s,s.sampleRate * 10,1,bufnum:1001); | |
| SynthDef(\pstr01,{ | |
| arg inBus=26,outBus,sdur,sMul=2; | |
| var in,lBuf,tg,env,ply,env2,lfn; | |
| env2 = Line.ar(0,0,sdur,doneAction:2); | |
| lfn = LFNoise1.ar(200).range(0.0001,0.01); | |
| in = Array.newClear(2); | |
| lBuf = Array.newClear(2); | |
| ply = Array.newClear(2); | |
| tg = Impulse.ar(100); | |
| env = Line.ar(0,10,10*sMul,doneAction:0); | |
| 2.do({ |i| | |
| in[i] = In.ar(inBus + i,1); | |
| RecordBuf.ar(in[i], ~bStr[i] , 0, 1, 0, 1, 0, 1); | |
| ply[i] = Mix.ar(TGrains.ar(2,tg, ~bStr[i], 1, (env+lfn) ,0.02)); | |
| }); | |
| ReplaceOut.ar(0,ply*6) | |
| }).add | |
| ); | |
| //////////////////////////////////////////////////////////////////////////// | |
| //////////////////////////////////////////////////////////////////////////// | |
| ( | |
| SynthDef(\comp01,{ | |
| var in, in2; | |
| in = In.ar(0,2); | |
| // in = Compander.ar(in,in,0.5,0.6,1,0.01,0.01); | |
| in = Limiter.ar(in,0.95,0.01); | |
| ReplaceOut.ar(0,in) | |
| }).add | |
| ); | |
| //////////////////////////////////////////////////////////////////////////// | |
| //////////////////////////////////////////////////////////////////////////// | |
| f = SoundFile.new; | |
| ~bufinit = { |array| | |
| ~buf = Array.newClear(array.size*2); // バッファー | |
| ~bBeat = Array.new; // 4分音符 | |
| ~bDiv = Array.new; // 16分音符分のサンプル数 | |
| ~bSteps = Array.new; // 16分音符で割った総ステップ数 (4/4の1小節分で16ステップ) | |
| ~bBpm = Array.new; // サンプルのテンポ | |
| ~bProb = Array.new; | |
| ~bLevel = Array.new; | |
| fork{ "Loading sample(s)...".postln; | |
| array.size.do({ |i| var bCn ; bCn = (i * 2); | |
| f.openRead(array[i][0]); | |
| // f.path.post; " ->".post;f.numChannels.postln; | |
| ~bBeat = ~bBeat.add(array[i][1]); | |
| ~bDiv = ~bDiv.add((f.numFrames) / 16.0 / (~bBeat[i] / 4.0) ); | |
| ~bSteps = ~bSteps.add((~bBeat[i]/4.0) * 16.0); | |
| ~bBpm = ~bBpm.add(60000.0 / ((f.numFrames / (f.sampleRate/1000.0))/~bBeat[i]) ); | |
| ~bLevel = ~bLevel.add(array[i][2]); | |
| ~bProb = ~bProb.add(array[i][3]); | |
| if ( ~ bBeat[i] == 0 , {~bDiv[i]= 1 ; ~bSteps[i]= 1 ; ~bBpm[i] = 0;} | |
| ); | |
| if (f.numChannels == 1, | |
| { 2.do({|j| // mono // | |
| ~buf[bCn + j] = Buffer.readChannel(s,f.path,channels:0,bufnum:bCn+j, | |
| action:{|bbb| }) | |
| }); | |
| }, | |
| {2.do({|j| // stereo // | |
| ~buf[bCn + j] = Buffer.readChannel(s,f.path,channels:j,bufnum:bCn+j, | |
| action:{|bbb|}) | |
| }); | |
| }) ; | |
| }) ;s.sync; "Done.".postln} | |
| }; | |
| ) | |
| bbb.normalize | |
| //////////////////////////////////////////////////////////////////////////// | |
| //////////////////////////////////////////////////////////////////////////// | |
| ( //2 | |
| ~buffers = [ //// ["path",beats,amp,prob] , ["path",beats,amp,prob] ... //// | |
| ["/your/audio/sample/path/here_001.aif",4,1,0.7], | |
| ["/your/audio/sample/path/here_002.aif",4,1,0.7], | |
| ["/your/audio/sample/path/here_003.aif",0,1,0.7] // "beats -> 0" means "one-shot sample" | |
| ]; | |
| ~bufinit.value(~buffers); | |
| ) | |
| //// BufferCheck //// | |
| (~buf.postln;~bBeat.postln;~bDiv.postln;~bSteps.postln;~bBpm; ); | |
| //////////////////////////////////////////// | |
| //////////////////////////////////////////// | |
| ( //3 | |
| ~bpm = 160 ; // <-Set BPM | |
| ~sf = 0.00; | |
| ~beatT = 60/~bpm; | |
| ~beatF = ~bpm/60; | |
| TempoClock.default.tempo = ~bpm/60; | |
| ~bStr[2] = Buffer.alloc(s,s.sampleRate * (~beatT * 8),2,bufnum:1002); | |
| ~maxStp = ((~bSteps.maxItem) - 1).asInteger; | |
| ~numbuf = nil; | |
| ~buffers.size.do({|i| | |
| ~numbuf = ~numbuf.add(i); | |
| if (~bBpm[i] == 0 ,{~bBpm[i]=~bpm}; | |
| )}); | |
| ~prob = Pwrand(~numbuf,~bProb.normalizeSum,inf); | |
| ~syn01G = Group.head(s); | |
| ~fftG = Group.after(~syn01G); | |
| ~fltG = Group.after(~fftG); | |
| ~loopG = Group.after(~fltG); | |
| ~rvsG = Group.after(~loopG); | |
| ~ballG = Group.after(~rvsG); | |
| ~compG = Group.after(~ballG); | |
| ~ballfirst = Synth.head(~ballG,\bballbypass); | |
| ~bloopfirst = Synth.head(~loopG,\loopbypass); | |
| ~fltfirst = Synth.head(~fltG,\fltbypass); | |
| ~compS = Synth.head(~compG,\comp01); | |
| ~pB0 = Pseg(Pseq([1,1],1),0.5,\lin); | |
| ~pB1 = Pseg(Pseq([1,2],1),0.5,\lin); | |
| ~pB2 = Pseg(Pseq([1,0.5],1),0.5,\lin); | |
| ~pB3 = Pseg(Pseq([2,1],1),0.5,\lin); | |
| ~pB4 = Pseg(Pseq([0.5,1],1),0.5,\lin); | |
| ~pB5 = Pseg(Pseq([1,4],1),0.5,\lin); | |
| ~pB6 = Pseg(Pseq([1,0.25],1),0.5,\lin); | |
| ~pB = [~pB0,~pB0,~pB0,~pB0,~pB1,~pB2,~pB3,~pB4,~pB5,~pB6]; | |
| ///////////////////////////////////////////////////////////// | |
| ( | |
| Pdef(\prvs,Pmono( | |
| \rvs01, | |
| \group,~rvsG, | |
| \dur,0.25, | |
| \trg,Pseq([1,Pn(\,31)],inf), | |
| \sel,Pwrand([Pn(0,4),Pwrand([1,0],[0.05,0.95],8), Pn(1,16)] ,[80,8,1].normalizeSum,inf) | |
| )) | |
| ); | |
| ///////////////////////////////////////////////////////////// | |
| ( | |
| Pdef(\pflt01,Pbind( | |
| \instrument , \pflt, | |
| \group,~fltG, | |
| \addAction,1, | |
| \dur,Pwhite(1,4,inf), | |
| \trg, Pseq([1],inf), | |
| \freq, Pwrand([1,\],[1,15].normalizeSum,inf), | |
| \envD, ~beatT * Pkey(\dur), | |
| \fStr, Plprand(50,10000,inf), | |
| \fEnd, Plprand(50,10000,inf), | |
| \sign , Pif (Pkey(\fStr) > Pkey(\fEnd) , -1,1) | |
| )) | |
| ); | |
| ///////////////////////////////////////////////////////////// | |
| ( | |
| Pdef(\pball,Pbind( | |
| \freq,\, | |
| \onn , Pwrand([1,2,0],[2, 2 , 10].normalizeSum,inf), | |
| \dur , Pwhite(4,8,inf).collect({|evt| ~balldur = evt}), | |
| \doit , Pswitch ( [0, | |
| Pfuncn({ | |
| var sign,srt,end,cv; | |
| srt = ([1,2,4,32,64].choose); | |
| end = if( srt > 31 , {[1,2,4].choose},{[32,64,128].choose}); | |
| if ( (srt - end) > 0 , {sign = -1},{sign = 1}); | |
| Synth.tail(~ballG,\bball,[\dT,~beatT*[1,2,4].choose,\dF,~beatF,\dSrt,srt,\dEnd,end,\cutDcy,[0.11,4].choose, | |
| \crv,4*sign]) | |
| },1) | |
| , | |
| Pfuncn({ | |
| var sign,srt,end,cv; | |
| srt = ([1,2,4,32,64].choose); | |
| Synth.tail(~ballG,\pstr01,[\sdur,~beatT*[1,2,4,~balldur].choose,\sMul,[2,4].choose]) | |
| },1 | |
| ) ],Pkey(\onn)) | |
| )) | |
| ); | |
| ///////////////////////////////////////////////////////////// | |
| ( | |
| Pdef(\pfft01,Pmono( | |
| \fft01, | |
| \group , ~fftG, | |
| \inBus , 20, | |
| \outBus ,30, | |
| \tg , 1, | |
| \sel, Pwrand([0,1,2,3],[40,3,2,6].normalizeSum,inf), | |
| \mFq , Plprand(10,1000,inf), | |
| \wipe , Pwhite(0.5,0.90,inf), | |
| \dur , Prand([1,2,0.5],inf) | |
| )) | |
| ); | |
| ///////////////////////////////////////////////////////////// | |
| ( | |
| Pdef(\ploop,Pbind( | |
| \instrument,\plooper, | |
| \group, ~loopG, | |
| \addAction,1, | |
| // \plsRt, ~beatF * Prand([3,2.5,2,0.33334,0.5,0.25],inf), | |
| \freq,Pwrand([1,\],[1,20].normalizeSum,inf), | |
| \legato,1, | |
| \dur,Prand([1,4],inf), | |
| \plsRt, Pif ( Pkey(\dur) < 2 , ~beatF * Prand([2,2,666666666,3,4],inf), | |
| ~beatF * Prand([1,2,1.5,1.3333333334,],inf)) | |
| )) | |
| ); | |
| ///////////////////////////////////////////////////////////// | |
| ( | |
| Pdef(\p001, | |
| Pchain( | |
| Pbind( | |
| \group , ~syn01G, | |
| \dur,Pwrand([Pseq([0.25+~sf,0.5,0.25-~sf],1),0.5,Pseq([0.25+~sf,0.25-~sf],1),Pn(0.125,4),Pn(0.0625,8)],[5,3,10,1,1].normalizeSum,inf), | |
| // \dur,Pseq([(0.25 + ~sf),(0.25 - ~sf)],inf), | |
| \pBsel , Pstep(Pwhite(0,~pB.size,inf),0.5).collect({|evt| ~pbselect = evt}), | |
| \rate , Pn ( Pfunc{~lastrate} * Pif( Pkey(\dur ) < 0.25 , | |
| Pswitch(~pB, Pfunc{~pbselect}) | |
| ,1),inf) | |
| ), | |
| Pstep( | |
| Pmono( | |
| \pbuf001, | |
| \outBus,20, | |
| \bnum,~prob, | |
| \lev, Pswitch(~bLevel, Pkey(\bnum) ), | |
| \oneShot , Pswitch(~bBeat,Pkey(\bnum)).collect({|evt| ~oneS = evt}), | |
| \sLoop , Pif( Pkey(\oneShot) < 1 ,0,1), | |
| // \sPosSet , Pwhite(0,~maxStp,inf) % Pswitch(~bSteps,Pkey(\bnum)), | |
| \sPosSet , ((Pseries(0,1,inf) + | |
| Pwrand([0,Pwhite(-2,2,1),Pwhite(-5,5,2),Pn(-3,3)],[20,1,1,1].normalizeSum,inf)) % | |
| Pswitch(~bSteps,Pkey(\bnum))).collect({|evn| ~prepos = evn}), | |
| \sPosSet, Pif ( Pfunc({ (~prepos.asInteger).even}) , Pkey(\sPosSet), Pkey(\sPosSet)+~sf ), | |
| \sPos, Pif( Pkey(\oneShot) < 1, 0 , | |
| Pswitch(~bDiv,Pkey(\bnum))* Pkey(\sPosSet) ) , | |
| \rate,( Pif( Pkey(\oneShot) < 1, 1 , | |
| ((~bpm/ Pswitch(~bBpm,Pkey(\bnum))) * Pwrand([1,-1],[0.85,0.15],inf)))).collect({|evt| ~lastrate = evt}), | |
| \trg,1, | |
| \pLen, (Pswitch(~bDiv,Pkey(\bnum))* 2 ), | |
| \pSftD,Prand([2,4,0.25,0.5],inf), | |
| \sel, Pwrand([0,1],[20,1].normalizeSum,inf), | |
| // -- debug -- | |
| // \sPos, Pswitch(~bDiv,Pkey(\bnum))* (Pseries(0,1,inf)%16) , | |
| // \rate,(~bpm/ Pswitch(~bBpm,Pkey(\bnum))), | |
| // \sel, 0, | |
| // \pos,Pwrand([0,Pwhite(-1.0,1.0,1)],[0.7,0.3],inf) | |
| \pos,0 | |
| ),Pseq([0.25+~sf,0.25-~sf],inf) | |
| ) | |
| ) | |
| ) | |
| ); | |
| ~fftoffs = (( 2048 / s.sampleRate) / ~beatT).neg; | |
| Pdef(\p001).play(quant:[4,~fftoffs,0.2]); | |
| Pdef(\pfft01).play(quant:[4,~fftoffs,0.2]); | |
| Pdef(\ploop).play(quant:[4,0,0.2]); | |
| Pdef(\prvs).play(quant:[4,0,0.1]); | |
| Pdef(\pball).play(quant:[4,0,0.1]); | |
| Pdef(\pflt01).play(quant:[4,0,0.1]); | |
| ) | |
| //////////////////////////////////////////////////////////////////////////////////////// | |
| //////////////////////////////////////////////////////////////////////////////////////// | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment