Exemplo n.º 1
0
void ampegdecoder::readmain(grsistruct (*si)[2])
{
  int stereo=(hdrmode==3)?1:2;

  int maindatabegin = mpgetbits(hdrlsf?8:9);

  mpgetbits(hdrlsf?(stereo==1)?1:2:(stereo==1)?5:3);

  if (!si)
    mpgetbits(hdrlsf?(stereo==1)?64:128:(stereo==1)?127:247);
  else
  {
    int ngr=hdrlsf?1:2;
    int gr,ch;
    for (gr=0; gr<ngr; gr++)
      for (ch=0; ch<stereo; ch++)
      {
        si[ch][gr].ch=ch;
        si[ch][gr].gr=gr;
      }

    for (gr=0; gr<ngr; gr++)
      for (ch=0; ch<stereo; ch++)
        readsfsi(si[ch][gr]);

    int bitpos=0;
      for (gr=0; gr<ngr; gr++)
        for (ch=0; ch<stereo; ch++)
          readgrsi(si[ch][gr], bitpos);
  }

  int mainslots=(hdrlsf?72:144)*1000*ratetab[hdrlsf?1:0][2][hdrbitrate]/(freqtab[hdrfreq]>>hdrlsf)+(hdrpadding?1:0)-4-(hdrcrc?2:0)-(hdrlsf?(stereo==1)?9:17:(stereo==1)?17:32);

  if (huffoffset<maindatabegin)
    huffoffset=maindatabegin;
  memmove(huffbuf, huffbuf+huffoffset-maindatabegin, maindatabegin);
  getbytes(huffbuf+maindatabegin, mainslots);
  huffoffset=maindatabegin+mainslots;
  bitbuf=huffbuf;
  bitbufpos=&huffbit;
}
Exemplo n.º 2
0
/* Reads a single line into data which must be at least (pbm->width+7)/8
   bytes of storage */
