/* make_template.c (tool for Simple Mandarin tone recognizer using pitch track) Makes a template pitch track given two or more sample pitch tracks (with the 4 tones, and only the 4 tones, in order), by normalizing, standardizing, and averaging the pitch tracks of each of the inputs. Jim Gilsinan IV gilsinan@post.harvard.edu http://www.fas.harvard.edu/~gilsinan/ Senior Thesis Harvard University 2000-2001 */ #define PADDING 10 #include #include #include "tone.h" #include "syllable.h" int main (int argc, char ** argv) { float *pitch_track[4]; float standard_pitch_track[4][STANDARD_LEN]; float template_track[4][STANDARD_LEN]; int * offset; int syllable_count; int *tone_length; int i, j, k; FILE * pitch_track_file; printf ("Tools for Simple Mandarin Tone Recognizer:\n"); printf ("Pitch Track Template Maker\n"); if (argc < 4) { printf ("Usage: make_template \n"); printf (" [ ...]\n"); exit ( 0 ); } // allocate memory for pitch track lengths tone_length = malloc(4*sizeof(int)); // clear cumulative pitch track for (i = 0; i < 4; i++) for (j = 0; j < STANDARD_LEN; j++) template_track[i][j] = 0; // now read in each of the pitch tracks and accumulate them for (i = 0; i < argc-2; i++){ printf("Processing [%s]...\n", argv[i+2]); if (!(pitch_track_file = fopen (argv[i+2], "r"))) { printf("Error opening file: %s\n", argv[i+2]); exit ( 1 ); } offset = detect_syllables(pitch_track_file, &syllable_count); if (syllable_count != 4) { printf("Pitch track file [%s] doesn't contain 4 syllables!\n", argv[i+2]); exit(1); } for (j = 0; j < 4; j++ ) { pitch_track[j] = get_syllable(pitch_track_file, &tone_length[j], offset[j]); normalize_syllable(pitch_track[j], tone_length[j]); standardize_syllable( pitch_track[j], tone_length[j], standard_pitch_track[j] ); for (k = 0; k < STANDARD_LEN; k++) template_track[j][k] += standard_pitch_track[j][k]; } fclose(pitch_track_file); free (offset); } // now divide through by number of files to get average for (i = 0; i < 4; i++) for (j = 0; j < STANDARD_LEN; j++) template_track[i][j] /= (argc-2); if (!(pitch_track_file = fopen (argv[1], "w"))) { printf("Error opening file: %s\n", argv[1]); exit ( 1 ); } // write out the template file printf("Writing [%s]...", argv[1]); for (i = 0; i < 4; i++) { for (j = 0; j < PADDING; j++) fprintf(pitch_track_file, "0\n"); for (j = 0; j < STANDARD_LEN; j++) fprintf(pitch_track_file, "%f\n", template_track[i][j]); for (j = 0; j < PADDING; j++) fprintf(pitch_track_file, "0\n"); } printf("done!\n"); fclose(pitch_track_file); exit(0); }