本文整理汇总了C++中HTS_calloc函数的典型用法代码示例。如果您正苦于以下问题:C++ HTS_calloc函数的具体用法?C++ HTS_calloc怎么用?C++ HTS_calloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HTS_calloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HTS_Window_load
/* HTS_Window_load: load dynamic windows */
static HTS_Boolean HTS_Window_load(HTS_Window * win, HTS_File ** fp, int size)
{
int i, j;
int fsize, length;
char buff[HTS_MAXBUFLEN];
HTS_Boolean result = TRUE;
/* check */
if (win == NULL || fp == NULL || size <= 0)
return FALSE;
win->size = size;
win->l_width = (int *) HTS_calloc(win->size, sizeof(int));
win->r_width = (int *) HTS_calloc(win->size, sizeof(int));
win->coefficient = (double **) HTS_calloc(win->size, sizeof(double *));
/* set delta coefficents */
for (i = 0; i < win->size; i++) {
if (HTS_get_token(fp[i], buff) == FALSE) {
result = FALSE;
fsize = 1;
} else {
fsize = atoi(buff);
if (fsize <= 0) {
result = FALSE;
fsize = 1;
}
}
/* read coefficients */
win->coefficient[i] = (double *) HTS_calloc(fsize, sizeof(double));
for (j = 0; j < fsize; j++) {
if (HTS_get_token(fp[i], buff) == FALSE) {
result = FALSE;
win->coefficient[i][j] = 0.0;
} else {
win->coefficient[i][j] = (double) atof(buff);
}
}
/* set pointer */
length = fsize / 2;
win->coefficient[i] += length;
win->l_width[i] = -length;
win->r_width[i] = length;
if (fsize % 2 == 0)
win->r_width[i]--;
}
/* calcurate max_width to determine size of band matrix */
win->max_width = 0;
for (i = 0; i < win->size; i++) {
if (win->max_width < abs(win->l_width[i]))
win->max_width = abs(win->l_width[i]);
if (win->max_width < abs(win->r_width[i]))
win->max_width = abs(win->r_width[i]);
}
if (result == FALSE) {
HTS_Window_clear(win);
return FALSE;
}
return TRUE;
}
示例2: HTS_Engine_load_gv_from_fn
/* HTS_Engine_load_gv_from_fn: load GV pdfs and trees from file names */
void HTS_Engine_load_gv_from_fn(HTS_Engine * engine, char **pdf_fn,
char **tree_fn, int stream_index,
int interpolation_size)
{
int i;
FILE **pdf_fp, **tree_fp;
pdf_fp = (FILE **) HTS_calloc(interpolation_size, sizeof(FILE *));
if (tree_fn)
tree_fp = (FILE **) HTS_calloc(interpolation_size, sizeof(FILE *));
else
tree_fp = NULL;
for (i = 0; i < interpolation_size; i++) {
pdf_fp[i] = HTS_get_fp(pdf_fn[i], "rb");
if (tree_fn) {
if (tree_fn[i])
tree_fp[i] = HTS_get_fp(tree_fn[i], "r");
else
tree_fp[i] = NULL;
}
}
HTS_Engine_load_gv_from_fp(engine, pdf_fp, tree_fp, stream_index,
interpolation_size);
for (i = 0; i < interpolation_size; i++) {
fclose(pdf_fp[i]);
if (tree_fp && tree_fp[i])
fclose(tree_fp[i]);
}
HTS_free(pdf_fp);
if (tree_fp)
HTS_free(tree_fp);
}
示例3: HTS_Engine_load_parameter_from_fn
/* HTS_Engine_load_parameter_from_fn: load parameter pdfs, trees and windows from file names */
void HTS_Engine_load_parameter_from_fn(HTS_Engine * engine, char **pdf_fn,
char **tree_fn, char **win_fn,
int stream_index, HTS_Boolean msd_flag,
int window_size, int interpolation_size)
{
int i;
FILE **pdf_fp, **tree_fp, **win_fp;
pdf_fp = (FILE **) HTS_calloc(interpolation_size, sizeof(FILE *));
tree_fp = (FILE **) HTS_calloc(interpolation_size, sizeof(FILE *));
win_fp = (FILE **) HTS_calloc(window_size, sizeof(FILE *));
for (i = 0; i < interpolation_size; i++) {
pdf_fp[i] = HTS_get_fp(pdf_fn[i], "rb");
tree_fp[i] = HTS_get_fp(tree_fn[i], "r");
}
for (i = 0; i < window_size; i++)
win_fp[i] = HTS_get_fp(win_fn[i], "r");
HTS_Engine_load_parameter_from_fp(engine, pdf_fp, tree_fp, win_fp,
stream_index, msd_flag,
window_size, interpolation_size);
for (i = 0; i < interpolation_size; i++) {
fclose(pdf_fp[i]);
fclose(tree_fp[i]);
}
for (i = 0; i < window_size; i++)
fclose(win_fp[i]);
HTS_free(pdf_fp);
HTS_free(tree_fp);
HTS_free(win_fp);
}
示例4: HTS_Audio_open
/* HTS_Audio_open: open audio device */
static void HTS_Audio_open(HTS_Audio * audio, int sampling_rate, int max_buff_size)
{
MMRESULT error;
if (audio->sampling_rate == sampling_rate && audio->max_buff_size == max_buff_size)
return;
HTS_Audio_close(audio);
audio->sampling_rate = sampling_rate;
audio->max_buff_size = max_buff_size;
if (audio->max_buff_size <= 0)
return;
/* queue */
audio->which_buff = 1;
audio->now_buff_1 = FALSE;
audio->now_buff_2 = FALSE;
audio->buff = (short *) HTS_calloc(max_buff_size, sizeof(short));
/* format */
audio->waveformatex.wFormatTag = WAVE_FORMAT_PCM;
audio->waveformatex.nChannels = AUDIO_CHANNEL;
audio->waveformatex.nSamplesPerSec = sampling_rate;
audio->waveformatex.wBitsPerSample = sizeof(short) * 8;
audio->waveformatex.nBlockAlign = AUDIO_CHANNEL * audio->waveformatex.wBitsPerSample / 8;
audio->waveformatex.nAvgBytesPerSec = sampling_rate * audio->waveformatex.nBlockAlign;
/* open */
error = waveOutOpen(&audio->hwaveout, WAVE_MAPPER, &audio->waveformatex, (DWORD) HTS_Audio_callback_function, (DWORD) audio, CALLBACK_FUNCTION);
if (error != MMSYSERR_NOERROR)
HTS_error(0, "hts_engine: Failed to open your output audio device to play waveform.\n");
/* prepare */
audio->buff_1.lpData = (LPSTR) HTS_calloc(max_buff_size, sizeof(short));
audio->buff_1.dwBufferLength = max_buff_size * sizeof(short);
audio->buff_1.dwFlags = WHDR_BEGINLOOP | WHDR_ENDLOOP;
audio->buff_1.dwLoops = 1;
audio->buff_1.lpNext = 0;
audio->buff_1.reserved = 0;
error = waveOutPrepareHeader(audio->hwaveout, &(audio->buff_1), sizeof(WAVEHDR));
if (error != MMSYSERR_NOERROR)
HTS_error(0, "hts_engine: Cannot initialize audio datablocks to play waveform.\n");
audio->buff_2.lpData = (LPSTR) HTS_calloc(max_buff_size, sizeof(short));
audio->buff_2.dwBufferLength = max_buff_size * sizeof(short);
audio->buff_2.dwFlags = WHDR_BEGINLOOP | WHDR_ENDLOOP;
audio->buff_2.dwLoops = 1;
audio->buff_2.lpNext = 0;
audio->buff_2.reserved = 0;
error = waveOutPrepareHeader(audio->hwaveout, &(audio->buff_2), sizeof(WAVEHDR));
if (error != MMSYSERR_NOERROR)
HTS_error(0, "hts_engine: Cannot initialize audio datablocks to play waveform.\n");
}
示例5: HTS_Model_load_tree
/* HTS_Model_load_tree: load trees */
static void HTS_Model_load_tree(HTS_Model * model, FILE * fp)
{
char buff[HTS_MAXBUFLEN];
HTS_Question *question, *last_question;
HTS_Tree *tree, *last_tree;
int state;
/* check */
if (fp == NULL)
HTS_error(1, "HTS_Model_load_tree: File for trees is not specified.\n");
model->ntree = 0;
last_question = NULL;
last_tree = NULL;
while (!feof(fp)) {
HTS_get_pattern_token(fp, buff);
/* parse questions */
if (strcmp(buff, "QS") == 0) {
question = (HTS_Question *) HTS_calloc(1, sizeof(HTS_Question));
HTS_Question_load(question, fp);
if (model->question)
last_question->next = question;
else
model->question = question;
question->next = NULL;
last_question = question;
}
/* parse trees */
state = HTS_get_state_num(buff);
if (state != 0) {
tree = (HTS_Tree *) HTS_calloc(1, sizeof(HTS_Tree));
tree->next = NULL;
tree->root = NULL;
tree->head = NULL;
tree->state = state;
HTS_Tree_parse_pattern(tree, buff);
HTS_Tree_load(tree, fp, model->question);
if (model->tree)
last_tree->next = tree;
else
model->tree = tree;
tree->next = NULL;
last_tree = tree;
model->ntree++;
}
}
/* No Tree information in tree file */
if (model->tree == NULL)
HTS_error(1, "HTS_Model_load_tree: No trees are loaded.\n");
}
示例6: HTS_freqt
/* HTS_freqt: frequency transformation */
static void HTS_freqt(HTS_Vocoder * v, const double *c1, const int m1, double *c2, const int m2, const double a)
{
int i, j;
const double b = 1 - a * a;
double *g;
if (m2 > v->freqt_size) {
if (v->freqt_buff != NULL)
HTS_free(v->freqt_buff);
v->freqt_buff = (double *) HTS_calloc(m2 + m2 + 2, sizeof(double));
v->freqt_size = m2;
}
g = v->freqt_buff + v->freqt_size + 1;
for (i = 0; i < m2 + 1; i++)
g[i] = 0.0;
for (i = -m1; i <= 0; i++) {
if (0 <= m2)
g[0] = c1[-i] + a * (v->freqt_buff[0] = g[0]);
if (1 <= m2)
g[1] = b * v->freqt_buff[0] + a * (v->freqt_buff[1] = g[1]);
for (j = 2; j <= m2; j++)
g[j] = v->freqt_buff[j - 1] + a * ((v->freqt_buff[j] = g[j]) - g[j - 1]);
}
HTS_movem(g, c2, m2 + 1);
}
示例7: HTS_ModelSet_load_parameter
/* HTS_ModelSet_load_parameter: load model */
void HTS_ModelSet_load_parameter(HTS_ModelSet * ms, FILE ** pdf_fp,
FILE ** tree_fp, FILE ** win_fp,
int stream_index, HTS_Boolean msd_flag,
int window_size, int interpolation_size)
{
int i;
/* check */
if (pdf_fp == NULL)
HTS_error(1,
"HTS_ModelSet_load_parameter: File for pdfs is not specified.\n");
if (tree_fp == NULL)
HTS_error(1,
"HTS_ModelSet_load_parameter: File for wins is not specified.\n");
if (win_fp == NULL)
HTS_error(1,
"HTS_ModelSet_load_parameter: File for wins is not specified.\n");
/* initialize */
if (!ms->stream) {
ms->stream = (HTS_Stream *) HTS_calloc(ms->nstream, sizeof(HTS_Stream));
for (i = 0; i < ms->nstream; i++)
HTS_Stream_initialize(&ms->stream[i]);
}
/* load */
HTS_Stream_load_pdf_and_tree(&ms->stream[stream_index], pdf_fp, tree_fp,
msd_flag, interpolation_size);
HTS_Stream_load_dynamic_window(&ms->stream[stream_index], win_fp,
window_size);
}
示例8: HTS_Stream_load_pdf_and_tree
/* HTS_Stream_load_pdf_and_tree: load PDFs and trees */
static void HTS_Stream_load_pdf_and_tree(HTS_Stream * stream, FILE ** pdf_fp,
FILE ** tree_fp, HTS_Boolean msd_flag,
int interpolation_size)
{
int i;
/* initialize */
stream->msd_flag = msd_flag;
stream->interpolation_size = interpolation_size;
stream->model =
(HTS_Model *) HTS_calloc(interpolation_size, sizeof(HTS_Model));
/* load */
for (i = 0; i < stream->interpolation_size; i++) {
if (!pdf_fp[i])
HTS_error(1,
"HTS_Stream_load_pdf_and_tree: File for duration PDFs is not specified.\n");
if (!tree_fp[i])
HTS_error(1,
"HTS_Stream_load_pdf_and_tree: File for duration trees is not specified.\n");
HTS_Model_initialize(&stream->model[i]);
HTS_Model_load_tree(&stream->model[i], tree_fp[i]);
HTS_Model_load_pdf(&stream->model[i], pdf_fp[i], stream->model[i].ntree,
stream->msd_flag);
}
/* check */
for (i = 1; i < stream->interpolation_size; i++)
if (stream->model[0].vector_length != stream->model[i].vector_length)
HTS_error(1,
"HTS_Stream_load_pdf_and_tree: Vector sizes of state output vectors are different in between given modelsets.\n");
/* set */
stream->vector_length = stream->model[0].vector_length;
}
示例9: HTS_Tree_parse_pattern
/* HTS_Tree_parse_pattern: parse pattern specified for each tree */
static void HTS_Tree_parse_pattern(HTS_Tree * tree, char *string)
{
char *left, *right;
HTS_Pattern *pattern, *last_pattern;
tree->head = NULL;
last_pattern = NULL;
/* parse tree pattern */
if ((left = strchr(string, '{')) != NULL) { /* pattern is specified */
string = left + 1;
if (*string == '(')
++string;
right = strrchr(string, '}');
if (string < right && *(right - 1) == ')')
--right;
*right = ',';
/* parse pattern */
while ((left = strchr(string, ',')) != NULL) {
pattern = (HTS_Pattern *) HTS_calloc(1, sizeof(HTS_Pattern));
if (tree->head) {
last_pattern->next = pattern;
} else {
tree->head = pattern;
}
*left = '\0';
pattern->string = HTS_strdup(string);
string = left + 1;
pattern->next = NULL;
last_pattern = pattern;
}
}
}
示例10: HTS_b2en
/* HTS_b2en: calculate frame energy */
static double HTS_b2en(HTS_Vocoder * v, const double *b, const int m, const double a)
{
int i;
double en = 0.0;
double *cep;
double *ir;
if (v->spectrum2en_size < m) {
if (v->spectrum2en_buff != NULL)
HTS_free(v->spectrum2en_buff);
v->spectrum2en_buff = (double *) HTS_calloc((m + 1) + 2 * IRLENG, sizeof(double));
v->spectrum2en_size = m;
}
cep = v->spectrum2en_buff + m + 1;
ir = cep + IRLENG;
HTS_b2mc(b, v->spectrum2en_buff, m, a);
HTS_freqt(v, v->spectrum2en_buff, m, cep, IRLENG - 1, -a);
HTS_c2ir(cep, IRLENG, ir, IRLENG);
for (i = 0; i < IRLENG; i++)
en += ir[i] * ir[i];
return (en);
}
示例11: HTS_Question_load
/* HTS_Question_load: Load questions from file */
static void HTS_Question_load(HTS_Question * question, FILE * fp)
{
char buff[HTS_MAXBUFLEN];
HTS_Pattern *pattern, *last_pattern;
/* get question name */
HTS_get_pattern_token(fp, buff);
question->string = HTS_strdup(buff);
question->head = NULL;
/* get pattern list */
HTS_get_pattern_token(fp, buff);
last_pattern = NULL;
if (strcmp(buff, "{") == 0) {
while (1) {
HTS_get_pattern_token(fp, buff);
pattern = (HTS_Pattern *) HTS_calloc(1, sizeof(HTS_Pattern));
if (question->head)
last_pattern->next = pattern;
else /* first time */
question->head = pattern;
pattern->string = HTS_strdup(buff);
pattern->next = NULL;
HTS_get_pattern_token(fp, buff);
if (!strcmp(buff, "}"))
break;
last_pattern = pattern;
}
}
}
示例12: HTS_gc2gc
/* HTS_gc2gc: generalized cepstral transformation */
static void HTS_gc2gc(HTS_Vocoder * v, double *c1, const int m1, const double g1, double *c2, const int m2, const double g2)
{
int i, min, k, mk;
double ss1, ss2, cc;
if (m1 > v->gc2gc_size) {
if (v->gc2gc_buff != NULL)
HTS_free(v->gc2gc_buff);
v->gc2gc_buff = (double *) HTS_calloc(m1 + 1, sizeof(double));
v->gc2gc_size = m1;
}
HTS_movem(c1, v->gc2gc_buff, m1 + 1);
c2[0] = v->gc2gc_buff[0];
for (i = 1; i <= m2; i++) {
ss1 = ss2 = 0.0;
min = m1 < i ? m1 : i - 1;
for (k = 1; k <= min; k++) {
mk = i - k;
cc = v->gc2gc_buff[k] * c2[mk];
ss2 += k * cc;
ss1 += mk * cc;
}
if (i <= m1)
c2[i] = v->gc2gc_buff[i] + (g2 * ss2 - g1 * ss1) / i;
else
c2[i] = (g2 * ss2 - g1 * ss1) / i;
}
}
示例13: HTS_lsp2en
/* HTS_lsp2en: calculate frame energy */
static double HTS_lsp2en(HTS_Vocoder * v, double *lsp, size_t m, double alpha)
{
size_t i;
double en = 0.0;
double *buff;
if (v->spectrum2en_size < m) {
if (v->spectrum2en_buff != NULL)
HTS_free(v->spectrum2en_buff);
v->spectrum2en_buff = (double *) HTS_calloc(m + 1 + IRLENG, sizeof(double));
v->spectrum2en_size = m;
}
buff = v->spectrum2en_buff + m + 1;
/* lsp2lpc */
HTS_lsp2lpc(v, lsp + 1, v->spectrum2en_buff, m);
if (v->use_log_gain)
v->spectrum2en_buff[0] = exp(lsp[0]);
else
v->spectrum2en_buff[0] = lsp[0];
/* mgc2mgc */
if (NORMFLG1)
HTS_ignorm(v->spectrum2en_buff, v->spectrum2en_buff, m, v->gamma);
else if (MULGFLG1)
v->spectrum2en_buff[0] = (1.0 - v->spectrum2en_buff[0]) * ((double) v->stage);
if (MULGFLG1)
for (i = 1; i <= m; i++)
v->spectrum2en_buff[i] *= -((double) v->stage);
HTS_mgc2mgc(v, v->spectrum2en_buff, m, alpha, v->gamma, buff, IRLENG - 1, 0.0, 1);
for (i = 0; i < IRLENG; i++)
en += buff[i] * buff[i];
return en;
}
示例14: HTS_Vocoder_postfilter_mcp
/* HTS_Vocoder_postfilter_mcp: postfilter for MCP */
void HTS_Vocoder_postfilter_mcp(HTS_Vocoder *v, double *mcp, const int m,
double alpha, double beta)
{
double e1, e2;
int k;
if (beta > 0.0 && m > 1) {
if (v->postfilter_size < m) {
if (v->postfilter_buff != NULL)
HTS_free(v->postfilter_buff);
v->postfilter_buff = (double *) HTS_calloc(m + 1, sizeof(double));
v->postfilter_size = m;
}
HTS_mc2b(mcp, v->postfilter_buff, m, alpha);
e1 = HTS_b2en(v, v->postfilter_buff, m, alpha);
v->postfilter_buff[1] -= beta * alpha * mcp[2];
for (k = 2; k <= m; k++)
v->postfilter_buff[k] *= (1.0 + beta);
e2 = HTS_b2en(v, v->postfilter_buff, m, alpha);
v->postfilter_buff[0] += log(e1 / e2) / 2;
HTS_b2mc(v->postfilter_buff, mcp, m, alpha);
}
}
示例15: HTS_Stream_load_pdf
/* HTS_Stream_load_pdf: load pdf */
static HTS_Boolean HTS_Stream_load_pdf(HTS_Stream * stream, HTS_File ** fp, int ntree, int interpolation_size)
{
int i;
HTS_Boolean result = TRUE;
/* initialize */
stream->interpolation_size = interpolation_size;
stream->model = (HTS_Model *) HTS_calloc(interpolation_size, sizeof(HTS_Model));
/* load pdfs */
for (i = 0; i < stream->interpolation_size; i++) {
HTS_Model_initialize(&stream->model[i]);
if (HTS_Model_load_pdf(&stream->model[i], fp[i], ntree, &stream->msd_flag) == FALSE)
result = FALSE;
}
if (result == FALSE) {
HTS_Stream_clear(stream);
return FALSE;
}
/* check */
for (i = 1; i < stream->interpolation_size; i++) {
if (stream->model[0].vector_length != stream->model[1].vector_length) {
HTS_error(1, "HTS_Stream_load_pdf: # of states are different in between given modelsets.\n");
HTS_Stream_clear(stream);
return FALSE;
}
}
/* set */
stream->vector_length = stream->model[0].vector_length;
return TRUE;
}