Example #1
0
Chorus::Chorus (Parameters *param, float * efxoutl_, float * efxoutr_)
	:lfo(param), Effect(WetDry)
{
	this->param = param;
    efxoutl = efxoutl_;
    efxoutr = efxoutr_;
    dlk = 0;
    drk = 0;
    maxdelay = lrintf (MAX_CHORUS_DELAY / 1000.0 * SAMPLE_RATE);
    delayl = new float[maxdelay+1];
    delayr = new float[maxdelay+1];


    float tmp = 0.08f;
    ldelay = new delayline(param,tmp, 2);
    rdelay = new delayline(param,tmp, 2);
    ldelay -> set_averaging(0.005f);
    rdelay -> set_averaging(0.005f);
    ldelay->set_mix( 0.5f );
    rdelay->set_mix( 0.5f );

    oldr = 0.0f;
    oldl = 0.0f;
    awesome_mode = 0;

    lfo.effectlfoout (&lfol, &lfor);
    dl2 = getdelay (lfol);
    dr2 = getdelay (lfor);

	Ppreset = 0;
    setpreset (0,Ppreset);

    cleanup ();
};
Example #2
0
Chorus::Chorus (float * efxoutl_, float * efxoutr_)
{
    efxoutl = efxoutl_;
    efxoutr = efxoutr_;
    dlk = 0;
    drk = 0;
    maxdelay = lrintf (MAX_CHORUS_DELAY / 1000.0 * SAMPLE_RATE);
    delayl = new float[maxdelay];
    delayr = new float[maxdelay];

    Ppreset = 0;
    setpreset (0,Ppreset);

    float tmp = 0.08f;
    ldelay = new delayline(tmp, 2);
    rdelay = new delayline(tmp, 2);
    ldelay -> set_averaging(0.005f);
    rdelay -> set_averaging(0.005f);
    ldelay->set_mix( 0.5f );
    rdelay->set_mix( 0.5f );

    oldr = 0.0f;
    oldl = 0.0f;
    awesome_mode = 0;

    lfo.effectlfoout (&lfol, &lfor);
    dl2 = getdelay (lfol);
    dr2 = getdelay (lfor);
    cleanup ();
};
Example #3
0
extern double critical_delay(lofig_list* lofig)
{
    losig_list* losig;
    char* signame;

    losig=critical_output(lofig);

    if (!losig->NAMECHAIN) {
        fprintf(stderr,"critical_delay: no losig name\n");
        autexit(1);
    }
    signame=losig->NAMECHAIN->DATA;

    if (losig->TYPE==EXTERNAL) return getdelay(output_name(signame));
    return getdelay(signame);
}
Example #4
0
Chorus::Chorus (float * efxoutl_, float * efxoutr_)
{
  efxoutl = efxoutl_;
  efxoutr = efxoutr_;
  dlk = 0;
  drk = 0;
  maxdelay = lrintf (MAX_CHORUS_DELAY / 1000.0 * SAMPLE_RATE);
  delayl = new float[maxdelay];
  delayr = new float[maxdelay];

  Ppreset = 0;
  setpreset (0,Ppreset);

  lfo.effectlfoout (&lfol, &lfor);
  dl2 = getdelay (lfol);
  dr2 = getdelay (lfor);
  cleanup ();
};
Example #5
0
extern losig_list* critical_output(lofig_list* lofig)
{
    double delay, max_delay=-1;
    losig_list* output=NULL, *losig;
    char* signame;

    for (losig=lofig->LOSIG; losig; losig=losig->NEXT) {
        if (!losig->NAMECHAIN) {
            fprintf(stderr,"critical_output: no losig name\n");
            autexit(1);
        }
        signame=losig->NAMECHAIN->DATA;
        if (losig->TYPE==EXTERNAL) delay=getdelay(output_name(signame));
        else delay=getdelay(signame);
        if (delay>max_delay) {
            max_delay=delay;
            output=losig;
        }
    }

    return output;
}
Example #6
0
File: schedbench.c Project: 8l/rose
int main (int argv, char **argc)
{
 

#pragma omp parallel
  { 
#pragma omp master 
    {
  nthreads = omp_get_num_threads(); 
    }
  } 
 
  printf("Running OpenMP benchmark on %d thread(s)\n", nthreads); 

  /* TUNE LENGTH OF LOOP BODY */ 
  getdelay(); 
  itersperthr = 1204; /*change from 128 to 256 for more test on guided,Liao*/
  innerreps = 1000;

  /* GENERATE REFERENCE TIME */ 
  refer();   

  /* TEST STATIC */ 
  teststatic(); 

  /* TEST STATIC,n */
  cksz = 1;
  while (cksz <= itersperthr){
    teststaticn();
    cksz *= 2;    
  }

  /* TEST DYNAMIC,n */

  cksz = 1;
  while (cksz <= itersperthr){
    testdynamicn();
    cksz *= 2;    
  }

  /* TEST GUIDED,n */
  cksz = 1;
  while (cksz <= itersperthr*2/nthreads){ /*increase cksz*/
    testguidedn();
    cksz *= 2;    
  }
  
}
Example #7
0
extern void save_xsch(FILE* xsch_stream, lofig_list* lofig, ptype_list* long_path, int color_mode)
{
   long color;
   ptype_list* ptype, *ptype2=NULL;
   float delay=0, delay_out=0;
   char mes[1024];
   char* signame = NULL;
   locon_list* locon;
   losig_list* losig;
   float gradient=1;
   int count;
   loins_list* loins;
   char *source, *dest=NULL, *last_sig;
   chain_list* chain, *loinschain=NULL;
   chain_list* lofigchain;
   losig_list* losig_aux;

   /*build gradient*/
   if (long_path && color_mode==XSCH_GRADIENT) {
      /*get time of last entry*/
      count=1;
      for (ptype=long_path; ptype->NEXT; ptype=ptype->NEXT) count++;
      
      if (!ptype->DATA) {
         fprintf(stderr,"save_xsch: compute error\n");
         exit(1);
      }
      delay=ptype->TYPE;
      gradient=delay/((float)XSCH_COLOR_MAX);
   }
   
   /*color for signals*/
   for (losig=lofig->LOSIG; losig; losig=losig->NEXT) {

      if (!losig->NAMECHAIN || !losig->NAMECHAIN->DATA) {
         fprintf(stderr,"save_xsch: no name for signal\n");
         exit(1);
      }
      signame=losig->NAMECHAIN->DATA;
      
      if (isvdd(signame) || isvss(signame)) continue;
      
      if (losig->TYPE==EXTERNAL) {
         /*search external output*/
         ptype=getptype(losig->USER,LOFIGCHAIN);
         for (lofigchain=ptype->DATA; lofigchain; lofigchain=lofigchain->NEXT) {
            locon=lofigchain->DATA;
            if (locon->TYPE==EXTERNAL && locon->DIRECTION!=IN) break;
         }
         if (lofigchain) delay=getdelay(output_name(signame));
         else delay=getdelay(signame);
      }   
      else delay=getdelay(signame);
      
      switch (color_mode) {
      case XSCH_GRADIENT: color=gradient_color(delay,gradient); break;
      case XSCH_CRITICAL_PATH: default: color=XSCH_NEUTRAL_COLOR; break;
      }
      
      flush_losig(xsch_stream, signame, color, delay, losig->TYPE);
      
   }
   
   
   /*color for instances*/
   for (loins=lofig->LOINS; loins; loins=loins->NEXT) {
      /*search signal output*/
      for (locon=loins->LOCON; locon; locon=locon->NEXT) {
         if (locon->DIRECTION==UNKNOWN) {
            fprintf(stderr,"BEH: 'linkage %s' in figure '%s' isn't accepted\n",
            locon->NAME,loins->INSNAME);
            exit(1);
         }
         if (locon->DIRECTION==OUT || locon->DIRECTION==INOUT 
           || locon->DIRECTION==TRISTATE || locon->DIRECTION==TRANSCV) break;
      }
      if (!locon) {
         fprintf(stderr,"save_xsch: no output found for '%s'\n",loins->INSNAME);
         exit(1);
      }
      losig=locon->SIG;
      signame=losig->NAMECHAIN->DATA;
      
      delay=getdelay(loins->INSNAME);
     
      switch (color_mode) {
      case XSCH_GRADIENT: color=gradient_color(delay,gradient); break;
      case XSCH_CRITICAL_PATH: default:
         /*is instance in critical path?*/
         for (ptype=long_path; ptype; ptype=ptype->NEXT) {
            if ((char*)ptype->DATA!=signame) continue;
          /*if output and input signals belong to critical path, then instance belongs*/
            for (locon=loins->LOCON; locon; locon=locon->NEXT) {
               if (locon->DIRECTION==OUT || locon->DIRECTION==TRISTATE) continue;
               losig_aux=locon->SIG;
               /*is signal in critical path?*/
               for (ptype2=long_path; ptype2; ptype2=ptype2->NEXT) {
                  if ((char*)ptype2->DATA==losig_aux->NAMECHAIN->DATA) break;
               }
               if (ptype2) break;
            }
            ptype=ptype2;  /*found?*/
            break;
         }
         
         /*build critical path list*/
         if (ptype) loinschain=addchain(loinschain,loins);
     
         if (ptype) color=XSCH_RED_COLOR;
         else color=XSCH_NEUTRAL_COLOR;
      }
      flush_loins(xsch_stream, loins->INSNAME, color, delay);
      
   }
   

   /*color for connectors*/
   for (locon=lofig->LOCON; locon; locon=locon->NEXT) {

      if (isvdd(locon->NAME) || isvss(locon->NAME)) continue;
      
      switch (locon->DIRECTION) {
      case IN: 
         delay_out=getdelay(locon->NAME);
         sprintf(mes, "%d ps",(int)delay_out);
         break;
      case OUT: case TRISTATE: 
         delay_out=getdelay(output_name(locon->NAME));
         sprintf(mes, "%d ps",(int)delay_out);
         break;
      case INOUT: case TRANSCV: 
         delay=getdelay(locon->NAME);
         delay_out=getdelay(output_name(locon->NAME));
         sprintf(mes, "%d ps on input; %d ps on output",(int)delay,(int)delay_out);
         break;
      }

      switch (color_mode) {
      case XSCH_GRADIENT: color=gradient_color(delay_out,gradient); break;
      case XSCH_CRITICAL_PATH: default:
         /* seek if signal is in a long path*/
         for (ptype=long_path; ptype; ptype=ptype->NEXT) {
            if ((char*)ptype->DATA==locon->NAME) break;
         }
   
         if (ptype) color=XSCH_RED_COLOR;
         else color=XSCH_NEUTRAL_COLOR;
      }
      flush_stream_special(xsch_stream, locon->NAME, color, mes);
   }  


   /*critical path*/
   if (loinschain && long_path && color_mode==XSCH_CRITICAL_PATH) {
      source=NULL;
      last_sig=NULL;
      for (ptype=long_path; ptype; ptype=ptype->NEXT) {
         signame=ptype->DATA;
         for (chain=loinschain; chain; chain=chain->NEXT) {
            loins=chain->DATA;
            /*search signal output*/
            for (locon=loins->LOCON; locon; locon=locon->NEXT) {
               if (locon->DIRECTION==OUT || locon->DIRECTION==INOUT 
                || locon->DIRECTION==TRISTATE || locon->DIRECTION==TRANSCV) {
                  losig=locon->SIG;
                  if (losig->NAMECHAIN->DATA==signame) {
                     dest=loins->INSNAME;
                     break;
                  }
               }   
            }
            if (locon) break;
         }  
         /*if no instance found it is external connector. it has the same name than signal*/
         if (!locon) dest=signame;
      
         if (source)
            flush_path(xsch_stream, source, last_sig, dest, XSCH_RED_COLOR, delay, INTERNAL);
      
         source=dest;
         last_sig=signame;
      }
      
      /*for last signal search output*/
      if (losig) {
         ptype=getptype(losig->USER,LOFIGCHAIN);
         for (chain=ptype->DATA; chain; chain=chain->NEXT) {
            locon=chain->DATA;
            /*port of circuit*/
            if (locon->TYPE==EXTERNAL) {dest=locon->NAME; break;}
            loins=locon->ROOT;
            /*register input if no error*/
            if (locon->DIRECTION==IN || locon->DIRECTION==INOUT || locon->DIRECTION==TRANSCV)
            {dest=loins->INSNAME; break;}
         }
         flush_path(xsch_stream, source, signame, dest, XSCH_RED_COLOR, delay, losig->TYPE);
      }
      
   }

   freechain(loinschain);
}
static ptype_list* search_long_path(loins_list* loins, befig_list* befig)
{
   loins_list* loins_aux, *best_loins=NULL;
   locon_list* locon;
   losig_list* losig, *best_losig=NULL;
   char* signame;
   chain_list* loconchain;
   ptype_list* ptype, *ret;
   float max_delay=-1, delay;
   bereg_list* bereg;
   biabl_list* biabl;

   if (!loins) {
      fprintf(stderr,"search_long_path: NULL pointer\n");
      exit(1);
   }
   
   /*seek the latest input in cell*/
   for (locon=loins->LOCON; locon; locon=locon->NEXT) {
      /*only inputs*/
      if (locon->DIRECTION==OUT || locon->DIRECTION==TRISTATE
       || isvss(locon->NAME) || isvdd(locon->NAME)) continue;
      losig=locon->SIG;
      if (!losig->NAMECHAIN) {
         fprintf(stderr,"search_long_path: NULL pointer\n");
         exit(1);
      }
      signame=(char*) losig->NAMECHAIN->DATA;
      delay=getdelay(signame);
      if (delay>max_delay) {
         best_losig=losig;
         max_delay=delay;
      }   
   }
   
   /*no input found  -> constant*/
   if (!best_losig) return NULL;
   
   losig=best_losig;
   ptype=getptype(losig->USER,LOFIGCHAIN);
   if (!ptype || !ptype->DATA) {
      fprintf(stderr,"search_long_path: NULL pointer\n");
      exit(1);
   }
   signame=(char*) losig->NAMECHAIN->DATA;
   
   ret=addptype(NULL, (int) max_delay, signame);

   /*stop at leaves or flip-flop */
   if (losig->TYPE==EXTERNAL) return ret;
   for (bereg=befig->BEREG; bereg; bereg=bereg->NEXT) {
      if (bereg->NAME!=signame) continue;
      /*is it a flip-flop?*/
      for (biabl=bereg->BIABL; biabl; biabl=biabl->NEXT) {
         if (getptype(biabl->USER,ABL_STABLE)) return ret; 
      }
   }

   /*search driver of signal (latest if bus)*/
   max_delay=-1;   
   
   for (loconchain=(chain_list*) ptype->DATA; loconchain; loconchain=loconchain->NEXT) {
      locon=(locon_list*) loconchain->DATA;
      /*only outputs*/
      if (locon->DIRECTION==IN || isvss(locon->NAME) || isvdd(locon->NAME) 
       || locon->TYPE==EXTERNAL) continue;
      loins_aux=locon->ROOT;
      if (loins_aux==loins) continue;
      delay=getdelay(loins_aux->INSNAME);
      if (delay>max_delay) {
         best_loins=loins_aux;
         max_delay=delay;
      }   
   }   

   if (!best_loins) {
      fprintf(stderr,"search_long_path: no loins found for driving losig '%s'\n",signame);
      exit(1);
   }
   
   ret->NEXT=search_long_path(best_loins, befig);
   return ret;
}
Example #9
0
static ptype_list* search_long_path(losig_list* losig, int ck_include)
{
    loins_list* best_loins=NULL;
    locon_list* locon;
    losig_list *best_losig=NULL;
    loins_list* loins;
    befig_list* befig;
    char* signame, *ck=NULL;
    int reg=0;  /*flag for flip-flop*/
    chain_list* lofigchain;
    ptype_list* ptype, *ret;
    double max_delay=-1, delay;
    cell_list* cell;
    biabl_list* biabl;

    if (!losig) {
        fprintf(stderr,"search_long_path: NULL pointer\n");
        autexit(1);
    }

    if (!losig->NAMECHAIN) {
        fprintf(stderr,"search_long_path: no losig name\n");
        autexit(1);
    }

    signame=(char*) losig->NAMECHAIN->DATA;


    /*control combinational loop, not to recurse infinitively*/
    if ( searchauthelem( ControlLoop, (char*) losig ) )
    {
        fprintf(stderr,"Warning: combinational loop on signal %s\n", signame );
        return ret;
    }

    addauthelem( ControlLoop, (char*) losig, 1 );


    /*search drivers*/
    ptype=getptype(losig->USER,LOFIGCHAIN);
    if (!ptype || !ptype->DATA) {
        fprintf(stderr,"search_long_path: no lofigchain found\n");
        autexit(1);
    }

    for (lofigchain=(chain_list*) ptype->DATA; lofigchain; lofigchain=lofigchain->NEXT) {
        locon=(locon_list*) lofigchain->DATA;
        if (locon->DIRECTION==UNKNOWN) {
            fprintf(stderr,"BEH: 'linkage %s' isn't accepted\n",
                    locon->NAME);
            autexit(1);
        }
        /*only outputs*/
        if (isvss(locon->NAME) || isvdd(locon->NAME)
                || locon->DIRECTION==IN || locon->TYPE==EXTERNAL) continue;
        loins=locon->ROOT;
        delay=loins_delay(loins,signame);
        if (delay>max_delay) {
            best_loins=loins;
            max_delay=delay;
        }
    }


    loins=best_loins;
    ret=addptype(NULL, (long) max_delay>=0?max_delay:getdelay(signame), losig);
    if (!loins) return ret;

    /*stop at flip-flop*/
    cell=getCell(loins->FIGNAME);
    if (!cell) {
        fprintf(stderr,"library error: no cell '%s.vbe' found\n",
                loins->FIGNAME);
        autexit(1);
    }
    befig=cell->BEFIG;
    if (befig->BEREG) {
        for ( biabl = cell->BEFIG->BEREG->BIABL; biabl; biabl = biabl->NEXT )
        {
            ptype=getptype(biabl->USER,ABL_STABLE);
            if (ptype) {
                /*do not include clock in path*/
                if (!ck_include) return ret;
                reg=1;
                ck=ptype->DATA;
                break;
            }
        }
    }

    max_delay=-1;
    /*seek the latest input in cell*/
    for (locon=loins->LOCON; locon; locon=locon->NEXT) {
        if (locon->DIRECTION==UNKNOWN) {
            fprintf(stderr,"BEH: 'linkage %s' in figure '%s' isn't accepted\n",
                    locon->NAME,loins->FIGNAME);
            autexit(1);
        }
        /*only inputs*/
        if (locon->DIRECTION==OUT || locon->DIRECTION==TRISTATE
                || isvss(locon->NAME) || isvdd(locon->NAME)) continue;
        /* if flip-flop, accept only clock */
        if (reg && ck!=locon->NAME) continue;
        losig=locon->SIG;
        if (!losig->NAMECHAIN) {
            fprintf(stderr,"search_long_path: no name on signal\n");
            autexit(1);
        }
        signame=(char*) losig->NAMECHAIN->DATA;
        delay=getdelay(signame);
        if (delay>max_delay) {
            best_losig=losig;
            max_delay=delay;
        }
    }

    losig=best_losig;


    /*no input found  -> constant*/
    if (!losig) return ret;

    ret->NEXT=search_long_path(losig,ck_include);
    return ret;
}
Example #10
0
File: rx.c Project: gegel/pairphone
//*****************************************************************************
//receiving loop: grab 48KHz baseband samples from Line,
//demodulate, decrypt, decode, play 8KHz voice over Speaker
int rx(int typing)
{
 //input: -1 for no typing chars, 1 - exist some chars in input buffer
 //output: 0 - no any jobs doing, 1 - some jobs were doing
 int i;
 float f;
 int job=0; //flag of any job were doing 
 char lag_flag=0; //block lag is locked (modems synchronization complete)
 //char lock_flag=0; //phase of carrier (1333Hz, 6 samples per period) is locked
 //char sync_flag=0; //the difference of frequency transmitter-to-receiver sampling rate is locked
 //char current_lag=0;  //block lag (0-90, aligned to last bit position, the 6 samples for bit)

 char info[8]={0}; //call info

 //regularly play Speaker's buffer
 job=playjit(); //the first try to play a tail of samples in buffer
 //check for we have enough samples for demodulation
 if(cnt<180*6) //check we haven't enough of unprocessed samples
 {
  //move tail to start of receiving buffer
  if(samples>speech) //check for tail
  {
   for(i=0; i<cnt; i++) speech[i]=samples[i]; //move tail to start of buffer
   samples=speech; //set pointer to start of buffer
  }
  //record
  i=_soundgrab((char*)(samples+cnt), 180*6);  //try to grab new 48KHZ samples from Line

  if((i>0)&&(i<=(180*6))) //some samples grabbed
  {
   cnt+=i;  //add grabbed  samples to account
   job+=4;  //set job
  }
 }
 else //we have enough samples for processing
 {
  i=Demodulate(samples, buf); //process samples: 36*6 (35-37)*6 samples
  samples+=i; //move pointer to next samples (with frequency adjusting)
  cnt-=i; //decrease the number of unprocessed samples
  if(0x80&buf[11]) //checks flag for output data block is ready
  {
   //check for synck and averages BER
   lag_flag=!(!(buf[11]&0x40)); //block lag is locked (synchronization compleet)
   //lock_flag=!(!(buf[11]&0x20)); //phaze of carrier (1333Hz, 6 samples per period) is locked
   //sync_flag=!(!(buf[11]&0x10)); //the differency of frequency transmitter-to-receiver sampling rate is locked
   //current_lag=buf[10]>>1;  //block lag (0-90, aligned to last bit position, the 6 samples for bit)
   if(lag_flag) //check modem sync
   {
    //averages BER
    i=(0x0F&buf[11]); //count symbols errors (only 1 error per 9-bit symbol can be detected)
    fber*=0.99; //fber in range 0-900
    fber+=i;  //in range 0-9 errored bits per 90 bits treceived
   }
   //output statistics
   if(typing<0) //output call's info if no characters were typed by user
   {
    f=Mute(0);   //get packets counter value
    i=State(0); //get current connection step * vad flag 
	
	//notification of state and voice output 
    if(!i) strcpy(info, (char*)"IDLE"); 
    else if(abs(i)<8) strcpy(info, (char*)"CALL");  
    else if(f<=0) strcpy(info, (char*)"MUTE");
    else if(i<0) strcpy(info, (char*)"PAUS");
    else strcpy(info, (char*)"TALK");

    if(f<0) f=-f; //absolute value
    i=f*0.0675; //computes total time of the call in sec: each packet 67,5 ms

    f=fau/4-100; //computes authentification level in %
    if(f<0) f=0; //only positive results have reason
    //current state notification
    if(lag_flag) printf("%s %dmin %dsec BER:%0.02f AU:%d%%\r", info, i/60, i%60, fber/90, (int)f);
    else printf("%s %dmin %dsec BER:---- AU:%d%%\r", info, i/60, i%60, (int)f); //lost of sync in modem
   }

   //process received packet detects voice/silence type
   buf[11]=0xFE; //set flag default as for silence descriptor
   if(lag_flag) //check modem sync
   {
    i=ProcessPkt(buf);  //decode received packet
    if(i>=0) //received packet is a control type
    {
     fau*=0.99;  //fau in range 0-800 (400 for random data)
     fau+=i; //averages authentication level
    }
    else if(i==-3) 
	{
	 buf[11]=0xFF; //set flag for voice data received 
	}
   } //end of sync ok, packets processing
  } //end of data block received
 } //end of a portion of sampless processing

 //check we have received data and output buffer is empty for decoding
 if((0x0E&buf[11])&&(l_jit_buf<=180))
 {
  //decode voice data or set silency
  job+=16; //set job
  if(1&buf[11]) //this is a voice frame, decode it
  {
   melpe_s(sp, buf); //decode 81 bits in 11 bytes to 540 8KHz samples 
  }
  else memset(sp, 0, 1080); //or output 67.5 mS of silence
  buf[11]=0; //clears flag: data buffer is processed

  //computes average playing delay
  i=getdelay()+l_jit_buf; //total number of unplayed samples in buffers
  fdelay*=0.9; //averages
  fdelay+=i;
  //computes optimal resapling ratio for the optimum delay
  f=fabs(fdelay/10-720)/10000000; //correction rate due inconsistency
  if(i<360) qff-=f;  //adjust current ratio
  else if(i>1080) qff+=f;
  if(qff<0.888) qff=0.888; //restrictions
  else if(qff>1.142) qff=1.142;

  //resample and play to Headset
  if(l_jit_buf>180) l_jit_buf=0; //prevent overflow
  l_jit_buf+=resample(sp, jit_buf+l_jit_buf, qff); //resample buffer for playing
  playjit(); //immediately try to play buffer
 }
 return job;
}
Example #11
0
static int insert_buffer(losig_list* losig, lofig_list* lofig, int optim_level, long index)
{
   double capa, init_capa;
   cell_list* buffer;
   chain_list* namechain, *sigchain=NULL;
   char* signame;
   lofig_list* model;
   losig_list* losig_buf;
   loins_list* loins_buf;
   locon_list* locon;
   losig_list* losig_vdd=NULL, *losig_vss=NULL, *losig_aux;
   ptype_list* ptype, *buffer_ptype;
   double delay, best_delay, init_delay;
   loins_list* loins;
   chain_list* lofigchain,*newlofigchain=NULL;
   int buffer_is_better=0, change=1;    /*flags*/
   chain_list* pred;
   chain_list* temp;


   buffer=getCellbuffer();
   /*no buffer in library*/
   if (!buffer) return 0;
   
   if (!losig->NAMECHAIN) {
      fprintf(stderr,"insert_buffer: no name on signal\n");
      autexit(1);
   }

   best_delay=critical_delay(lofig);
   init_capa=getcapacitance(losig->NAMECHAIN->DATA);

   /*add buffer to netlist*/
   signame=getautoname(losig->NAMECHAIN->DATA);
   namechain=addchain(NULL,signame);
   losig_buf=addlosig(lofig,index,namechain,INTERNAL);
   putcapacitance(signame,0);
   putdelay(signame,0);
   model=getlofig(buffer->BEFIG->NAME,'A');
   
   /*search vdd and vss*/
   for (locon=lofig->LOCON; locon; locon=locon->NEXT) {
      if (isvdd(locon->NAME)) losig_vdd=locon->SIG;
      if (isvss(locon->NAME)) losig_vss=locon->SIG;
   }
   
   /*build list of signal*/
   for (locon=model->LOCON;locon; locon=locon->NEXT) {
      if (locon->DIRECTION==UNKNOWN) {
         fprintf(stderr,"BEH: 'linkage %s' in figure '%s' isn't accepted\n",
         locon->NAME,model->NAME);
         autexit(1);
      }
      if (isvdd(locon->NAME)) losig_aux=losig_vdd;
      else if (isvss(locon->NAME)) losig_aux=losig_vss;
      else if (locon->DIRECTION==OUT) losig_aux=losig_buf;
      else if (locon->DIRECTION==IN) losig_aux=losig;
      else {
         fprintf(stderr,"insert_buffer: buffer port '%s' unknown\n",locon->NAME);
         autexit(1);
      }
      sigchain=addchain(sigchain,losig_aux);
   }

   
   sigchain=reverse(sigchain);
   loins_buf=addloins(lofig,signame,model,sigchain);
   freechain(sigchain);
   /*to check changes*/
   init_delay=getdelay(losig->NAMECHAIN->DATA);
   init_capa=getcapacitance(losig->NAMECHAIN->DATA);
   loins_capacitance(loins_buf,1/*add capa*/);
  
   /*lofigchain*/
   for (locon=loins_buf->LOCON;locon; locon=locon->NEXT) {
      if (locon->DIRECTION==UNKNOWN) {
         fprintf(stderr,"BEH: 'linkage %s' in figure '%s' isn't accepted\n",
         locon->NAME,loins_buf->INSNAME);
         autexit(1);
      }
      if (isvdd(locon->NAME)) losig_aux=losig_vdd;
      else if (isvss(locon->NAME)) losig_aux=losig_vss;
      else if (locon->DIRECTION==OUT) losig_aux=losig_buf;
      else if (locon->DIRECTION==IN) losig_aux=losig;
      else {
         fprintf(stderr,"insert_buffer: buffer port '%s' unknown\n",locon->NAME);
         autexit(1);
      }
      ptype=getptype(losig_aux->USER,LOFIGCHAIN);
      if (!ptype) losig_aux->USER=addptype(losig_aux->USER,LOFIGCHAIN,addchain(NULL,locon));
      else ptype->DATA=addchain(ptype->DATA,locon);
   }
   
   /*move all instance after buffer*/
   ptype=getptype(losig->USER,LOFIGCHAIN);
   buffer_ptype=getptype(losig_buf->USER,LOFIGCHAIN);
   if (!ptype || !buffer_ptype) {
      fprintf(stderr,"insert_buffer: LOFIGCHAIN not found\n");
      autexit(1);
   }
   
   for (lofigchain=((chain_list*)ptype->DATA)->NEXT/*first is entry of buffer*/;
        lofigchain; lofigchain=lofigchain->NEXT) {
      locon=(locon_list*) lofigchain->DATA;
      if (locon->DIRECTION==UNKNOWN) {
         fprintf(stderr,"BEH: 'linkage %s' isn't accepted\n",
         locon->NAME);
         autexit(1);
      }
      /*do not move drivers and port of circuit*/
      if (locon->TYPE==EXTERNAL || locon->DIRECTION!=IN) {
         newlofigchain=addchain(newlofigchain,locon);
         continue;
      }
      
      loins=locon->ROOT;
      /*change capacitance*/
      loins_capacitance(loins,0/*remove  capa*/);
      /*change netlist*/
      locon->SIG=losig_buf;
      buffer_ptype->DATA=addchain(buffer_ptype->DATA,locon);
      loins_capacitance(loins,1/*add capa*/);
   }
   
   /*put back drivers*/
   freechain(((chain_list*)ptype->DATA)->NEXT/*first is entry of buffer*/);
   ((chain_list*)ptype->DATA)->NEXT=newlofigchain;
   
   /*eval all changes*/
   propagate_loins_delay(loins_buf);

   /*relaxation algorithm*/
   while (change) {
      change=0;
      pred=NULL;
      buffer_ptype=getptype(losig_buf->USER,LOFIGCHAIN);
      ptype=getptype(losig->USER,LOFIGCHAIN);
      if (!buffer_ptype || !buffer_ptype->DATA) {
         fprintf(stderr,"insert_buffer: LOFIGCHAIN is empty\n");
         autexit(1);
      }
      
      /*put critical path before buffer*/
      for (lofigchain=buffer_ptype->DATA; lofigchain->NEXT/*last is buffer output*/;
           lofigchain=lofigchain->NEXT) {
         locon=lofigchain->DATA;
         loins=locon->ROOT;
      
         /*change capacitance*/
         loins_capacitance(loins,0/*remove capa*/);
         /*change netlist*/
         locon->SIG=losig;
         ptype->DATA=addchain(ptype->DATA,locon);
         loins_capacitance(loins,1/*add capa*/);

         /*put over*/
         if (pred) pred->NEXT=lofigchain->NEXT;
         else buffer_ptype->DATA=lofigchain->NEXT;
      
         /*eval all changes*/
         propagate_loins_delay(loins);
         propagate_loins_delay(loins_buf);
         delay=critical_delay(lofig);
      
         if (delay<best_delay) {
            /*finish change*/
            best_delay=delay; 
            change=1;   /*flag of change*/
            buffer_is_better=1;
            lofigchain->NEXT=NULL;
            freechain(lofigchain);
            break;
         }
         else {
            /*remove change*/
            if (pred) pred->NEXT=lofigchain;
            else buffer_ptype->DATA=lofigchain;
            
            /*unchange capacitance*/
            loins_capacitance(loins,0/*remove capa*/);
            /*unchange netlist*/
            locon->SIG=losig_buf;
            temp=ptype->DATA;
            ptype->DATA=temp->NEXT;
            temp->NEXT=NULL;
            freechain(temp);
            loins_capacitance(loins,1/*add capa*/);
            /*avoid change*/
            propagate_loins_delay(loins_buf);
            propagate_loins_delay(loins);
            
            /*for next loop*/
            pred=lofigchain;
         }
      }
      
   }/*end of while*/
   
   if (buffer_is_better) {
      /*chose the best buffer*/
      change_instance(loins_buf, losig_buf, lofig, optim_level);
   }   
   else {  /*if insert buffer is worst than before, remove it*/
      /*remove all references of buffer in lofigchain*/
      for (locon=loins_buf->LOCON; locon; locon=locon->NEXT) {
         losig_aux=locon->SIG;
         ptype=getptype(losig_aux->USER,LOFIGCHAIN);
         if (!ptype) break;
         pred=NULL;
         for (lofigchain=ptype->DATA; lofigchain; lofigchain=lofigchain->NEXT) {
            if (lofigchain->DATA==locon) {
               if (pred) pred->NEXT=lofigchain->NEXT;
               else ptype->DATA=lofigchain->NEXT;
               lofigchain->NEXT=NULL;
               freechain(lofigchain);
               break;
            }
            pred=lofigchain;
         }
      }
      
      buffer_ptype=getptype(losig_buf->USER,LOFIGCHAIN);
      ptype=getptype(losig->USER,LOFIGCHAIN);
      if (buffer_ptype) {
       for (lofigchain=buffer_ptype->DATA; lofigchain; lofigchain=lofigchain->NEXT) {
         locon=lofigchain->DATA;
         loins=locon->ROOT;
         /*change capacitance*/
         loins_capacitance(loins,0/*remove capa*/);
         /*change netlist*/
         locon->SIG=losig;
         ptype->DATA=addchain(ptype->DATA,locon);
         loins_capacitance(loins,1/*add capa*/);
         propagate_loins_delay(loins);
       }
      
       freechain(buffer_ptype->DATA);
       buffer_ptype->DATA=NULL;
      }
      
      loins_capacitance(loins_buf,0/*remove capa*/);
      dellosig(lofig,index);
      delloins(lofig,loins_buf->INSNAME);
      propagate_losig_delay(losig);
   
      /*verify no change on timing*/
      delay=critical_delay(lofig);
      capa=getcapacitance(losig->NAMECHAIN->DATA);
      //01/09/2004 xtof's modification: rounding problem
      if ((int)(capa + 0.5)!=(int)(init_capa + 0.5) || (int)(delay + 0.5)!=(int)(best_delay + 0.5) 
       || (int)(init_delay + 0.5)!=(int)(getdelay(losig->NAMECHAIN->DATA) + 0.5)) {
         fprintf(stderr,
         "insert_buffer: compute error %e!=%e fF   %f!=%f ps    %f!=%f ps\n",
         capa,init_capa,delay,best_delay, init_delay, getdelay(losig->NAMECHAIN->DATA));
         autexit(1);
      }   
   
   }
      
   return buffer_is_better;
}
Example #12
0
/*
 * Apply the effect
 */
