Exemplo n.º 1
0
static void ritmo1_bang(t_ritmo1 *x) {

	int i, vecsize;
	t_garray *arysrc;
	t_garray *arydest;
	t_float *vecsrc;
	t_float *vecdest;

	if (!(arysrc = (t_garray *)pd_findbyclass(x->x_arrayname_src, garray_class)))
	{
        pd_error(x, "%s: no such array", x->x_arrayname_src->s_name);
	}
    else if (!garray_getfloatarray(arysrc, &vecsize, &vecsrc))
	{
		pd_error(x, "%s: bad template for tabwrite", x->x_arrayname_src->s_name);
	}
	  else 	if (!(arydest = (t_garray *)pd_findbyclass(x->x_arrayname_dest, garray_class)))
	{
        pd_error(x, "%s: no such array", x->x_arrayname_dest->s_name);
	}
    else if (!garray_getfloatarray(arydest, &vecsize, &vecdest))
	{
		pd_error(x, "%s: bad template for tabwrite", x->x_arrayname_dest->s_name);
	}
	else // I got arrays and data
	{
		// step 1: compute the pattern
		// and write it in vecdest
		for (i=0; i<16; i++)
		{
	//		vecdest[i] = (x->buf1[i] + x->buf2[i] + x->buf3[i] + vecsrc[i])/4;
			vecdest[i] = (x->buf1[i] + vecsrc[i])/2;
		}
		// redraw the arrays
		garray_redraw(arysrc);
		garray_redraw(arydest);

		// step 2: cycle buffers
	//	x->buf3 = x->buf2;
	//	x->buf2 = x->buf1;
	//	x->buf1 = x->buf3;
		// fill the first buffer with src data
		for (i=0; i<16; i++)
		{
			x->buf1[i] = vecsrc[i];
			vecsrc[i]=0;
		}
	}
}
Exemplo n.º 2
0
static t_float *n_CLNLMS_tilde_check_array(t_symbol *array_sym_name, t_int length)
{
  int n_points;
  t_garray *a;
  t_float *vec;
  
  if(!(a = (t_garray *)pd_findbyclass(array_sym_name, garray_class)))
  {
    error("%s: no such array for n_CLNLMS~", array_sym_name->s_name);
    return((t_float *)0);
  }
  else if(!garray_getfloatarray(a, &n_points, &vec))
  {
    error("%s: bad template for n_CLNLMS~", array_sym_name->s_name);
    return((t_float *)0);
  }
  else if(n_points < length)
  {
    error("%s: bad array-size for n_CLNLMS~: %d", array_sym_name->s_name, n_points);
    return((t_float *)0);
  }
  else
  {
    return(vec);
  }
}
Exemplo n.º 3
0
void chopper_set(t_chopper *x, t_symbol *wavename)
{
  int frames;
  t_garray *a;
  x->disabled = 0;

  x->b_frames = 0;
  x->b_nchans = 1;
  if (!(a = (t_garray *)pd_findbyclass(wavename, garray_class))) {
      if (*wavename->s_name) pd_error(x, "chopper~: %s: no such array",
				      wavename->s_name);
      x->b_samples = 0;
      x->disabled = 1;
    }
  else if (!garray_getfloatarray(a, &frames, &x->b_samples)) {
      pd_error(x, "%s: bad template for chopper~", wavename->s_name);
      x->b_samples = 0;
      x->disabled = 1;
    }
  else  {
    x->b_frames = frames;
//    post("%d frames in buffer",x->b_frames);
    garray_usedindsp(a);
  }
}
Exemplo n.º 4
0
t_pd_err carray_buffer_set(t_carray *x, t_eattr *attr, long argc, t_atom* argv)
{
    int i;
    x->f_array = NULL;
    if(argc && argv && atom_gettype(argv) == A_SYM)
    {
        x->f_name = atom_getsym(argv);
        if(!(x->f_array  = (t_garray *)pd_findbyclass(x->f_name, garray_class)))
        {
            x->f_array = NULL;
            x->f_name = gensym("(null)");
            x->f_buffer_size = 0;
            x->f_buffer = NULL;
        }
        else if(!garray_getfloatarray(x->f_array, &x->f_buffer_size, &x->f_buffer))
        {
            x->f_array = NULL;
            x->f_name = gensym("(null)");
            x->f_buffer_size = 0;
            x->f_buffer = NULL;
        }
        else
        {
            for(i = 0; i < x->f_buffer_size; i++)
                post("%f", x->f_buffer[i]);
            ebox_invalidate_layer((t_ebox*)x, gensym("buffer_layer"));
            ebox_redraw((t_ebox*)x);
        }
    }

    return 0;
}
Exemplo n.º 5
0
/////////////////////////////////////////////////////////
// floatMess
//
/////////////////////////////////////////////////////////
void spline_path :: floatMess(float val)
{
    if (!m_array)
    {
        error("no array");
        return;
    }

    int size;
    t_float *vec;
    if (!garray_getfloatarray(m_array, &size, &vec))
        return;

    if (size % m_numDimens)
    {
        error("size is not a mod of dimensions");
        return;
    }

    float output[64];
    splineFunc(val, output, m_numDimens, size / m_numDimens, vec);

	t_atom argv[64];
    for (int i = 0; i < m_numDimens; i++)
        SETFLOAT((&argv[i]), output[i]);

	outlet_list(m_out1, &s_list, m_numDimens, argv);
}
Exemplo n.º 6
0
Arquivo: FIR~.c Projeto: IcaroL2ORK/pd
void FIR_tilde_set(t_FIR_tilde *x, t_symbol *table_name, t_floatarg forder)
{
  t_garray *ga;
  int table_size;
  int order = (int)forder;
  
  x->x_table_name = table_name;
  if(!(ga = (t_garray *)pd_findbyclass(x->x_table_name, garray_class)))
  {
    if(*table_name->s_name)
      error("FIR~: %s: no such table~", x->x_table_name->s_name);
    x->x_coef_beg = 0;
  }
  else if(!garray_getfloatarray(ga, &table_size, &x->x_coef_beg))
  {
    error("%s: bad template for FIR~", x->x_table_name->s_name);
    x->x_coef_beg = 0;
  }
  else if(table_size < order)
  {
    error("FIR~: tablesize %d < order %d !!!!", table_size, order);
    x->x_coef_beg = 0;
  }
  else
    garray_usedindsp(ga);
  x->x_rw_index = 0;
  if(order > x->x_fir_order)/* resize */
    x->x_history_beg =  (t_float *)resizebytes(x->x_history_beg, 2*x->x_fir_order*sizeof(t_float), 2*order*sizeof(float));
  x->x_fir_order = order;
}
Exemplo n.º 7
0
static void tabwrite_float(t_tabwrite *x, t_float f)
{
#ifdef ROCKBOX
    int vecsize;
#else
    int i, vecsize;
#endif
    t_garray *a;
    t_sample *vec;

    if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
    	pd_error(x, "%s: no such array", x->x_arrayname->s_name);
    else if (!garray_getfloatarray(a, &vecsize, &vec))
    	pd_error(x, "%s: bad template for tabwrite", x->x_arrayname->s_name);
    else
    {
    	int n = x->x_ft1;
    	double timesince = clock_gettimesince(x->x_updtime);
    	if (n < 0) n = 0;
    	else if (n >= vecsize) n = vecsize-1;
    	vec[n] = ftofix(f);
    	if (timesince > 1000)
    	{
    	    tabwrite_tick(x);
    	}
    	else
    	{
    	    if (x->x_set == 0)
    	    {
    	    	clock_delay(x->x_clock, 1000 - timesince);
    	    	x->x_set = 1;
    	    }
    	}
    }
}
Exemplo n.º 8
0
static t_int *terrain_perform(t_int *w)
{
    t_terrain *x = (t_terrain *)(w[1]);
    t_float *inx = (t_float *)(w[2]);
    t_float *iny = (t_float *)(w[3]);
    t_float *out = (t_float *)(w[4]);
    int n = (int)(w[5]);
	t_buffer *b = x->l_buf;
	float *tab;
	float x_coords, y_coords, hopsize;
	long index1, index2, chan, nc,fsize, nframes;
	  size_t frames;
	register short p = 0,q;
	
	if (!b)
		goto zero;
	/* changes suggested by Krzysztof */
		 if (!garray_getfloatarray(b, &frames, &tab))
		goto zero;
	nc = 1;
	/* end of changes */
	fsize=x->l_framesize;
	nframes = x->l_numframes;
	hopsize = x->l_hopsize;
	while (--n) {
		x_coords = *++inx;
		y_coords = *++iny; 
		if (y_coords<0.) y_coords = 0.;
		if (y_coords>1.0) y_coords = 1.0; // constrain y coordinates to 0 to 1
		index1 = x_coords*fsize;
		if (index1<0) index1 = 0;
		if (index1>=fsize) index1 = fsize-1; // constrain index coordinates to the frame boundaries
		// check buffer~ boundaries
		if (index1 >= (long)frames)
			index1 = frames - 1;
		if (index1+((nframes-1)*fsize) >= (long)frames) // out of bounds
			goto zero;
		// figure out which two frames we're between...
		q=0;
		while (++q<nframes) {
			if (y_coords<=(hopsize*q)) {
				p = q-1;
				q=nframes;
			}
		}
		index1 = index1+(p*fsize); // current frame
		index2 = index1+fsize; // one frame later
		if (nc > 1) {
			index1 = index1 * nc;
			index2 = index2 * nc;
		}
		y_coords = (y_coords*(nframes-1))-p;
		*++out = ((1.-y_coords)*tab[index1])+(y_coords*tab[index2]); // this is wrong -- y_coords amp isn't scaling yet.
	}
	return (w+6);
zero:
	while (--n) *++out = 0.;
	return (w+6);
}
Exemplo n.º 9
0
Arquivo: pique.c Projeto: Angeldude/pd
static void pique_list(t_pique *x, t_symbol *s, int argc, t_atom *argv)
{
    int npts = atom_getintarg(0, argc, argv);
    t_symbol *symreal = atom_getsymbolarg(1, argc, argv);
    t_symbol *symimag = atom_getsymbolarg(2, argc, argv);
    int npeak = atom_getintarg(3, argc, argv);
    int n;
    t_garray *a;
    t_float *fpreal, *fpimag;
    if (npts < 8 || npeak < 1) error("pique: bad npoints or npeak");
    if (npeak > x->x_n) npeak = x->x_n;
    if (!(a = (t_garray *)pd_findbyclass(symreal, garray_class)) ||
    	!garray_getfloatarray(a, &n, &fpreal) ||
    	    n < npts)
    	    	error("%s: missing or bad array", symreal->s_name);
    else if (!(a = (t_garray *)pd_findbyclass(symimag, garray_class)) ||
    	!garray_getfloatarray(a, &n, &fpimag) ||
    	    n < npts)
    	    	error("%s: missing or bad array", symimag->s_name);
    else
    {
    	int nfound, i;
    	float *fpfreq = x->x_freq;
    	float *fpamp = x->x_amp;
    	float *fpampre = x->x_ampre;
    	float *fpampim = x->x_ampim;
    	pique_doit(npts, fpreal, fpimag, npeak,
    	    &nfound, fpfreq, fpamp, fpampre, fpampim, x->x_errthresh);
    	for (i = 0; i < nfound; i++, fpamp++, fpfreq++, fpampre++, fpampim++)
    	{
    	    t_atom at[5];
    	    SETFLOAT(at, (float)i);
    	    SETFLOAT(at+1, *fpfreq);
    	    SETFLOAT(at+2, *fpamp);
    	    SETFLOAT(at+3, *fpampre);
    	    SETFLOAT(at+4, *fpampim);
    	    outlet_list(x->x_obj.ob_outlet, &s_list, 5, at);   
    	}
    }
}
Exemplo n.º 10
0
void arrayfilt_setarray(t_arrayfilt *x, t_symbol *arrayname)
{
    t_garray *a;
	if (!(a = (t_garray *)pd_findbyclass(arrayname, garray_class))) {
		if (*arrayname->s_name) pd_error(x, "player~: %s: no such array", arrayname->s_name);
    }
	else  {
		garray_usedindsp(a);
        if (!garray_getfloatarray(a, &x->a_frames, &x->a_samples))
        {
            pd_error(x, "%s: bad template for player~", arrayname->s_name);
        }
	}
}
Exemplo n.º 11
0
/*
 * max_ex_tab -- evaluate this table access
 *		 eptr is the name of the table and arg is the index we
 *		 have to put the result in optr
 *		 return 1 on error and 0 otherwise
 *
 * Arguments:
 *  the expr object
 *  table 
 *  the argument 
 *  the result pointer 
 */
