本文整理汇总了C++中ckd_salloc函数的典型用法代码示例。如果您正苦于以下问题:C++ ckd_salloc函数的具体用法?C++ ckd_salloc怎么用?C++ ckd_salloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ckd_salloc函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: importname2rulename
/* Extract as rulename everything after the secondlast dot, if existent.
* Because everything before the secondlast dot is the path-specification. */
static char *
importname2rulename(char *importname)
{
char *rulename = ckd_salloc(importname);
char *last_dotpos;
char *secondlast_dotpos;
if ((last_dotpos = strrchr(rulename+1, '.')) != NULL) {
*last_dotpos='\0';
if ((secondlast_dotpos = strrchr(rulename+1, '.')) != NULL) {
*last_dotpos='.';
*secondlast_dotpos='<';
secondlast_dotpos = ckd_salloc(secondlast_dotpos);
ckd_free(rulename);
return secondlast_dotpos;
}
else {
*last_dotpos='.';
return rulename;
}
}
else {
return rulename;
}
}
开发者ID:andradeandrey,项目名称:pocketsphinx.js,代码行数:27,代码来源:jsgf.c
示例2: jsgf_set_search_path
static void
jsgf_set_search_path(jsgf_t * jsgf, const char *filename)
{
char *jsgf_path;
#if !defined(_WIN32_WCE)
if ((jsgf_path = getenv("JSGF_PATH")) != NULL) {
char *word, *c;
/* FIXME: This should be a function in libsphinxbase. */
word = jsgf_path = ckd_salloc(jsgf_path);
while ((c = strchr(word, ':'))) {
*c = '\0';
jsgf->searchpath = glist_add_ptr(jsgf->searchpath, word);
word = c + 1;
}
jsgf->searchpath = glist_add_ptr(jsgf->searchpath, word);
jsgf->searchpath = glist_reverse(jsgf->searchpath);
return;
}
#endif
if (!filename) {
jsgf->searchpath =
glist_add_ptr(jsgf->searchpath, ckd_salloc("."));
return;
}
jsgf_path = ckd_salloc(filename);
path2dirname(filename, jsgf_path);
jsgf->searchpath = glist_add_ptr(jsgf->searchpath, jsgf_path);
}
开发者ID:Amponti,项目名称:SpeechRecognition_DE1-SOC,代码行数:31,代码来源:jsgf.c
示例3: ps_search_init
void
ps_search_init(ps_search_t *search, ps_searchfuncs_t *vt,
const char *type,
const char *name,
cmd_ln_t *config, acmod_t *acmod, dict_t *dict,
dict2pid_t *d2p)
{
search->vt = vt;
search->name = ckd_salloc(name);
search->type = ckd_salloc(type);
search->config = config;
search->acmod = acmod;
if (d2p)
search->d2p = dict2pid_retain(d2p);
else
search->d2p = NULL;
if (dict) {
search->dict = dict_retain(dict);
search->start_wid = dict_startwid(dict);
search->finish_wid = dict_finishwid(dict);
search->silence_wid = dict_silwid(dict);
search->n_words = dict_size(dict);
}
else {
search->dict = NULL;
search->start_wid = search->finish_wid = search->silence_wid = -1;
search->n_words = 0;
}
}
开发者ID:Amponti,项目名称:SpeechRecognition_DE1-SOC,代码行数:30,代码来源:pocketsphinx.c
示例4: ckd_calloc
SWIGINTERN Hypothesis *new_Hypothesis(char const *hypstr,char const *uttid,int best_score){
Hypothesis *h = ckd_calloc(1, sizeof(*h));
if (hypstr)
h->hypstr = ckd_salloc(hypstr);
if (uttid)
h->uttid = ckd_salloc(uttid);
h->best_score = best_score;
return h;
}
开发者ID:omtinez,项目名称:PocketSphinxAndroidLibrary,代码行数:10,代码来源:pocketsphinx_wrap.c
示例5: kb_set_uttid
void
kb_set_uttid(const char *_uttid, const char *_uttfile, kb_t * _kb)
{
assert(_kb != NULL);
assert(_uttid != NULL);
ckd_free(_kb->uttid);
_kb->uttid = NULL;
_kb->uttid = ckd_salloc(_uttid);
ckd_free(_kb->uttfile);
_kb->uttfile = NULL;
if (_uttfile)
_kb->uttfile = ckd_salloc(_uttfile);
}
开发者ID:4auka,项目名称:cmusphinx,代码行数:15,代码来源:kb.c
示例6: jsgf_define_rule
jsgf_rule_t *
jsgf_define_rule(jsgf_t * jsgf, char *name, jsgf_rhs_t * rhs,
int is_public)
{
jsgf_rule_t *rule;
void *val;
if (name == NULL) {
name = ckd_malloc(strlen(jsgf->name) + 16);
sprintf(name, "<%s.g%05d>", jsgf->name,
hash_table_inuse(jsgf->rules));
}
else {
char *newname;
newname = jsgf_fullname(jsgf, name);
name = newname;
}
rule = ckd_calloc(1, sizeof(*rule));
rule->refcnt = 1;
rule->name = ckd_salloc(name);
rule->rhs = rhs;
rule->is_public = is_public;
E_INFO("Defined rule: %s%s\n",
rule->is_public ? "PUBLIC " : "", rule->name);
val = hash_table_enter(jsgf->rules, name, rule);
if (val != (void *) rule) {
E_WARN("Multiply defined symbol: %s\n", name);
}
return rule;
}
开发者ID:Amponti,项目名称:SpeechRecognition_DE1-SOC,代码行数:33,代码来源:jsgf.c
示例7: build_filenames
void
build_filenames(cmd_ln_t *config, char const *basename,
char **out_infile, char **out_outfile)
{
char const *di, *do_, *ei, *eo;
di = cmd_ln_str_r(config, "-di");
do_ = cmd_ln_str_r(config, "-do");
ei = cmd_ln_str_r(config, "-ei");
eo = cmd_ln_str_r(config, "-eo");
*out_infile = string_join(di ? di : "",
di ? "/" : "",
basename,
ei ? "." : "",
ei ? ei : "",
NULL);
*out_outfile = string_join(do_ ? do_ : "",
do_ ? "/" : "",
basename,
eo ? "." : "",
eo ? eo : "",
NULL);
/* Build output directory structure if possible/requested (it is
* by default). */
if (cmd_ln_boolean_r(config, "-build_outdirs")) {
char *dirname = ckd_salloc(*out_outfile);
path2dirname(*out_outfile, dirname);
build_directory(dirname);
ckd_free(dirname);
}
}
开发者ID:kirpen,项目名称:pocketsphinx.js,代码行数:32,代码来源:sphinx_fe.c
示例8: ngram_model_set_map_words
void
ngram_model_set_map_words(ngram_model_t * base,
const char **words, int32 n_words)
{
ngram_model_set_t *set = (ngram_model_set_t *) base;
int32 i;
/* Recreate the word mapping. */
if (base->writable) {
for (i = 0; i < base->n_words; ++i) {
ckd_free(base->word_str[i]);
}
}
ckd_free(base->word_str);
ckd_free_2d((void **) set->widmap);
base->writable = TRUE;
base->n_words = base->n_1g_alloc = n_words;
base->word_str = ckd_calloc(n_words, sizeof(*base->word_str));
set->widmap =
(int32 **) ckd_calloc_2d(n_words, set->n_models,
sizeof(**set->widmap));
hash_table_empty(base->wid);
for (i = 0; i < n_words; ++i) {
int32 j;
base->word_str[i] = ckd_salloc(words[i]);
(void) hash_table_enter_int32(base->wid, base->word_str[i], i);
for (j = 0; j < set->n_models; ++j) {
set->widmap[i][j] = ngram_wid(set->lms[j], base->word_str[i]);
}
}
}
开发者ID:Amponti,项目名称:SpeechRecognition_DE1-SOC,代码行数:31,代码来源:ngram_model_set.c
示例9: ngram_model_set_init
ngram_model_t *
ngram_model_set_init(cmd_ln_t * config,
ngram_model_t ** models,
char **names, const float32 * weights, int32 n_models)
{
ngram_model_set_t *model;
ngram_model_t *base;
logmath_t *lmath;
int32 i, n;
if (n_models == 0) /* WTF */
return NULL;
/* Do consistency checking on the models. They must all use the
* same logbase and shift. */
lmath = models[0]->lmath;
for (i = 1; i < n_models; ++i) {
if (logmath_get_base(models[i]->lmath) != logmath_get_base(lmath)
|| logmath_get_shift(models[i]->lmath) !=
logmath_get_shift(lmath)) {
E_ERROR
("Log-math parameters don't match, will not create LM set\n");
return NULL;
}
}
/* Allocate the combined model, initialize it. */
model = ckd_calloc(1, sizeof(*model));
base = &model->base;
model->n_models = n_models;
model->lms = ckd_calloc(n_models, sizeof(*model->lms));
model->names = ckd_calloc(n_models, sizeof(*model->names));
/* Initialize weights to a uniform distribution */
model->lweights = ckd_calloc(n_models, sizeof(*model->lweights));
{
int32 uniform = logmath_log(lmath, 1.0 / n_models);
for (i = 0; i < n_models; ++i)
model->lweights[i] = uniform;
}
/* Default to interpolate if weights were given. */
if (weights)
model->cur = -1;
n = 0;
for (i = 0; i < n_models; ++i) {
model->lms[i] = ngram_model_retain(models[i]);
model->names[i] = ckd_salloc(names[i]);
if (weights)
model->lweights[i] = logmath_log(lmath, weights[i]);
/* N is the maximum of all merged models. */
if (models[i]->n > n)
n = models[i]->n;
}
/* Allocate the history mapping table. */
model->maphist = ckd_calloc(n - 1, sizeof(*model->maphist));
/* Now build the word-ID mapping and merged vocabulary. */
build_widmap(base, lmath, n);
return base;
}
开发者ID:Amponti,项目名称:SpeechRecognition_DE1-SOC,代码行数:60,代码来源:ngram_model_set.c
示例10: add_trans
static int
add_trans(s2_fsg_t *_fsg,int _from,int _to,float32 _prob,char *_word)
{
s2_fsg_trans_t *trans=NULL;
char *word=NULL;
trans=(s2_fsg_trans_t*)ckd_calloc(1,sizeof(s2_fsg_trans_t));
if (trans==NULL)
goto cleanup;
if (_word!=NULL) {
word=(char*)ckd_salloc(_word);
if (word==NULL)
goto cleanup;
}
trans->from_sate=_from;
trans->to_state=_to;
trans->prob=_prob;
trans->word=word;
trans->next=_fsg->trans_list;
_fsg->trans_list=trans;
return 0;
cleanup:
if (trans!=NULL)
ckd_free(trans);
if (word!=NULL)
ckd_free(word);
return -1;
}
开发者ID:channainfo,项目名称:sphinx3-verboice,代码行数:33,代码来源:s3_cfg_convert.c
示例11: build_output_uttfile
/*
* Build a filename int buf as follows (without file extension):
* if dir ends with ,CTLand ctlspec does not begin with /, filename is dir/ctlspec
* if dir ends with ,CTL and ctlspec DOES begin with /, filename is ctlspec
* if dir does not end with ,CTL, filename is dir/uttid,
* where ctlspec is the complete utterance spec in the input control file, and
* uttid is the last component of ctlspec.
*/
static void
build_output_uttfile(char *buf, char *dir, char *uttid, char *ctlspec)
{
int32 k;
k = strlen(dir);
if ((k > 4) && (strcmp(dir + k - 4, ",CTL") == 0)) { /* HACK!! Hardwired ,CTL */
if (ctlspec[0] != '/') {
strcpy(buf, dir);
buf[k - 4] = '/';
strcpy(buf + k - 3, ctlspec);
}
else
strcpy(buf, ctlspec);
}
else {
strcpy(buf, dir);
buf[k] = '/';
strcpy(buf + k + 1, uttid);
}
/* Build output directory structure if possible/requested (it is
* by default). */
if (cmd_ln_boolean("-build_outdirs")) {
char *dirname = ckd_salloc(buf);
path2dirname(buf, dirname);
build_directory(dirname);
ckd_free(dirname);
}
}
开发者ID:Ankit77,项目名称:cmusphinx,代码行数:37,代码来源:main_align.c
示例12: read_word_str
static void
read_word_str(ngram_model_t * base, FILE * fp)
{
int32 k;
uint32 i, j;
char *tmp_word_str;
/* read ascii word strings */
base->writable = TRUE;
fread(&k, sizeof(k), 1, fp);
tmp_word_str = (char *) ckd_calloc((size_t) k, 1);
fread(tmp_word_str, 1, (size_t) k, fp);
/* First make sure string just read contains n_counts[0] words (PARANOIA!!) */
for (i = 0, j = 0; i < (uint32) k; i++)
if (tmp_word_str[i] == '\0')
j++;
if (j != base->n_counts[0]) {
E_ERROR
("Error reading word strings (%d doesn't match n_unigrams %d)\n",
j, base->n_counts[0]);
}
/* Break up string just read into words */
j = 0;
for (i = 0; i < base->n_counts[0]; i++) {
base->word_str[i] = ckd_salloc(tmp_word_str + j);
if (hash_table_enter(base->wid, base->word_str[i],
(void *) (long) i) != (void *) (long) i) {
E_WARN("Duplicate word in dictionary: %s\n",
base->word_str[i]);
}
j += strlen(base->word_str[i]) + 1;
}
free(tmp_word_str);
}
开发者ID:day279,项目名称:sphinxbase,代码行数:35,代码来源:ngram_model_trie.c
示例13: ps_add_word
int
ps_add_word(ps_decoder_t *ps,
char const *word,
char const *phones,
int update)
{
int32 wid, lmwid;
ngram_model_t *lmset;
s3cipid_t *pron;
char **phonestr, *tmp;
int np, i, rv;
/* Parse phones into an array of phone IDs. */
tmp = ckd_salloc(phones);
np = str2words(tmp, NULL, 0);
phonestr = ckd_calloc(np, sizeof(*phonestr));
str2words(tmp, phonestr, np);
pron = ckd_calloc(np, sizeof(*pron));
for (i = 0; i < np; ++i) {
pron[i] = bin_mdef_ciphone_id(ps->acmod->mdef, phonestr[i]);
if (pron[i] == -1) {
E_ERROR("Unknown phone %s in phone string %s\n",
phonestr[i], tmp);
ckd_free(phonestr);
ckd_free(tmp);
ckd_free(pron);
return -1;
}
}
/* No longer needed. */
ckd_free(phonestr);
ckd_free(tmp);
/* Add it to the dictionary. */
if ((wid = dict_add_word(ps->dict, word, pron, np)) == -1) {
ckd_free(pron);
return -1;
}
/* No longer needed. */
ckd_free(pron);
/* Now we also have to add it to dict2pid. */
dict2pid_add_word(ps->d2p, wid);
if ((lmset = ps_get_lmset(ps)) != NULL) {
/* Add it to the LM set (meaning, the current LM). In a perfect
* world, this would result in the same WID, but because of the
* weird way that word IDs are handled, it doesn't. */
if ((lmwid = ngram_model_add_word(lmset, word, 1.0))
== NGRAM_INVALID_WID)
return -1;
}
/* Rebuild the widmap and search tree if requested. */
if (update) {
if ((rv = ps_search_reinit(ps->search, ps->dict, ps->d2p) < 0))
return rv;
}
return wid;
}
开发者ID:006,项目名称:ios_lab,代码行数:60,代码来源:pocketsphinx.c
示例14: dict_ciphone_id
static s3cipid_t
dict_ciphone_id(dict_t * d, const char *str)
{
if (d->mdef)
return mdef_ciphone_id(d->mdef, str);
else {
void *val;
if (hash_table_lookup(d->pht, str, &val) < 0) {
s3cipid_t id;
id = (d->n_ciphone)++;
if (id >= MAX_S3CIPID)
E_FATAL
("Too many CIphones in dictionary; increase MAX_S3CIPID\n");
d->ciphone_str[id] = (char *) ckd_salloc(str); /* Freed in dict_free() */
if (hash_table_enter(d->pht, d->ciphone_str[id], (void *)(long)id) != (void *)(long)id)
E_FATAL("hash_table_enter(local-phonetable, %s) failed\n", str);
return id;
}
else
return (s3cipid_t)(long)val;
}
}
开发者ID:hschwenk,项目名称:cslm-toolkit,代码行数:26,代码来源:dict.c
示例15: split_topn
int
split_topn(char const *str, uint8 *out, int nfeat)
{
char *topn_list = ckd_salloc(str);
char *c, *cc;
int i, maxn;
c = topn_list;
i = 0;
maxn = 0;
while (i < nfeat && (cc = strchr(c, ',')) != NULL) {
*cc = '\0';
out[i] = atoi(c);
if (out[i] > maxn) maxn = out[i];
c = cc + 1;
++i;
}
if (i < nfeat && *c != '\0') {
out[i] = atoi(c);
if (out[i] > maxn) maxn = out[i];
++i;
}
while (i < nfeat)
out[i++] = maxn;
ckd_free(topn_list);
return maxn;
}
开发者ID:elliotfiske,项目名称:cmu-lextool,代码行数:28,代码来源:s2_semi_mgau.c
示例16: evaluate_string
static void
evaluate_string(ngram_model_t *lm, logmath_t *lmath, const char *text)
{
char *textfoo;
char **words;
int32 n, ch, noovs, nccs, lscr;
/* Split it into an array of strings. */
textfoo = ckd_salloc(text);
n = str2words(textfoo, NULL, 0);
if (n < 0)
E_FATAL("str2words(textfoo, NULL, 0) = %d, should not happen\n", n);
if (n == 0) /* Do nothing! */
return;
words = ckd_calloc(n, sizeof(*words));
str2words(textfoo, words, n);
ch = calc_entropy(lm, words, n, &nccs, &noovs, &lscr);
printf("input: %s\n", text);
printf("cross-entropy: %f bits\n",
ch * log(logmath_get_base(lmath)) / log(2));
/* Calculate perplexity pplx = exp CH */
printf("perplexity: %f\n", logmath_exp(lmath, ch));
printf("lm score: %d\n", lscr);
/* Report OOVs and CCs */
printf("%d words evaluated\n", n);
printf("%d OOVs, %d context cues removed\n",
noovs, nccs);
ckd_free(textfoo);
ckd_free(words);
}
开发者ID:AaronZhangL,项目名称:pocketsphinx.js,代码行数:35,代码来源:sphinx_lm_eval.c
示例17: add_item
static s3_cfg_item_t *
add_item(s3_cfg_t *_cfg, char *_name)
{
s3_cfg_item_t *item = NULL;
char *name = NULL;
int index;
assert(_cfg != NULL);
assert(_name != NULL);
index = s3_arraylist_count(&_cfg->item_info);
item = (s3_cfg_item_t *)ckd_calloc(1, sizeof(s3_cfg_item_t));
name = (char *)ckd_salloc(_name);
s3_arraylist_init(&item->rules);
/* create item's new id */
item->id = (name[0] == S3_CFG_NONTERM_PREFIX ? 0 : S3_CFG_TERM_BIT) | index;
item->name = name;
item->nil_rule = NULL;
hash_table_enter(_cfg->name2id, name, (void *)item->id);
s3_arraylist_set(&_cfg->item_info, index, item);
return item;
}
开发者ID:elliotfiske,项目名称:cmu-lextool,代码行数:28,代码来源:s3_cfg.c
示例18: huff_node_new_str
static huff_node_t *
huff_node_new_str(char const *val)
{
huff_node_t *hn = (huff_node_t*)ckd_calloc(1, sizeof(*hn));
hn->r.sval = ckd_salloc(val);
return hn;
}
开发者ID:catseattrees,项目名称:pocketsphinxnet,代码行数:7,代码来源:huff_code.cpp
示例19: fsg_model_word_add
int
fsg_model_word_add(fsg_model_t * fsg, char const *word)
{
int wid;
/* Search for an existing word matching this. */
wid = fsg_model_word_id(fsg, word);
/* If not found, add this to the vocab. */
if (wid == -1) {
wid = fsg->n_word;
if (fsg->n_word == fsg->n_word_alloc) {
fsg->n_word_alloc += 10;
fsg->vocab = ckd_realloc(fsg->vocab,
fsg->n_word_alloc *
sizeof(*fsg->vocab));
if (fsg->silwords)
fsg->silwords =
bitvec_realloc(fsg->silwords, fsg->n_word_alloc);
if (fsg->altwords)
fsg->altwords =
bitvec_realloc(fsg->altwords, fsg->n_word_alloc);
}
++fsg->n_word;
fsg->vocab[wid] = ckd_salloc(word);
}
return wid;
}
开发者ID:vinodkumarkv13,项目名称:sphinx-on-android,代码行数:27,代码来源:fsg_model.c
示例20: acmod_init_feat
static int
acmod_init_feat(acmod_t *acmod)
{
acmod->fcb =
feat_init(cmd_ln_str_r(acmod->config, "-feat"),
cmn_type_from_str(cmd_ln_str_r(acmod->config,"-cmn")),
cmd_ln_boolean_r(acmod->config, "-varnorm"),
agc_type_from_str(cmd_ln_str_r(acmod->config, "-agc")),
1, cmd_ln_int32_r(acmod->config, "-ceplen"));
if (acmod->fcb == NULL)
return -1;
if (cmd_ln_str_r(acmod->config, "-lda")) {
E_INFO("Reading linear feature transformation from %s\n",
cmd_ln_str_r(acmod->config, "-lda"));
if (feat_read_lda(acmod->fcb,
cmd_ln_str_r(acmod->config, "-lda"),
cmd_ln_int32_r(acmod->config, "-ldadim")) < 0)
return -1;
}
if (cmd_ln_str_r(acmod->config, "-svspec")) {
int32 **subvecs;
E_INFO("Using subvector specification %s\n",
cmd_ln_str_r(acmod->config, "-svspec"));
if ((subvecs = parse_subvecs(cmd_ln_str_r(acmod->config, "-svspec"))) == NULL)
return -1;
if ((feat_set_subvecs(acmod->fcb, subvecs)) < 0)
return -1;
}
if (cmd_ln_exists_r(acmod->config, "-agcthresh")
&& 0 != strcmp(cmd_ln_str_r(acmod->config, "-agc"), "none")) {
agc_set_threshold(acmod->fcb->agc_struct,
cmd_ln_float32_r(acmod->config, "-agcthresh"));
}
if (acmod->fcb->cmn_struct
&& cmd_ln_exists_r(acmod->config, "-cmninit")) {
char *c, *cc, *vallist;
int32 nvals;
vallist = ckd_salloc(cmd_ln_str_r(acmod->config, "-cmninit"));
c = vallist;
nvals = 0;
while (nvals < acmod->fcb->cmn_struct->veclen
&& (cc = strchr(c, ',')) != NULL) {
*cc = '\0';
acmod->fcb->cmn_struct->cmn_mean[nvals] = FLOAT2MFCC(atof_c(c));
c = cc + 1;
++nvals;
}
if (nvals < acmod->fcb->cmn_struct->veclen && *c != '\0') {
acmod->fcb->cmn_struct->cmn_mean[nvals] = FLOAT2MFCC(atof_c(c));
}
ckd_free(vallist);
}
return 0;
}
开发者ID:JonGBowen,项目名称:GoodVibes,代码行数:59,代码来源:acmod.c
注:本文中的ckd_salloc函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论