void
Chorus::out (float * smpsl, float * smpsr)
{
    int i;
    float tmp;
    dl1 = dl2;
    dr1 = dr2;
    lfo.effectlfoout (&lfol, &lfor);

    if(awesome_mode) { //use interpolated delay line for better sound
        float tmpsub;

        dl2 = delay + lfol * depth;
        dr2 = delay + lfor * depth;
        if (Poutsub != 0) tmpsub = -1.0f;
        else tmpsub = 1.0f;

        for (i = 0; i < param->PERIOD; i++) {
            //Left
            mdel = (dl1 * (float)(param->PERIOD - i) + dl2 * (float)i) / param->fPERIOD;
            tmp = smpsl[i] + oldl*fb;
            efxoutl[i] = tmpsub*ldelay->delay(tmp, mdel, 0, 1, 0);
            oldl = efxoutl[i];

            //Right
            mdel = (dr1 * (float)(param->PERIOD - i) + dr2 * (float)i) / param->fPERIOD;
            tmp = smpsr[i] + oldr*fb;
            efxoutr[i] = tmpsub*rdelay->delay(tmp, mdel, 0, 1, 0);
            oldr =  efxoutr[i];
        }

    } else {

        dl2 = getdelay (lfol);
        dr2 = getdelay (lfor);
        for (i = 0; i < param->PERIOD; i++) {
            float inl = smpsl[i];
            float inr = smpsr[i];
            //LRcross
            float l = inl;
            float r = inr;
            inl = l * (1.0f - lrcross) + r * lrcross;
            inr = r * (1.0f - lrcross) + l * lrcross;

            //Left channel

            //compute the delay in samples using linear interpolation between the lfo delays
            mdel = (dl1 * (float)(param->PERIOD - i) + dl2 * (float)i) / param->fPERIOD;
            if (++dlk >= maxdelay)
                dlk = 0;
            float tmp = (float) dlk - mdel + (float)maxdelay * 2.0f;	//where should I get the sample from

			((dlhi)=((tmp>0) ? ( (int)(tmp) ) :( (int)(tmp-1.0f) )));
            dlhi %= maxdelay;

            dlhi2 = (dlhi - 1 + maxdelay) % maxdelay;
            dllo = 1.0f - fmodf (tmp, 1.0f);
            efxoutl[i] = delayl[dlhi2] * dllo + delayl[dlhi] * (1.0f - dllo);
            delayl[dlk] = inl + efxoutl[i] * fb;

            //Right channel

            //compute the delay in samples using linear interpolation between the lfo delays
            mdel = (dr1 * (float)(param->PERIOD - i) + dr2 * (float)i) / param->fPERIOD;
            if (++drk >= maxdelay)
                drk = 0;
            tmp = (float)drk - mdel + (float)maxdelay * 2.0f;	//where should I get the sample from

			((dlhi)=((tmp>0) ? ( (int)(tmp) ) :( (int)(tmp-1.0f) )));
            dlhi %= maxdelay;

            dlhi2 = (dlhi - 1 + maxdelay) % maxdelay;
            dllo = 1.0f - fmodf (tmp, 1.0f);
            efxoutr[i] = delayr[dlhi2] * dllo + delayr[dlhi] * (1.0f - dllo);
            delayr[dlk] = inr + efxoutr[i] * fb;

        };


        if (Poutsub != 0)
            for (i = 0; i < param->PERIOD; i++) {
                efxoutl[i] *= -1.0f;
                efxoutr[i] *= -1.0f;
            };


        for (int i = 0; i < param->PERIOD; i++) {
            efxoutl[i] *= panning;
            efxoutr[i] *= (1.0f - panning);
        };

    } //end awesome_mode test
};
Example #13
0
/*
 * Apply the effect
 */