int pbm_readline(pbm_stat* pbm,unsigned char* data)
{
  int tmp,tmp2;

  if(pbm->current_line >= pbm->height) return 0;

  if (pbm->unread)
    {
      memcpy (data, pbm->revdata, (pbm->width+7)/8);
      pbm->current_line++;
      pbm->unread = 0;
      free (pbm->revdata);
      return 1;
    }

  switch(pbm->version)
  {
  case P1:
    if(getbytes(pbm->fptr,pbm->width,data))
    {
      pbm->current_line++;
      return 1;
    }
    return 0;

  case P4:
    tmp=(pbm->width+7)/8;
    tmp2=fread(data,1,tmp,pbm->fptr);
    if(tmp2 == tmp)
    {
      pbm->current_line++;
      return 1;
    }
    fprintf(stderr,"pbm_readline(): error reading line data (%d)\n",tmp2);
    return 0;

  default:
    fprintf(stderr,"pbm_readline(): unknown PBM version\n");
    return 0;
  }
}
Exemplo n.º 3
0
static void bfcc_tilde_filterbank_multiply(t_sample *in, int normalize, t_filter *x_filterbank, t_indices *x_indices, int num_filters)
{
	int i, j, k;
	float sum, sumsum, *filter_power;

	// create local memory
	filter_power = (float *)getbytes(0);
	filter_power = (float *)t_resizebytes(filter_power, 0, num_filters * sizeof(float));

 	sumsum = 0;
	
	for(i=0; i<num_filters; i++)
    {
	   	sum = 0;
 
		for(j=x_indices[i].index[0], k=0; j< (int)(x_indices[i].index[1] + 1); j++, k++)	
	    	sum += in[j] * x_filterbank[i].filter[k];
		
		sum /= k;
		filter_power[i] = sum;  // get the total power.  another weighting might be better.

 		sumsum += sum;  // normalize so power in all bands sums to 1
	};
	
	if(normalize)
	{
		// prevent divide by 0
		if(sumsum==0)
			sumsum=1;
		else
			sumsum = 1/sumsum; // take the reciprocal here to save a divide below
	}
	else
		sumsum=1;
		
	for(i=0; i<num_filters; i++)
		in[i] = filter_power[i]*sumsum;

	// free local memory
	t_freebytes(filter_power, num_filters * sizeof(float));
}
Exemplo n.º 4
0
static void deltas_set(t_deltas *x, t_float lo, t_float hi, t_float size)
{
	if (size<1)
	{
		size=1;
		logpost(x, 2, "[deltas]: minimum size is 1");
	}
	if (hi>size)
	{
		logpost(x, 2, "[deltas]: higher bound (%g) cannot be greater than the buffer size (%g)",
                hi, size);	
		hi=size;
	}
	if (lo<0)
	{
		logpost(x, 2, "[deltas]: lower bound cannot be negative");
		lo=0;
	}
	if (hi<1)
	{
		logpost(x, 2, "[deltas]: higher bound cannot be smaller than one");
		hi=1;
	}
	if (hi<=lo)
	{
		logpost(x, 2, "[deltas]: higher bound (%g) must be greater than lower bound (%g)", hi, lo);	
		lo=hi-1.0;
	}

	x->m_hi=(t_float)((int)hi);
	x->m_lo=(t_float)((int)lo);

    if (x->m_buffer_size != size)
    {
        freebytes(x->m_buffer, x->m_buffer_size);
        x->m_buffer_size = (int)size;
        x->m_buffer = (t_float*)getbytes(sizeof(t_float)*x->m_buffer_size);
        deltas_clear(x);
        x->m_buffer_index=0;
    }
}
Exemplo n.º 5
0
 void *readsfx_new(t_floatarg fnchannels, t_floatarg fbufsize)
{
    t_readsfx *x;
    int nchannels = fnchannels, bufsize = fbufsize, i;
    char *buf;
    
    if (nchannels < 1)
        nchannels = 1;
    else if (nchannels > MAXSFCHANS)
        nchannels = MAXSFCHANS;
    if (bufsize <= 0) bufsize = DEFBUFPERCHAN * nchannels;
    else if (bufsize < MINBUFSIZE)
        bufsize = MINBUFSIZE;
    else if (bufsize > MAXBUFSIZE)
        bufsize = MAXBUFSIZE;
    buf = getbytes(bufsize);
    if (!buf) return (0);
    
    x = (t_readsfx *)pd_new(readsfx_tilde_class);
    
    for (i = 0; i < nchannels; i++)
        outlet_new(&x->x_obj, gensym("signal"));
    x->x_noutlets = nchannels;
    x->x_bangout = outlet_new(&x->x_obj, &s_bang);
    pthread_mutex_init(&x->x_mutex, 0);
    pthread_cond_init(&x->x_requestcondition, 0);
    pthread_cond_init(&x->x_answercondition, 0);
    x->x_vecsize = MAXVECSIZE;
    x->x_state = STATE_IDLE;
    x->x_clock = clock_new(x, (t_method)readsfx_tick);
    x->x_canvas = canvas_getcurrent();
    x->x_bytespersample = 2;
    x->x_sfchannels = 1;
    x->x_fd = -1;
    x->x_buf = buf;
    x->x_bufsize = bufsize;
    x->x_fifosize = x->x_fifohead = x->x_fifotail = x->x_requestcode = 0;
//    x->x_reader_obj = sfxreader_new();
    pthread_create(&x->x_childthread, 0, readsfx_child_main, x);
    return (x);
}
Exemplo n.º 6
0
static void mtx_resize_matrix(t_matrix *x, t_symbol *s, int argc, t_atom *argv)
{
    int row=atom_getfloat(argv);
    int col=atom_getfloat(argv+1);
    int r = x->current_row, c = x->current_col;
    int R=0, ROW, COL;

    if (argc<2) {
        post("mtx_add: crippled matrix");
        return;
    }
    if ((col<1)||(row<1)) {
        post("mtx_add: invalid dimensions");
        return;
    }
    if (col*row>argc-2) {
        post("sparse matrix not yet supported : use \"mtx_check\"");
        return;
    }

    if (!r)r=row;
    if (!c)c=col;

    if (r==row && c==col) { /* no need to change */
        outlet_anything(x->x_obj.ob_outlet, gensym("matrix"), argc, argv);
        return;
    }

    x->atombuffer=(t_atom *)getbytes((c*r+2)*sizeof(t_atom));
    setdimen(x, r, c);
    matrix_set(x, 0);

    ROW=(r<row)?r:row;
    COL=(c<col)?c:col;
    R=ROW;
    while(R--)memcpy(x->atombuffer+2+(ROW-R-1)*c, argv+2+(ROW-R-1)*col, COL*sizeof(t_atom));

    matrix_bang(x);

    freebytes(x->atombuffer, (c*r+2)*sizeof(t_atom));
}
Exemplo n.º 7
0
void hammerpanel_setopendir(t_hammerfile *f, t_symbol *dir)
{
    if (f->f_currentdir && f->f_currentdir != &s_)
    {
	if (dir && dir != &s_)
	{
	    int length;
	    if (length = ospath_length(dir->s_name, f->f_currentdir->s_name))
	    {
		char *path = getbytes(length + 1);
		if (ospath_absolute(dir->s_name, f->f_currentdir->s_name, path))
		    /* LATER stat (think how to report a failure) */
		    f->f_currentdir = gensym(path);
		freebytes(path, length + 1);
	    }
	}
	else if (f->f_canvas)
	    f->f_currentdir = canvas_getdir(f->f_canvas);
    }
    else bug("hammerpanel_setopendir");
}
Exemplo n.º 8
0
static void add_ldsp_triplet(int i, int j, int k, t_def_ls *x)
     /* adds i,j,k triplet to structure*/
{
  struct t_ls_set *trip_ptr, *prev;
  trip_ptr = x->x_ls_set;
  prev = NULL;
  while (trip_ptr != NULL)
	{
    prev = trip_ptr;
    trip_ptr = trip_ptr->next;
  }
  trip_ptr = (struct t_ls_set*) getbytes (sizeof (struct t_ls_set));
  if(prev == NULL)
    x->x_ls_set = trip_ptr;
  else 
    prev->next = trip_ptr;
  trip_ptr->next = NULL;
  trip_ptr->ls_nos[0] = i;
  trip_ptr->ls_nos[1] = j;
	trip_ptr->ls_nos[2] = k;
}
Exemplo n.º 9
0
static void *makesymbol_new(t_symbol* UNUSED(s), int argc, t_atom *argv)
{
  t_makesymbol *x = (t_makesymbol *)pd_new(makesymbol_class);

  x->buf = (char *)getbytes(MAXSTRINGLENG * sizeof(char));

  x->mask  = x->buf;

  if (argc) {
    atom_string(argv, x->buf, MAXSTRINGLENG);
    x->x_sym = gensym(x->buf);
  } else {
    x->mask = "%s%s%s%s%s%s%s%s%s%s";
    x->x_sym = gensym("");
  }

  outlet_new(&x->x_obj, gensym("symbol"));
  inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("symbol"), gensym("sym1"));

  return (x);
}
Exemplo n.º 10
0
static void lhisti_set(t_lhisti *x, t_float lo, t_float hi, t_float nbins)
{
	if (nbins<1)
	{
		nbins=1;
		post("lhisti: number of bins is minimum 1...");
	}
	if (hi<=lo)
	{
		post("lhisti: higher bound must be higher than lower bound...");	
		hi=lo+1.0f;
	}
	freebytes(x->m_lhisti, x->m_nbins);
	x->m_hi=hi;
	x->m_lo=lo;
	x->m_nbins=(int)nbins;
	x->m_scale=(float)x->m_nbins/(hi-lo);
    x->m_lhisti = (float*)getbytes(sizeof(float)*x->m_nbins);

	lhisti_clear(x);
}
Exemplo n.º 11
0
Arquivo: param.c Projeto: Angeldude/pd
// SPECIAL PARAM SAVE FUNCTION
static void paramClass_save(t_paramClass *x, t_binbuf* bb,int f) {
	
	//post("save:%i",f);
	
	
	// f = -1 for the main save file
	// f => 0 if it is a preset
	if ( f >= 0 && x->nopresets) return;
	
	//Put my data in binbuf
	if ((x->selector != &s_bang)) {
		int ac = x->ac + 2;
		t_atom *av = getbytes(ac*sizeof(*av));	
		tof_copy_atoms(x->av,av+2,x->ac);
		SETSYMBOL(av, x->param->path);
		SETSYMBOL(av+1, x->selector);
		binbuf_add(bb, ac, av);
		binbuf_addsemi(bb);
		freebytes(av, ac*sizeof(*av));
	}
}
Exemplo n.º 12
0
Arquivo: hist.c Projeto: Angeldude/pd
static void hist_bang(t_hist *x)
{
	int i,n;
	float *f;
	t_atom *ap,*app;

	n=x->m_nbins;
    ap = (t_atom *)getbytes(sizeof(t_atom)*n);
	app=ap;

	i=x->m_nbins;
	f=x->m_hist;

    while(i--){
      SETFLOAT(app, *f);
	  f++;
      app++;
    }
	outlet_list(x->x_obj.ob_outlet,gensym("list"),n,ap);
	freebytes(ap, sizeof(t_atom)*n);
}
Exemplo n.º 13
0
static void *zNdelay_new(t_floatarg f)
{
    t_zNdelay *x = (t_zNdelay *)pd_new(zNdelay_class);
    int i = f;
    t_sample *b;

    if (i<=0) i=1;
    i++;

    x->bufsize = i;
    x->buf = (t_sample *)getbytes(sizeof(t_sample) * x->bufsize);
    b=x->buf;
    while (i--) {
        *b++=0;
    }
    x->phase = 0;

    inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("ft1"));
    outlet_new(&x->x_obj, gensym("signal"));
    return (x);
}
Exemplo n.º 14
0
static void listfind_list2(t_listfind*x,t_symbol*s, int argc, t_atom*argv)
{
  if(x->x_argv!=0) {
    freebytes(x->x_argv, sizeof(t_atom)*x->x_argc);
  }
  x->x_argc=0;
  x->x_argv=0;

  DEBUGFUN(post("list of length %d", argc));

  if(argc>0) {
    int i;
    x->x_argc=argc;
    x->x_argv=(t_atom*)getbytes((x->x_argc)*sizeof(t_atom));
    for(i=0; i<argc; i++) {
      x->x_argv[i]=argv[i];
    }
  }

  DEBUGFUN(post("list2: %d %x", x->x_argc, x->x_argv));
}
Exemplo n.º 15
0
Arquivo: d_delay.c Projeto: Tzero2/pd
static void *sigdelwrite_new(t_symbol *s, t_floatarg msec)
{
    int nsamps;
    t_sigdelwrite *x = (t_sigdelwrite *)pd_new(sigdelwrite_class);
    if (!*s->s_name) s = gensym("delwrite~");
    pd_bind(&x->x_obj.ob_pd, s);
    x->x_sym = s;
    if (msec == 0) msec = 1000;
    nsamps = msec * sys_getsr() * (t_float)(0.001f);
    if (nsamps < 1) nsamps = 1;
    nsamps += ((- nsamps) & (SAMPBLK - 1));
    nsamps += DEFDELVS;
    x->x_cspace.c_n = nsamps;
    x->x_cspace.c_vec =
        (t_sample *)getbytes((nsamps + XTRASAMPS) * sizeof(t_sample));
    x->x_cspace.c_phase = XTRASAMPS;
    x->x_sortno = 0;
    x->x_vecsize = 0;
    x->x_f = 0;
    return (x);
}
Exemplo n.º 16
0
STATIC_INLINE void string2atom(t_atom *ap, char* cp, int clen){
  char *buffer=getbytes(sizeof(char)*(clen+1));
  char *endptr[1];
  t_float ftest;
  strncpy(buffer, cp, clen);
  buffer[clen]=0;
  ftest=strtod(buffer, endptr);
  /* what should we do with the special cases of hexadecimal values, "INF" and "NAN" ???
   * strtod() parses them to numeric values:
   * symbol "hallo 0x12" will become "list hallo 18"
   * do we want this ??
   */
  if (buffer+clen!=*endptr){
    /* strtof() failed, we have a symbol */
    SETSYMBOL(ap, gensym(buffer));    
  } else {
    /* it is a number. */
    SETFLOAT(ap,ftest);
  }
  freebytes(buffer, sizeof(char)*(clen+1));
}
Exemplo n.º 17
0
static void fudiparse_list(t_fudiparse *x, t_symbol*s, int argc, t_atom*argv) {
  size_t len = argc;
  t_binbuf* bbuf = binbuf_new();
  char*cbuf;
  if((size_t)argc > x->x_numbytes) {
    freebytes(x->x_bytes, x->x_numbytes);
    x->x_numbytes = argc;
    x->x_bytes = getbytes(x->x_numbytes);
  }
  cbuf = x->x_bytes;

  while(argc--) {
    char b = atom_getfloat(argv++);
    *cbuf++ = b;
  }
  binbuf_text(bbuf, x->x_bytes, len);

  fudiparse_binbufout(x, bbuf);

  binbuf_free(bbuf);
}
Exemplo n.º 18
0
void alist_clone(t_alist *x, t_alist *y)
{
    int i;
    y->l_pd = alist_class;
    y->l_n = x->l_n;
    y->l_npointer = x->l_npointer;
    if (!(y->l_vec = (t_listelem *)getbytes(y->l_n * sizeof(*y->l_vec))))
    {
        y->l_n = 0;
        error("list_alloc: out of memory");
    }
    else for (i = 0; i < x->l_n; i++)
    {
        y->l_vec[i].l_a = x->l_vec[i].l_a;
        if (y->l_vec[i].l_a.a_type == A_POINTER)
        {
            gpointer_copy(y->l_vec[i].l_a.a_w.w_gpointer, &y->l_vec[i].l_p);
            y->l_vec[i].l_a.a_w.w_gpointer = &y->l_vec[i].l_p;
        }
    }
}
Exemplo n.º 19
0
/* reallocate tables for storing sample data */
static t_int scratcher_reallocate(t_scratcher *x, t_int ioldsize, t_int inewsize)
{
    t_float *pdata;

    pdata = x->x_sdata;
    if ( !(x->x_sdata = getbytes( inewsize*sizeof(float) ) ) )
    {
        post( "scratcher~ : could not allocate %d bytes", inewsize*sizeof(t_float) );
        return -1;
    }
    else
    {
        post( "scratcher~ : allocated %d bytes", inewsize*sizeof(t_float) );
    }
    if ( pdata != NULL )
    {
        freebytes(pdata, ioldsize*sizeof(t_float) );
        post( "scratcher~ : freed %d bytes", ioldsize*sizeof(t_float) );
    }
    return 0;
}
Exemplo n.º 20
0
static void *dac_new(t_symbol *s, int argc, t_atom *argv)
{
    t_dac *x = (t_dac *)pd_new(dac_class);
    t_atom defarg[2], *ap;
    int i;
    if (!argc)
    {
        argv = defarg;
        argc = 2;
        SETFLOAT(&defarg[0], 1);
        SETFLOAT(&defarg[1], 2);
    }
    x->x_n = argc;
    x->x_vec = (t_int *)getbytes(argc * sizeof(*x->x_vec));
    for (i = 0; i < argc; i++)
        x->x_vec[i] = atom_getintarg(i, argc, argv);
    for (i = 1; i < argc; i++)
        inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
    x->x_f = 0;
    return (x);
}
Exemplo n.º 21
0
static void *fofsynth_new(t_symbol* s,t_float a,t_float b,t_float c,t_float d)
{
     int maxgrains = MAXGRAINS;
     t_fofsynth *x = (t_fofsynth *)pd_new(fofsynth_class);

     x->debug = 0;
     x->x_arrayname = s;

     if (s == &s_)
	  x->x_arrayname = NULL;

     /* setup the grain queue */
     
     x->grainbase = getbytes(sizeof(t_grain)*maxgrains);
     x->maxgrains = maxgrains;
     grain_makecyclic(x->grainbase,maxgrains);
     x->grainstart = x->grainbase;
     x->grainend = x->grainbase;    
     x->numgrains = 0;

     /* some of them could be signals too */

     floatinlet_new(&x->x_obj, &x->formfreq);
     floatinlet_new(&x->x_obj, &x->risedur);
     floatinlet_new(&x->x_obj, &x->falldur);

     x->fundph = 0.0; 
     x->fundfreq = 200.0;
     x->formfreq = 600.0; 
     x->risedur = 5.0; 
     x->falldur = 140.0; 

     if (a) x->fundfreq = a;
     if (b) x->formfreq = b; 
     if (c) x->risedur = c; 
     if (d) x->falldur = d; 

     outlet_new(&x->x_obj, &s_signal);
     return (x);
}
Exemplo n.º 22
0
static t_lifop_prioritylist*lifop_genprioritylist(t_lifop*x, t_float priority)
{
  t_lifop_prioritylist*result=0, *dummy=0;

  if(x->lifo_list!=0)
    {
      /*
       * do we already have this priority ?
       * if so, just return a pointer to that lifo
       * else set the dummy-pointer to the lifo BEFORE the new one
       */
      dummy=x->lifo_list;
      while(dummy!=0){
        t_float prio=dummy->priority;
        if(prio==priority)return dummy;
        if(prio>priority)break;
        result=dummy;
        dummy=dummy->next;
      }
      dummy=result;
    }
  /* create a new priority list */
  result = (t_lifop_prioritylist*)getbytes(sizeof( t_lifop_prioritylist));
  result->priority=priority;
  result->lifo_start=0;

  /* insert it into the list of priority lists */
  if(dummy==0){
    /* insert at the beginning */
    result->next=x->lifo_list;
    x->lifo_list=result;   
  } else {
    /* post insert into the list of LIFOs */
    result->next=dummy->next;
    dummy->next =result;
  }

  /* return the result */
  return result;
}
Exemplo n.º 23
0
/* generate sample data */
static t_int formant_gendata(t_formant *x)
{
    t_float t, b, fs;

    if ( x->x_size <= 0 || x->x_central_freq <= 0 || x->x_filter_width <= 0 || x->x_skirt_width <= 0 )
    {
        error( "formant~ : error generating data : negative or null parameter(s)" );
        return -1;
    }

    x->x_gendata = 1;

    /* freeing data */
    formant_free( x );
    if ( !( x->x_data = (float*) getbytes( x->x_size*sizeof(float) ) ) )
    {
        post( "formant~ : error generating data : cannot allocate table" );
        return -1;
    }

    fs = 0;
    while( fs < x->x_size-1 )
    {
        t = (fs/x->x_samplerate) * x->x_time_stretch; /* time taken from zero */
        b = M_PI / x->x_skirt_width ;
        if ( t < b )
        {
            *(x->x_data+(int)fs) = 0.5*(1-cos(x->x_skirt_width*t))*exp(- x->x_filter_width*t )*sin( x->x_central_freq*t);
        }
        else
        {
            *(x->x_data+(int)fs) = exp(- x->x_filter_width*t )*sin( x->x_central_freq*t);
        }
        fs++;
    }

    /* everything went fine */
    x->x_gendata = 0;
    return 0;
}
Exemplo n.º 24
0
int Read1NVTFrame(t_sdif_fileinfo *x, FILE *f, char *name, SDIF_FrameHeader *fhp) {
	// Just read the frame header, so go through the matrices looking for 1NVTs to print

    SDIFresult r;
	int i, sz;
	SDIF_MatrixHeader mh;
	char *buf;
	
	for (i = 0; i < fhp->matrixCount; ++i) {
        if (r = SDIF_ReadMatrixHeader(&mh, f)) {
        	object_error((t_object *)x, NAME ": error reading matrix header: %s", SDIF_GetErrorString(r));
   			return 0;     	
		}
		
		if (SDIF_Char4Eq("1NVT", mh.matrixType) && mh.matrixDataType == SDIF_UTF8) {
			sz = SDIF_GetMatrixDataSize(&mh);
			buf = (char *) getbytes(sz);
			if (buf == 0) {
				object_error((t_object *)x, NAME ": out of memory; can't read name/value table");
				return 0;
			}
			if (r = SDIF_ReadMatrixData((void *) buf, f, &mh)) {
			    object_error((t_object *)x, NAME ": error reading 1NVT matrix data: %s", SDIF_GetErrorString(r));
			    return 0;
			}
			//post("Name/value table:");
			//post("%s", buf);
			SDIFfileinfo_output1NVT(x, buf, fhp);
			freebytes(buf, sz);						
		} else {
			if (SDIF_Char4Eq("1NVT", mh.matrixType)) {
				object_post((t_object *)x, NAME ": 1NVT matrix has unexpected matrix data type 0x%x; skipping",  mh.matrixDataType);
			}				
			if (r = SDIF_SkipMatrix(&mh, f)) {
			    object_error((t_object *)x, NAME ": error skipping 1NVT matrix: %s", SDIF_GetErrorString(r));
			    return 0;
			 }
	    }
	  }
}
Exemplo n.º 25
0
static void spec2_tab_conv_tilde_dsp(t_spec2_tab_conv_tilde *x, t_signal **sp)
{
  int n = (sp[0]->s_n)/2;
  t_garray *a;
  int n_points;
  
  if(x->x_has_changed)
  {
    x->x_has_changed = 0;
    if(!(a = (t_garray *)pd_findbyclass(x->x_sym_array, garray_class)))
    {
      if(*x->x_sym_array->s_name)
        error("spec2_tab_conv~: %s: no such array", x->x_sym_array->s_name);
    }
    else if(!iemarray_getarray(a, &n_points, &x->x_beg_array))
      error("%s: bad template for spec2_tab_conv~", x->x_sym_array->s_name);
    else 
    {
      if(n_points > (n+1))
        n_points = n+1;
      if(x->x_winsize < 0)
        x->x_winsize = 0;
      if(x->x_winsize > n_points)
        x->x_winsize = n_points;
    }
  }
  
  if(!x->x_blocksize)
  {
    x->x_spec = (t_float *)getbytes(3*(n+1)*sizeof(t_float));
    x->x_blocksize = n;
  }
  else if(x->x_blocksize != n)
  {
    x->x_spec = (t_float *)resizebytes(x->x_spec, 3*(x->x_blocksize+1)*sizeof(t_float), 3*(n+1)*sizeof(t_float));
    x->x_blocksize = n;
  }
  
  dsp_add(spec2_tab_conv_tilde_perform, 4, sp[0]->s_vec, sp[1]->s_vec, x, n);
}
Exemplo n.º 26
0
/*--------------------------------------------------------------------
 * new SIZE
 *--------------------------------------------------------------------*/
