Пример #1
0
static void dump_sue(dump *ctx, type *ty)
{
	struct_union_enum_st *sue = type_is_s_or_u_or_e(ty);
	sue_member **mi;

	if(!sue)
		return;

	dump_inc(ctx);

	for(mi = sue->members; mi && *mi; mi++){
		if(sue->primitive == type_enum){
			enum_member *emem = (*mi)->enum_member;

			dump_desc(ctx, emem->spel, emem, &emem->where);

			if(emem->val && emem->val != (expr *)-1){
				dump_inc(ctx);
				dump_expr(emem->val, ctx);
				dump_dec(ctx);
			}

			dump_attributes(emem->attr, ctx);

		}else{
			decl *d = (*mi)->struct_member;

			dump_decl(d, ctx, "member");

			dump_sue(ctx, d->ref);
		}
	}

	dump_dec(ctx);
}
Пример #2
0
void dump_expr_assign(const expr *e, dump *ctx)
{
	dump_desc_expr(ctx, "assignment", e);
	dump_inc(ctx);
	dump_expr(e->lhs, ctx);
	dump_dec(ctx);
	dump_inc(ctx);
	dump_expr(e->rhs, ctx);
	dump_dec(ctx);
}
Пример #3
0
void dump_expr_addr(const expr *e, dump *ctx)
{
	if(e->bits.lbl.spel){
		dump_desc_expr(ctx, "label address", e);
		dump_inc(ctx);
		dump_strliteral(ctx, e->bits.lbl.spel, strlen(e->bits.lbl.spel));
		dump_dec(ctx);
	}else{
		dump_desc_expr(ctx, "address-of", e);
		dump_inc(ctx);
		dump_expr(e->lhs, ctx);
		dump_dec(ctx);
	}
}
Пример #4
0
void dump_expr_funcall(const expr *e, dump *ctx)
{
	expr **iter;

	dump_desc_expr(ctx, "call", e);

	dump_inc(ctx);
	dump_expr(e->expr, ctx);
	dump_dec(ctx);

	dump_inc(ctx);
	for(iter = e->funcargs; iter && *iter; iter++)
		dump_expr(*iter, ctx);

	dump_dec(ctx);
}
Пример #5
0
void dump_expr_stmt(const expr *e, dump *ctx)
{
	dump_desc_expr(ctx, "statement expression", e);
	dump_inc(ctx);
	dump_stmt(e->code, ctx);
	dump_dec(ctx);
}
Пример #6
0
static void dump_gasm(symtable_gasm *gasm, dump *ctx)
{
	dump_desc(ctx, "global asm", gasm, &gasm->where);

	dump_inc(ctx);
	dump_strliteral(ctx, gasm->asm_str, strlen(gasm->asm_str));
	dump_dec(ctx);
}
Пример #7
0
void dump_stmt_label(const stmt *s, dump *ctx)
{
	dump_desc_stmt_newline(ctx, "label", s, 0);
	dump_printf_indent(ctx, 0, " %s\n", s->bits.lbl.spel);

	dump_inc(ctx);
	dump_stmt(s->lhs, ctx);
	dump_dec(ctx);
}
Пример #8
0
void dump_expr_compound_lit(const expr *e, dump *ctx)
{
	decl *const d = e->bits.complit.decl;

	dump_desc_expr(ctx, "compound literal", e);

	dump_inc(ctx);
	dump_init(ctx, d->bits.var.init.dinit);
	dump_dec(ctx);
}
Пример #9
0
void dump_stmt_goto(const stmt *s, dump *ctx)
{
	if(s->expr){
		dump_desc_stmt(ctx, "computed-goto", s);

		dump_inc(ctx);
		dump_expr(s->expr, ctx);
		dump_dec(ctx);
	}else{
		dump_desc_stmt_newline(ctx, "goto", s, 0);
		dump_printf_indent(ctx, 0, " %s\n", s->bits.lbl.spel);
	}
}
Пример #10
0
void dump_stmt_if(const stmt *s, dump *ctx)
{
	dump_desc_stmt(ctx, "if", s);

	dump_inc(ctx);

	dump_flow(s->flow, ctx);

	dump_expr(s->expr, ctx);
	dump_stmt(s->lhs, ctx);
	if(s->rhs)
		dump_stmt(s->rhs, ctx);
	dump_dec(ctx);
}
Пример #11
0
void dump_stmt_for(const stmt *s, dump *ctx)
{
	dump_desc_stmt(ctx, "for", s);

	dump_inc(ctx);

	dump_flow(s->flow, ctx);

	if(s->flow->for_init) dump_expr(s->flow->for_init, ctx);
	if(s->flow->for_while) dump_expr(s->flow->for_while, ctx);
	if(s->flow->for_inc) dump_expr(s->flow->for_inc, ctx);

	dump_stmt(s->lhs, ctx);

	dump_dec(ctx);
}
Пример #12
0
void dump_expr_if(const expr *e, dump *ctx)
{
	dump_desc_expr(ctx, "conditional", e);

	dump_inc(ctx);

	dump_expr(e->expr, ctx);

	if(e->lhs)
		dump_expr(e->lhs, ctx);
	else
		dump_printf(ctx, "?: lhs\n");

	dump_expr(e->rhs, ctx);

	dump_dec(ctx);
}
Пример #13
0
void dump_expr_assign_compound(const expr *e, dump *ctx)
{
	dump_desc_expr_newline(ctx, "compound assignment", e, 0);

	dump_printf_indent(ctx, 0, " %s%s=",
			e->assign_is_post ? "post-assignment " : "",
			op_to_str(e->bits.compoundop.op));

	if(e->bits.compoundop.upcast_ty){
		dump_printf_indent(ctx, 0, " upcast='%s'",
				type_to_str(e->bits.compoundop.upcast_ty));
	}

	dump_printf_indent(ctx, 0, "\n");

	dump_inc(ctx);
	dump_expr(e->lhs, ctx);
	dump_expr(e->rhs, ctx);
	dump_dec(ctx);
}
Пример #14
0
void dump_init(dump *ctx, decl_init *dinit)
{
	if(dinit == DYNARRAY_NULL){
		dump_printf(ctx, "<null init>\n");
		return;
	}

	switch(dinit->type){
		case decl_init_scalar:
		{
			dump_expr(dinit->bits.expr, ctx);
			break;
		}

		case decl_init_brace:
		{
			decl_init **i;

			dump_desc(ctx, "brace init", dinit, &dinit->where);

			dump_inc(ctx);

			for(i = dinit->bits.ar.inits; i && *i; i++)
				dump_init(ctx, *i);

			dump_dec(ctx);
			break;
		}

		case decl_init_copy:
		{
			struct init_cpy *cpy = *dinit->bits.range_copy;
			dump_init(ctx, cpy->range_init);
			break;
		}
	}
}
Пример #15
0
void dump_decl(decl *d, dump *ctx, const char *desc)
{
	const int is_func = !!type_is(d->ref, type_func);
	type *ty;

	if(!desc){
		if(d->spel){
			desc = is_func ? "function" : "variable";
		}else{
			desc = "type";
		}
	}

	dump_desc_colour_newline(ctx, desc, d, &d->where,
			maybe_colour(ctx->fout, col_desc_decl), 0);

	if(d->proto)
		dump_printf_indent(ctx, 0, " prev %p", (void *)d->proto);

	if(d->spel)
		dump_printf_indent(ctx, 0, " %s", d->spel);

	dump_type(ctx, d->ref);

	if(d->store)
		dump_printf_indent(ctx, 0, " %s", decl_store_to_str(d->store));

	dump_printf_indent(ctx, 0, "\n");

	if(!is_func){
		type *tof = type_skip_non_tdefs(d->ref);
		if(tof->type == type_tdef && !tof->bits.tdef.decl){
			/* show typeof expr */
			dump_inc(ctx);
			dump_expr(tof->bits.tdef.type_of, ctx);
			dump_dec(ctx);
		}

		if(d->bits.var.field_width){
			dump_inc(ctx);
			dump_expr(d->bits.var.field_width, ctx);
			dump_dec(ctx);
		}

		if(!d->spel){
			dump_sue(ctx, d->ref);
		}else if(d->bits.var.init.dinit){
			dump_inc(ctx);
			dump_init(ctx, d->bits.var.init.dinit);
			dump_dec(ctx);
		}
	}

	dump_inc(ctx);
	dump_attributes(d->attr, ctx);
	ty = type_skip_non_attr(d->ref);
	if(ty && ty->type == type_attr)
		dump_attributes(ty->bits.attr, ctx);
	dump_dec(ctx);

	if(is_func && d->bits.func.code){
		funcargs *fa = type_funcargs(d->ref);

		dump_inc(ctx);
		dump_args(fa, ctx);
		dump_stmt(d->bits.func.code, ctx);
		dump_dec(ctx);
	}
}
Пример #16
0
float nlp(
  void *nlp_state, 
  float  Sn[],			/* input speech vector */
  int    n,			/* frames shift (no. new samples in Sn[]) */
  int    pmin,                  /* minimum pitch value */
  int    pmax,			/* maximum pitch value */
  float *pitch,			/* estimated pitch period in samples */
  COMP   Sw[],                  /* Freq domain version of Sn[] */
  COMP   W[],                   /* Freq domain window */
  float *prev_Wo
)
{
    NLP   *nlp;
    float  notch;		    /* current notch filter output    */
    COMP   fw[PE_FFT_SIZE];	    /* DFT of squared signal (input)  */
    COMP   Fw[PE_FFT_SIZE];	    /* DFT of squared signal (output) */
    float  gmax;
    int    gmax_bin;
    int    m, i,j;
    float  best_f0;
    TIMER_VAR(start, tnotch, filter, peakpick, window, fft, magsq, shiftmem);
    
    assert(nlp_state != NULL);
    nlp = (NLP*)nlp_state;
    m = nlp->m;

    TIMER_SAMPLE(start);

    /* Square, notch filter at DC, and LP filter vector */

    for(i=m-n; i<m; i++) 	    /* square latest speech samples */
	nlp->sq[i] = Sn[i]*Sn[i];

    for(i=m-n; i<m; i++) {	/* notch filter at DC */
	notch = nlp->sq[i] - nlp->mem_x;
	notch += COEFF*nlp->mem_y;
	nlp->mem_x = nlp->sq[i];
	nlp->mem_y = notch;
	nlp->sq[i] = notch + 1.0;  /* With 0 input vectors to codec,
				      kiss_fft() would take a long
				      time to execute when running in
				      real time.  Problem was traced
				      to kiss_fft function call in
				      this function. Adding this small
				      constant fixed problem.  Not
				      exactly sure why. */
    }

    TIMER_SAMPLE_AND_LOG(tnotch, start, "      square and notch");

    for(i=m-n; i<m; i++) {	/* FIR filter vector */

	for(j=0; j<NLP_NTAP-1; j++)
	    nlp->mem_fir[j] = nlp->mem_fir[j+1];
	nlp->mem_fir[NLP_NTAP-1] = nlp->sq[i];

	nlp->sq[i] = 0.0;
	for(j=0; j<NLP_NTAP; j++)
	    nlp->sq[i] += nlp->mem_fir[j]*nlp_fir[j];
    }

    TIMER_SAMPLE_AND_LOG(filter, tnotch, "      filter");
 
    /* Decimate and DFT */

    for(i=0; i<PE_FFT_SIZE; i++) {
	fw[i].real = 0.0;
	fw[i].imag = 0.0;
    }
    for(i=0; i<m/DEC; i++) {
	fw[i].real = nlp->sq[i*DEC]*nlp->w[i];
    }
    TIMER_SAMPLE_AND_LOG(window, filter, "      window");
    #ifdef DUMP
    dump_dec(Fw);
    #endif

    kiss_fft(nlp->fft_cfg, (kiss_fft_cpx *)fw, (kiss_fft_cpx *)Fw);
    TIMER_SAMPLE_AND_LOG(fft, window, "      fft");

    for(i=0; i<PE_FFT_SIZE; i++)
	Fw[i].real = Fw[i].real*Fw[i].real + Fw[i].imag*Fw[i].imag;

    TIMER_SAMPLE_AND_LOG(magsq, fft, "      mag sq");
    #ifdef DUMP
    dump_sq(nlp->sq);
    dump_Fw(Fw);
    #endif

    /* find global peak */

    gmax = 0.0;
    gmax_bin = PE_FFT_SIZE*DEC/pmax;
    for(i=PE_FFT_SIZE*DEC/pmax; i<=PE_FFT_SIZE*DEC/pmin; i++) {
	if (Fw[i].real > gmax) {
	    gmax = Fw[i].real;
	    gmax_bin = i;
	}
    }
    
    TIMER_SAMPLE_AND_LOG(peakpick, magsq, "      peak pick");

    //#define POST_PROCESS_MBE
    #ifdef POST_PROCESS_MBE
    best_f0 = post_process_mbe(Fw, pmin, pmax, gmax, Sw, W, prev_Wo);
    #else
    best_f0 = post_process_sub_multiples(Fw, pmin, pmax, gmax, gmax_bin, prev_Wo);
    #endif

    TIMER_SAMPLE_AND_LOG(shiftmem, peakpick,  "      post process");

    /* Shift samples in buffer to make room for new samples */

    for(i=0; i<m-n; i++)
	nlp->sq[i] = nlp->sq[i+n];

    /* return pitch and F0 estimate */

    *pitch = (float)SAMPLE_RATE/best_f0;

    TIMER_SAMPLE_AND_LOG2(shiftmem,  "      shift mem");

    TIMER_SAMPLE_AND_LOG2(start,  "      nlp int");

    return(best_f0);  
}