Пример #1
0
int cst_socket_server(const char *name, int port,
                      int (process_client) (int name, int fd))
{
    struct sockaddr_in serv_addr;
    int fd, fd1;
    int client_name = 0;
    int one = 1;

    fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

    if (fd < 0)
    {
        cst_errmsg("can't open socket %d\n", port);
        return -1;
    }

    if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &one, sizeof(int)) <
        0)
    {
        cst_errmsg("socket SO_REUSERADDR failed\n");
        return -1;
    }

    memset(&serv_addr, 0, sizeof(serv_addr));
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_port = htons(port);
    serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);

    if (bind(fd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) != 0)
    {
        cst_errmsg("socket: bind failed\n");
        return -1;
    }

    if (listen(fd, 5) != 0)
    {
        cst_errmsg("socket: listen failed\n");
        return -1;
    }

    if (name)
        printf("server (%s) started on port %d\n", name, port);

    while (1)                   /* never exits except by signals */
    {
        if ((fd1 = accept(fd, 0, 0)) < 0)
        {
            cst_errmsg("socket: accept failed\n");
            return -1;
        }

        client_name++;

        (process_client) (client_name, fd1);

        close(fd1);
    }

    return 0;
}
Пример #2
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;
}
Пример #3
0
int audio_write_wince(cst_audiodev *ad, void *samples, int num_bytes)
{
    au_wince_pdata *pd = ad->platform_data;
    WAVEHDR *hdr;
    MMRESULT err;

    if (num_bytes == 0)
        return 0;

    hdr = cst_alloc(WAVEHDR,1);
    hdr->lpData = cst_alloc(char,num_bytes);
    memcpy(hdr->lpData,samples,num_bytes);
    hdr->dwBufferLength = num_bytes;

    err = waveOutPrepareHeader(pd->wo, hdr, sizeof(*hdr));
    if (err != MMSYSERR_NOERROR)
    {
        cst_errmsg("Failed to prepare header %p: %x\n", hdr, err);
        cst_error();
    }

    if (InterlockedIncrement(&pd->bcnt) == 8)
        WaitForSingleObject(pd->wevt, INFINITE);
    err = waveOutWrite(pd->wo, hdr, sizeof(*hdr));
    if (err != MMSYSERR_NOERROR)
    {
        cst_errmsg("Failed to write header %p: %x\n", hdr, err);
        cst_error();
    }
    return num_bytes;
}
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;
}
Пример #5
0
static void parse_usage(const char *progname,
			const char *s1, const char *s2,
			const char *description)
{
    cst_errmsg("%s: %s %s\n", progname,s1,s2);
    cst_errmsg("%s\n",description);
    exit(0);
}
Пример #6
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;
}
Пример #7
0
int relation_load(cst_relation *r, const char *filename)
{
    cst_tokenstream *fd;
    cst_item *item;
    const char *token=0;

    if ((fd = ts_open(filename,NULL,";","","")) == 0)
    {
	cst_errmsg("relation_load: can't open file \"%s\" for reading\n",
		   filename);
	return CST_ERROR_FORMAT;
    }

    for ( ; !ts_eof(fd); )
    {
	token = ts_get(fd);
	if (cst_streq("#",token))
	    break;
    }
#import "OpenEarsStaticAnalysisToggle.h"
#ifdef STATICANALYZEDEPENDENCIES
#define __clang_analyzer__ 1
#endif
#if !defined(__clang_analyzer__) || defined(STATICANALYZEDEPENDENCIES)
#undef __clang_analyzer__
    if (!cst_streq("#",token))
#endif        
    {
	cst_errmsg("relation_load: no end of header marker in \"%s\"\n",
		   filename);
	ts_close(fd);
	return CST_ERROR_FORMAT;
    }

    while (!ts_eof(fd))
    {
	token = ts_get(fd);
	if (cst_streq(token,""))
	    continue;
	item = relation_append(r,NULL);
	item_set_float(item,"end",(float)cst_atof(token));
#import "OpenEarsStaticAnalysisToggle.h"
#ifdef STATICANALYZEDEPENDENCIES
#define __clang_analyzer__ 1
#endif
#if !defined(__clang_analyzer__) || defined(STATICANALYZEDEPENDENCIES)
#undef __clang_analyzer__
        
	token = ts_get(fd);
#endif        
	token = ts_get(fd);
	item_set_string(item,"name",token);
    }

    ts_close(fd);
    return CST_OK_FORMAT;
}
Пример #8
0
size_t cst_regsub(const cst_regstate *state, const char *in, char *out, size_t max)
{
	const char *src;
	char *dst;
	int c, no, len;
	size_t count;

	if (state == NULL || in == NULL) {
		cst_errmsg("NULL parm to regsub\n");
		cst_error();
	}

	src = in;
	dst = out;
	count = 0;
	while ((c = *src++) != '\0') {
		if (out && dst + 1 > out + max - 1)
			break;
		if (c == '&')
			no = 0;
		else if (c == '\\' && '0' <= *src && *src <= '9')
			no = *src++ - '0';
		else
			no = -1;

 		if (no < 0) {	/* Ordinary character. */
 			if (c == '\\' && (*src == '\\' || *src == '&'))
 				c = *src++;
			if (out)
				*dst++ = c;
			count++;
 		} else if (state->startp[no] != NULL && state->endp[no] != NULL) {
			len = state->endp[no] - state->startp[no];
			if (out) {
				if (dst + len > out + max - 1)
					len = (out + max - 1) - dst;
				strncpy(dst, state->startp[no], len);
				dst += len;
				/* strncpy hit NUL. */
				if (len != 0 && *(dst-1) == '\0') {
					cst_errmsg("damaged match string");
					cst_error();
				}
			}
			count += len;
		}
	}
	if (out && dst - out + 1 < max)
		*dst++ = '\0';

	return count;
}
Пример #9
0
/* HTS_Engine_load: load HTS voices */
HTS_Boolean HTS_Engine_load(HTS_Engine * engine, char **voices)
{
   size_t i;
   size_t nstream;
   const char *option, *find;
   float tempfloat;

   /* reset engine */
   HTS_Engine_clear(engine);

   /* load voices */
   if (HTS_ModelSet_load(&engine->ms, voices) != TRUE) {
      HTS_Engine_clear(engine);
      return FALSE;
   }
   nstream = HTS_ModelSet_get_nstream(&engine->ms);

   /* global */
   engine->condition.sampling_frequency = HTS_ModelSet_get_sampling_frequency(&engine->ms);
   engine->condition.fperiod = HTS_ModelSet_get_fperiod(&engine->ms);
   engine->condition.msd_threshold = cst_alloc(double,nstream);
   for (i = 0; i < nstream; i++)
      engine->condition.msd_threshold[i] = 0.5;

   /* spectrum */
   option = HTS_ModelSet_get_option(&engine->ms, 0);
   find = strstr(option, "GAMMA=");
   if (find != NULL) {
      cst_errmsg("Non-Zero GAMMA not supported\n");
      HTS_Engine_clear(engine);
      return FALSE;
   }
   find = strstr(option, "LN_GAIN=1");
   if (find != NULL) {
      cst_errmsg("Non-Zero LN_GAIN not supported\n");
      HTS_Engine_clear(engine);
      return FALSE;
   }
   find = strstr(option, "ALPHA=");
   if (find != NULL) {
      if (bell_validate_atof(&find[strlen("ALPHA=")],&tempfloat)) {
         engine->condition.alpha = tempfloat;
      } else {
         cst_errmsg("Voice file option 'ALPHA' is not float, setting to default 0.42\n");
         engine->condition.alpha = 0.42;
      }
   }

   return TRUE;
}
Пример #10
0
int relation_load(cst_relation *r, const char *filename)
{
    cst_tokenstream *fd;
    cst_item *item;
    const char *token=0;

    if ((fd = ts_open(filename,NULL,";","","")) == 0)
    {
	cst_errmsg("relation_load: can't open file \"%s\" for reading\n",
		   filename);
	return CST_ERROR_FORMAT;
    }

    for ( ; !ts_eof(fd); )
    {
	token = ts_get(fd);
	if (cst_streq("#",token))
	    break;
    }
 

    if (!cst_streq("#",token))
        
    {
	cst_errmsg("relation_load: no end of header marker in \"%s\"\n",
		   filename);
	ts_close(fd);
	return CST_ERROR_FORMAT;
    }

    while (!ts_eof(fd))
    {
	token = ts_get(fd);
	if (cst_streq(token,""))
	    continue;
	item = relation_append(r,NULL);
	item_set_float(item,"end",(float)cst_atof(token));
 

        
	token = ts_get(fd);
       
	token = ts_get(fd);
	item_set_string(item,"name",token);
    }

    ts_close(fd);
    return CST_OK_FORMAT;
}
Пример #11
0
cst_utterance *join_units_simple(cst_utterance *utt)
{
    cst_wave *w = 0;
    cst_lpcres *lpcres;
    const char *resynth_type;
    const cst_val *streaming_info_val;

    resynth_type = get_param_string(utt->features, "resynth_type", "fixed");

    asis_to_pm(utt);
    concat_units(utt);

    lpcres = val_lpcres(utt_feat_val(utt, "target_lpcres"));

    streaming_info_val = get_param_val(utt->features, "streaming_info", NULL);
    if (streaming_info_val)
    {
        lpcres->asi = val_audio_streaming_info(streaming_info_val);
        lpcres->asi->utt = utt;
    }

    if (cst_streq(resynth_type, "fixed"))
        w = lpc_resynth_fixedpoint(lpcres);
    else
    {
        cst_errmsg("unknown resynthesis type %s\n", resynth_type);
        cst_error();            /* Should not happen */
    }

    utt_set_wave(utt, w);

    return utt;
}
Пример #12
0
void feat_set(cst_features *f, const char* name, const cst_val *val)
{
    cst_featvalpair *n;
    n = feat_find_featpair(f,name);

    if (val == NULL)
    {
	cst_errmsg("cst_val: trying to set a NULL val for feature \"%s\"\n",
		   name);
    }
    else if (n == NULL)
    {   /* first reference to this feature so create new fpair */
	cst_featvalpair *p;
	p = (cst_featvalpair *)cst_local_alloc(f->ctx, sizeof(*p));
#import "OpenEarsStaticAnalysisToggle.h"
#ifdef STATICANALYZEDEPENDENCIES
#define __clang_analyzer__ 1
#endif
#if !defined(__clang_analyzer__) || defined(STATICANALYZEDEPENDENCIES)
#undef __clang_analyzer__
        
	p->next = f->head;
      
	p->name = name; 
	p->val = val_inc_refcount(val);
	f->head = p;
    }
    else
    {
	delete_val(n->val);
	n->val = val_inc_refcount(val);
    }
#endif      
}
Пример #13
0
int cst_track_save_est_binary(cst_track *t, const char *filename)
{
    cst_file fd;
    float foo;
    int i, j;

    if ((fd = cst_fopen(filename, CST_OPEN_WRITE | CST_OPEN_BINARY)) == NULL)
    {
        cst_errmsg("cst_track_save_est_binary: can't open file \"%s\"\n",
                   filename);
        return -1;
    }

    cst_fprintf(fd, "EST_File Track\n");
    cst_fprintf(fd, "DataType binary\n");
    cst_fprintf(fd, "ByteOrder %s\n",
                CST_LITTLE_ENDIAN ? BYTE_ORDER_LITTLE : BYTE_ORDER_BIG);
    cst_fprintf(fd, "NumFrames %d\n", t->num_frames);
    cst_fprintf(fd, "NumChannels %d\n", t->num_channels);
    cst_fprintf(fd, "BreaksPresent true\n");
    cst_fprintf(fd, "EST_Header_End\n");

    foo = 1.0;                  /* put a bogus 'breaks' value in for now */
    for (i = 0; i < t->num_frames; i++)
    {
        cst_fwrite(fd, t->times + i, sizeof(float), 1);
        cst_fwrite(fd, &foo, sizeof(float), 1);
        for (j = 0; j < t->num_channels; j++)
            cst_fwrite(fd, &(t->frames[i][j]), sizeof(float), 1);
    }

    cst_fclose(fd);

    return 0;
}
Пример #14
0
cst_item *item_add_daughter(cst_item *i,cst_item *nd)
{
    cst_item *p,*rnd;

    p = item_last_daughter(i);

    if (p)
	rnd=item_append(p,nd);
    else
    {   /* first new daughter */
	if (nd && (nd->relation == i->relation))
	{
	    /* got to delete it first as nd can't be in a relation twice */
	    cst_errmsg("item_add_daughter: already in relation\n");
	    return 0;
	}
	else
	    rnd = new_item_relation(i->relation,nd);

	rnd->u = i;
	i->d = rnd;
    }

    return rnd;
}
Пример #15
0
int audio_drain_alsa(cst_audiodev *ad)
{
  int result;
  result = snd_pcm_drop((snd_pcm_t *) ad->platform_data);
  if (result < 0)
  {
	cst_errmsg("audio_drain_alsa: Error: %s.\n", snd_strerror(result));
  }
/* Prepare device for more data */
  result = snd_pcm_prepare((snd_pcm_t *) ad->platform_data);
if (result < 0)
  {
	cst_errmsg("audio_drain_alsa: Error: %s.\n", snd_strerror(result));
  }
  return result;
}
Пример #16
0
int relation_save(cst_relation *r, const char *filename)
{
    cst_file fd;
    cst_item *item;

    if (cst_streq(filename, "-"))
        fd = stdout;
    else

    if ((fd = cst_fopen(filename, CST_OPEN_WRITE)) == 0)
    {
        cst_errmsg("relation_save: can't open file \"%s\" for writing\n",
                   filename);
        return CST_ERROR_FORMAT;
    }

    for (item = relation_head(r); item; item = item_next(item))
    {
        if (item_feat_present(item, "end"))
            cst_fprintf(fd, "%f ", item_feat_float(item, "end"));
        else
            cst_fprintf(fd, "%f ", 0.00);
        if (item_feat_present(item, "name"))
            cst_fprintf(fd, "%s ", item_feat_string(item, "name"));
        else
            cst_fprintf(fd, "%s ", "_");
        cst_fprintf(fd, "\n");
    }
    if (fd != stdout)
        cst_fclose(fd);

    return CST_OK_FORMAT;
}
Пример #17
0
static double cal_xmcxmc(long clsidx,
		  DVECTOR x,
		  DMATRIX mm,	// [num class][dim]
		  DMATRIX cm)	// [num class * dim][dim]
{
    long clsnum, k, l, b, dim;
    double *vec = NULL;
    double td, d;

    dim = x->length;
    clsnum = mm->row;
    b = clsidx * dim;
    if (mm->col != dim || cm->col != dim || clsnum * dim != cm->row) {
	cst_errmsg("Error cal_xmcxmc: different dimension\n");
        cst_error();
    }

    // memory allocation
    vec = mlpg_alloc((int)dim, double);
    for (k = 0; k < dim; k++) vec[k] = x->data[k] - mm->data[clsidx][k];
    for (k = 0, d = 0.0; k < dim; k++) {
	for (l = 0, td = 0.0; l < dim; l++) td += vec[l] * cm->data[l + b][k];
	d += td * vec[k];
    }
    // memory free
    mlpg_free(vec); vec = NULL;

    return d;
}
Пример #18
0
void feat_set(cst_features *f, const char* name, const cst_val *val)
{
    cst_featvalpair *n;
    n = feat_find_featpair(f,name);

    if (val == NULL)
    {
	cst_errmsg("cst_val: trying to set a NULL val for feature \"%s\"\n",
		   name);
    }
    else if (n == NULL)
    {   /* first reference to this feature so create new fpair */
	cst_featvalpair *p;
	p = (cst_featvalpair *)cst_local_alloc(f->ctx, sizeof(*p));
	p->next = f->head;
	p->name = name; 
	p->val = val_inc_refcount(val);
	f->head = p;
    }
    else
    {
	delete_val(n->val);
	n->val = val_inc_refcount(val);
    }
}
Пример #19
0
static double get_gauss_dia(long clsidx,
		     DVECTOR vec,		// [dim]
		     DVECTOR detvec,		// [clsnum]
		     DMATRIX weightmat,		// [clsnum][1]
		     DMATRIX meanmat,		// [clsnum][dim]
		     DMATRIX invcovmat)		// [clsnum][dim]
{
    double gauss, sb;
    long k;

    if (detvec->data[clsidx] <= 0.0) {
	cst_errmsg("#error: det <= 0.0\n");
        cst_error();
    }

    for (k = 0, gauss = 0.0; k < vec->length; k++) {
	sb = vec->data[k] - meanmat->data[clsidx][k];
	gauss += sb * invcovmat->data[clsidx][k] * sb;
    }

    gauss = weightmat->data[clsidx][0]
	/ sqrt(pow(2.0 * PI, (double)vec->length) * detvec->data[clsidx])
	* exp(-gauss / 2.0);

    return gauss;
}
Пример #20
0
// diagonal covariance
static DVECTOR xget_detvec_diamat2inv(DMATRIX covmat)	// [num class][dim]
{
    long dim, clsnum;
    long i, j;
    double det;
    DVECTOR detvec = NODATA;

    clsnum = covmat->row;
    dim = covmat->col;
    // memory allocation
    detvec = xdvalloc(clsnum);
    for (i = 0; i < clsnum; i++) {
	for (j = 0, det = 1.0; j < dim; j++) {
	    det *= covmat->data[i][j];
	    if (det > 0.0) {
		covmat->data[i][j] = 1.0 / covmat->data[i][j];
	    } else {
		cst_errmsg("error:(class %ld) determinant <= 0, det = %f\n", i, det);
                xdvfree(detvec);
		return NODATA;
	    }
	}
	detvec->data[i] = det;
    }

    return detvec;
}
Пример #21
0
static void mlgparaChol(DMATRIX pdf, PStreamChol *pst, DMATRIX mlgp)
{
    int t, d;

    // error check
    if (pst->vSize * 2 != pdf->col || pst->order + 1 != mlgp->col) {
	cst_errmsg("Error mlgparaChol: Different dimension\n");
        cst_error();
    }

    // mseq: U^{-1}*M,	ifvseq: U^{-1}
    for (t = 0; t < pst->T; t++) {
	for (d = 0; d < pst->vSize; d++) {
	    pst->mseq[t][d] = pdf->data[t][d];
	    pst->ivseq[t][d] = pdf->data[t][pst->vSize + d];
	}
    } 

    // ML parameter generation
    mlpgChol(pst);

    // extracting parameters
    for (t = 0; t < pst->T; t++)
	for (d = 0; d <= pst->order; d++)
	    mlgp->data[t][d] = pst->c[t][d];

    return;
}
Пример #22
0
int cst_track_save_est(cst_track *t, const char *filename)
{
    cst_file fd;
    int i, j;

    if ((fd = cst_fopen(filename, CST_OPEN_WRITE | CST_OPEN_BINARY)) == NULL)
    {
        cst_errmsg("cst_track_save_est: can't open file \"%s\"\n", filename);
        return -1;
    }

    cst_fprintf(fd, "EST_File Track\n");
    cst_fprintf(fd, "DataType ascii\n");
    cst_fprintf(fd, "NumFrames %d\n", t->num_frames);
    cst_fprintf(fd, "NumChannels %d\n", t->num_channels);
    cst_fprintf(fd, "BreaksPresent true\n");
    cst_fprintf(fd, "EST_Header_End\n");

    for (i = 0; i < t->num_frames; i++)
    {
        cst_fprintf(fd, "%f\t1 \t", t->times[i]);
        for (j = 0; j < t->num_channels; j++)
            cst_fprintf(fd, "%f ", t->frames[i][j]);
        cst_fprintf(fd, "\n");
    }

    cst_fclose(fd);

    return 0;
}
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;
}
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;
}
Пример #25
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;
}
Пример #26
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);
}
Пример #27
0
/* Returns zero if recovery was successful. */
static int recover_from_error(snd_pcm_t *pcm_handle, ssize_t res)
{
  res = snd_pcm_prepare(pcm_handle);
  if (res < 0)
  {
	/* Unknown failure */
	cst_errmsg("audio_recover_from_write_error: %s.\n", snd_strerror(res));
	return res;
  }
  return 0;
}
Пример #28
0
static int auserver_process_client(int client_name, int fd)
{
    /* Gets called for each client */
    snd_header header;
    int r;

    printf("client %d connected, ",client_name);
    fflush(stdout);
    /* Get header */
    r = read(fd,&header,sizeof(header));
    if (r != sizeof(header))
    {
	cst_errmsg("socket: connection didn't give a header\n");
	return -1;
    }
    if (CST_LITTLE_ENDIAN)
    {
	header.magic = SWAPINT(header.magic);
	header.hdr_size = SWAPINT(header.hdr_size);
	header.data_size = SWAPINT(header.data_size);
	header.encoding = SWAPINT(header.encoding);
	header.sample_rate = SWAPINT(header.sample_rate);
	header.channels = SWAPINT(header.channels);
    }

    if (header.magic != CST_SND_MAGIC)
    {
	cst_errmsg("socket: client something other than snd waveform\n");
	return -1;
    }

    printf("%d bytes at %d rate, ", header.data_size, header.sample_rate);
    fflush(stdout);

    if (play_wave_from_socket(&header,fd) == CST_OK_FORMAT)
	printf("successful\n");
    else
	printf("unsuccessful\n");
    
    return 0;
}
Пример #29
0
const char *val_string(const cst_val *v)
{
    if (v && (CST_VAL_TYPE(v) == CST_VAL_TYPE_STRING))
	return CST_VAL_STRING(v);
    else
    {
	cst_errmsg("VAL: tried to access string in %d typed val\n",
		   (v ? CST_VAL_TYPE(v) : -1));
	cst_error();
    }
    return 0;
}
Пример #30
0
const cst_val *val_cdr(const cst_val *v)
{
    if (v && cst_val_consp(v))
	return CST_VAL_CDR(v);
    else
    {
	cst_errmsg("VAL: tried to access cdr in %d typed val\n",
		   (v ? CST_VAL_TYPE(v) : -1));
	cst_error();
    }
    return 0;
}