コード例 #1
0
ファイル: any2bytes.c プロジェクト: Angeldude/pd
/*--------------------------------------------------------------------
 * anything
 */
static void any2bytes_anything(t_any2bytes *x, t_symbol *sel, int argc, t_atom *argv)
{
  //-- convert any -> bytes -> atoms
  t_pdstring_atoms arg_atoms = {argv,argc,0};
  pdstring_bytes_clear(&x->x_bytes);
  pdstring_any2bytes(x, &x->x_bytes, sel, &arg_atoms, x->x_binbuf);
  pdstring_bytes2atoms(x, &x->x_atoms, &x->x_bytes, x->x_eos);

  //-- output
  outlet_list(x->x_outlet, &s_list, x->x_atoms.a_len, x->x_atoms.a_buf);
}
コード例 #2
0
/*--------------------------------------------------------------------
 * get OFFSET LENGTH
 */
static void array2rawbytes_get(t_array2rawbytes *x, t_float offset_f, t_float len_f)
{
  int offset=offset_f, len=len_f, fvecsize, cvecsize;
  t_garray *a;
  t_float *fvec;
  unsigned char *cvec;

  //-- sanity check(s)
  if (!(a = (t_garray *)pd_findbyclass(x->x_name, garray_class))) {
    pd_error(x, "array2rawbytes_get: no such array '%s'", x->x_name->s_name);
    return;
  }

  //-- get float* from array
  if (!garray_getfloatarray(a, &fvecsize, &fvec))
    pd_error(x,"array2rawbytes: bad template for write to array '%s'", x->x_name->s_name);

  //-- get character offset & len
  cvec     = (unsigned char*)fvec;
  cvecsize = fvecsize*sizeof(t_float)/sizeof(unsigned char);
  post("array2rawbytes[x=%p]: char data: cvecsize=%d", x, cvecsize);

  //-- tweak out-of-bounds values
  post("array2rawbytes[x=%p]: pre-tweak: offset=%d, len=%d", x, offset, len);

  offset %= cvecsize;
  if (len <= 0 || offset+len >= cvecsize)
    len = cvecsize - offset;

  post("array2rawbytes[x=%p]: post-tweak: offset=%d, len=%d", x, offset, len);

  //-- munge x_bytes
  x->x_bytes.b_buf = cvec+offset;
  x->x_bytes.b_len = len;

  //-- convert bytes -> atoms
  pdstring_bytes2atoms(x, &x->x_atoms, &x->x_bytes, PDSTRING_EOS_NONE);

  //-- output
  outlet_list(x->x_outlet, &s_list, x->x_atoms.a_len, x->x_atoms.a_buf);
}