int
max_ex_tab(struct expr *expr, fts_symbol_t s, struct ex_ex *arg,
    struct ex_ex *optr)
{
#ifdef PD
	t_garray *garray;
	int size, indx;
	t_float *vec;

	if (!s || !(garray = (t_garray *)pd_findbyclass(s, garray_class)) ||
	    !garray_getfloatarray(garray, &size, &vec))
	{
		optr->ex_type = ET_FLT;
		optr->ex_flt = 0;
		pd_error(expr, "no such table '%s'", s->s_name);
		return (1);
	}
	optr->ex_type = ET_FLT;

	switch (arg->ex_type) {
	case ET_INT:
		indx = arg->ex_int;
		break;
	case ET_FLT:
		/* strange interpolation code deleted here -msp */
		indx = arg->ex_flt;
		break;

	default:	/* do something with strings */
		pd_error(expr, "expr: bad argument for table '%s'\n", fts_symbol_name(s));
		indx = 0;
	}
	if (indx < 0) indx = 0;
	else if (indx >= size) indx = size - 1;
	optr->ex_flt = vec[indx];
#else /* MSP */
	/*
	 * table lookup not done for MSP yet
	 */
	post("max_ex_tab: not complete for MSP yet!");
	optr->ex_type = ET_FLT;
	optr->ex_flt = 0;
#endif	
	return (0);
}
Exemplo n.º 12
0
void tabwrite_tilde_set(t_tabwrite_tilde *x, t_symbol *s)
{
    t_garray *a;

    x->x_arrayname = s;
    if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
    {
    	if (*s->s_name) pd_error(x, "tabwrite~: %s: no such array",
    	    x->x_arrayname->s_name);
    	x->x_vec = 0;
    }
    else if (!garray_getfloatarray(a, &x->x_nsampsintab, &x->x_vec))
    {
    	error("%s: bad template for tabwrite~", x->x_arrayname->s_name);
    	x->x_vec = 0;
    }
    else garray_usedindsp(a);
}
Exemplo n.º 13
0
void hoa_grain_buffer_set(t_hoa_grain *x, t_symbol *s)
{
    t_garray *a = NULL;
    x->f_buffer_name = s;
    if (!(a = (t_garray *)pd_findbyclass(x->f_buffer_name, garray_class)))
    {
        x->f_buffer = 0;
        x->f_number_of_samples = 0;
    }
    else if (!garray_getfloatarray(a, &x->f_number_of_samples, &x->f_buffer))
    {
        x->f_buffer = 0;
        x->f_number_of_samples = 0;
    }
    else
    {
        x->f_ambi_grain->writeWidowFunction(x->f_buffer, x->f_number_of_samples);
    }
}
Exemplo n.º 14
0
///////////////
// check if array exists and whether it is a floatarray
//
///////////////
static t_float* checkarray(t_symbol *s, int &length)
{
  t_garray *a;
  t_float  *fp;
  length = 0;

  if (!(a = reinterpret_cast<t_garray*>(pd_findbyclass(s, garray_class))))    {
    if (*s->s_name) error("vertex_tabread: %s: no such array", s->s_name);
    fp = 0;
  } else if (!garray_getfloatarray(a, &length, &fp))   {
    error("%s: bad template for vertex_tabread", s->s_name);
    fp = 0;
  }
  
  if (length==0){
    error("vertex_tabread: table %s is zero-lengthed", s->s_name);
    fp=0;
  }
  return fp;
}
Exemplo n.º 15
0
/*--------------------------------------------------------------------
 * get OFFSET LENGTH
 */