void
Chorus::out (float * smpsl, float * smpsr)
{
  int i;
  dl1 = dl2;
  dr1 = dr2;
  lfo.effectlfoout (&lfol, &lfor);

  dl2 = getdelay (lfol);
  dr2 = getdelay (lfor);

  for (i = 0; i < PERIOD; i++)
    {
      float inl = smpsl[i];
      float inr = smpsr[i];
      //LRcross
      float l = inl;
      float r = inr;
      inl = l * (1.0f - lrcross) + r * lrcross;
      inr = r * (1.0f - lrcross) + l * lrcross;

      //Left channel

      //compute the delay in samples using linear interpolation between the lfo delays
      mdel = (dl1 * (float)(PERIOD - i) + dl2 * (float)i) / fPERIOD;
      if (++dlk >= maxdelay)
	dlk = 0;
      float tmp = (float) dlk - mdel + (float)maxdelay * 2.0f;	//where should I get the sample from

      F2I (tmp, dlhi);
      dlhi %= maxdelay;

      dlhi2 = (dlhi - 1 + maxdelay) % maxdelay;
      dllo = 1.0f - fmodf (tmp, 1.0f);
      efxoutl[i] = delayl[dlhi2] * dllo + delayl[dlhi] * (1.0f - dllo);
      delayl[dlk] = inl + efxoutl[i] * fb;

      //Right channel

      //compute the delay in samples using linear interpolation between the lfo delays
      mdel = (dr1 * (float)(PERIOD - i) + dr2 * (float)i) / fPERIOD;
      if (++drk >= maxdelay)
	drk = 0;
      tmp = (float)drk - mdel + (float)maxdelay * 2.0f;	//where should I get the sample from

      F2I (tmp, dlhi);
      dlhi %= maxdelay;

      dlhi2 = (dlhi - 1 + maxdelay) % maxdelay;
      dllo = 1.0f - fmodf (tmp, 1.0f);
      efxoutr[i] = delayr[dlhi2] * dllo + delayr[dlhi] * (1.0f - dllo);
      delayr[dlk] = inr + efxoutr[i] * fb;

    };

  if (Poutsub != 0)
    for (i = 0; i < PERIOD; i++)
      {
	efxoutl[i] *= -1.0f;
	efxoutr[i] *= -1.0f;
      };


  for (int i = 0; i < PERIOD; i++)
    {
      efxoutl[i] *= panning;
      efxoutr[i] *= (1.0f - panning);
    };
};