Exemplo n.º 1
0
static void *nearestPoint_new(t_float dim)
{
    t_nearestPoint *x = (t_nearestPoint *)pd_new(nearestPoint_class);
	int i;
	
    x->nearest = outlet_new(&x->x_obj, &s_float);
    x->nearestDist = outlet_new(&x->x_obj, &s_float);
    inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("list"), gensym("nearest"));
    	
	if(dim)
		x->dimensions = dim;
	else
		x->dimensions = 2;

    x->numPoints = 0;

    x->x_coordinates = (t_coordinate *)t_getbytes(x->numPoints);

	// resize feature input buffer to default dimensions
    x->x_input = (t_float *)t_getbytes(x->dimensions*sizeof(t_float));

    // initialize feature input buffer
	for(i=0; i<x->dimensions; i++)
		x->x_input[i] = 0.0;

	post("nearestPoint: dimensionality: %i.", x->dimensions);

    return (x);
}
Exemplo n.º 2
0
t_binbuf *binbuf_new(void)
{
    t_binbuf *x = (t_binbuf *)t_getbytes(sizeof(*x));
    x->b_n = 0;
    x->b_vec = t_getbytes(0);
    return (x);
}
Exemplo n.º 3
0
static t_symbol *dogensym(const char *s, t_symbol *oldsym,
    t_pdinstance *pdinstance)
{
    t_symbol **sym1, *sym2;
    unsigned int hash = 5381;
    int length = 0;
    const char *s2 = s;
    while (*s2) /* djb2 hash algo */
    {
        hash = ((hash << 5) + hash) + *s2;
        length++;
        s2++;
    }
    sym1 = pdinstance->pd_symhash + (hash & (SYMTABHASHSIZE-1));
    while ((sym2 = *sym1))
    {
        if (!strcmp(sym2->s_name, s)) return(sym2);
        sym1 = &sym2->s_next;
    }
    if (oldsym)
        sym2 = oldsym;
    else sym2 = (t_symbol *)t_getbytes(sizeof(*sym2));
    sym2->s_name = t_getbytes(length+1);
    sym2->s_next = 0;
    sym2->s_thing = 0;
    strcpy(sym2->s_name, s);
    *sym1 = sym2;
    return (sym2);
}
Exemplo n.º 4
0
void *granulesf_new(t_symbol *msg, short argc, t_atom *argv)
{

    t_granulesf *x = (t_granulesf *)pd_new(granulesf_class);
    outlet_new(&x->x_obj, gensym("signal"));
    outlet_new(&x->x_obj, gensym("signal"));
    x->wavebuf = (t_pdbuffer*)malloc(sizeof(t_pdbuffer));
    x->windowbuf = (t_pdbuffer*)malloc(sizeof(t_pdbuffer));
	srand(time(0)); //need "seed" message
    
	x->pitchscale = (float *) t_getbytes(MAXSCALE * sizeof(float));
	x->grains = (t_grain *) t_getbytes(MAXGRAINS * sizeof(t_grain));
	
    
	// default names
	x->wavename = gensym("waveform");
	x->windowname = gensym("window");

    
    // apparently Pd lacks this Max/MSP bug
	x->wavename = atom_getsymbolarg(0,argc,argv);
	x->windowname = atom_getsymbolarg(1,argc,argv);

    
	x->sr = sys_getsr();
	if(! x->sr )
		x->sr = 44100;
    
	granulesf_init(x,0);
    
    
    return (x);
}
Exemplo n.º 5
0
t_symbol *dogensym(const char *s, t_symbol *oldsym)
{
    t_symbol **sym1, *sym2;
    unsigned int hash1 = 0,  hash2 = 0;
    int length = 0;
    const char *s2 = s;
    while (*s2)
    {
        hash1 += *s2;
        hash2 += hash1;
        length++;
        s2++;
    }
    sym1 = symhash + (hash2 & (HASHSIZE-1));
    while (sym2 = *sym1)
    {
        if (!strcmp(sym2->s_name, s)) return(sym2);
        sym1 = &sym2->s_next;
    }
    if (oldsym) sym2 = oldsym;
    else
    {
        sym2 = (t_symbol *)t_getbytes(sizeof(*sym2));
        sym2->s_name = t_getbytes(length+1);
        sym2->s_next = 0;
        sym2->s_thing = 0;
        strcpy(sym2->s_name, s);
    }
    *sym1 = sym2;
    return (sym2);
}
Exemplo n.º 6
0
t_binbuf *binbuf_duplicate(t_binbuf *y)
{
    t_binbuf *x = (t_binbuf *)t_getbytes(sizeof(*x));
    x->b_n = y->b_n;
    x->b_vec = t_getbytes(x->b_n * sizeof(*x->b_vec));
    memcpy(x->b_vec, y->b_vec, x->b_n * sizeof(*x->b_vec));
    return (x);
}
Exemplo n.º 7
0
static void *magSpec_tilde_new(t_symbol *s, int argc, t_atom *argv)
{
    t_magSpec_tilde *x = (t_magSpec_tilde *)pd_new(magSpec_tilde_class);
	int i, isPow2;
	s=s;
	
	x->x_mag = outlet_new(&x->x_obj, gensym("list"));
	
	if(argc > 0)
	{
		x->window = atom_getfloat(argv);
		isPow2 = (int)x->window && !( ((int)x->window-1) & (int)x->window );
		
		if(!isPow2)
		{
			error("requested window size is not a power of 2. default value of 1024 used instead");
			x->window = 1024;
		};
	}
	else
		x->window = 1024;	
	
	
	x->sr = 44100.0;
	x->n = 64.0;
	x->overlap = 1;
	x->windowFunction = 4; // 4 is hann window
	x->normalize = 1;
	x->powerSpectrum = 0;
	x->lastDspTime = clock_getlogicaltime();

	x->signal_R = (t_sample *)t_getbytes((x->window+x->n) * sizeof(t_sample));

 	for(i=0; i<(x->window+x->n); i++)
		x->signal_R[i] = 0.0;

  	x->blackman = (t_float *)t_getbytes(x->window*sizeof(t_float));
  	x->cosine = (t_float *)t_getbytes(x->window*sizeof(t_float));
  	x->hamming = (t_float *)t_getbytes(x->window*sizeof(t_float));
  	x->hann = (t_float *)t_getbytes(x->window*sizeof(t_float));

 	// initialize signal windowing functions
	tIDLib_blackmanWindow(x->blackman, x->window);
	tIDLib_cosineWindow(x->cosine, x->window);
	tIDLib_hammingWindow(x->hamming, x->window);
	tIDLib_hannWindow(x->hann, x->window);

    post("magSpec~: window size: %i", (int)x->window);
    
    return (x);
}
Exemplo n.º 8
0
static void *pique_new(t_floatarg f)
{
    int n = f;
    t_pique *x = (t_pique *)pd_new(pique_class);
    if (n < 1) n = 100;
    x->x_n = n;
    x->x_errthresh = 0;
    x->x_freq = t_getbytes(n * sizeof(*x->x_freq));
    x->x_amp = t_getbytes(n * sizeof(*x->x_amp));
    x->x_ampre = t_getbytes(n * sizeof(*x->x_ampre));
    x->x_ampim = t_getbytes(n * sizeof(*x->x_ampim));
    outlet_new(&x->x_obj, &s_list);
    return (x);
}
Exemplo n.º 9
0
Arquivo: dict.c Projeto: pure-data/xeq
/* adapted dogensym() from m_class.c */
t_symbol *dict_dokey(t_dict *x, char *s, t_symbol *oldsym)
{
    t_symbol **sym1, *sym2;
    unsigned int hash1 = 0,  hash2 = 0;
    int length = 0;
    char *s2 = s;
    int mask = x->d_hashsize - 1;
#ifdef DICT_DEBUG
    startpost("make symbol-key from \"%s\"", s);
#endif
    while (*s2)
    {
	hash1 += *s2;
	hash2 += hash1;
	length++;
	s2++;
    }
    sym1 = x->d_hashtable + (hash2 & mask);
#ifdef DICT_DEBUG
    post(" in slot %d", (hash2 & mask));
#endif
    while (sym2 = *sym1)
    {
#ifdef DICT_DEBUG
	post("try \"%s\"", sym2->s_name);
#endif
	if (!strcmp(sym2->s_name, s))
	{
#ifdef DICT_DEBUG
	    post("found at address %x", (int)sym2);
#endif
	    return(sym2);
	}
	sym1 = &sym2->s_next;
    }
    if (oldsym) sym2 = oldsym;
    else
    {
    	sym2 = (t_symbol *)t_getbytes(sizeof(*sym2));
    	sym2->s_name = t_getbytes(length+1);
    	sym2->s_next = 0;
    	sym2->s_thing = 0;
    	strcpy(sym2->s_name, s);
    }
    *sym1 = sym2;
#ifdef DICT_DEBUG
    post("appended at address %x", (int)sym2);
#endif
    return (sym2);
}
Exemplo n.º 10
0
static void pack_bang(t_pack *x)
{
    int i, reentered = 0, size = x->x_n * sizeof (t_atom);
    t_gpointer *gp;
    t_atom *outvec;
    for (i = x->x_nptr, gp = x->x_gpointer; i--; gp++)
    	if (!gpointer_check(gp, 1))
    {
    	pd_error(x, "pack: stale pointer");
    	return;
    }
    	/* reentrancy protection.  The first time through use the pre-allocated
	x_outvec; if we're reentered we have to allocate new memory. */
    if (!x->x_outvec)
    {
    	    /* LATER figure out how to deal with reentrancy and pointers... */
    	if (x->x_nptr)
	    post("pack_bang: warning: reentry with pointers unprotected");
	outvec = t_getbytes(size);
	reentered = 1;
    }
    else
    {
    	outvec = x->x_outvec;
	x->x_outvec = 0;
    }
    memcpy(outvec, x->x_vec, size);
    outlet_list(x->x_obj.ob_outlet, &s_list, x->x_n, outvec);
    if (reentered)
    	t_freebytes(outvec, size);
    else x->x_outvec = outvec;
}
Exemplo n.º 11
0
EXTERN t_pdinstance *pdinstance_new(void)
{
    t_pdinstance *x = (t_pdinstance *)getbytes(sizeof(t_pdinstance));
    t_class *c;
    int i;
    pd_this = x;
    s_inter_newpdinstance();
    pdinstance_init(x);
    sys_lock();
    pd_globallock();
    pd_instances = (t_pdinstance **)resizebytes(pd_instances,
        pd_ninstances * sizeof(*pd_instances),
        (pd_ninstances+1) * sizeof(*pd_instances));
    pd_instances[pd_ninstances] = x;
    for (c = class_list; c; c = c->c_next)
    {
        c->c_methods = (t_methodentry **)t_resizebytes(c->c_methods,
            pd_ninstances * sizeof(*c->c_methods),
            (pd_ninstances + 1) * sizeof(*c->c_methods));
        c->c_methods[pd_ninstances] = t_getbytes(0);
        for (i = 0; i < c->c_nmethod; i++)
            class_addmethodtolist(c, &c->c_methods[pd_ninstances], i,
                c->c_methods[0][i].me_fun,
                dogensym(c->c_methods[0][i].me_name->s_name, 0, x),
                    c->c_methods[0][i].me_arg, x);
    }
    pd_ninstances++;
    pdinstance_renumber();
    pd_bind(&glob_pdobject, gensym("pd"));
    text_template_init();
    garray_init();
    pd_globalunlock();
    sys_unlock();
    return (x);
}
Exemplo n.º 12
0
static void* pod_tilde_new(t_floatarg window_size, t_floatarg hop_size)
{
    t_pod_tilde *x = (t_pod_tilde *)pd_new(pod_tilde_class);
    inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
        
    // Leftmost outlet outputs a bang
    x->bang = outlet_new(&x->x_obj, &s_bang);
    
    // Initialize filter coeffs
    // Outer
    x->o_a1 = 0.0;
    x->o_a2 = 0.0;
    x->o_b0 = 0.0;
    x->o_b1 = 0.7221;
    x->o_b2 = -0.6918;
    
    // Middle
    x->m_a1 = 1.6456;
    x->m_a2 = 0.6791;
    x->m_b0 = 0.8383;
    x->m_b1 = 0.0;
    x->m_b2 = -0.8383;
    
    // Window Size
    x->window_size = window_size;           // There should be a check to see if this is a power of two
    x->signal = (t_sample *)t_getbytes(x->window_size * sizeof(t_sample));
    x->analysis = (t_sample *)t_getbytes(x->window_size * sizeof(t_sample));
    x->window = (t_float *)t_getbytes(x->window_size * sizeof(t_float));
    for (int i = 0; i < x->window_size; i++)
    {
        x->signal[i] = 0.0;
        x->analysis[i] = 0.0;
        x->window[i] = 0.0;
    }
    pod_tilde_create_window(x);
    
    x->hop_size = hop_size;                 // This is in samples
    x->dsp_tick = 0;
    
    
    post("pod~ v.0.1 by Gregoire Tronel, Jay Clark, and Scott McCoid");
    post("window size: %i", x->window_size);
    post("hop size: %i", x->hop_size);
    
    return (void *)x; 
}
Exemplo n.º 13
0
static void vline_tilde_float(t_vline *x, t_float f)
{
    t_time timenow = clock_gettimesince(x->x_referencetime);
    t_sample inlet1 = (x->x_inlet1 < 0 ? 0 : (t_sample)x->x_inlet1);
    t_sample inlet2 = (t_sample) x->x_inlet2;
    t_time starttime = timenow + inlet2;
    t_vseg *s1, *s2, *deletefrom = 0,
    	*snew = (t_vseg *)t_getbytes(sizeof(*snew));
    if (PD_BADFLOAT(f))
	f = 0;

    	/* negative delay input means stop and jump immediately to new value */
    if (inlet2 < 0)
    {
    	vline_tilde_stop(x);
	x->x_value = ftofix(f);
	return;
    }
    	/* check if we supplant the first item in the list.  We supplant
	an item by having an earlier starttime, or an equal starttime unless
	the equal one was instantaneous and the new one isn't (in which case
	we'll do a jump-and-slide starting at that time.) */
    if (!x->x_list || x->x_list->s_starttime > starttime ||
    	(x->x_list->s_starttime == starttime &&
	    (x->x_list->s_targettime > x->x_list->s_starttime || inlet1 <= 0)))
    {
    	deletefrom = x->x_list;
	x->x_list = snew;
    }
    else
    {
    	for (s1 = x->x_list; (s2 = s1->s_next); s1 = s2)
	{
    	    if (s2->s_starttime > starttime ||
    		(s2->s_starttime == starttime &&
		    (s2->s_targettime > s2->s_starttime || inlet1 <= 0)))
	    {
    		deletefrom = s2;
		s1->s_next = snew;
		goto didit;
	    }
	}
	s1->s_next = snew;
	deletefrom = 0;
    didit: ;
    }
    while (deletefrom)
    {
    	s1 = deletefrom->s_next;
	t_freebytes(deletefrom, sizeof(*deletefrom));
	deletefrom = s1;
    }
    snew->s_next = 0;
    snew->s_target = f;
    snew->s_starttime = starttime;
    snew->s_targettime = starttime + inlet1;
    x->x_inlet1 = x->x_inlet2 = 0;
}
Exemplo n.º 14
0
void classtable_register(t_class *c)
{
    t_classtable *t;
    for(t = ct; t; t = t->ct_next)
        if (t->ct_class == c) post("already registered %s", c->c_name->s_name);
    t = (t_classtable *)t_getbytes(sizeof(*t));
    t->ct_class = c;
    t->ct_next = ct;
    ct = t;
}
Exemplo n.º 15
0
Arquivo: m_pd.c Projeto: Tzero2/pd
void pd_pushsym(t_pd *x)
{
    t_gstack *y = (t_gstack *)t_getbytes(sizeof(*y));
    y->g_what = s__X.s_thing;
    y->g_next = gstack_head;
    y->g_loadingabstraction = pd_loadingabstraction;
    pd_loadingabstraction = 0;
    gstack_head = y;
    s__X.s_thing = x;
}
Exemplo n.º 16
0
static void *netreceive_new(t_symbol *s, int argc, t_atom *argv)
{
    t_netreceive *x = (t_netreceive *)pd_new(netreceive_class);
    int portno = 0;
    x->x_ns.x_protocol = SOCK_STREAM;
    x->x_old = 0;
    x->x_ns.x_bin = 0;
    x->x_nconnections = 0;
    x->x_connections = (int *)t_getbytes(0);
    x->x_ns.x_sockfd = -1;
    if (argc && argv->a_type == A_FLOAT)
    {
        portno = atom_getfloatarg(0, argc, argv);
        x->x_ns.x_protocol = (atom_getfloatarg(1, argc, argv) != 0 ?
            SOCK_DGRAM : SOCK_STREAM);
        x->x_old = (!strcmp(atom_getsymbolarg(2, argc, argv)->s_name, "old"));
        argc = 0;
    }
    else 
    {
        while (argc && argv->a_type == A_SYMBOL &&
            *argv->a_w.w_symbol->s_name == '-')
        {
            if (!strcmp(argv->a_w.w_symbol->s_name, "-b"))
                x->x_ns.x_bin = 1;
            else if (!strcmp(argv->a_w.w_symbol->s_name, "-u"))
                x->x_ns.x_protocol = SOCK_DGRAM;
            else
            {
                pd_error(x, "netreceive: unknown flag ...");
                postatom(argc, argv); endpost();
            }
            argc--; argv++;
        }
    }
    if (argc && argv->a_type == A_FLOAT)
        portno = argv->a_w.w_float, argc--, argv++;
    if (argc)
    {
        pd_error(x, "netreceive: extra arguments ignored:");
        postatom(argc, argv); endpost();
    }
    if (x->x_old)
    {
        /* old style, nonsecure version */
        x->x_ns.x_msgout = 0;
    }
    else x->x_ns.x_msgout = outlet_new(&x->x_ns.x_obj, &s_anything);
        /* create a socket */
    if (portno > 0)
        netreceive_listen(x, portno);

    return (x);
}
Exemplo n.º 17
0
static void bark_create_loudness_weighting(t_bark *x)
{
	int i;
	t_float bark_sum, *bark_freqs;

	bark_freqs = (t_float *)t_getbytes(x->numFilters * sizeof(t_float));

	bark_sum = x->barkSpacing;

	for(i=0; i<x->numFilters; i++)
	{
		bark_freqs[i] = tIDLib_bark2freq(bark_sum);
		bark_sum += x->barkSpacing;
	}

	for(i=0; i<x->numFilters; i++)
	{
		int nearIdx;
		t_float nearFreq, diffFreq, diffdB, dBint;

		nearIdx = tIDLib_nearestBinIndex(bark_freqs[i], weights_freqs, NUMWEIGHTPOINTS);
		nearFreq = weights_freqs[nearIdx];
		diffdB = 0;

		// this doesn't have to be if/else'd into a greater/less situation.  later on i should write a more general interpolation solution, and maybe move it up to 4 points instead.
		if(bark_freqs[i]>nearFreq)
		{
			if(nearIdx<=NUMWEIGHTPOINTS-2)
			{
				diffFreq = (bark_freqs[i] - nearFreq)/(weights_freqs[nearIdx+1] - nearFreq);
				diffdB = diffFreq * (weights_dB[nearIdx+1] - weights_dB[nearIdx]);
			}

			dBint = weights_dB[nearIdx] + diffdB;
		}
		else
		{
			if(nearIdx>0)
			{
				diffFreq = (bark_freqs[i] - weights_freqs[nearIdx-1])/(nearFreq - weights_freqs[nearIdx-1]);
				diffdB = diffFreq * (weights_dB[nearIdx] - weights_dB[nearIdx-1]);
			}

			dBint = weights_dB[nearIdx-1] + diffdB;
		}

		if(x->powerSpectrum)
			x->loudWeights[i] = pow(10.0, dBint*0.1);
		else
			x->loudWeights[i] = pow(10.0, dBint*0.05);

	}
}
Exemplo n.º 18
0
void *multigrain_new(t_symbol *msg, short argc, t_atom *argv)
{
    t_multigrain *x = (t_multigrain *)object_alloc(multigrain_class);
    float f = 2;
    int i;
    dsp_setup((t_pxobject *)x,1);

    
    srand(time(0)); //need "seed" message
    
    x->pitchscale = (float *) t_getbytes(MAXSCALE * sizeof(float));
    x->grains = (t_grain *) t_getbytes(MAXGRAINS * sizeof(t_grain));
    
    
    // default names
    x->wavename = gensym("waveform");
    x->windowname = gensym("window");
    
    if( argc < 2){
        error("Must enter wave buffer, window buffer, and output channel count");
        return NULL;
    }
    if(argc > 0)
        atom_arg_getsym(&x->wavename,0,argc,argv);
    if(argc > 1)
        atom_arg_getsym(&x->windowname,1,argc,argv);
    if(argc > 2)
        atom_arg_getfloat(&f,2,argc,argv);
    
    x->output_channels = (long) f;
    for(i = 0; i < x->output_channels; i++){
        outlet_new((t_pxobject *)x, "signal");
    }
    x->wavebuf = buffer_ref_new((t_object*)x, x->wavename);
    x->windowbuf = buffer_ref_new((t_object*)x, x->windowname);
    
    
    multigrain_init(x,0);
    return x;
}
Exemplo n.º 19
0
static void *specCentroid_new(t_symbol *s)
{
    t_specCentroid *x = (t_specCentroid *)pd_new(specCentroid_class);
	int i;
	t_garray *a;

	x->x_centroid = outlet_new(&x->x_obj, &s_float);
	
	if(s)
	{
		x->x_arrayname = s;

	    if(!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
	        ;
	    else if(!garray_getfloatwords(a, &x->x_arrayPoints, &x->x_vec))
	    	pd_error(x, "%s: bad template for specCentroid", x->x_arrayname->s_name);
	}
	else
		error("specCentroid: no array specified.");

	x->sr = 44100.0;
	x->window = 1; // should be a bogus size initially to force the proper resizes when a real _analyze request comes through
	x->windowFuncSize = 1;
	x->windowFunction = 4; // 4 is hann window
	x->powerSpectrum = 0; // choose mag (0) or power (1) spec in the specCentroid computation

	x->maxWindowSize = MAXWINDOWSIZE; // this seems to be the maximum size allowable by mayer_realfft();
	x->powersOfTwo = (int *)t_getbytes(sizeof(int));

	x->powersOfTwo[0] = 64; // must have at least this large of a window

	i=1;
	while(x->powersOfTwo[i-1] < x->maxWindowSize)
	{
		x->powersOfTwo = (int *)t_resizebytes(x->powersOfTwo, i*sizeof(int), (i+1)*sizeof(int));
		x->powersOfTwo[i] = pow(2, i+6); // +6 because we're starting at 2**6
		i++;
	}

	x->powTwoArrSize = i;

	x->signal_R = (t_sample *)t_getbytes(x->window*sizeof(t_sample));

	for(i=0; i<x->window; i++)
		x->signal_R[i] = 0.0;

  	x->blackman = (t_float *)t_getbytes(x->windowFuncSize*sizeof(t_float));
  	x->cosine = (t_float *)t_getbytes(x->windowFuncSize*sizeof(t_float));
  	x->hamming = (t_float *)t_getbytes(x->windowFuncSize*sizeof(t_float));
  	x->hann = (t_float *)t_getbytes(x->windowFuncSize*sizeof(t_float));

 	// initialize signal windowing functions
	tIDLib_blackmanWindow(x->blackman, x->windowFuncSize);
	tIDLib_cosineWindow(x->cosine, x->windowFuncSize);
	tIDLib_hammingWindow(x->hamming, x->windowFuncSize);
	tIDLib_hannWindow(x->hann, x->windowFuncSize);

    return (x);
}
Exemplo n.º 20
0
t_pd *pd_new(t_class *c)
{
    t_pd *x;
    if (!c)
        bug ("pd_new: apparently called before setup routine");
    x = (t_pd *)t_getbytes(c->c_size);
    *x = c;
    if (c->c_patchable)
    {
        ((t_object *)x)->ob_inlet = 0;
        ((t_object *)x)->ob_outlet = 0;
    }
    return (x);
}
Exemplo n.º 21
0
static void *specSkewness_tilde_new(t_symbol *s, int argc, t_atom *argv)
{
    t_specSkewness_tilde *x = (t_specSkewness_tilde *)pd_new(specSkewness_tilde_class);
	int i, isPow2;
	s=s;

	x->x_skewness = outlet_new(&x->x_obj, &s_float);

	if(argc > 0)
	{
		x->window = atom_getfloat(argv);
		isPow2 = (int)x->window && !( ((int)x->window-1) & (int)x->window );

		if(!isPow2)
		{
			error("requested window size is not a power of 2. default value of 1024 used instead");
			x->window = 1024;
		};
	}
	else
		x->window = 1024;

	x->sr = 44100.0;
	x->n = 64.0;
	x->overlap = 1;
	x->windowFunction = 4; // 4 is hann window
	x->powerSpectrum = 0;
	x->lastDspTime = clock_getlogicaltime();

	x->signal_R = (t_sample *)t_getbytes((x->window+x->n) * sizeof(t_sample));

 	for(i=0; i<(x->window+x->n); i++)
		x->signal_R[i] = 0.0;

  	x->blackman = (t_float *)t_getbytes(x->window*sizeof(t_float));
  	x->cosine = (t_float *)t_getbytes(x->window*sizeof(t_float));
  	x->hamming = (t_float *)t_getbytes(x->window*sizeof(t_float));
  	x->hann = (t_float *)t_getbytes(x->window*sizeof(t_float));

 	// initialize signal windowing functions
	tIDLib_blackmanWindow(x->blackman, x->window);
	tIDLib_cosineWindow(x->cosine, x->window);
	tIDLib_hammingWindow(x->hamming, x->window);
	tIDLib_hannWindow(x->hann, x->window);

	x->binFreqs = (t_float *)t_getbytes(x->window*sizeof(t_float));

	// freqs for each bin based on current window size and sample rate
	for(i=0; i<x->window; i++)
		x->binFreqs[i] = (x->sr/x->window)*i;

    post("specSkewness~: window size: %i", (int)x->window);

    return (x);
}
Exemplo n.º 22
0
t_gstub *gstub_new(t_glist *gl, t_array *a)
{
    t_gstub *gs = t_getbytes(sizeof(*gs));
    if (gl)
    {
        gs->gs_which = GP_GLIST;
        gs->gs_un.gs_glist = gl;
    }
    else
    {
        gs->gs_which = GP_ARRAY;
        gs->gs_un.gs_array = a;
    }
    gs->gs_refcount = 0;
    return (gs);
}
Exemplo n.º 23
0
Arquivo: m_obj.c Projeto: cviejo/mPD
t_outconnect *obj_connect(t_object *source, int outno,
    t_object *sink, int inno)
{
    //fprintf(stderr,"obj_connect\n");
    t_inlet *i;
    t_outlet *o;
    t_pd *to;
    t_outconnect *oc, *oc2;

    /* ignore attempts to connect to the same object
       this occurs sometimes using undo/redo */
    if (source == sink)
        return (0);
    
    for (o = source->ob_outlet; o && outno; o = o->o_next, outno--) ;
    if (!o) return (0);
    
    if (sink->ob_pd->c_firstin)
    {
        if (!inno)
        {
            to = &sink->ob_pd;
            goto doit;
        }
        else inno--;
    }
    for (i = sink->ob_inlet; i && inno; i = i->i_next, inno--) ;
    if (!i) return (0);
    to = &i->i_pd;
doit:
    oc = (t_outconnect *)t_getbytes(sizeof(*oc));
    oc->oc_next = 0;
    oc->oc_to = to;
        /* append it to the end of the list */
        /* LATER we might cache the last "oc" to make this faster. */
    if ((oc2 = o->o_connections))
    {
        while (oc2->oc_next) oc2 = oc2->oc_next;
        oc2->oc_next = oc;
    }
    else o->o_connections = oc;
    if (o->o_sym == &s_signal) canvas_update_dsp();

    return (oc);
}
Exemplo n.º 24
0
static void *
shmsrc_tilde_new(t_symbol *s, t_floatarg num_outlets)
{
  t_shmsrc_tilde *x = (t_shmsrc_tilde *)pd_new(shmsrc_tilde_class);

  x->x_audio_queue = g_async_queue_new();

  //num inlet is also considered as the number of channels
  if (num_outlets < 1)
    x->x_num_outlets = 1;
  else
    x->x_num_outlets = num_outlets;

  x->x_f = 0;
  x->x_last_perform_date = -1.0;
  //x->x_stream_data_date = -1.0;
  x->x_sample_duration = -1.0;
  x->x_stream_sample_duration = -1.0;
  x->x_reader = NULL;
  x->x_pd_samplerate = -1.0;
  x->x_current_audio_buf = NULL;

  sprintf (x->x_shmdata_prefix, "/tmp/pd_");
  sprintf (x->x_shmdata_name, "%s",s->s_name);
  sprintf (x->x_shmdata_path, "%s%s",
	   x->x_shmdata_prefix,
	   x->x_shmdata_name);

  int i;
  for (i = 0; i < x->x_num_outlets; i++)
    outlet_new(&x->x_obj, &s_signal);

  x->x_myvec = (t_int **)t_getbytes(sizeof(t_int *) * (x->x_num_outlets + 3));
  if (!x->x_myvec)
    {
      error("shmsrc~: out of memory");
      return NULL;
    }
  x->x_reader = NULL;
  shmsrc_tilde_reader_restart (x);

  return (x);
}
Exemplo n.º 25
0
void resample_dsp(t_resample *x,
		  t_sample* in,  int insize,
		  t_sample* out, int outsize,
		  int method)
{
  if (insize == outsize){
    bug("nothing to be done");
    return;
  }

  if (insize > outsize) { /* downsampling */
    if (insize % outsize) {
      error("bad downsampling factor");
      return;
    }
    switch (method) {
    default:
      dsp_add(downsampling_perform_0, 4, in, out, insize/outsize, insize);
    }


  } else { /* upsampling */
    if (outsize % insize) {
      error("bad upsampling factor");
      return;
    }
    switch (method) {
    case 1:
      dsp_add(upsampling_perform_hold, 4, in, out, outsize/insize, insize);
      break;
    case 2:
      if (x->bufsize != 1) {
	t_freebytes(x->buffer, x->bufsize*sizeof(*x->buffer));
	x->bufsize = 1;
	x->buffer = t_getbytes(x->bufsize*sizeof(*x->buffer));
      }
      dsp_add(upsampling_perform_linear, 5, x, in, out, outsize/insize, insize);
      break;
    default:
      dsp_add(upsampling_perform_0, 4, in, out, outsize/insize, insize);
    }
  }
}
Exemplo n.º 26
0
/***********************buffsize**********************/
void phasevoc_tilde_buffsize (t_phasevoc_tilde *x, t_floatarg g)
{
  if (g<=0)
    {
      post("buffsize must be greater than 0: buffsize = 5");
      x->circBuffSeconds = 5;
    }
  else
    {
      x->circBuffSeconds = g;
      // memset(x->circBuff, 0, sizeof(float) * x->circBuffLength);
      x->circBuffLength = x->circBuffSeconds * x->sampleRate;
      
      x->circBuff = (t_float *)t_getbytes(0);
      x->circBuff = (t_float *)t_resizebytes(x->circBuff, 0, sizeof(float) * x->circBuffLength);
      
      phasevoc_tilde_reinit(x);
      
      post("input buffer is %f seconds", g);
    }
}
Exemplo n.º 27
0
static void nearestPoint_add(t_nearestPoint *x, t_symbol *s, int argc, t_atom *argv)
{
	int i, pointIdx, dimensions;

	pointIdx = x->numPoints;
	dimensions = argc;
	s=s; // to get rid of 'unused variable' warning

	if(dimensions == x->dimensions)
	{
		x->x_coordinates = (t_coordinate *)t_resizebytes(x->x_coordinates, x->numPoints * sizeof(t_coordinate), (x->numPoints+1) * sizeof(t_coordinate));
		
		x->x_coordinates[pointIdx].coordinate = (t_float *)t_getbytes(dimensions*sizeof(t_float));
		
		x->numPoints++;
				
		for(i=0; i<dimensions; i++)
			x->x_coordinates[pointIdx].coordinate[i] = atom_getfloat(argv+i);
	}
	else
		error("nearestPoint: dimensionality mismatch.");
}
Exemplo n.º 28
0
/* search for abstraction; register a creator if found */
static int sys_do_load_abs(t_canvas *canvas, const char *objectname,
    const char *path)
{
    int fd;
    static t_gobj*abstraction_classes = 0;
    char dirbuf[MAXPDSTRING], classslashclass[MAXPDSTRING], *nameptr;
        /* NULL-path is only used as a last resort,
           but we have already tried all paths */
    if (!path) return (0);

    snprintf(classslashclass, MAXPDSTRING, "%s/%s", objectname, objectname);
    if ((fd = sys_trytoopenone(path, objectname, ".pd",
              dirbuf, &nameptr, MAXPDSTRING, 1)) >= 0 ||
        (fd = sys_trytoopenone(path, objectname, ".pat",
              dirbuf, &nameptr, MAXPDSTRING, 1)) >= 0 ||
        (fd = sys_trytoopenone(path, classslashclass, ".pd",
              dirbuf, &nameptr, MAXPDSTRING, 1)) >= 0)
    {
        t_class*c=0;
        close(fd);
            /* found an abstraction, now register it as a new pseudo-class */
        class_set_extern_dir(gensym(dirbuf));
        if((c=class_new(gensym(objectname),
                        (t_newmethod)do_create_abstraction, 0,
                        0, 0, A_GIMME, 0)))
        {
                /* store away the newly created class, maybe we will need it one day */
            t_gobj*absclass=0;
            absclass=t_getbytes(sizeof(*absclass));
            absclass->g_pd=c;
            absclass->g_next=abstraction_classes;
            abstraction_classes=absclass;
        }
        class_set_extern_dir(&s_);

        return (1);
    }
    return (0);
}
Exemplo n.º 29
0
void resamplefrom_dsp(t_resample *x,
			   t_sample *in,
			   int insize, int outsize, int method)
{
  if (insize==outsize) {
   t_freebytes(x->s_vec, x->s_n * sizeof(*x->s_vec));
    x->s_n = 0;
    x->s_vec = in;
    return;
  }

  if (x->s_n != outsize) {
    t_sample *buf=x->s_vec;
    t_freebytes(buf, x->s_n * sizeof(*buf));
    buf = (t_sample *)t_getbytes(outsize * sizeof(*buf));
    x->s_vec = buf;
    x->s_n   = outsize;
  }

  resample_dsp(x, in, insize, x->s_vec, x->s_n, method);
  return;
}
Exemplo n.º 30
0
void resampleto_dsp(t_resample *x,
			 t_sample *out, 
			 int insize, int outsize, int method)
{
  if (insize==outsize) {
    if (x->s_n)t_freebytes(x->s_vec, x->s_n * sizeof(*x->s_vec));
    x->s_n = 0;
    x->s_vec = out;
    return;
  }

  if (x->s_n != insize) {
    t_sample *buf=x->s_vec;
    t_freebytes(buf, x->s_n * sizeof(*buf));
    buf = (t_sample *)t_getbytes(insize * sizeof(*buf));
    x->s_vec = buf;
    x->s_n   = insize;
  }

  resample_dsp(x, x->s_vec, x->s_n, out, outsize, method);

  return;
}