Exemplo n.º 1
0
int audio_close_wince(cst_audiodev *ad)
{
    au_wince_pdata *pd = ad->platform_data;
    MMRESULT err;

    if (ad)
    {
        /* Okay, I actually think this isn't a race, because
           bcnt is only ever decremented asynchronously, and
           the asynchronous callback can't be interrupted.  So
           the only issue is whether it hits zero between the
           time we test it and the time we start waiting, and
           in this case, the event will get set anyway. */
        if (pd->bcnt > 0)
            WaitForSingleObject(pd->bevt, INFINITE);
        pd->in_reset = 1;
        err = waveOutReset(pd->wo);
        if (err != MMSYSERR_NOERROR)
        {
            cst_errmsg("Failed to reset output device: %x\n", err);
            cst_error();
        }
        pd->in_reset = 0;
        free_queue_empty(ad);
        err = waveOutClose(pd->wo);
        if (err != MMSYSERR_NOERROR)
        {
            cst_errmsg("Failed to close output device: %x\n", err);
            cst_error();
        }
        cst_free(pd);
        cst_free(ad);
    }
    return 0;
}
cst_filemap *cst_read_whole_file(const char *path)
{
    cst_filemap *fmap;
    cst_file fh;

    if ((fh = cst_fopen(path, CST_OPEN_READ)) < 0) {
	cst_errmsg("cst_read_whole_file: Failed to open file\n");
	return NULL;
    }

    fmap = cst_alloc(cst_filemap, 1);
    fmap->fh = fh;
    fmap->mapsize = cst_filesize(fmap->fh);
    fmap->mem = cst_alloc(char, fmap->mapsize);
    if (cst_fread(fmap->fh, fmap->mem, 1, fmap->mapsize) < fmap->mapsize)
    {
	cst_errmsg("cst_read_whole_file: read() failed\n");
	cst_fclose(fmap->fh);
	cst_free(fmap->mem);
	cst_free(fmap);
	return NULL;
    }

    return fmap;
}
Exemplo n.º 3
0
cst_val *en_exp_real(const char *numstring)
{
    char *aaa, *p;
    cst_val *r;

    if (numstring && (numstring[0] == '-'))
	r = cons_val(string_val("minus"),
		     en_exp_real(&numstring[1]));
    else if (numstring && (numstring[0] == '+'))
	r = cons_val(string_val("plus"),
		     en_exp_real(&numstring[1]));
    else if (((p=strchr(numstring,'e')) != 0) ||
	     ((p=strchr(numstring,'E')) != 0))
    {
	aaa = cst_strdup(numstring);
	aaa[cst_strlen(numstring)-cst_strlen(p)] = '\0';
	r = val_append(en_exp_real(aaa),
		       cons_val(string_val("e"),
				en_exp_real(p+1)));
	cst_free(aaa);
    }
    else if ((p=strchr(numstring,'.')) != 0)
    {
	aaa = cst_strdup(numstring);
	aaa[cst_strlen(numstring)-cst_strlen(p)] = '\0';
	r = val_append(en_exp_number(aaa),
		       cons_val(string_val("point"),
				en_exp_digits(p+1)));
	cst_free(aaa);
    }
    else
	r = en_exp_number(numstring);  /* I don't think you can get here */

    return r;
}
Exemplo n.º 4
0
void delete_tokenstream(cst_tokenstream *ts)
{
    cst_free(ts->whitespace);
    cst_free(ts->token);
    if (ts->prepunctuation) cst_free(ts->prepunctuation);
    if (ts->postpunctuation) cst_free(ts->postpunctuation);
    cst_free(ts);
}
Exemplo n.º 5
0
cst_audiodev *audio_open_wince(int sps, int channels, int fmt)
{
    cst_audiodev *ad;
    au_wince_pdata *pd;
    HWAVEOUT wo;
    WAVEFORMATEX wfx;
    MMRESULT err;

    ad = cst_alloc(cst_audiodev,1);
    ad->sps = ad->real_sps = sps;
    ad->channels = ad->real_channels = channels;
    ad->fmt = ad->real_fmt = fmt;

    memset(&wfx,0,sizeof(wfx));
    wfx.nChannels = channels;
    wfx.nSamplesPerSec = sps;

    switch (fmt)
    {
    case CST_AUDIO_LINEAR16:
        wfx.wFormatTag = WAVE_FORMAT_PCM;
        wfx.wBitsPerSample = 16;
        break;
    case CST_AUDIO_LINEAR8:
        wfx.wFormatTag = WAVE_FORMAT_PCM;
        wfx.wBitsPerSample = 8;
        break;
    default:
        cst_errmsg("audio_open_wince: unsupported format %d\n", fmt);
        cst_free(ad);
        cst_error();
    }
    wfx.nBlockAlign = wfx.nChannels*wfx.wBitsPerSample/8;
    wfx.nAvgBytesPerSec = wfx.nSamplesPerSec*wfx.nBlockAlign;
    err = waveOutOpen(
        &wo,
        WAVE_MAPPER,
        &wfx,
        (DWORD_PTR)sndbuf_done,
        (DWORD_PTR)ad,
        CALLBACK_FUNCTION
        );

    if (err != MMSYSERR_NOERROR)
    {
        cst_errmsg("Failed to open output device: %x\n", err);
        cst_free(ad);
        cst_error();
    }

    pd = cst_alloc(au_wince_pdata,1);
    pd->wo = wo;
    pd->bevt = CreateEvent(NULL,FALSE,FALSE,NULL);
    pd->wevt = CreateEvent(NULL,FALSE,FALSE,NULL);
    pd->bcnt = 0;
    ad->platform_data = pd;
    return ad;
}
Exemplo n.º 6
0
void delete_lexicon(cst_lexicon *lex)
{   /* But I doubt if this will ever be called, lexicons are mapped */
    /* This probably isn't complete */
    if (lex)
    {
        cst_free(lex->data);
        cst_free(lex);
    }
}
int cst_free_whole_file(cst_filemap *fmap)
{
    if (cst_fclose(fmap->fh) < 0) {
	cst_errmsg("cst_free_whole_file: close() failed\n");
	return -1;
    }
    cst_free(fmap->mem);
    cst_free(fmap);
    return 0;
}
Exemplo n.º 8
0
static void finish_header(HWAVEOUT drvr, WAVEHDR *hdr)
{
    if (waveOutUnprepareHeader(drvr,hdr,sizeof(*hdr))
        != MMSYSERR_NOERROR)
    {
        cst_errmsg("Failed to unprepare header %p\n", hdr);
        cst_error();
    }
    cst_free(hdr->lpData);
    cst_free(hdr);
}
cst_wave *lpc_resynth(cst_lpcres *lpcres)
{
    cst_wave *w;
    int i,j,r,o,k;
    int ci,cr;
    float *outbuf, *lpccoefs;
    int pm_size_samps;

    /* Get a new wave to build the signal into */
    w = new_wave();
    cst_wave_resize(w,lpcres->num_samples,1);
    w->sample_rate = lpcres->sample_rate;
    /* outbuf is a circular buffer with past relevant samples in it */
    outbuf = cst_alloc(float,1+lpcres->num_channels);
    /* unpacked lpc coefficients */
    lpccoefs = cst_alloc(float,lpcres->num_channels);

    for (r=0,o=lpcres->num_channels,i=0; i < lpcres->num_frames; i++)
    {
	pm_size_samps = lpcres->sizes[i];

	/* Unpack the LPC coefficients */
	for (k=0; k<lpcres->num_channels; k++)
	{
	    lpccoefs[k] = (float)((((double)lpcres->frames[i][k])/65535.0)*
			   lpcres->lpc_range) + lpcres->lpc_min;
	}
	/* Note we don't zero the lead in from the previous part */
	/* seems like you should but it makes it worse if you do */
/*	memset(outbuf,0,sizeof(float)*(1+lpcres->num_channels)); */

	/* resynthesis the signal */
	for (j=0; j < pm_size_samps; j++,r++)
	{
            outbuf[o] = (float)cst_ulaw_to_short(lpcres->residual[r]);
	    cr = (o == 0 ? lpcres->num_channels : o-1);
	    for (ci=0; ci < lpcres->num_channels; ci++)
	    {
		outbuf[o] += lpccoefs[ci] * outbuf[cr];
		cr = (cr == 0 ? lpcres->num_channels : cr-1);
	    }
	    w->samples[r] = (short)(outbuf[o]);
	    o = (o == lpcres->num_channels ? 0 : o+1);
	}
    }

    cst_free(outbuf);
    cst_free(lpccoefs);

    return w;

}
cst_wave *lpc_resynth_sfp(cst_lpcres *lpcres)
{
    /* The fixed point spike excited, without floats */
    cst_wave *w;
    int i,j,r,o,k;
    int ci,cr;
    int *outbuf, *lpccoefs;
    int pm_size_samps, ilpc_min, ilpc_range;
    //int pp = 0;

    /* Get a new wave to build the signal into */
    w = new_wave();
    cst_wave_resize(w,lpcres->num_samples,1);
    w->sample_rate = lpcres->sample_rate;
    /* outbuf is a circular buffer with past relevant samples in it */
    outbuf = cst_alloc(int,1+lpcres->num_channels);
    /* unpacked lpc coefficients */
    lpccoefs = cst_alloc(int,lpcres->num_channels);
    ilpc_min = (int)(lpcres->lpc_min*32768.0);
    /* assume range is never > abs(16) */
    ilpc_range = (int)(lpcres->lpc_range*2048.0);

    for (r=0,o=lpcres->num_channels,i=0; i < lpcres->num_frames; i++)
    {
	pm_size_samps = lpcres->sizes[i];

	/* Unpack the LPC coefficients */
	for (k=0; k<lpcres->num_channels; k++)
	    lpccoefs[k]=((lpcres->frames[i][k]/2*ilpc_range)/2048+ilpc_min)/2;

	/* resynthesis the signal */
	for (j=0; j < pm_size_samps; j++,r++)
	{
	    outbuf[o] = (int)cst_ulaw_to_short(lpcres->residual[r]);
	    cr = (o == 0 ? lpcres->num_channels : o-1);
	    for (ci=0; ci < lpcres->num_channels; ci++)
	    {
		outbuf[o] += (lpccoefs[ci]*outbuf[cr])/16384;
		cr = (cr == 0 ? lpcres->num_channels : cr-1);
	    }
	    w->samples[r] = (short)outbuf[o];
	    //pp = outbuf[o];
	    o = (o == lpcres->num_channels ? 0 : o+1);
	}
    }

    cst_free(outbuf);
    cst_free(lpccoefs);

    return w;

}
Exemplo n.º 11
0
void xdvfree(DVECTOR x)
{
    if (x != NULL) {
	if (x->data != NULL) {
	    cst_free(x->data);
	}
	if (x->imag != NULL) {
	    cst_free(x->imag);
	}
	cst_free(x);
    }

    return;
}
Exemplo n.º 12
0
/* HTS_b2en: calculate frame energy */
static double HTS_b2en(HTS_Vocoder * v, const double *b, const size_t m, const double a)
{
   size_t i;
   double en = 0.0;
   double *cep;
   double *ir;

   if (v->spectrum2en_size < m) {
      if (v->spectrum2en_buff != NULL)
         cst_free(v->spectrum2en_buff);
      v->spectrum2en_buff = cst_alloc(double,((m + 1) + 2 * IRLENG));
      v->spectrum2en_size = m;
   }
   cep = v->spectrum2en_buff + m + 1;
   ir = cep + IRLENG;

   b2mc(b, v->spectrum2en_buff, m, a);
   freqt(v->spectrum2en_buff, m, cep, IRLENG, -a);
   c2ir(cep, IRLENG, ir);

   for (i = 0; i < IRLENG; i++)
      en += ir[i] * ir[i];

   return (en);
}
Exemplo n.º 13
0
cst_filemap *cst_mmap_file(const char *path)
{
	HANDLE ffm;
	cst_filemap *fmap = NULL;

	/* By default, CreateFile uses wide-char strings; this doesn't do the expected 
	   thing when passed non-wide strings
	   
	   We're explicitly using the non-wide version of CreateFile to
	   sidestep this issue.  If you're having problems with unicode
	   pathnames, you'll need to change this to call CreateFileW (and
	   then ensure you're always passing a wide-char string). */

	ffm = CreateFileA(path,GENERIC_READ,FILE_SHARE_READ,NULL,
			 OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
	if (ffm == INVALID_HANDLE_VALUE) { 
		return NULL;
	} else {
		fmap = cst_alloc(cst_filemap,1);
		fmap->h = CreateFileMapping(ffm,NULL,PAGE_READONLY,0,0,NULL);
		fmap->mapsize = GetFileSize(fmap->h, NULL);
		fmap->mem = MapViewOfFile(fmap->h,FILE_MAP_READ,0,0,0);
		if (fmap->h == NULL || fmap->mem == NULL) {
			CloseHandle(ffm);
			cst_free(fmap);
			return NULL;
		}
	}

	return fmap;
}
Exemplo n.º 14
0
static void parse_description(const char *description, cst_features *f)
{
    /* parse the description into something more usable */
    cst_tokenstream *ts;
    const char *arg;
    char *op;
    const char *xop;

    ts = ts_open_string(description,
			" \t\r\n", /* whitespace */
			"{}[]|",   /* singlecharsymbols */
			"",        /* prepunctuation */
			"");       /* postpunctuation */
    while (!ts_eof(ts))
    {
	op = cst_strdup(ts_get(ts));
	if ((op[0] == '-') && (cst_strchr(ts->whitespace,'\n') != 0))
	{   /* got an option */
            xop = feat_own_string(f,op);
	    arg = ts_get(ts);
	    if (arg[0] == '<')
		feat_set_string(f,xop,arg);
	    else
		feat_set_string(f,xop,"<binary>");
        }
        cst_free(op);
    }

    ts_close(ts);

}
Exemplo n.º 15
0
bard_window *bard_make_help_window(bard_reader *br)
{
    bard_window *hw;
    int indent = 10;
    char *bhs;

    hw = bard_window_new("help",
                         br->display->screen_width-(2*indent),
                         br->display->screen_height-(2*indent),
                         br->display->screen->format);
    hw->x_offset = indent;
    hw->y_offset = indent;
    hw->font_name = 
        cst_strdup(get_param_string(br->config,"-font",BARD_DEFAULT_FONT));
    hw->font_size =
        get_param_int(br->config,"-help_font_size",
                      get_param_int(br->config,"-font_size",
                                    BARD_DEFAULT_FONT_SIZE));
    /* We assume we can open this font, as if we couldn't when initializing */
    /* the display window, we'd have failed by now */
    hw->font = bard_window_open_font(hw->font_name,hw->font_size);

    hw->background_color = 
        bard_color_get(br->colors,
         get_param_string(br->config,"-help_background_color","cornsilk"));
    hw->foreground_color = 
        bard_color_get(br->colors,
         get_param_string(br->config,"-help_foreground_color","steelblue"));
    hw->highlight_color = 
        bard_color_get(br->colors,
         get_param_string(br->config,"-help_highlight_color","blue"));

    hw->tm=10;
    hw->bm=10;
    hw->tlm=10;
    hw->trm=10;

    bhs = cst_alloc(char,cst_strlen(bard_help_string)+
                    cst_strlen(BARD_PROJECT_VERSION)+
                    cst_strlen(BARD_PROJECT_STATE)+
                    cst_strlen(BARD_PROJECT_DATE)+1);
    cst_sprintf(bhs,bard_help_string,BARD_PROJECT_VERSION,
                BARD_PROJECT_STATE,
                BARD_PROJECT_DATE);

    hw->ts = ts_open_string(bhs,
                     cst_ts_default_whitespacesymbols,
                     "",
                     cst_ts_default_prepunctuationsymbols,
                     cst_ts_default_postpunctuationsymbols);
    hw->ts_mode = "literal";
    cst_free(bhs);

    hw->update = bard_window_help_update;

    /* Put something on the screen */
    bard_window_display_from_pos(hw,0);

    return hw;
}
Exemplo n.º 16
0
int cst_munmap_file(cst_filemap *fmap)
{
	UnmapViewOfFile(fmap->mem);
	CloseHandle(fmap->h);
	cst_free(fmap);
	return 0;
}
Exemplo n.º 17
0
static void ef_set(cst_features *f,const char *fv,const char *type)
{
    /* set feature from fv (F=V), guesses type if not explicit type given */
    const char *val;
    char *feat;

    if ((val = strchr(fv,'=')) == 0)
    {
	fprintf(stderr,
		"flite: can't find '=' in featval \"%s\", ignoring it\n",
		fv);
    }
    else
    {
	feat = cst_strdup(fv);
	feat[cst_strlen(fv)-cst_strlen(val)] = '\0';
	val = val+1;
	if ((type && cst_streq("int",type)) ||
	    ((type == 0) && (cst_regex_match(cst_rx_int,val))))
	    feat_set_int(f,feat,atoi(val));
	else if ((type && cst_streq("float",type)) ||
		 ((type == 0) && (cst_regex_match(cst_rx_double,val))))
	    feat_set_float(f,feat,atof(val));
	else
	    feat_set_string(f,feat,val);
        cst_free(feat);
    }
}
Exemplo n.º 18
0
int mimic_audio_write(cst_audiodev *ad, void *buff, int num_bytes)
{
    void *abuf = buff, *nbuf = NULL;
    int rv, i, real_num_bytes = num_bytes;

    if (ad->rateconv)
    {
        short *in, *out;
        int insize, outsize, n;

        insize = real_num_bytes / 2;
        in = (short *) buff;

        outsize = ad->rateconv->outsize;
        nbuf = out = cst_alloc(short, outsize);
        real_num_bytes = outsize * 2;

        while ((n = cst_rateconv_in(ad->rateconv, in, insize)) > 0)
        {
            in += n;
            insize -= n;
            while ((n = cst_rateconv_out(ad->rateconv, out, outsize)) > 0)
            {
                out += n;
                outsize -= n;
            }
        }
        real_num_bytes -= outsize * 2;
        if (abuf != buff)
            cst_free(abuf);
        abuf = nbuf;
    }
Exemplo n.º 19
0
int in_lex(const cst_lexicon *l, const char *word, const char *pos,
           const cst_features *feats)
{
    /* return TRUE is its in the lexicon */
    int r = FALSE, i;
    char *wp;

    wp = cst_alloc(char,cst_strlen(word)+2);
    cst_sprintf(wp,"%c%s",(pos ? pos[0] : '0'),word);

    for (i=0; l->addenda && l->addenda[i]; i++)
    {
        if (((wp[0] == '0') || (wp[0] == l->addenda[i][0][0])) &&
                (cst_streq(wp+1,l->addenda[i][0]+1)))
        {
            r = TRUE;
            break;
        }
    }

    if (!r && (lex_lookup_bsearch(l,wp) >= 0))
        r = TRUE;

    cst_free(wp);
    return r;
}
Exemplo n.º 20
0
cst_val *lts_apply_val(const cst_val *wlist,const char *feats,const cst_lts_rules *r)
{
    /* for symbol to symbol mapping */
    const cst_val *v;
    cst_val *p;
    char *word;
    int i,j;

    word = cst_alloc(char,val_length(wlist)+1);

    for (v=wlist,i=0; v; v=val_cdr(v),i++)
    {
	for (j=0; r->letter_table[j]; j++)
	    if (cst_streq(val_string(val_car(v)),r->letter_table[j]))
	    {
		word[i] = j;
		break;
	    }
        if (!r->letter_table[j])
        {
#if 0
            printf("awb_debug unknown letter >%s<\n",val_string(val_car(v)));
#endif
            i--;  /* can't find this letter so skip it */
        }
    }

    p = lts_apply(word,feats,r);
    cst_free(word);

    return p;
}
Exemplo n.º 21
0
int flowm_say_text(TCHAR *text)
{
    char *s;
    int ns;
    cst_voice *v;

    if (previous_wave)
    {
        delete_wave(previous_wave);
        previous_wave = NULL;
    }

    s = cst_wstr2cstr(text);               /* text to synthesize */
    v = VoxDefs[flowm_selected_voice].v;   /* voice to synthesize with */

    feat_remove(v->features,"print_info_relation");
    if (flowm_selected_relation == 1)
        feat_set_string(v->features, "print_info_relation", "Word");
    if (flowm_selected_relation == 2)
        feat_set_string(v->features, "print_info_relation", "Segment");

    /* Do the synthesis */
    previous_wave = flite_text_to_wave(s,v);

    ns = cst_wave_num_samples(previous_wave);

    cst_free(s);
    audio_flush(fl_ad);
    audio_close(fl_ad); 
    fl_ad = NULL;

    return ns;
}
Exemplo n.º 22
0
cst_val *en_exp_letters(const char *lets)
{
    /* returns these as list of single char symbols */
    char *aaa;
    cst_val *r;
    int i;

    aaa = cst_alloc(char,2);
    aaa[1] = '\0';
    for (r=0,i=0; lets[i] != '\0'; i++)
    {
	aaa[0] = lets[i];
	if (isupper((int)aaa[0])) 
	    aaa[0] = tolower((int)aaa[0]);
	if (strchr("0123456789",aaa[0]))
	    r = cons_val(string_val(digit2num[aaa[0]-'0']),r);
	else if (cst_streq(aaa,"a"))
	    r = cons_val(string_val("_a"),r);
	else
	    r = cons_val(string_val(aaa),r);
    }
    cst_free(aaa);

    return val_reverse(r);
}
Exemplo n.º 23
0
/* HTS_Engine_clear: free engine */
void HTS_Engine_clear(HTS_Engine * engine)
{
   if (engine->condition.msd_threshold != NULL)
      cst_free(engine->condition.msd_threshold);

   HTS_ModelSet_clear(&engine->ms);
   HTS_Engine_initialize(engine);
}
int cst_free_part_file(cst_filemap *fmap)
{
    if (cst_fclose(fmap->fh) < 0) {
	cst_errmsg("cst_munmap_file: cst_fclose() failed\n");
	return -1;
    }
    cst_free(fmap);
    return 0;
}
Exemplo n.º 25
0
void dvialloc(DVECTOR x)
{
    if (x->imag != NULL) {
	cst_free(x->imag);
    }
    x->imag = cst_alloc(double,x->length);

    return;
}
Exemplo n.º 26
0
static void extend_buffer(char **buffer,int *buffer_max,int at_least)
{
    int new_max;

    new_max = (*buffer_max)+at_least;
    cst_free(*buffer);
    *buffer = cst_alloc(char,new_max);
    *buffer_max = new_max;
}			  
Exemplo n.º 27
0
int cst_free_whole_file(cst_filemap *fmap)
{
    if (cst_fclose(fmap->fh) < 0) {
	cst_errmsg("cst_read_whole_file: cst_fclose() failed\n");
	return -1;
    }
    VirtualFree(fmap->mem, fmap->mapsize, MEM_DECOMMIT);
    cst_free(fmap);
    return 0;
}
Exemplo n.º 28
0
void delete_val(cst_val *v)
{
    if (v)
    {
        if (cst_val_consp(v))
        {
            delete_val(CST_VAL_CAR(v));
            delete_val(CST_VAL_CDR(v));
            cst_free(v);
        }
        else if (val_dec_refcount(v) == 0)
        {
            if (CST_VAL_TYPE(v) == CST_VAL_TYPE_STRING)
                cst_free(CST_VAL_VOID(v));
            else if (CST_VAL_TYPE(v) >= CST_VAL_TYPE_FIRST_FREE)
                (cst_val_defs[CST_VAL_TYPE(v)/2].delete_function)(CST_VAL_VOID(v));
            cst_free(v);
        }
    }
}
Exemplo n.º 29
0
void xdmfree(DMATRIX matrix)
{
    int i;

    if (matrix != NULL) {
	if (matrix->data != NULL) {
            for (i=0; i<matrix->row; i++)
                cst_free(matrix->data[i]);
            cst_free(matrix->data);
	}
	if (matrix->imag != NULL) {
            for (i=0; i<matrix->row; i++)
                cst_free(matrix->imag[i]);
            cst_free(matrix->imag);
	}
	cst_free(matrix);
    }

    return;
}
Exemplo n.º 30
0
int audio_close_sun(cst_audiodev *ad)
{
    int rv;

    if (ad == NULL)
        return 0;

    rv = close((int) ad->platform_data);
    cst_free(ad);
    return rv;
}