anafeadist.c
来自「speech signal process tools」· C语言 代码 · 共 816 行 · 第 1/2 页
C
816 行
tot_pitch += diff_pitch[i_rec][j]; } if ( ele_num > raw_len[i_rec] - 1 ) { if (debug_level > 4) (void) fprintf (stderr, " anafea_distort: not enough elements in raw_power array.\n"); } else { diff_raw[i_rec][j] = anafea_rec1->raw_power[ele_num] - anafea_rec2->raw_power[ele_num]; tot_raw += diff_raw[i_rec][j]; } if ( ele_num > lpc_len[i_rec] - 1 ) { if (debug_level > 4) (void) fprintf (stderr, " anafea_distort: not enough elements in lpc_power array.\n"); } else { diff_lpc[i_rec][j] = anafea_rec1->lpc_power[ele_num] - anafea_rec2->lpc_power[ele_num]; tot_lpc += diff_lpc[i_rec][j]; } if (debug_level > 3) { (void) fprintf (stderr, " anafea_distort: tot_diff: ref_c = %f, pitch = %f\n", tot_ref_c, tot_pitch); (void) fprintf (stderr, " raw = %f, lpc = %f\n", tot_raw, tot_lpc); } (void) fflush (stderr); } /* end for */ free ((char *) ref_coeff1); free ((char *) ref_coeff2); } /* end big for loop */ if ( Eflag ) /* then print results for each element */ pr_ana_ele(); if ( rflag && !Eflag ) { /* print only Record and File Averages */ pr_ana_rec_avg(); /* print Record Average */ pr_ana_file_avg(); /* print File Average */ return; } pr_ana_ele_avg(); /* print Element Average */ if ( rflag ) pr_ana_rec_avg(); /* print Record Average */ pr_ana_file_avg(); /* print File Average */ pr_is_dist(); /* print Spectral Distortions */ pr_tot_is_dist(); /* print TOTAL Spectral Distortions */} /* end anafea_distort() */static char *check_frames (anafea_rec1, anafea_rec2)struct anafea *anafea_rec1;struct anafea *anafea_rec2;{/* * This module checks if two frames are compatible * (i.e. both frames must be either "Voiced" for "Unvoiced") * if one is "Voiced" and the other "Unvoiced", then * check_frames prints a message on stderr and exits with exit (1) * otherwise it returns a string of type of frame (" Voiced " or "Unvoiced"). * */ static char *Voiced = " Voiced "; static char *Unvoiced = "Unvoiced"; static char *Silence = "Silence "; static char *Transition = " Trans. ";/* * External Variable Used: * * int debug_level; print messages for debugging purpose * int rec_num; current record number * */ if (debug_level > 0) (void) fprintf (stderr, "\n"); switch (*anafea_rec1->frame_type) { case VOICED: if (*anafea_rec2->frame_type != VOICED) type_conflict (*anafea_rec1->frame_type, *anafea_rec2->frame_type); if (debug_level > 3) (void) fprintf (stderr, "check_frames: voiced frame\n"); return (Voiced); case UNVOICED: if (*anafea_rec2->frame_type != UNVOICED && *anafea_rec2->frame_type != NONE) type_conflict (*anafea_rec1->frame_type, *anafea_rec2->frame_type); if (debug_level > 3) (void) fprintf (stderr, "check_frames: unvoiced frame\n"); return (Unvoiced); case NONE: if (*anafea_rec2->frame_type != UNVOICED && *anafea_rec2->frame_type != NONE) type_conflict (*anafea_rec1->frame_type, *anafea_rec2->frame_type); if (debug_level > 3) (void) fprintf (stderr, "check_frames: NONE type frame\n"); return (Unvoiced); case SILENCE: if (*anafea_rec2->frame_type != SILENCE) type_conflict (*anafea_rec1->frame_type, *anafea_rec2->frame_type); if (debug_level > 3) (void) fprintf (stderr, "check_frames: silent frame\n"); Fprintf (stderr, "anafea_distort: cannot handle SILENCE frames, yet.\n"); exit (1); break; case UNKNOWN: if (*anafea_rec2->frame_type != UNKNOWN) type_conflict (*anafea_rec1->frame_type, *anafea_rec2->frame_type); if (debug_level > 3) (void) fprintf (stderr, "check_frames: silent frame\n"); Fprintf (stderr, "anafea_distort: cannot handle UNKNOWN frames, yet.\n"); exit (1); break; case TRANSITION: if (*anafea_rec2->frame_type != TRANSITION) type_conflict (*anafea_rec1->frame_type, *anafea_rec2->frame_type); if (debug_level > 3) (void) fprintf (stderr, "check_frames: transition frame\n"); Fprintf (stderr, "anafea_distort: cannot handle TRANSITION frames, yet.\n"); exit (1); break; default: (void) fprintf (stderr, "anafea_distort: unknown frame type, code: %d\n", *anafea_rec1->frame_type); exit (1); break; }} static voidtype_conflict (type1, type2)short type1;short type2;{ /* inconsistent frames */ (void) fprintf (stderr, "anafea_distort: fatal error, one %s frame other %s frame.\n", frame_types[type1], frame_types[type2]); (void) fprintf (stderr, "anafea_distort: record number %d\n", rec_num); (void) fflush (stderr); exit (1);}static voidcheck_anafea_arrays (f1h, anafea_rec1, f2h, anafea_rec2)struct header *f1h;struct anafea *anafea_rec1;struct header *f2h;struct anafea *anafea_rec2;{ int pitch_len2; /* temporary variable to compare length of p_pulse_len */ int raw_len2; /* temporary variable to compare length of raw_power */ int lpc_len2; /* temporary variable to compare length of lpc_power */ int maxpulses1, maxpulses2; int maxraw1, maxraw2; int maxlpc1, maxlpc2; if (debug_level > 0) (void) fprintf (stderr, "\n"); /* check if pitch pulse lengths are equal */ maxpulses1 = *(int *) get_genhd ("maxpulses", f1h); maxpulses2 = *(int *) get_genhd ("maxpulses", f2h); pitch_len[i_rec] = array_len (anafea_rec1->p_pulse_len, maxpulses1, 0); pitch_len2 = array_len (anafea_rec2->p_pulse_len, maxpulses2, 0); if ( pitch_len[i_rec] != pitch_len2 ) { (void) fprintf (stderr, "check_anafea_arrays: pitch pulse lengths are not equal in record no. %d\n", rec_num); exit (1); } /* check if raw power lengths are equal */ maxraw1 = *(int *) get_genhd ("maxraw", f1h); maxraw2 = *(int *) get_genhd ("maxraw", f2h); raw_len[i_rec] = array_len (anafea_rec1->raw_power, maxraw1, -1); raw_len2 = array_len (anafea_rec2->raw_power, maxraw2, -1); if ( raw_len[i_rec] != raw_len2 ) { (void) fprintf (stderr, "check_anafea_arrays: raw power lengths not equal in record no. %d\n", rec_num); exit (1); } /* check if lpc power lengths are equal */ maxlpc1 = *(int *) get_genhd ("maxlpc", f1h); maxlpc2 = *(int *) get_genhd ("maxlpc", f2h); lpc_len[i_rec] = array_len (anafea_rec1->lpc_power, maxlpc1, -1); lpc_len2 = array_len (anafea_rec2->lpc_power, maxlpc2, -1); if ( lpc_len[i_rec] != lpc_len2 ) { (void) fprintf (stderr, "check_anafea_arrays: lpc power lengths not equal in record no. %d\n", rec_num); exit (1); } }static voidconvert_to_rc (spec_param1, spec_param2, order)float *spec_param1;float *spec_param2;int order;{/* * G L O B A L * V A R I A B L E S * R E F E R E N C E D * * struct header *f1h; * struct header *f2h; * * float *ref_coeff1; * float *ref_coeff2; * */ float bw = 4000.; int i; /* * Convert the spectral parameter representations to reflection coefficients * for file1. */ switch (*(short *) get_genhd ("spec_rep", f1h)) { case RC: for (i = 0; i <= order - 1; i++) ref_coeff1[i] = spec_param1[i]; break; case LAR: if (reps_rc (spec_param1, LAR, ref_coeff1, order, bw) == -1) { Fprintf (stderr, "anafea_distort: convert_to_rc: trouble converting from LAR to RC.\n"); exit (1); } break; case LSF: bw = *(float *) get_genhd ("src_sf", f1h) / 2.0; if (reps_rc (spec_param1, LSF, ref_coeff1, order, bw) == -1) { Fprintf (stderr, "anafea_distort: convert_to_rc: trouble converting from LSF to RC.\n"); exit (1); } break; case AUTO: if (reps_rc (spec_param1, AUTO, ref_coeff1, order, bw) == -1) { Fprintf (stderr, "anafea_distort: convert_to_rc: trouble converting from AUTO to RC.\n"); exit (1); } break; default: Fprintf (stderr, "anafea_distort: convert_to_rc: Unknown spectral representation, code: %d.\n", *(short *) get_genhd ("spec_rep", f1h)); exit (1); break; } /* end switch (*(short *) get_genhd ("spec_rep", f1h)) */ if (debug_level > 4) { for (i = 0; i <= order - 1; i++) (void) fprintf (stderr, "convert_to_rc: ref_coeff1[%d] = %f\n", i, ref_coeff1[i]); (void) fprintf (stderr, "\n"); }/* * Now convert the spectral parameter representations to reflection * coefficients for file2. */ switch (*(short *) get_genhd ("spec_rep", f2h)) { case RC: for (i = 0; i <= order - 1; i++) ref_coeff2[i] = spec_param2[i]; break; case LAR: if (reps_rc (spec_param2, LAR, ref_coeff2, order, bw) == -1) { Fprintf (stderr, "anafea_distort: convert_to_rc: trouble converting from LAR to RC.\n"); exit (1); } break; case LSF: bw = *(float *) get_genhd ("src_sf", f2h) / 2.0; if (reps_rc (spec_param2, LSF, ref_coeff2, order, bw) == -1) { Fprintf (stderr, "anafea_distort: convert_to_rc: trouble converting from LSF to RC.\n"); exit (1); } break; case AUTO: if (reps_rc (spec_param2, AUTO, ref_coeff2, order, bw) == -1) { Fprintf (stderr, "anafea_distort: convert_to_rc: trouble converting from AUTO to RC.\n"); exit (1); } break; default: Fprintf (stderr, "anafea_distort: convert_to_rc: Unknown spectral representation, code: %d.\n", *(short *) get_genhd ("spec_rep", f2h)); exit (1); break; } /* end switch (*(short *) get_genhd ("spec_rep", f2h)) */ if (debug_level > 4) { for (i = 0; i <= order - 1; i++) (void) fprintf (stderr, "convert_to_rc: ref_coeff2[%d] = %f\n", i, ref_coeff2[i]); (void) fprintf (stderr, "\n"); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?