Beispiel #1
0
int main(void)
{
	float a,b,c,x;
	adr=Malloc(4096);
	ability=Dsp_RequestUniqueAbility();
	status=Dsp_LoadProg(file,ability,adr);
	if (!status)
	{
		printf("\n\nComparaison SIN/DSP_SIN\n\n");
		for(i=0;i<360;i+=36)
		{
			x=i;
			a=sin((double)(x*2.0*M_PI)/360.0);
			b=dsp_sin(x);
			c=0;
			if (fabs(a)>0.00001)
				c=fabs(100.0*(a-b)/a);	/* calcul de l'erreur */
			printf("SIN(%f)=%f   DSP_SIN(%f)=%f   Erreur=%f %%\n",x,a,x,b,c);
		}
	
		printf("\n\nComparaison COS/DSP_COS\n\n");
		for(i=0;i<360;i+=36)
		{
			x=i;
			a=cos((double)(x*2.0*M_PI)/360.0);
			b=dsp_cos(x);
			c=0;
			if (fabs(a)>0.00001)
				c=fabs(100.0*(a-b)/a);	/* calcul de l'erreur */
			printf("COS(%f)=%f   DSP_COS(%f)=%f   Erreur=%f %%\n",x,a,x,b,c);
		}

		printf("\n\nComparaison SQRT/DSP_SQR\n\n");
		for(i=0;i<10;i++)
		{
			x=i/10.0;
			a=sqrt(x);
			b=dsp_sqr(x);
			c=0;
			if (fabs(a)>0.00001)
				c=fabs(100.0*(a-b)/a);	/* calcul de l'erreur */
			printf("SQRT(%f)=%f   DSP_SQR(%f)=%f   Erreur=%f %%\n",x,a,x,b,c);
		}
	}
	else
		printf("Fichier %s introuvable.\n",file);
		
	printf("Appuyez sur une touche\n");
	Bconin(2);
	Mfree(adr);
	return 0;
}
Beispiel #2
0
static int _dsp_vad_calc_1_0(dsp_sample_t *voice,
			dsp_vad_t *vad, dsp_sample_t *samples)
	{
	int i, idx, activity = 0;
	mx_real_t e_sum, e_sum2, le, lemin, lemax, va;
	mx_real_t snr;
	dsp_vad_state_t newstate, mark;

	/* Praeemphase ausfuehren ... */
	dsp_preemph(vad->signal, samples, vad->frame_len, V1_0_PREEMPH_A, 0);

	/* ... und mittelwertbereinigte Signalenergie berechnen ... */
	e_sum = e_sum2 = 0;
	for (i = 0; i < vad->frame_len; i++) {
		e_sum += vad->signal[i];
		e_sum2 += dsp_sqr(vad->signal[i]);
		}
	le = dsp_log10(e_sum2 / vad->frame_len -
			dsp_sqr(e_sum / vad->frame_len));

	/* ... ggf. Energiehistogram aktualisieren ... */
	idx = mx_histogram_val2idx(vad->ehist, le);
	if (!(idx >= 0 && idx == vad->last_idx &&
	      mx_histogram_prob(vad->ehist, le) > V1_0_EHIST_BUCKET_HIGH))
		mx_histogram_update(vad->ehist, le);
	vad->last_idx = idx;

	/* ... Histogrammdynamik ermitteln ... */
	lemin = mx_histogram_invprob_le(vad->ehist, V1_0_PROB_LOW) -
				vad->ehist->resolution / 2;
	lemax = mx_histogram_invprob_le(vad->ehist, V1_0_PROB_HIGH) +
				vad->ehist->resolution / 2;

	/* ... Signalrauschabstand schaetzen und ... */
	snr = 10 * (lemax - lemin);

	/* ... Entscheidungsparameter fuer voice activity berechnen ... */
	if (snr >= V1_0_SNR_MIN) 
		va = (le - lemin) / (lemax - lemin);
	else	va = 0.0;

	newstate = _dsp_vad_newstate_1_0(vad, va);

	/* ... ggf. bei best. Zustandsuebergaengen Daten manipulieren ... */
	/* ... falls 'starting -> no_decision/silence/voice' ... */
	if (vad->state == dsp_vad_starting && newstate != dsp_vad_starting) {
		/*
		 * ... alle mit Marke 'starting' gespeicherten Signalframes
		 * nach neu berechmetem Zustand ummarkieren
		 */
		for (i = 0; i < vad->sigbuf->length; i++) {
			if (dsp_delay_accessm(NULL, &mark, vad->sigbuf, i) < 0)
				break;

			if (mark != dsp_vad_starting)
				break;

			dsp_delay_mark(vad->sigbuf, i, newstate);
			}
		}

	/* ... und neu berechneten Zustand uebernehmen ... */
	vad->state = newstate;

	/* ... aktuellen Frame IMMER speichern ... */
	dsp_delay_pushm(vad->sigbuf, samples, vad->state);

	return(vad->state);
	}