static void array2rawbytes_get(t_array2rawbytes *x, t_float offset_f, t_float len_f)
{
  int offset=offset_f, len=len_f, fvecsize, cvecsize;
  t_garray *a;
  t_float *fvec;
  unsigned char *cvec;

  //-- sanity check(s)
  if (!(a = (t_garray *)pd_findbyclass(x->x_name, garray_class))) {
    pd_error(x, "array2rawbytes_get: no such array '%s'", x->x_name->s_name);
    return;
  }

  //-- get float* from array
  if (!garray_getfloatarray(a, &fvecsize, &fvec))
    pd_error(x,"array2rawbytes: bad template for write to array '%s'", x->x_name->s_name);

  //-- get character offset & len
  cvec     = (unsigned char*)fvec;
  cvecsize = fvecsize*sizeof(t_float)/sizeof(unsigned char);
  post("array2rawbytes[x=%p]: char data: cvecsize=%d", x, cvecsize);

  //-- tweak out-of-bounds values
  post("array2rawbytes[x=%p]: pre-tweak: offset=%d, len=%d", x, offset, len);

  offset %= cvecsize;
  if (len <= 0 || offset+len >= cvecsize)
    len = cvecsize - offset;

  post("array2rawbytes[x=%p]: post-tweak: offset=%d, len=%d", x, offset, len);

  //-- munge x_bytes
  x->x_bytes.b_buf = cvec+offset;
  x->x_bytes.b_len = len;

  //-- convert bytes -> atoms
  pdstring_bytes2atoms(x, &x->x_atoms, &x->x_bytes, PDSTRING_EOS_NONE);

  //-- output
  outlet_list(x->x_outlet, &s_list, x->x_atoms.a_len, x->x_atoms.a_buf);
}
Exemplo n.º 16
0
// set user defined grain buffer
static void granu_set_array(t_grans *x, t_symbol *s)
{

    t_garray *a;
    
    x->x_arrayname = s;
    if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
    {
        if (*s->s_name)
            pd_error(x, "granufm~: %s: no such array", x->x_arrayname->s_name);
        
        x->x_vec = 0;
    }
    else if (!garray_getfloatarray(a, &x->x_npoints, &x->x_vec)) //store array in vector
    {
        pd_error(x, "granufm~: failed to get buffer data for %s", x->x_arrayname->s_name);
        x->x_vec = 0;
    }
    else garray_usedindsp(a);

}
Exemplo n.º 17
0
///////////////
// check if array exists and whether it is a floatarray
//
///////////////
t_float* pix_curve :: checkarray(t_symbol *s, int *length)
{
    t_garray *a;
    t_float  *fp;
    *length = 0;

    if (!(a = (t_garray *)pd_findbyclass(s, garray_class)))
    {
    	if (*s->s_name) error("%s: no such array", s->s_name);
    	fp = 0;
    }
    else if (!garray_getfloatarray(a, length, &fp))
    {
    	error("%s: bad template for tabwrite~", s->s_name);
    	fp = 0;
    }

    if (*length==0){
      error("table %s is zero-lengthed", s->s_name);
      fp=0;
    }
    return fp;
}
Exemplo n.º 18
0
void pvwarpb_attachbuf(t_pvwarpb *x)
{
  	int frames;
    t_symbol *buffername = x->buffername;
	t_garray *a;
    
	x->b_frames = 0;
	x->b_valid = 0;
	if (!(a = (t_garray *)pd_findbyclass(buffername, garray_class)))
    {
		if (*buffername->s_name) pd_error(x, "player~: %s: no such array",
                                          buffername->s_name);
    }
	else if (!garray_getfloatarray(a, &frames, &x->b_samples))
    {
		pd_error(x, "%s: bad template for player~", buffername->s_name);
    }
	else  {
		x->b_frames = frames;
		x->b_valid = 1;
		garray_usedindsp(a);
	}
}
Exemplo n.º 19
0
Arquivo: score.c Projeto: Angeldude/pd
static void score_float(t_score *x, t_floatarg f)
{
	/* This is the score following algorhythm:

	    first, we check if the note we got is in the score. In case
		it's not the next note, we'll search 'skipnotes' in advance.
		In case that fails we go back 'skipnotes' and check them. As
		extra these notes have to be 'younger' than 'skiptime' (to 
		avoid going back too far in case of slow melodies)
		As last resort we check if we probably just got the same not 
		again (double trigger from keyboard or the like) 
	                                                                 */

	t_int velo = x->x_velo;     /* get the velocity */
	t_garray *b = x->x_buf;		/* make local copy of array */
	float *tab;                 /* we'll store notes in here */
	int items;
	int i, j, n, check;

	x->x_pitch = (t_int)f;
	x->x_error = 0;

		/* check our array */
	if (!b)
	{
		post("score: no array selected!");
		x->x_error = 1;
		goto output;
	}
	if (!garray_getfloatarray(b, &items, &tab))
	{
		post("score: couldn't read from array!");
		x->x_error = 1;
		goto output;
	}

	if (x->x_state)	/* score follower is running */
	{
		n = check = x->x_notecount;		/* make local copys */

		if (x->x_velo != 0)		/* store note-on in alloctable */
		{
				/* store note in alloctable */
			x->x_alloctable[n] = (t_int)x->x_pitch;
				/* store note-on time */
			x->x_starttime[n] = clock_getlogicaltime();
			if(++x->x_notecount >= MAX_NOTES)x->x_notecount = 0;  /* total number of notes has increased */
		} else return;	/* we don't care about note-off's */

			/* first we try to find a match within the skip area */
			/* ( probably looking ahead in the score ) */
		for (i = x->x_index + 1; i < (x->x_index + x->x_skipindex + 1); i++)
		{
			// post("%d: %d -> %d", i, x->x_alloctable[n], (t_int)tab[i]);
			if(x->x_alloctable[n] == (t_int)tab[i])
			{
				if(i - x->x_index != 1) post("score: skipped %d notes!", i - x->x_index - 1);
				x->x_alloctable[n] = -1;		/* delete note, we've matched it! */
				x->x_index = i;
				goto output;
			}
		}

			/* then we look back within the boudaries of skiptime */
		for (i = x->x_index - 1; i > (x->x_index - x->x_skipindex) - 1; i--)
		{
			check = n;	/* get current notecount */

			for (j = 0; j < MAX_NOTES; j++)	/* check with every note from our alloctable */
			{ 
				if (x->x_alloctable[check] == (t_int)tab[i])	/* this one would fit */
				{
						/* check the time restrictions */
					if (clock_gettimesince(x->x_starttime[check]) < x->x_skiptime)
					{
						if (i != x->x_index) post("score: skipped %d notes in score!", x->x_index - i);
						if (j != 0) post("score: skipped %d notes from input!", j);
						post("score: going back by %g milliseconds!", clock_gettimesince(x->x_starttime[check]));
						x->x_index = i;
							/* new notecount: we assume the notes we skipped are errors made by the */
							/* performer. new notes will be added right behind the last valid one */
						x->x_notecount = (check++) % MAX_NOTES;
						x->x_alloctable[x->x_notecount - 1] = -1;	/* delete note since we've matched it */
						goto output;
					}
					else /* ough, too old ! */
					{
						post("score: matching note is too old! (ignored)");
						x->x_alloctable[check] = 0;		/* delete note since it's too old */
						x->x_error = 1;
						goto output;	/* stop with first match as all others would be far older */
					}
				}
				if(--check < 0) check = MAX_NOTES - 1;	/* decrease counter */
														/* as we want to go back in time */
			}
		}
			/* or is it just the same note again ??? (double trigger...) */
		if(x->x_pitch == x->x_lastpitch)
		{
			post("score: repetition! (ignored)");
			x->x_alloctable[x->x_notecount - 1] = -1; /* forget this one */
			return;
		}

			/* in case we found nothing: indicate that! */
		x->x_error = 1;
		post("score: couldn't find any matches !");
		x->x_lastpitch = x->x_pitch;
		goto output;
	}
	else return;

output:
		/* output index */
	outlet_float(x->x_outindex, x->x_index);
		/* bang in case of error */
	if(x->x_error) outlet_bang(x->x_outerror);
}
Exemplo n.º 20
0
Arquivo: flite.c Projeto: Angeldude/pd
/*--------------------------------------------------------------------
 * flite_synth : synthesize current text-buffer
 *--------------------------------------------------------------------*/