static void *weightmap_new(t_floatarg f, t_floatarg max)
{
  t_weightmap *x;
  int i;

  x = (t_weightmap *)pd_new(weightmap_class);

  // create float (index) outlet
  outlet_new(&x->x_obj, &s_float);
  // create list (dump) outlet
  x->x_dumpoutlet = outlet_new(&x->x_obj, &s_list);

  // set number of elements
  x->x_nvalues = f;
  if ( x->x_nvalues < 1 ) x->x_nvalues = 1;

  // set maximum expected input probability
  x->x_wmax = max;
  if (!x->x_wmax) x->x_wmax = DEFAULT_WEIGHT_MAX;

  // allocate weight-vector
  x->x_weights = (t_float *)getbytes(x->x_nvalues*sizeof(t_float));
  if (!x->x_weights) {
    pd_error(x,"weightmap : failed to allocate weight vector");
    return NULL;
  }

  // initialize weights
  for (i = 0; i < x->x_nvalues; i++) {
    *(x->x_weights+i) = DEFAULT_WEIGHT_VALUE;
  }
  // initialize sum
  x->x_wsum = DEFAULT_WEIGHT_VALUE * x->x_nvalues;

#ifdef WEIGHTMAP_DEBUG
  post("weightmap_debug : create : nvalues=%d , wmax=%f", x->x_nvalues, x->x_wmax);
#endif

  return (void *)x;
}
Exemplo n.º 27
0
static void delay_maxsize(t_delay *x, t_float f)
{
//	   int maxsize = x->x_maxsize = (f > 1 ? (int)f : 1);
//     t_float *buf = (t_float *)getbytes(maxsize * sizeof(*buf));
//     if (x->x_delsize > x->x_maxsize)
// 	x->x_delsize = x->x_maxsize;
//     x->x_buf = x->x_whead = buf;
//     x->x_bufend = buf + maxsize - 1;
int maxsize = (f < 1 ? 1 : (int)f);
if (maxsize > x->x_maxsofar)
{
	x->x_maxsofar = maxsize;
	if (x->x_buf == x->x_bufini)
	{
		if (!(x->x_buf = (t_float *)getbytes((maxsize + 2*DELAY_GUARD - 1) * sizeof(*x->x_buf))))
		{
			x->x_buf = x->x_bufini;
			x->x_maxsize = DELAY_DEFMAXSIZE;
			pd_error(x, "unable to resize buffer; using size %d", DELAY_DEFMAXSIZE);
		}
	}
	else if (x->x_buf)
	{
		if (!(x->x_buf = (t_float *)resizebytes(x->x_buf, 
			(x->x_maxsize + 2*DELAY_GUARD - 1) * sizeof(*x->x_buf),
			(maxsize + 2*DELAY_GUARD - 1) * sizeof(*x->x_buf))))
		{
			x->x_buf = x->x_bufini;
			x->x_maxsize = DELAY_DEFMAXSIZE;
			pd_error(x, "unable to resize buffer; using size %d", DELAY_DEFMAXSIZE);
		}		
	}
}
x->x_maxsize = maxsize;
if (x->x_delsize > maxsize)
	x->x_delsize = maxsize;
x->x_remain = 0;
delay_clear(x);
delay_bounds(x);
} 
Exemplo n.º 28
0
static void lhisti_set(t_lhisti *x, t_float lo, t_float hi, t_float nbins)
{
	if (nbins<1)
	{
		nbins=1;
		logpost(x, 2, "[lhisti] number of bins is minimum 1");
	}
	if (hi<=lo)
	{
		post("[lhisti] higher bound (%g) must be greater than lower bound (%g)",
             hi, lo);	
		hi=lo+1.0f;
	}
	freebytes(x->m_lhisti, x->m_nbins);
	x->m_hi=hi;
	x->m_lo=lo;
	x->m_nbins=(int)nbins;
	x->m_scale=(t_float)x->m_nbins/(hi-lo);
    x->m_lhisti = (t_float*)getbytes(sizeof(t_float)*x->m_nbins);

	lhisti_clear(x);
}
Exemplo n.º 29
0
static void list2symbol_anything(t_list2symbol *x, t_symbol *s, int argc,
                                 t_atom *argv)
{
  if(x->ap) {
    freebytes(x->ap, x->ac*sizeof(t_atom));
    x->ap=0;
  }

  x->s =s;
  x->ac=argc;

  if(x->ac) {
    x->ap=(t_atom*)getbytes(x->ac*sizeof(t_atom));
  }
  if(x->ap) {
    t_atom*ap=x->ap;
    while(argc--) {
      *ap++=*argv++;
    }
  }
  list2symbol_bang(x);
}
Exemplo n.º 30
0
static void t3_line_tilde_dsp(t_t3_line_tilde *x, t_signal **sp)
{
  int i;
  t_float val, *trans;
  
  if(sp[0]->s_n > x->x_n)
  {
    freebytes(x->x_beg, x->x_n*sizeof(t_float));
    x->x_n = (int)sp[0]->s_n;
    x->x_beg = (t_float *)getbytes(x->x_n*sizeof(t_float));
  }
  else
    x->x_n = (int)sp[0]->s_n;
  i = x->x_n;
  val = x->x_cur_val;
  trans = x->x_beg;
  while(i--)
    *trans++ = val;
  x->x_ms2samps = 0.001*(double)sp[0]->s_sr;
  x->x_ticks2ms = (double)x->x_n / x->x_ms2samps;
  dsp_add(t3_line_tilde_perform, 3, sp[0]->s_vec, x, sp[0]->s_n);
}