[PD-dev] signal nan values

Andrew Hassall a.r.hassall at gmail.com
Fri Apr 22 19:04:53 CEST 2011


Yeah I thought it must be my code.

But I've also noticed a difference in the performance of the code from
windows to linux, in linux the graph doesn't crash, but the externals
are behaving differently. (In windows the external has the correct
behaviour then crashes, but in linux it doesn't crash but still has
nan values but also doesn't have the correct behaviour)

I've also noticed that there is another problem in one of my other
files, in lpcanalysis_tilde_perform()

the code for both perform functions is below
but as a quick explanation, I'm assuming an overlap of 50% and need
the last 40 values from the previous frame in order for the algorithm
to work correctly.

I think the problem must be to with copying the previous values but
they do seem to copy across correctly if I output a value from one
frame and compare it to the corresponding value in prev in the next
frame.

lpcanalysis
"
t_int *lpcanalysis_tilde_perform(t_int *w)

{
	t_lpcanalysis_tilde *x = (t_lpcanalysis_tilde *)(w[1]);
	t_sample *in1 = (t_sample *)(w[2]);
	t_sample *out = (t_sample *)(w[3]);
	int n = (int)w[4];

	t_sample *in = x->in;
	t_sample *win = x->win;

	float *phis = x->phis;
	float *ks   = x->ks;
	float *es   = x->es;
	float *as   = x->as;
	int   p     = x->p;

	t_sample *prev = x->previous;

	int i=0;
	int k=0;
	int m=0;
	int j=0;
	float sum=0;
	float window;
	int np = n+p;
	int halfn = n*0.5;

        // copy previous values and input into one array
	for (i=0;i<p;i++){
		*(in+i) = *(prev+39-(p-1)+i);
	}
	for (i=p;i<np;i++){
		*(in+i) = *(in1+i-p);
	}

	// windowing using a hamming window not hanning
	for (i=0; i<np;i++) {
		window = 0.54-(0.46*(cos((2*i*M_PI)/(np-1))));
		*(win+i) = window*(*(in+i));
	}

	// autocorrelation
	for (k=0;k<=p;k++) {
		sum=0;
		for (m=0;(m+k)<np;m++){
			sum+= *(win+m) * *(win+m+k);
		}
		*(phis+k) = sum;
	}

	// levinson durbin algorithm
	*es = *phis;
	for (i=1;i<=p;i++) {
		sum=0;
		for (j=1;j<=(i-1);j++){
			sum += x->alphas[j][i-1]* *(phis+i-j);
		}
		*(ks+i) = (float)(*(phis+i)-sum)/(float)(*(es+i-1));
		x->alphas[i][i] = *(ks+i);
		if (i>1){
			for (j=1;j<=(i-1);j++){
				x->alphas[j][i] = x->alphas[j][i-1]-*(ks+i)*x->alphas[i-j][i-1];
			}
		}
		*(es+i) = (1-pow(*(ks+i),2))* *(es+i-1);
        }

	for(j=1;j<=p;j++){
		SETFLOAT(x->a_at+(j-1),x->alphas[j][p]);
		*(as+j-1) = x->alphas[j][p];
	}

	//filter signal
	for (m=p;m<np;m++){
		sum = 0;
		for (k=1;k<=p;k++) {
			sum += *(in+m-k) * *(as+(k-1));
		}
		*(out+(m-p)) = *(in+m)-sum;
	}

	// output alphas
	outlet_list(x->p_list_out,0,p,x->a_at);

        // copy last 40 values
	for (i=0;i<40;i++) {
		*(prev+i) = *(in+halfn+p-40+i);
	}
	return (w+5);

}
"

lpcsynthesis

"
t_int *lpcsynthesis_tilde_perform(t_int *w)
{
	t_lpcsynthesis_tilde *x = (t_lpcsynthesis_tilde *)(w[1]);
	t_sample *in = (t_sample *)(w[2]);
	t_sample *out1 = (t_sample *)(w[3]);
	int n = (int)w[4];

	float *as    = x->as;
	int   p      = x->p;
	t_sample *out = x->out;
	t_sample *prev = x->previous;

	int i;
	int k;
	float sum;
	int np = n+p;
	int halfn = n*0.5;

// copy previous values into start of array
	for (i=0;i<p;i++) {
		*(out+i) = *(prev+39-(p-1)+i);
	}

// filter
	for (i=p;i<np;i++) {
		sum = 0;
		for (k=1;k<=p;k++){
				sum += *(out+i-k) * (*(as+k-1));
		}
	}

//copy new values into out array
	for (i=0;i<n;i++) {
		*(out1+i) = *(out+i+p);
	}

// save previous values
	for (i=0;i<40;i++) {
		*(prev+i) = *(out+p+halfn-40+i);
	}

	return (w+5);
}
"


2011/4/22 IOhannes m zmölnig <zmoelnig at iem.at>:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 04/22/2011 01:31 PM, Andrew Hassall wrote:
>> or could it just be other problems with the audio setup (I still
>> haven't got the pd audio settings correct on ubuntu, but it still
>> manages to process input from the mic).
>
> given that valgrind produces an error each time
> "lpcsynthesis_tilde_perform()" is called and that hundreds if not
> thousands of people do not experience spurious crashes with their Pd
> that are related to (improper) soundcard settings, i would say it is
> your code (or whoever wrote lpcsynthesis_tile_perform())
>
> fgmadr
> IOhannes
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.11 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk2xlUkACgkQkX2Xpv6ydvRNqQCfVCy7CMQFrRP4Mgvx1NVyl1xQ
> nNsAnj2mVM9z/Row1qN/xeJGZrfYhZY9
> =OiXz
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> Pd-dev mailing list
> Pd-dev at iem.at
> http://lists.puredata.info/listinfo/pd-dev
>



More information about the Pd-dev mailing list