[livecode] last night's code

From: Nick Collins <nc272_at_cam.ac.uk>
Date: Tue, 08 Feb 2005 17:34:04 +0000

great to see you all and play in Berlin. I enclose last night's code (C and
SuperCollider stuff) as a fond memory of our time together. Typos and
unnecessary variables and other fumblings caused by your distracting me
with such engaging activity.

best,
N

//C for the Breakcore plug-in

#include "SC_PlugIn.h"

static InterfaceTable *ft;

struct Breakcore : public Unit
{
        uint32 mBufNum,mBufSize;
        float * mBuf;
        int captureon,captureneeds,repeatpos,capturepos;
        float m_prevtrig;
        int duration;
};



extern "C" {

        void Breakcore_next_k(Breakcore *unit, int inNumSamples);
        void Breakcore_Ctor(Breakcore* unit);
}


void Breakcore_Ctor( Breakcore* unit ) {
        
        SETCALC(Breakcore_next_k);
        
        World *world = unit->mWorld;

        uint32 bufnum = (uint32)ZIN0(0);
        if (bufnum >= world->mNumSndBufs) bufnum = 0;
        unit->mBufNum=bufnum;
        
        printf("Breacore activated with bufnum %d \n",bufnum);
        
        SndBuf *buf = world->mSndBufs + bufnum;
        
        unit->mBufSize = buf->samples;
        
        unit->mBuf = buf->data;
        
        unit->captureon= 0;
        unit->captureneeds= 1000;
        unit->capturepos= 0;
        unit->repeatpos=0;
        unit->m_prevtrig=0;
        
        unit->duration=1000;
}


//bufnum, 0 capturein 1, capturetrigger 2, duration of repeat 3, ampdropout
4

void Breakcore_next_k( Breakcore *unit, int inNumSamples ) {
        
        float *out = ZOUT(0);
        
        float curtrig= ZIN0(2);
        int duration= unit->duration; //(int)ZIN0(3);
        //float ampdropout= (float)ZIN0(3);
        float * in = ZIN(1);
        
        //printf("duration %d curtrig %f\n",duration, curtrig);
        
        
        int bufsize=unit->mBufSize;
        
        float * data= unit->mBuf;
        


        if (unit->m_prevtrig <= 0.f && curtrig > 0.f){
                
                //printf("capture \n");
        
                
                unit->captureon=1;
                unit->duration=(int)ZIN0(3);
                duration= unit->duration;
                unit->captureneeds=duration; //can't be less than 64
                unit->capturepos=0;
                unit->repeatpos=0;
        }
        
        int captureon,captureneeds,repeatpos,capturepos;

        captureon= unit->captureon;
        captureneeds= unit->captureneeds;
        capturepos= unit->capturepos;
        repeatpos= unit->repeatpos;

        for (int j=0; j<inNumSamples;++j)
        {

                if(captureon==1) {
                
                        data[capturepos]=in[j];
                
                        capturepos++;
                        
                        if(capturepos==captureneeds) {
                        unit->capturepos=0;
                        unit->captureon=0;
                        captureon=0;
                        }
                };
                
                
                ZXP(out)=data[repeatpos];
                
                repeatpos= (repeatpos+1)%captureneeds;
                
        }
        
        unit->capturepos= capturepos;
        unit->repeatpos= repeatpos;

        unit->m_prevtrig = curtrig;

}


extern "C" void load(InterfaceTable *inTable) {
        
        ft = inTable;
        
        DefineSimpleCantAliasUnit(Breakcore);
        
}




//class:

//bufnum, 0 capturein 1, capturetrigger 2, duration of repeat 3, ampdropout
4
Breakcore : UGen
{
        *ar { arg bufnum=0, capturein, capturetrigger, duration=0.1, ampdropout;
                ^this.multiNew('audio', bufnum, capturein, capturetrigger, duration,
ampdropout);
        }
}

//help:


Breakcore breakcore simulator

Breakcore.ar(bufnum, capturein, capturetrigger, duration, ampdropout)

This is noisy


//duration in samples

(60/183)*0.25*44100

b = Buffer.alloc(s,44100);

~breakfilenames= Array.fill(9,{arg i; var str;
str=("sounds/SCsamp/breaks/hiphop/hop"++(i+1).asString);

if((i==3) || (i==5),{str=str++".aif"});
str
});

~breakbeatlengths= [4,4,8,4,8,4,4,8,8];

~breaks= Array.fill(~breakbeatlengths.size,{arg i;
Buffer.read(s,~breakfilenames[i])});


(
SynthDef("help-Breakcore",{ arg out=0, bufnum=0, target=0;
var playbuf;

playbuf=PlayBuf(1,target, loop:1)

        Out.ar(out,
                 Breakcore.ar(bufnum, In.ar(8)*0.3,
Impulse.kr(4),5512,0)*Line.kr(1,0,10,doneAction:2)
        )
}).play(s,[\bufnum,b.bufnum, breaks[0].bufnum]);
)



(
SynthDef("help-Breakcore",{ arg out=0, bufnum=0, target=0;
var playbuf;

playbuf=PlayBuf.ar(1,target,MouseX.kr(1,2), loop:1);
//AudioIn.ar(1,0.1)
        Out.ar(out,
                 Breakcore.ar(bufnum,playbuf ,
Impulse.kr(LFNoise0.kr(4,10,12)),LFNoise0.kr(8,1900,2000),0) )
}).play(s,[\bufnum,b.bufnum, \target, ~breaks[2].bufnum]);
)



(60/180)*44100*0.25


3614/4
Received on Tue Feb 08 2005 - 17:35:33 GMT

This archive was generated by hypermail 2.4.0 : Sun Aug 20 2023 - 16:02:23 BST