void flite_synth(t_flite *x) {
  cst_wave *wave;
  int i,vecsize;
  t_garray *a;
  t_float *vec;

# ifdef FLITE_DEBUG
  post("flite: got message 'synth'");
# endif

  // -- sanity checks
  if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) {
    pd_error(x,"flite: no such array '%s'", x->x_arrayname->s_name);
    return;
  }
  if (!x->textbuf) {
    pd_error(x,"flite: attempt to synthesize empty text-buffer!");
    return;
  }

# ifdef FLITE_DEBUG
  post("flite: flite_text_to_wave()");
# endif
  wave = flite_text_to_wave(x->textbuf,voice);

  if (!wave) {
    pd_error(x,"flite: synthesis failed for text '%s'", x->textbuf);
    return;
  }

  // -- resample
# ifdef FLITE_DEBUG
  post("flite: cst_wave_resample()");
# endif
  cst_wave_resample(wave,sys_getsr());

  // -- resize & write to our array
# ifdef FLITE_DEBUG
  post("flite: garray_resize(%d)", wave->num_samples);
# endif

  garray_resize(a, wave->num_samples);
  if (!garray_getfloatarray(a, &vecsize, &vec))
    pd_error(x,"flite: bad template for write to array '%s'", x->x_arrayname->s_name);

