Пример #1
0
CAMLprim value caml_bjack_write(value device, value data)
{
    CAMLparam2(device,data);
    int n = caml_string_length(data) ;
    jack_driver_t* drv = Bjack_drv_val(device);
    long ret;
    char* buf = malloc(n) ;
    memcpy(buf,String_val(data),n);

    if (drv->num_output_channels > 0)
    {
        caml_enter_blocking_section();
        ret = JACK_Write(drv,(unsigned char *)buf,n);
        caml_leave_blocking_section();
    }
    else
    {
        caml_raise_constant(*caml_named_value("bio2jack_exn_too_many_output_channels"));
    }

    if (ret < 0) caml_failwith("jack_write");

    free(buf);

    CAMLreturn(Val_long(ret));
}
Пример #2
0
int audev_loop(mix_func_t mixfunc, generate_func_t genfunc, void *rock)
{
  char *ptr;
  int ix, res;
  long pos;

  while (1) {
    res = mixfunc(valbuffer, genfunc, rock);
    if (res)
      return TRUE;

    if (sound_format) {
      for (ix=0, ptr=rawbuffer; ix<samplesperbuf; ix++) {
        long samp = valbuffer[ix];
        if (samp > 0x7FFF)
          samp = 0x7FFF;
        else if (samp < -0x7FFF)
          samp = -0x7FFF;
        *ptr++ = ((samp >> 8) & 0xFF);
        *ptr++ = ((samp) & 0xFF);
      }
    }
    else {
      for (ix=0, ptr=rawbuffer; ix<samplesperbuf; ix++) {
        long samp = valbuffer[ix];
        if (samp > 0x7FFF)
          samp = 0x7FFF;
        else if (samp < -0x7FFF)
          samp = -0x7FFF;
        *ptr++ = ((samp) & 0xFF);
        *ptr++ = ((samp >> 8) & 0xFF);
      }
    }

    pos = 0;

    while (pos < sound_buffersize) {
      long written;
      long towrite = JACK_GetBytesFreeSpace(deviceid);

      if (towrite <= 0) {
        struct timeval tv = sleeptime;
        select(0, 0, 0, 0, &tv);
        continue;
      }

      if (towrite > sound_buffersize-pos)
        towrite = sound_buffersize-pos;

      written = JACK_Write(deviceid, (unsigned char *)rawbuffer + pos, towrite);
      if (written != towrite) {
        fprintf(stderr, "Device write incomplete: %ld of %ld\n", written, towrite);
        return FALSE;
      }

      pos += written;
    }

  }
Пример #3
0
/* write some audio out to the device */
static void jack_write(void * ptr, int length)
{
  long written;

  TRACE("starting length of %d\n", length);

  /* loop until we have written all the data out to the jack device */
  /* this is due to xmms' audio driver api */
  char *buf = (char*)ptr;
  while(length > 0)
  {
    TRACE("writing %d bytes\n", length);
    written = JACK_Write(driver, (unsigned char*)buf, length);
    length-=written;
    buf+=written;
  }
  TRACE("finished\n");
}