Beispiel #3
0
/**
* _dsp_mfcc_1_3(features, signal)
**/
int _dsp_mfcc_1_3(dsp_fextract_t *fex,
		mx_real_t *features, dsp_sample_t *signal)
	{
	static mx_real_t mtf[V1_1_N_FILTERS], bbr[V1_1_N_FILTERS];
	static dsp_filterbank_t *fb = NULL;
	static mx_real_t w[V1_1_FRAME_LEN];
	static mx_real_t p[V1_1_FRAME_LEN];
	static mx_complex_t z[V1_1_FRAME_LEN];
	static mx_real_t e[V1_1_N_FILTERS + 1];
	static mx_real_t C[V1_1_N_FILTERS];

	dsp_mfcc_t *cfg = fex->config;
	int i;

	/* ... Filterbank ggf. erzeugen ... */
	if (fb == NULL) {
		/* ... Mel-Skala erzeugen ... */
		if (dsp_mel_create(mtf, bbr, V1_1_N_FRESOLUTION, 
			V1_1_MIN_FREQ, V1_1_MAX_FREQ, 1.0, V1_1_N_FILTERS)
				!= V1_1_N_FILTERS)
			rs_error("problems creating mel-scale!");

		/* ... Plateau ist 1/4 Frequenzgruppe breit ... */
		for (i = 0; i < V1_1_N_FILTERS; i++)
			bbr[i] /= 4;
		fb = dsp_filterbank_create(V1_1_N_FILTERS, mtf, bbr,
				V1_1_N_FRESOLUTION,
				V1_1_MIN_FREQ, V1_1_MAX_FREQ);
		}

	/* Merkmalsberechnung durchfuehren, dazu ... */
	/* ... Hamming-Fenstern ... */
	dsp_window_hamming(w, signal, V1_1_FRAME_LEN);
	
	/* ... Leistungsdichtespektrum ... */
	for (i = 0; i < V1_1_FRAME_LEN; i++) {
		mx_re(z[i]) = w[i];
		mx_im(z[i]) = 0.0;
		}
	dsp_xfft(z, V1_1_FRAME_LEN, 0);
	/* Guenther normiert hinwaerts mit 1/n --- wir nicht */
	for (i = 0; i < V1_1_FRAME_LEN; i++)
		p[i] = (dsp_sqr(mx_re(z[i])) + dsp_sqr(mx_im(z[i]))) /
					dsp_sqr(V1_1_FRAME_LEN);

#ifdef DEBUG
for (i = 0; i < V1_1_FRAME_LEN; i++)
	fprintf(stderr, "%g ", p[i]);
fprintf(stderr, "\n");
#endif

	/* ... Mel-Filter ... */
	dsp_filterbank_apply(e, p, fb);

	/* ... Logarithmierung ... */
	for (i = 0; i < V1_1_N_FILTERS + 1; i++)
		e[i] = dsp_log10(e[i]);

	/* ... Cepstrum ... */
	dsp_dct(C, e + 1, V1_1_N_FILTERS, V1_1_N_BASEFEATURES);

	/* ... Gesamtmerkmalsvektor erzeugen ... */
	features[0] = e[0];
	memcpy(features + 1, C + 1, sizeof(mx_real_t) * (V1_1_N_BASEFEATURES - 1));

	/* ... Kanaladaption durch Mittelwertsbereinigung */
	dsp_channel(cfg->channel, features);

	/* ... Ableitung 1. und 2. Ordnung ... */
	dsp_delay_push(cfg->wderiv, features);

	/* ... berechnen sofern moeglich ... */
	if (dsp_deriv(features + V1_1_N_BASEFEATURES, cfg->wderiv, 1, V1_1_W_LENGTH) == 0 &&
	    dsp_deriv(features + 2 * V1_1_N_BASEFEATURES, cfg->wderiv, 2, V1_1_W_LENGTH) == 0) {
		/* ... zugehoerigen mittleren Vektor getlaettet erzeugen ... */
		dsp_tirol(features, cfg->wderiv);

		/* ... und Daten als gueltig erklaeren ... */
		return(V1_1_N_FEATURES);
		}
	else	return(0);	/* ... sonst: (noch) keine Merkmale! */
	}