# ifdef FLITE_DEBUG
  post("flite: ->write to garray loop<-");
# endif
  for (i = 0; i < wave->num_samples; i++) {
    *vec++ = wave->samples[i]/32767.0;
  }

  // -- outlet synth-done-bang
  outlet_bang(x->x_obj.ob_outlet);

  // -- cleanup
  delete_wave(wave);

  // -- redraw
  garray_redraw(a);
}
Exemplo n.º 21
0
void GArhythm_reinit_pop(t_GArhythm *x)
{
	int i, j, vecsize, ntot, tmp, me;
	float prob, variatore;
	t_garray *arysrc_strum1;
	t_garray *arysrc_strum2;
	t_garray *arysrc_strum3;
	t_garray *arysrc_strum4;
	t_float *vecsrc_strum1;
	t_float *vecsrc_strum2;
	t_float *vecsrc_strum3;
	t_float *vecsrc_strum4;

	// load tables

	if (!(arysrc_strum1 = (t_garray *)pd_findbyclass(x->x_arrayname_src_strum1, garray_class)))
	{
        pd_error(x, "%s: no such array", x->x_arrayname_src_strum1->s_name);
	}
    else if (!garray_getfloatarray(arysrc_strum1, &vecsize, &vecsrc_strum1))
	{
		pd_error(x, "%s: bad template for tabwrite", x->x_arrayname_src_strum1->s_name);
	} 
	else if (!(arysrc_strum2 = (t_garray *)pd_findbyclass(x->x_arrayname_src_strum2, garray_class)))
	{
        pd_error(x, "%s: no such array", x->x_arrayname_src_strum2->s_name);
	}
    else if (!garray_getfloatarray(arysrc_strum2, &vecsize, &vecsrc_strum2))
	{
		pd_error(x, "%s: bad template for tabwrite", x->x_arrayname_src_strum2->s_name);
	}
	else if (!(arysrc_strum3 = (t_garray *)pd_findbyclass(x->x_arrayname_src_strum3, garray_class)))
	{
        pd_error(x, "%s: no such array", x->x_arrayname_src_strum3->s_name);
	}
    else if (!garray_getfloatarray(arysrc_strum3, &vecsize, &vecsrc_strum3))
	{
		pd_error(x, "%s: bad template for tabwrite", x->x_arrayname_src_strum3->s_name);
	}
	else if (!(arysrc_strum4 = (t_garray *)pd_findbyclass(x->x_arrayname_src_strum4, garray_class)))
	{
        pd_error(x, "%s: no such array", x->x_arrayname_src_strum4->s_name);
	}
    else if (!garray_getfloatarray(arysrc_strum4, &vecsize, &vecsrc_strum4))
	{
		pd_error(x, "%s: bad template for tabwrite", x->x_arrayname_src_strum4->s_name);
	}
	
	for (i=0; i<MAX_POPULATION; i++)
		{
			for (j=0; j<BUFFER_LENGHT; j++)
			{
				char c = 0x00;
				if (vecsrc_strum1[j])
					c = c | 0x01;
				if (vecsrc_strum2[j])
					c = c | (0x01 << 1);
				if (vecsrc_strum3[j])
					c = c | (0x01 << 2);
				if (vecsrc_strum4[j])
					c = c | (0x01 << 3);
				x->population[i][j]=c;
			}
		}
}
Exemplo n.º 22
0
static void GArhythm_bang(t_GArhythm *x) {

	int i, j, vecsize, ntot, tmp, me;
	float prob, variatore;
	t_garray *arysrc_strum1;
	t_garray *arysrc_strum2;
	t_garray *arysrc_strum3;
	t_garray *arysrc_strum4;
	t_garray *arydest_strum1;
	t_garray *arydest_strum2;
	t_garray *arydest_strum3;
	t_garray *arydest_strum4;
	t_float *vecsrc_strum1;
	t_float *vecsrc_strum2;
	t_float *vecsrc_strum3;
	t_float *vecsrc_strum4;
	t_float *vecdest_strum1;
	t_float *vecdest_strum2;
	t_float *vecdest_strum3;
	t_float *vecdest_strum4;
	double rnd;
	int winner;
	double winner_fitness;

	char figli[MAX_POPULATION][BUFFER_LENGHT];

	// load tables

	if (!(arysrc_strum1 = (t_garray *)pd_findbyclass(x->x_arrayname_src_strum1, garray_class)))
	{
        pd_error(x, "%s: no such array", x->x_arrayname_src_strum1->s_name);
	}
    else if (!garray_getfloatarray(arysrc_strum1, &vecsize, &vecsrc_strum1))
	{
		pd_error(x, "%s: bad template for tabwrite", x->x_arrayname_src_strum1->s_name);
	} 
	else if (!(arysrc_strum2 = (t_garray *)pd_findbyclass(x->x_arrayname_src_strum2, garray_class)))
	{
        pd_error(x, "%s: no such array", x->x_arrayname_src_strum2->s_name);
	}
    else if (!garray_getfloatarray(arysrc_strum2, &vecsize, &vecsrc_strum2))
	{
		pd_error(x, "%s: bad template for tabwrite", x->x_arrayname_src_strum2->s_name);
	}
	else if (!(arysrc_strum3 = (t_garray *)pd_findbyclass(x->x_arrayname_src_strum3, garray_class)))
	{
        pd_error(x, "%s: no such array", x->x_arrayname_src_strum3->s_name);
	}
    else if (!garray_getfloatarray(arysrc_strum3, &vecsize, &vecsrc_strum3))
	{
		pd_error(x, "%s: bad template for tabwrite", x->x_arrayname_src_strum3->s_name);
	}
	else if (!(arysrc_strum4 = (t_garray *)pd_findbyclass(x->x_arrayname_src_strum4, garray_class)))
	{
        pd_error(x, "%s: no such array", x->x_arrayname_src_strum4->s_name);
	}
    else if (!garray_getfloatarray(arysrc_strum4, &vecsize, &vecsrc_strum4))
	{
		pd_error(x, "%s: bad template for tabwrite", x->x_arrayname_src_strum4->s_name);
	}
	  else 	if (!(arydest_strum1 = (t_garray *)pd_findbyclass(x->x_arrayname_dest_strum1, garray_class)))
	{
        pd_error(x, "%s: no such array", x->x_arrayname_dest_strum1->s_name);
	}
    else if (!garray_getfloatarray(arydest_strum1, &vecsize, &vecdest_strum1))
	{
		pd_error(x, "%s: bad template for tabwrite", x->x_arrayname_dest_strum1->s_name);
	}
	 else 	if (!(arydest_strum2 = (t_garray *)pd_findbyclass(x->x_arrayname_dest_strum2, garray_class)))
	{
        pd_error(x, "%s: no such array", x->x_arrayname_dest_strum2->s_name);
	}
    else if (!garray_getfloatarray(arydest_strum2, &vecsize, &vecdest_strum2))
	{
		pd_error(x, "%s: bad template for tabwrite", x->x_arrayname_dest_strum2->s_name);
	}
	 else 	if (!(arydest_strum3 = (t_garray *)pd_findbyclass(x->x_arrayname_dest_strum3, garray_class)))
	{
        pd_error(x, "%s: no such array", x->x_arrayname_dest_strum3->s_name);
	}
    else if (!garray_getfloatarray(arydest_strum3, &vecsize, &vecdest_strum3))
	{
		pd_error(x, "%s: bad template for tabwrite", x->x_arrayname_dest_strum3->s_name);
	}
	 else 	if (!(arydest_strum4 = (t_garray *)pd_findbyclass(x->x_arrayname_dest_strum4, garray_class)))
	{
        pd_error(x, "%s: no such array", x->x_arrayname_dest_strum4->s_name);
	}
    else if (!garray_getfloatarray(arydest_strum4, &vecsize, &vecdest_strum4))
	{
		pd_error(x, "%s: bad template for tabwrite", x->x_arrayname_dest_strum4->s_name);
	}
	else // I got arrays and data
	{
		// vecdest_strum2 e _strum1 contengono i valori in float degli array
		if (DEBUG)
			post("--------- starting process");
	
		// uccido a caso REINSERT_SRC elementi e inserisco il ritmo src al loro posto
		for (i=0; i<x->reinsert_src; i++)
		{
			rnd = rand()/((double)RAND_MAX + 1);
			me = (int) (rnd * MAX_POPULATION);
			for (j=0; j<BUFFER_LENGHT; j++)
			{
				char c = 0x00;
				if (vecsrc_strum1[j])
					c = c | 0x01;
				if (vecsrc_strum2[j])
					c = c | (0x01 << 1);
				if (vecsrc_strum3[j])
					c = c | (0x01 << 2);
				if (vecsrc_strum4[j])
					c = c | (0x01 << 3);
				x->population[me][j]=c;
			}
		}
		// uccido a caso REINSERT_LAST elementi e inserisco il last al loro posto
		for (i=0; i<x->reinsert_last; i++)
		{
			rnd = rand()/((double)RAND_MAX + 1);
			me = (int) (rnd * MAX_POPULATION);
			for (j=0; j<BUFFER_LENGHT; j++)
			{
				x->population[me][j]=x->last[j];
			}
		}

		// metà sono donne, prese a caso
		for (i=0; i<(MAX_POPULATION/2); i++)
		{
			int winner=CHOIR;
			int winner_value=0;
			int men[CHOIR];
			char figlio[BUFFER_LENGHT];
			double fitness1[CHOIR];
			double fitness2[CHOIR];
			double fitness3[CHOIR];
			double fitnessTOT[CHOIR];
			rnd = rand()/((double)RAND_MAX + 1);
			me =(int) ( rnd * MAX_POPULATION); // da 0 a MAX_POPULATION
			// me è la donna che valuta gli uomini

			if (DEBUG)
				post("woman %i = %i %i %i %i", me, x->population[me][0], x->population[me][1], x->population[me][2], x->population[me][3]);

			for (j=0; j<CHOIR; j++)
			{
				rnd = rand()/((double)RAND_MAX + 1);
				tmp =(int) ( rnd * MAX_POPULATION); // da 0 a MAX_POPULATION
				// tmp è questo uomo
				men[j] = tmp;
				fitness1[j]=GArhythm_evaluate_fitness1(x->population[me], x->population[tmp]);
				fitness2[j]=GArhythm_evaluate_fitness2(x->population[me], x->population[tmp]);
				fitness3[j]=GArhythm_evaluate_fitness3(x->population[me], x->population[tmp]);
				fitnessTOT[j]=fitness1[j] * (x->indice_aderenza) 
					+ fitness2[j] * (x->indice_riempimento) 
					+ (1 - fitness2[j]) * (1-(x->indice_riempimento)) 
					+ fitness3[j] * (x->indice_variazione)
					+ GArhythm_evaluate_fitness4(x->population[me], x->population[tmp]);
				if (winner_value <= fitnessTOT[j])
				{
					winner = tmp;
					winner_value = fitnessTOT[j];
				}
			}
			// winner è il maschio migliore nel coro
			if (DEBUG)
				post("ho scelto il maschio %i", winner);
			// genero un figlio
			GArhythm_create_child(x, x->population[me], x->population[winner], figlio);
			for (j=0; j<BUFFER_LENGHT; j++)
			{
				figli[i][j] = figlio[j];
			}
		}

		// uccido a caso metà popolazione e ci metto i nuovi nati
		for (i=0; i<(MAX_POPULATION/2); i++)
		{
			rnd = rand()/((double)RAND_MAX + 1);
			me =(int) ( rnd * MAX_POPULATION); // da 0 a MAX_POPULATION
			// me è chi deve morire

			for (j=0; j<BUFFER_LENGHT; j++)
			{
				x->population[me][j] = figli[i][j];
			}
		}

		// prendo il più adatto rispetto all'ultimo ritmo suonato
		winner = 0;
		winner_fitness = 0;
		for(i=0; i<BUFFER_LENGHT; i++)
		{
			double tmp1, tmp2, tmp3, tmpTOT;
			tmp1 = GArhythm_evaluate_fitness1(x->last, x->population[i]);
			tmp2 = GArhythm_evaluate_fitness2(x->last, x->population[i]);
			tmp3 = GArhythm_evaluate_fitness3(x->last, x->population[i]);
			tmpTOT = tmp1 * (x->indice_aderenza) 
					+ tmp2 * (x->indice_riempimento) 
					+ (1-tmp2) * (1-(x->indice_riempimento)) 
					+ tmp3 * (x->indice_variazione)
					+ GArhythm_evaluate_fitness4(x->last, x->population[i]);
			if (tmpTOT >= winner_fitness)
			{
				winner_fitness = tmpTOT;
				winner = i;
			}
		}
			
		for (i=0; i<BUFFER_LENGHT; i++)
		{
			// copio il vincitor ein x->last
			x->last[i] = x->population[winner][i];
			// scrivo i buffer in uscita
			vecdest_strum1[i]=((x->population[winner][i] & (0x01<<0)) ? 1 : 0);				
			vecdest_strum2[i]=((x->population[winner][i] & (0x01<<1)) ? 1 : 0);				
			vecdest_strum3[i]=((x->population[winner][i] & (0x01<<2)) ? 1 : 0);				
			vecdest_strum4[i]=((x->population[winner][i] & (0x01<<3)) ? 1 : 0);				
		}

		// redraw the arrays
		//garray_redraw(arysrc);
		garray_redraw(arydest_strum1);
		garray_redraw(arydest_strum2);
		garray_redraw(arydest_strum3);
		garray_redraw(arydest_strum4);


	}
}