/* Initialize necessary things */ static bool_t jack_init (void) { aud_config_set_defaults ("jack", jack_defaults); jack_cfg.isTraceEnabled = aud_get_bool ("jack", "isTraceEnabled"); jack_cfg.volume_left = aud_get_int ("jack", "volume_left"); jack_cfg.volume_right = aud_get_int ("jack", "volume_right"); TRACE("initializing\n"); JACK_Init(); /* initialize the driver */ /* set the bio2jack name so users will see xmms-jack in their */ /* jack client list */ JACK_SetClientName("audacious-jack"); /* set the port connection mode */ jack_set_port_connection_mode(); output_opened = FALSE; /* Always return OK, as we don't know about physical devices here */ return TRUE; }
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; }