示例#1
0
文件: trento.c 项目: amurtet/pd-dis
void trento_resize(t_trento *x, t_symbol *msg, int argc, t_atom *argv)
{
  t_word *samples;
  int new_frames;
  int i;
  int old_frames;
  if(argc!=1) {
    pd_error(x,"resize take 1 argument, not %d",argc);
    return;
  }
  new_frames = atom_getintarg(0,argc,argv);
  if(new_frames<0) {
    pd_error(x,"resize must be larger than 0");
    return;
  }
  if(!attach_array(x))
    return;
  old_frames = x->b_frames;
  if(new_frames<old_frames)
    pd_error(x,"Warning: some output may be delete");
  garray_resize(x->buffy, new_frames);
  if(!attach_array(x))
    return;
  samples = x->b_samples;
  for(i=old_frames;i<new_frames;i++)
    samples[i].w_float = 0.f;
  garray_redraw(x->buffy);
  return;
}
示例#2
0
文件: flite.c 项目: Angeldude/pd
/*--------------------------------------------------------------------
 * flite_synth : synthesize current text-buffer
 *--------------------------------------------------------------------*/
void flite_synth(t_flite *x) {
  cst_wave *wave;
  int i,vecsize;
  t_garray *a;
  t_float *vec;

# ifdef FLITE_DEBUG
  post("flite: got message 'synth'");
# endif

  // -- sanity checks
  if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) {
    pd_error(x,"flite: no such array '%s'", x->x_arrayname->s_name);
    return;
  }
  if (!x->textbuf) {
    pd_error(x,"flite: attempt to synthesize empty text-buffer!");
    return;
  }

# ifdef FLITE_DEBUG
  post("flite: flite_text_to_wave()");
# endif
  wave = flite_text_to_wave(x->textbuf,voice);

  if (!wave) {
    pd_error(x,"flite: synthesis failed for text '%s'", x->textbuf);
    return;
  }

  // -- resample
# ifdef FLITE_DEBUG
  post("flite: cst_wave_resample()");
# endif
  cst_wave_resample(wave,sys_getsr());

  // -- resize & write to our array
# ifdef FLITE_DEBUG
  post("flite: garray_resize(%d)", wave->num_samples);
# endif

  garray_resize(a, wave->num_samples);
  if (!garray_getfloatarray(a, &vecsize, &vec))
    pd_error(x,"flite: bad template for write to array '%s'", x->x_arrayname->s_name);

# ifdef FLITE_DEBUG
  post("flite: ->write to garray loop<-");
# endif
  for (i = 0; i < wave->num_samples; i++) {
    *vec++ = wave->samples[i]/32767.0;
  }

  // -- outlet synth-done-bang
  outlet_bang(x->x_obj.ob_outlet);

  // -- cleanup
  delete_wave(wave);

  // -- redraw
  garray_redraw(a);
}