Esempio n. 1
0
void PluginFx::process(float *work, int sampleSize) {
    if ( uiGain != 1 ) {
        for(int i=0; i < sampleSize; i++ )
            work[i] *= uiGain;
    }
    
    // don't apply the LPF if the cutoff is to maximum
    if ( uiCutoff == 1 )
        return;
    
    if ( uiCutoff != pCutoff || uiReso != pReso ) {
        rReso = (0.991-logsc(1-uiReso,0,0.991));
        R24 = 3.5 * rReso;
        
        float cutoffNorm = logsc(uiCutoff,60,19000);
        rCutoff = (float)tan(cutoffNorm * sampleRateInv * juce::float_Pi);
            
        pCutoff = uiCutoff;
        pReso = uiReso;
        
        R = 1 - rReso;
    }
        
    // THIS IS MY FAVORITE 4POLE OBXd filter
        
    // maybe smooth this value
    float g = rCutoff;
    float lpc = g / (1 + g);
    
    for(int i=0; i < sampleSize; i++ ) {
        float s = work[i];
        s = s - 0.45*tptlpupw(c,s,15,sampleRateInv);
        s = tptpc(d,s,bright);
        
        float y0 = NR24(s,g,lpc);
        
        //first low pass in cascade
        double v = (y0 - s1) * lpc;
        double res = v + s1;
        s1 = res + v;
        
        //damping
        s1 =atan(s1*rcor24)*rcor24Inv;
        float y1= res;
        float y2 = tptpc(s2,y1,g);
        float y3 = tptpc(s3,y2,g);
        float y4 = tptpc(s4,y3,g);
        float mc;
    
        switch(mmch) {
            case 0:
                mc = ((1 - mmt) * y4 + (mmt) * y3);
                break;
            case 1:
                mc = ((1 - mmt) * y3 + (mmt) * y2);
                break;
            case 2:
                mc = ((1 - mmt) * y2 + (mmt) * y1);
                break;
            case 3:
                mc = y1;
                break;
        }
        
        //half volume comp
        work[i] = mc * (1 + R24 * 0.45);
    }
}
int main (int argc, char *argv[]){

        slave_context context;
        char *str = (char *) malloc(sizeof(char) * 128);

        //-----------------------------------------------
        // RECUPERO LE INFORMAZIONI DEL PROCESSO
        //-----------------------------------------------
        slave_context_init(&context, argv);

        //-----------------------------------------------
        //      CICLO PER SVOLGERE IL COMANDO
        //-----------------------------------------------
        while(1){

                //-----------------------------------------------
                //      INCREMENTO I PROCESSI LIBERI
                //-----------------------------------------------
                sem_signal(SEMPROCFREE, context.sync_id.semid_sys  );

                //-----------------------------------------------
                //      SEGNALO DI AVER FINITO IL LAVORO PRECEDENTE
                //-----------------------------------------------
                sem_signal(context.id + 1,context.sync_id.semid_finish  );

                //-----------------------------------------------
                //      ASPETTO DI RICEVERE IL SEGNALE START
                //-----------------------------------------------
                sem_wait(context.id + 1, context.sync_id.semid_start  );

                // decremento il semaforo dei processi liberi
                sem_wait(SEMPROCFREE, context.sync_id.semid_sys);

                logsc(context.id, "Avvio...........OK\n");

                //-----------------------------------------------
                //      IMPOSTO LA FLAG DEL PROCESSO OCCUPATO
                //-----------------------------------------------
                sem_wait(MUTEXRES, context.sync_id.semid_sys);
                        context.shm_status[context.id].status = 0;
                sem_signal(MUTEXRES, context.sync_id.semid_sys);

                //-----------------------------------------------
                //      MEMORIZZO GLI OPERANDI PER IL CALCOLO
                //-----------------------------------------------
                read_operazione(&context);

                //-----------------------------------------------
                //      SEGNALO CHE MI SONO ARRIVATI I DATI
                //-----------------------------------------------
                sem_signal(SEMDATARECEIVE, context.sync_id.semid_sys );

                //-----------------------------------------------
                //      CONTROLLO CHE NON SIA IL SEGNALE KILL
                //-----------------------------------------------
                if(context.operazione_singola.kill == 'K'){
                        shm_detach(context.shm_operazione);
                        shm_detach(context.shm_status);
                        logsc(context.id, "Termino.........OK\n");
                        exit(0);
                }
                sprintf(str, "Dati arrivati...%d %c %d\n", context.operazione_singola.num1, context.operazione_singola.simbolo, context.operazione_singola.num2);
                logsc(context.id, str);

                //-----------------------------------------------
                //      CALCOLO IL RISULTATO
                //-----------------------------------------------
                calcolo_and_save_operazione(&context);

                //-----------------------------------------------
                //      SCRIVO I RISULTATI NELLA MEMORIA CONDIVISA
                //-----------------------------------------------
                sem_wait(MUTEXRES, context.sync_id.semid_sys  );
                        context.shm_status[context.id].status = 1;
                        context.shm_status[context.id].res = context.operazione_singola.res;
                        context.shm_status[context.id].pos = context.operazione_singola.pos;
                sem_signal(MUTEXRES, context.sync_id.semid_sys );
        }
        exit(0);
}// fine main