param_t append_param(const param_t params, const char * key, const char * val){ if(params == NULL){ return new_param(key, val); } else { param_t ret = params; param_t it = params; while(it->next){ it = it->next; } it->next = new_param(key, val); return ret; } }
static void process_subtitle(const char *ptr) { ptr = skip_whitespace(ptr); int l = skip_toeol(ptr) - ptr; if (l >= sizeof(script_title)) l = sizeof(script_title) - 1; sc_param *p = new_param(0); p->desc = malloc(l+1); strncpy(p->desc, ptr, l); p->desc[l] = 0; p->range_type = MENUITEM_SEPARATOR; }
// Extract name up to maxlen, find or create sc_param based on name // Return pointer past name. // Sets *sp to sc_param entry, or 0 if not found const char* get_name(const char *p, int maxlen, sc_param **sp, int create) { char str[MAX_PARAM_NAME_LEN+1]; *sp = 0; p = skip_whitespace(p); if (p[0] && isalpha(p[0])) { p = get_token(p, str, maxlen); *sp = find_param(str); if ((*sp == 0) && create) *sp = new_param(str); } return p; }
param_t update_param(const param_t params, const char * key, const char * val){ if(params == NULL){ return new_param(key, val); } else { param_t ret = params; param_t par = get_param(key, params); if(par){ par->value = strdup_r(par->value, val); } else { //FIXME: ..and this is why we need a hashmap. ret = append_param(ret, key, val); } return ret; } }
/** * <EN> * @brief Split input parameter for segmentation. * * Copy the rest samples in param to rest_param, and shrink the param * in mfcc instance. [start...param->samplenum] will be copied to * rest_param, and [0...end] will be left in param. * </EN> * <JA> * @brief セグメンテーション時に入力パラメータを分割する. * * 残りのサンプル(現在のフレームから終わりまで)を rest_param に * コピーし,元の param を短くする. [start...param->samplenum] が * rest_param にコピーされ,元の param には [0...end] が残る. * </JA> * * @param mfcc [i/o] MFCC calculation instance * @param start [in] copy start frame * @param end [in] original end frame * * @callgraph * @callergraph */ void mfcc_copy_to_rest_and_shrink(MFCCCalc *mfcc, int start, int end) { int t; /* copy rest parameters for next process */ mfcc->rest_param = new_param(); memcpy(&(mfcc->rest_param->header), &(mfcc->param->header), sizeof(HTK_Param_Header)); mfcc->rest_param->samplenum = mfcc->param->samplenum - start; mfcc->rest_param->header.samplenum = mfcc->rest_param->samplenum; mfcc->rest_param->veclen = mfcc->param->veclen; if (param_alloc(mfcc->rest_param, mfcc->rest_param->samplenum, mfcc->rest_param->veclen) == FALSE) { j_internal_error("ERROR: segmented: failed to allocate memory for rest param\n"); } /* copy data */ for(t=start;t<mfcc->param->samplenum;t++) { memcpy(mfcc->rest_param->parvec[t-start], mfcc->param->parvec[t], sizeof(VECT) * mfcc->rest_param->veclen); } /* shrink original param */ /* just shrink the length */ mfcc->param->samplenum = end; }
/** * <JA> * 音声波形データから MFCC パラメータを抽出する. * * @param speech [in] 音声波形データ * @param speechlen [in] @a speech の長さ(単位:サンプル数) * * @return 新たに割り付けられ抽出パラメータベクトルが格納されている * パラメータ構造体へのポインタを返す. * </JA> * <EN> * Extract MFCC parameters with sentence CMN from given waveform. * * @param speech [in] buffer of speech waveform * @param speechlen [in] length of @a speech in samples * * @return pointer to newly allocated parameter structure data with extracted * MFCC vector sequence. * </EN> */ HTK_Param *new_wav2mfcc(SP16 speech[], int speechlen) { HTK_Param *param; int framenum; int i; int len; if (ssload_filename && ssbuf == NULL) { /* load noise spectrum for spectral subtraction from file (once) */ if ((ssbuf = new_SS_load_from_file(ssload_filename, &sslen)) == NULL) { j_error("Error: failed to read \"%s\"\n", ssload_filename); } } if (sscalc) { /* compute noise spectrum from head silence for each input */ len = sscalc_len * para.smp_freq / 1000; if (len > speechlen) len = speechlen; #ifdef SSDEBUG printf("[%d]\n", len); #endif ssbuf = new_SS_calculate(speech, len, para, &sslen); } #ifdef SSDEBUG { int i; for(i=0;i<sslen;i++) { printf("%d: %f\n", i, ssbuf[i]); } } #endif /* calculate frame length from speech length, frame size and frame shift */ framenum = (int)((speechlen - para.framesize) / para.frameshift) + 1; if (framenum < 1) { j_printerr("input too short (%d samples), ignored\n", speechlen); return NULL; } /* malloc new param */ param = new_param(); param->parvec = (VECT **)mymalloc(sizeof(VECT *) * framenum); for(i=0;i<framenum;i++) { param->parvec[i] = (VECT *)mymalloc(sizeof(VECT) * para.veclen); } /* make MFCC from speech data */ Wav2MFCC(speech, param->parvec, para, speechlen, ssbuf, sslen); /* set miscellaneous parameters */ param->header.samplenum = framenum; param->header.wshift = para.smp_period * para.frameshift; param->header.sampsize = para.veclen * sizeof(VECT); /* not compressed */ param->header.samptype = F_MFCC; if (para.delta) param->header.samptype |= F_DELTA; if (para.acc) param->header.samptype |= F_ACCL; if (para.energy) param->header.samptype |= F_ENERGY; if (para.c0) param->header.samptype |= F_ZEROTH; if (para.absesup) param->header.samptype |= F_ENERGY_SUP; if (para.cmn) param->header.samptype |= F_CEPNORM; param->veclen = para.veclen; param->samplenum = framenum; return param; }
int main(int argc, char **argv) { vcedit_state *state; vorbis_comment *vc; param_t *param; int i; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); /* initialize the cmdline interface */ param = new_param(); parse_options(argc, argv, param); /* take care of opening the requested files */ /* relevent file pointers are returned in the param struct */ open_files(param); /* which mode are we in? */ if (param->mode == MODE_LIST) { state = vcedit_new_state(); if(vcedit_open(state, param->in) < 0) { fprintf(stderr, _("Failed to open file as vorbis: %s\n"), vcedit_error(state)); close_files(param); free_param(param); vcedit_clear(state); return 1; } /* extract and display the comments */ vc = vcedit_comments(state); print_comments(param->com, vc, param->raw); /* done */ vcedit_clear(state); close_files(param); free_param(param); return 0; } if (param->mode == MODE_WRITE || param->mode == MODE_APPEND) { state = vcedit_new_state(); if(vcedit_open(state, param->in) < 0) { fprintf(stderr, _("Failed to open file as vorbis: %s\n"), vcedit_error(state)); close_files(param); free_param(param); vcedit_clear(state); return 1; } /* grab and clear the exisiting comments */ vc = vcedit_comments(state); if(param->mode != MODE_APPEND) { vorbis_comment_clear(vc); vorbis_comment_init(vc); } for(i=0; i < param->commentcount; i++) { if(add_comment(param->comments[i], vc, param->raw) < 0) fprintf(stderr, _("Bad comment: \"%s\"\n"), param->comments[i]); } /* build the replacement structure */ if(param->commentcount==0) { /* FIXME should use a resizeable buffer! */ char *buf = (char *)malloc(sizeof(char)*1024); while (fgets(buf, 1024, param->com)) if (add_comment(buf, vc, param->raw) < 0) { fprintf(stderr, _("bad comment: \"%s\"\n"), buf); } free(buf); } /* write out the modified stream */ if(vcedit_write(state, param->out) < 0) { fprintf(stderr, _("Failed to write comments to output file: %s\n"), vcedit_error(state)); close_files(param); free_param(param); vcedit_clear(state); return 1; } /* done */ vcedit_clear(state); close_files(param); free_param(param); return 0; } /* should never reach this point */ fprintf(stderr, _("no action specified\n")); free_param(param); return 1; }
/** * <EN> * @brief Combine all loaded models and settings into one engine instance. * * This function will finalize preparation of recognition: * * - create required MFCC calculation instances, * - create recognition process instance for specified LM/AM combination, * - set model-specific recognition parameters, * - build tree lexicon for each process instance for the 1st pass, * - prepare work area and cache area for recognition, * - initialize some values / work area for frontend processing. * * After this function, all recognition setup was done and we are ready for * start recognition. * * This should be called after j_jconf_finalize() and j_load_all() has been * completed. You should put the jconf at recog->jconf before calling this * function. * </EN> * <JA> * @brief 全てのロードされたモデルと設定からエンジンインスタンスを * 最終構成する. * * この関数は,認識準備のための最終処理を行う. 内部では, * * - 必要な MFCC 計算インスタンスの生成 * - 指定された LM/AM の組からの認識処理インスタンス生成 * - モデルに依存する認識用パラメータの設定 * - 第1パス用の木構造化辞書を認識処理インスタンスごとに構築 * - 認識処理用ワークエリアとキャッシュエリアを確保 * - フロントエンド処理のためのいくつかの値とワークエリアの確保 * * を行う. この関数が終了後,エンジンインスタンス内の全てのセットアップ * は終了し,認識が開始できる状態となる. * * この関数は,j_jconf_finalize() と j_load_all() が終わった状態で * 呼び出す必要がある. 呼出し前には,recog->jconf に (j_load_all でともに * 使用した) jconf を格納しておくこと. * * </JA> * * @param recog [in] engine instance * * @return TRUE when all initialization successfully done, or FALSE if any * error has been occured. * * @callgraph * @callergraph * @ingroup instance * */ boolean j_final_fusion(Recog *recog) { MFCCCalc *mfcc; JCONF_SEARCH *sconf; PROCESS_AM *am; jlog("STAT: ------\n"); jlog("STAT: All models are ready, go for final fusion\n"); jlog("STAT: [1] create MFCC extraction instance(s)\n"); if (recog->jconf->input.type == INPUT_WAVEFORM) { /***************************************************/ /* create MFCC calculation instance from AM config */ /* according to the fixated parameter information */ /***************************************************/ create_mfcc_calc_instances(recog); } /****************************************/ /* create recognition process instances */ /****************************************/ jlog("STAT: [2] create recognition processing instance(s) with AM and LM\n"); for(sconf=recog->jconf->search_root;sconf;sconf=sconf->next) { if (j_launch_recognition_instance(recog, sconf) == FALSE) return FALSE; } /****************************/ /****** initialize GMM ******/ /****************************/ if (recog->gmm != NULL) { jlog("STAT: [2.5] create GMM instance\n"); if (gmm_init(recog) == FALSE) { jlog("ERROR: m_fusion: error in initializing GMM\n"); return FALSE; } } /* stage 4: setup output probability function for each AM */ jlog("STAT: [3] initialize for acoustic HMM calculation\n"); for(am=recog->amlist;am;am=am->next) { #ifdef ENABLE_PLUGIN /* set plugin function if specified */ if (am->config->gprune_method == GPRUNE_SEL_USER) { am->hmmwrk.compute_gaussset = (void (*)(HMMWork *, HTK_HMM_Dens **, int, int *, int)) plugin_get_func(am->config->gprune_plugin_source, "calcmix"); if (am->hmmwrk.compute_gaussset == NULL) { jlog("ERROR: calcmix plugin has no function \"calcmix\"\n"); return FALSE; } am->hmmwrk.compute_gaussset_init = (boolean (*)(HMMWork *)) plugin_get_func(am->config->gprune_plugin_source, "calcmix_init"); if (am->hmmwrk.compute_gaussset_init == NULL) { jlog("ERROR: calcmix plugin has no function \"calcmix_init\"\n"); return FALSE; } am->hmmwrk.compute_gaussset_free = (void (*)(HMMWork *)) plugin_get_func(am->config->gprune_plugin_source, "calcmix_free"); if (am->hmmwrk.compute_gaussset_free == NULL) { jlog("ERROR: calcmix plugin has no function \"calcmix_free\"\n"); return FALSE; } } #endif if (am->config->hmm_gs_filename != NULL) {/* with GMS */ if (outprob_init(&(am->hmmwrk), am->hmminfo, am->hmm_gs, am->config->gs_statenum, am->config->gprune_method, am->config->mixnum_thres) == FALSE) { return FALSE; } } else { if (outprob_init(&(am->hmmwrk), am->hmminfo, NULL, 0, am->config->gprune_method, am->config->mixnum_thres) == FALSE) { return FALSE; } } } /* stage 5: initialize work area for input and realtime decoding */ jlog("STAT: [4] prepare MFCC storage(s)\n"); if (recog->jconf->input.type == INPUT_VECTOR) { /* create an MFCC instance for MFCC input */ /* create new mfcc instance */ recog->mfcclist = j_mfcccalc_new(NULL); recog->mfcclist->id = 1; /* assign to the am */ for(am=recog->amlist;am;am=am->next) { am->mfcc = recog->mfcclist; } if (recog->gmm) recog->gmmmfcc = recog->mfcclist; } /* allocate parameter holders */ for(mfcc=recog->mfcclist;mfcc;mfcc=mfcc->next) { mfcc->param = new_param(); } /* initialize SS calculation work area */ if (recog->jconf->input.type == INPUT_WAVEFORM) { for(mfcc=recog->mfcclist;mfcc;mfcc=mfcc->next) { if (mfcc->frontend.sscalc) { mfcc->frontend.mfccwrk_ss = WMP_work_new(mfcc->para); if (mfcc->frontend.mfccwrk_ss == NULL) { jlog("ERROR: m_fusion: failed to initialize MFCC computation for SS\n"); return FALSE; } if (mfcc->frontend.sscalc_len * recog->jconf->input.sfreq / 1000 < mfcc->para->framesize) { jlog("ERROR: m_fusion: head sil length for SS (%d msec) is shorter than a frame (%d msec)\n", mfcc->frontend.sscalc_len, mfcc->para->framesize * 1000 / recog->jconf->input.sfreq); return FALSE; } } } } if (recog->jconf->decodeopt.realtime_flag) { jlog("STAT: [5] prepare for real-time decoding\n"); /* prepare for 1st pass pipeline processing */ if (recog->jconf->input.type == INPUT_WAVEFORM) { if (RealTimeInit(recog) == FALSE) { jlog("ERROR: m_fusion: failed to initialize recognition process\n"); return FALSE; } } } /* finished! */ jlog("STAT: All init successfully done\n\n"); /* set-up callback plugin if any */ #ifdef ENABLE_PLUGIN if (plugin_exec_engine_startup(recog) == FALSE) { jlog("ERROR: m_fusion: failed to execute callback setup in plugin\n"); return FALSE; } #endif return TRUE; }
int write_ogg_tag(const string fname, struct fennec_audiotag *wtag) { vcedit_state *state; vorbis_comment *vc; param_t *param; FILE *tfile; FILE *of; string outname; struct fennec_audiotag_item *ct; if(!fname || !wtag)return -3; setlocale(LC_ALL, ""); /* initialize the cmdline interface */ param = new_param(); tfile = _wfsopen(fname, uni("r+b"), _SH_DENYRW); if(!tfile) { MessageBox(0, uni("Access denied, please stop playback and try again (you don't need to close this window)."), uni("Tag Editing"), MB_ICONINFORMATION); return -1; } state = vcedit_new_state(); if(vcedit_open(state, tfile) < 0) { fclose(tfile); free_param(param); vcedit_clear(state); return -2; } vc = vcedit_comments(state); ct = &wtag->tag_title; if(ct->tsize)local_addcomment(vc, "TITLE", ct->tdata); else local_addcomment(vc, "TITLE", uni("") ); ct = &wtag->tag_album; if(ct->tsize)local_addcomment(vc, "ALBUM", ct->tdata); else local_addcomment(vc, "ALBUM", uni("") ); ct = &wtag->tag_artist; if(ct->tsize)local_addcomment(vc, "ARTIST", ct->tdata); else local_addcomment(vc, "ARTIST", uni("") ); ct = &wtag->tag_origartist; if(ct->tsize)local_addcomment(vc, "ORIGINALARTIST", ct->tdata); else local_addcomment(vc, "ORIGINALARTIST", uni("") ); ct = &wtag->tag_composer; if(ct->tsize)local_addcomment(vc, "COMPOSER", ct->tdata); else local_addcomment(vc, "COMPOSER", uni("") ); ct = &wtag->tag_lyricist; if(ct->tsize)local_addcomment(vc, "LYRICIST", ct->tdata); else local_addcomment(vc, "LYRICIST", uni("") ); ct = &wtag->tag_band; if(ct->tsize)local_addcomment(vc, "BANDNAME", ct->tdata); else local_addcomment(vc, "BANDNAME", uni("") ); ct = &wtag->tag_copyright; if(ct->tsize)local_addcomment(vc, "COPYRIGHT", ct->tdata); else local_addcomment(vc, "COPYRIGHT", uni("") ); ct = &wtag->tag_publish; if(ct->tsize)local_addcomment(vc, "PUBLISHER", ct->tdata); else local_addcomment(vc, "PUBLISHER", uni("") ); ct = &wtag->tag_encodedby; if(ct->tsize)local_addcomment(vc, "ENCODEDBY", ct->tdata); else local_addcomment(vc, "ENCODEDBY", uni("") ); ct = &wtag->tag_genre; if(ct->tsize)local_addcomment(vc, "GENRE", ct->tdata); else local_addcomment(vc, "GENRE", uni("") ); ct = &wtag->tag_year; if(ct->tsize)local_addcomment(vc, "YEAR", ct->tdata); else local_addcomment(vc, "YEAR", uni("") ); ct = &wtag->tag_url; if(ct->tsize)local_addcomment(vc, "URL", ct->tdata); else local_addcomment(vc, "URL", uni("") ); ct = &wtag->tag_offiartisturl; if(ct->tsize)local_addcomment(vc, "OFFICIALARTISTURL", ct->tdata); else local_addcomment(vc, "OFFICIALARTISTURL", uni("") ); ct = &wtag->tag_comments; if(ct->tsize)local_addcomment(vc, "COMMENT", ct->tdata); else local_addcomment(vc, "COMMENT", uni("") ); ct = &wtag->tag_lyric; if(ct->tsize)local_addcomment(vc, "LYRIC", ct->tdata); else local_addcomment(vc, "LYRIC", uni("") ); ct = &wtag->tag_bpm; if(ct->tsize)local_addcomment(vc, "BPM", ct->tdata); else local_addcomment(vc, "BPM", uni("") ); ct = &wtag->tag_tracknum; if(ct->tsize)local_addcomment(vc, "TRACKNUMBER", ct->tdata); else local_addcomment(vc, "TRACKNUMBER", uni("") ); outname = (string) malloc(str_size(fname) + (5 * sizeof(letter))); str_cpy(outname, fname); str_cat(outname, uni(".tmp")); of = _wfopen(outname, uni("wb")); if(vcedit_write(state, of) < 0) { fclose(of); fclose(tfile); free_param(param); vcedit_clear(state); free(outname); return 1; } fclose(of); /* done */ vcedit_clear(state); fclose(tfile); free_param(param); _wremove(fname); sys_sleep(0); _wrename(outname, fname); free(outname); return 0; }