CAMLprim value caml_bjack_get_bytes_per_output_frame(value d) { CAMLparam1(d); CAMLreturn(Val_long(JACK_GetBytesPerOutputFrame(Bjack_drv_val(d)))); }
int audev_init_device(char *devname, long ratewanted, int verbose, extraopt_t *extra) { extraopt_t *opt; int channels; unsigned long rate; int fragsize, format; long jbufframes, jbufsize; int res; if (verbose) { printf("Boodler: JackBIO sound driver.\n"); } if (deviceid) { fprintf(stderr, "Sound device is already open.\n"); return FALSE; } if (!ratewanted) ratewanted = DEFAULT_SOUNDRATE; if (!devname) devname = DEFAULT_CLIENTNAME; rate = ratewanted; channels = 2; fragsize = 32768; format = 0; /* default to little-endian */ for (opt=extra; opt->key; opt++) { if (!strcmp(opt->key, "end") && opt->val) { if (!strcmp(opt->val, "big")) format = 1; else if (!strcmp(opt->val, "little")) format = 0; } else if (!strcmp(opt->key, "connect") && opt->val) { if (!strcmp(opt->val, "none")) connect_mode = CONNECT_NONE; else if (!strcmp(opt->val, "output")) connect_mode = CONNECT_OUTPUT; else if (!strcmp(opt->val, "all")) connect_mode = CONNECT_ALL; else printf("JackB connect parameter must be none, output, or all.\n"); } else if (!strcmp(opt->key, "buffersize") && opt->val) { fragsize = atol(opt->val); } else if (!strcmp(opt->key, "listdevices")) { printf("JackB driver is unable to list devices.\n"); } } JACK_Init(); JACK_SetPortConnectionMode(connect_mode); JACK_SetClientName(devname); res = JACK_Open(&deviceid, 16, &rate, 2); if (res) { fprintf(stderr, "Unable to open JACK connection: error %d\n", res); return FALSE; } jbufsize = JACK_GetBytesFreeSpace(deviceid); jbufframes = jbufsize / JACK_GetBytesPerOutputFrame(deviceid); if (jbufframes/2 >= rate) { sleeptime.tv_sec = 1; sleeptime.tv_usec = 0; } else { sleeptime.tv_sec = 0; sleeptime.tv_usec = (jbufframes/2) * 1000000 / rate; } if (verbose) { printf("Jack client name is \"%s_...\"\n", devname); printf("Sample format is %s-endian.\n", (format ? "big" : "little")); printf("Sample rate is %ld fps.\n", rate); printf("Boodler buffer size is %d.\n", fragsize); printf("Bio2Jack buffer size is %ld (%ld frames).\n", jbufsize, jbufframes); switch (connect_mode) { case CONNECT_NONE: printf("Bio2Jack connect_mode=CONNECT_NONE.\n"); break; case CONNECT_OUTPUT: printf("Bio2Jack connect_mode=CONNECT_OUTPUT.\n"); break; case CONNECT_ALL: printf("Bio2Jack connect_mode=CONNECT_ALL.\n"); break; default: printf("Bio2Jack connect_mode=???.\n"); break; } } sound_rate = rate; sound_channels = channels; sound_format = format; sound_buffersize = fragsize; samplesperbuf = sound_buffersize / 2; framesperbuf = sound_buffersize / (2 * sound_channels); valbuffer = (long *)malloc(sizeof(long) * samplesperbuf); if (!valbuffer) { fprintf(stderr, "Unable to allocate sound buffer.\n"); JACK_Close(deviceid); deviceid = 0; return FALSE; } rawbuffer = (char *)malloc(sound_buffersize); if (!rawbuffer) { fprintf(stderr, "Unable to allocate sound buffer.\n"); free(valbuffer); JACK_Close(deviceid); deviceid = 0; return FALSE; } return TRUE; }