static int start_jack(AVFormatContext *context, AVFormatParameters *params) { JackData *self = context->priv_data; jack_status_t status; int i, test; double o, period; /* Register as a JACK client, using the context filename as client name. */ self->client = jack_client_open(context->filename, JackNullOption, &status); if (!self->client) { av_log(context, AV_LOG_ERROR, "Unable to register as a JACK client\n"); return AVERROR(EIO); } sem_init(&self->packet_count, 0, 0); self->sample_rate = jack_get_sample_rate(self->client); self->nports = params->channels; self->ports = av_malloc(self->nports * sizeof(*self->ports)); self->buffer_size = jack_get_buffer_size(self->client); /* Register JACK ports */ for (i = 0; i < self->nports; i++) { char str[16]; snprintf(str, sizeof(str), "input_%d", i + 1); self->ports[i] = jack_port_register(self->client, str, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); if (!self->ports[i]) { av_log(context, AV_LOG_ERROR, "Unable to register port %s:%s\n", context->filename, str); jack_client_close(self->client); return AVERROR(EIO); } } /* Register JACK callbacks */ jack_set_process_callback(self->client, process_callback, self); jack_on_shutdown(self->client, shutdown_callback, self); jack_set_xrun_callback(self->client, xrun_callback, self); /* Create time filter */ period = (double) self->buffer_size / self->sample_rate; o = 2 * M_PI * 1.5 * period; /// bandwidth: 1.5Hz self->timefilter = ff_timefilter_new (1.0 / self->sample_rate, sqrt(2 * o), o * o); /* Create FIFO buffers */ self->filled_pkts = av_fifo_alloc(FIFO_PACKETS_NUM * sizeof(AVPacket)); /* New packets FIFO with one extra packet for safety against underruns */ self->new_pkts = av_fifo_alloc((FIFO_PACKETS_NUM + 1) * sizeof(AVPacket)); if ((test = supply_new_packets(self, context))) { jack_client_close(self->client); return test; } return 0; }
int jack_initialize (jack_client_t *client, const char* load_init) { struct a2j* self = calloc(1, sizeof(struct a2j)); if (!self) { return -1; } self->jack_client = client; self->input = 1; self->ignore_hardware_ports = 0; self->finishing = 0; if (load_init) { char* args = strdup (load_init); char* token; char* ptr = args; char* savep; while (1) { if ((token = strtok_r (ptr, ", ", &savep)) == NULL) { break; } if (strncasecmp (token, "in", 2) == 0) { self->input = 1; } if (strncasecmp (token, "out", 2) == 0) { self->input = 0; } if (strncasecmp (token, "hw", 2) == 0) { self->ignore_hardware_ports = 0; } ptr = NULL; } free (args); } if (connect_to_alsa (self)) { free (self); return -1; } jack_set_process_callback (client, a2j_process, self); jack_set_freewheel_callback (client, a2j_freewheel, NULL); jack_on_shutdown (client, a2j_shutdown, NULL); jack_activate (client); return 0; }
JackCpp::AudioIO::AudioIO(std::string name, unsigned int inPorts, unsigned int outPorts, bool startServer) throw(std::runtime_error) : mCmdBuffer(256,true) { jack_options_t jack_open_options = JackNullOption; if(startServer == false) jack_open_options = JackNoStartServer; mJackState = notActive; //set the error callback jack_set_error_function (error_callback); /* try to become a client of the JACK server */ if ((mJackClient = jack_client_open (name.c_str(), jack_open_options, NULL)) == 0) { throw std::runtime_error("cannot create client jack server not running?"); } #ifdef __APPLE__ else { // because the mac version of jack is being totally LAME sleep(2); } #endif //set the shutdown callback jack_on_shutdown (mJackClient, shutdown_callback, this); //allocate ports if (inPorts > 0){ for(unsigned int i = 0; i < inPorts; i++){ std::string portname = "input"; portname.append(ToString(i)); mInputPorts.push_back( jack_port_register (mJackClient, portname.c_str(), JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0)); mPortNames.push_back(portname); } //reserve the data for the jack callback buffers for(unsigned int i = 0; i < mInputPorts.size(); i++) mJackInBuf.push_back(NULL); } if (outPorts > 0){ for(unsigned int i = 0; i < outPorts; i++){ std::string portname = "output"; portname.append(ToString(i)); mOutputPorts.push_back( jack_port_register (mJackClient, portname.c_str(), JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0)); mPortNames.push_back(portname); } //reserve the data for the jack callback buffers for(unsigned int i = 0; i < mOutputPorts.size(); i++) mJackOutBuf.push_back(NULL); } //set up the callback if(0 != jack_set_process_callback (mJackClient, JackCpp::AudioIO::jackProcessCallback, this)) throw std::runtime_error("cannot register process callback"); }
int_fast32_t jack_init(struct jack_data* data) { pthread_mutex_lock(&data->jack_mutex); if (data->jack_client != NULL) goto good; jack_options_t jack_option = data->start_jack_server ? JackNullOption : JackNoStartServer; data->jack_client = jack_client_open(data->device, jack_option, 0); if (data->jack_client == NULL) { blog(LOG_ERROR, "jack_client_open Error:" "Could not create JACK client! %s", data->device); goto error; } data->jack_ports = (jack_port_t**)bzalloc( sizeof(jack_port_t*) * data->channels); for (unsigned int i = 0; i < data->channels; ++i) { char port_name[10] = {'\0'}; snprintf(port_name, sizeof(port_name), "in_%d", i+1); data->jack_ports[i] = jack_port_register(data->jack_client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); if (data->jack_ports[i] == NULL) { blog(LOG_ERROR, "jack_port_register Error:" "Could not create JACK port! %s", port_name); goto error; } } if (jack_set_process_callback(data->jack_client, jack_process_callback, data) != 0) { blog(LOG_ERROR, "jack_set_process_callback Error"); goto error; } if (jack_activate(data->jack_client) != 0) { blog(LOG_ERROR, "jack_activate Error:" "Could not activate JACK client!"); goto error; } good: pthread_mutex_unlock(&data->jack_mutex); return 0; error: pthread_mutex_unlock(&data->jack_mutex); return 1; }
struct gojack_process_callback_sync * gojack_process_callback_sync_create(jack_client_t *client) { struct gojack_process_callback_sync *sync = (struct gojack_process_callback_sync *) malloc(sizeof(struct gojack_process_callback_sync)); void *arg = (void *) sync; sync->base = cgo_callback_sync_create(); cgo_callback_sync_set_log_callback(sync->base, &handle_log, NULL); sync->client = client; jack_set_process_callback(client, &handle_process, arg); return sync; }
jack_client_t* init_jack(void) { jack_client_t *client; const char *client_name = "simple_talker"; const char *server_name = NULL; jack_options_t options = JackNullOption; jack_status_t status; client = jack_client_open (client_name, options, &status, server_name); if (NULL == client) { fprintf (stderr, "jack_client_open() failed\n "); exit (1); } if (status & JackServerStarted) { fprintf (stderr, "JACK server started\n"); } if (status & JackNameNotUnique) { client_name = jack_get_client_name(client); fprintf (stderr, "unique name `%s' assigned\n", client_name); } jack_set_process_callback(client, process, 0); jack_on_shutdown(client, jack_shutdown, 0); if (jack_activate (client)) fprintf (stderr, "cannot activate client"); inputports = (jack_port_t**) malloc (CHANNELS * sizeof (jack_port_t*)); in = (jack_default_audio_sample_t**) malloc (CHANNELS * sizeof (jack_default_audio_sample_t*)); ringbuffer = jack_ringbuffer_create (SAMPLE_SIZE * DEFAULT_RINGBUFFER_SIZE * CHANNELS); jack_ringbuffer_mlock(ringbuffer); memset(in, 0, sizeof (jack_default_audio_sample_t*)*CHANNELS); memset(ringbuffer->buf, 0, ringbuffer->size); for(int i = 0; i < CHANNELS; i++) { char* portName; if (asprintf(&portName, "input%d", i) < 0) { fprintf(stderr, "Could not create portname for port %d", i); exit(1); } inputports[i] = jack_port_register (client, portName, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); if (NULL == inputports[i]) { fprintf (stderr, "cannot register input port \"%d\"!\n", i); jack_client_close (client); exit (1); } } return client; }
int rmdStartJackClient(JackData *jdata){ float ring_buffer_size=0.0; int pid; char pidbuf[8]; char rmd_client_name[32]; //construct the jack client name //which is recordMyDesktop-pid //in order to allow multiple //instances of recordMyDesktop //to connetc to a Jack Server strcpy(rmd_client_name,"recordMyDesktop-"); pid=getpid(); snprintf( pidbuf, 8, "%d", pid ); strcat(rmd_client_name,pidbuf); if ((jdata->client=(*jack_client_new)(rmd_client_name))==0){ fprintf(stderr,"Could not create new client!\n" "Make sure that Jack server is running!\n"); return 15; } //in contrast to ALSA and OSS, Jack dictates frequency //and buffersize to the values it was launched with. //Supposedly jack_set_buffer_size can set the buffersize //but that causes some kind of halt and keeps giving me //zero buffers. //recordMyDesktop cannot handle buffer size changes. //FIXME //There is a callback for buffer size changes that I should use. //It will provide clean exits, instead of ?segfaults? . //Continuing though is not possible, with the current layout //(it might be in some cases, but it will certainly be the cause //of unpredicted problems). A clean exit is preferable //and any recording up to that point will be encoded and saved. jdata->frequency=jack_get_sample_rate(jdata->client); jdata->buffersize=jack_get_buffer_size(jdata->client); ring_buffer_size=(jdata->ringbuffer_secs* jdata->frequency* sizeof(jack_default_audio_sample_t)* jdata->nports); jdata->sound_buffer= (*jack_ringbuffer_create)((int)(ring_buffer_size+0.5));//round up jack_set_process_callback(jdata->client,rmdJackCapture,jdata); jack_on_shutdown(jdata->client,rmdJackShutdown,jdata); if (jack_activate(jdata->client)) { fprintf(stderr,"cannot activate client!\n"); return 16; } if(rmdSetupPorts(jdata)){ jack_client_close(jdata->client); return 17; } return 0; }
int main(int narg, char **args) { int i; jack_nframes_t nframes; if((narg<6) || ((narg-3)%3 !=0)) { usage(); exit(1); } if((client = jack_client_open (args[1], JackNullOption, NULL)) == 0) { fprintf (stderr, "JACK server not running?\n"); return 1; } jack_set_process_callback (client, process, 0); output_port = jack_port_register (client, "out", JACK_DEFAULT_MIDI_TYPE, JackPortIsOutput, 0); nframes = jack_get_buffer_size(client); loop_index = 0; num_notes = (narg - 3)/3; note_frqs = malloc(num_notes*sizeof(unsigned char)); note_starts = malloc(num_notes*sizeof(jack_nframes_t)); note_lengths = malloc(num_notes*sizeof(jack_nframes_t)); loop_nsamp = atoi(args[2]); for(i=0; i<num_notes; i++) { note_starts[i] = atoi(args[3 + 3*i]); note_frqs[i] = atoi(args[4 + 3*i]); note_lengths[i] = atoi(args[5 + 3*i]); } if (jack_activate(client)) { fprintf (stderr, "cannot activate client"); return 1; } /* install a signal handler to properly quits jack client */ #ifndef WIN32 signal(SIGQUIT, signal_handler); signal(SIGHUP, signal_handler); #endif signal(SIGTERM, signal_handler); signal(SIGINT, signal_handler); /* run until interrupted */ while (1) { #ifdef WIN32 Sleep(1*1000); #else sleep(1); #endif }; jack_client_close(client); exit (0); }
ezjack_bundle_t *ezjack_open(const char *client_name, int inputs, int outputs, int bufsize, float freq, ezjack_portflags_t flags) { int i; ezjack_bundle_t bun; char namebuf[16]; // Open client jack_status_t temperr = lasterr; bun.client = jack_client_open(client_name, JackNoStartServer, &temperr); lasterr = temperr; if(bun.client == NULL) return NULL; bun.freq = freq; bun.bufsize = bufsize; bun.fbuflen = 0; bun.fbuf = NULL; // Create some ports bun.portstack.incount = 0; bun.portstack.outcount = 0; #define HELPER_OPEN_PORTS(foo, fooputs, foocount, foorb, foobuf, foofmt, flags) \ for(i = 0; i < fooputs; i++) \ { \ snprintf(namebuf, 16, foofmt, i+1); \ bun.portstack.foo[i] = jack_port_register(bun.client, namebuf, JACK_DEFAULT_AUDIO_TYPE, flags, bufsize); \ if(bun.portstack.foo[i] == NULL) \ { \ lasterr = JackFailure; \ jack_client_close(bun.client); \ return NULL; \ } \ \ bun.portstack.foorb[i] = jack_ringbuffer_create(bufsize*sizeof(float)); \ bun.portstack.foobuf[i] = malloc(bufsize*sizeof(float)); \ \ bun.portstack.foocount++; \ } HELPER_OPEN_PORTS(in, inputs, incount, inrb, inbuf, "in_%i", JackPortIsInput); HELPER_OPEN_PORTS(out, outputs, outcount, outrb, outbuf, "out_%i", JackPortIsOutput); #undef HELPER_OPEN_PORTS // Prepare our bundle ezjack_bundle_t *ret = malloc(sizeof(ezjack_bundle_t)); memcpy(ret, &bun, sizeof(ezjack_bundle_t)); // Set callback // FIXME: error needs to be acted upon jack_set_process_callback(bun.client, ezjack_default_callback, ret); return ret; }
int JACKstart(HOR *hor_) { JackOUT=hor_; jackclient = jack_client_open("Horgand",options,&status,NULL);; if (jackclient == NULL) { fprintf (stderr, "Cannot make a jack client, back to Alsa\n"); return (2); }; JackOUT->SAMPLE_RATE=DSAMPLE_RATE; fprintf (stderr, "Internal SampleRate = %d\nJack Output SampleRate= %d\n", JackOUT->SAMPLE_RATE, jack_get_sample_rate (jackclient)); if ((unsigned int) jack_get_sample_rate (jackclient) != (unsigned int) JackOUT->SAMPLE_RATE) fprintf (stderr, "Adjusting SAMPLE_RATE to jackd.\n"); JackOUT->SAMPLE_RATE = jack_get_sample_rate(jackclient); JackOUT->PERIOD = jack_get_buffer_size (jackclient); JackOUT->Put_Period(); jack_set_process_callback (jackclient, jackprocess, 0); outport_left = jack_port_register (jackclient, "out_1", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput | JackPortIsTerminal, 0); outport_right = jack_port_register (jackclient, "out_2", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput | JackPortIsTerminal, 0); jack_midi_in = jack_port_register(jackclient, "in", JACK_DEFAULT_MIDI_TYPE, JackPortIsInput, 0); if (jack_activate (jackclient)) { fprintf (stderr, "Cannot activate jack client, back to Alsa\n"); return (2); }; jack_connect (jackclient, jack_port_name (outport_left), "alsa_pcm:playback_1"); jack_connect (jackclient, jack_port_name (outport_right), "alsa_pcm:playback_2"); pthread_mutex_init (&jmutex, NULL); return 3; };
int JackSapaProxy::Setup(jack_client_t* client) { jack_log("JackSapaProxy::Setup"); //refer to system ports and create sapaproxy ports unsigned int i = 0, j = 0; const char **ports_system_capture; const char **ports_system_playback; unsigned int ports_system_capture_cnt = 0; unsigned int ports_system_playback_cnt = 0; char port_name[JACK_PORT_NAME_SIZE] = {0,}; ports_system_capture = jack_get_ports(client, "system:.*", NULL, JackPortIsPhysical | JackPortIsOutput); if (ports_system_capture != NULL) { for (i = 0; i < fCapturePorts && ports_system_capture[i]; i++) { sprintf(port_name, "__system_capture_%d", i + 1); fInputPorts[i] = jack_port_register(client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); sprintf(port_name, "capture_%d", i + 1); fOutputPorts[i] = jack_port_register(client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); ports_system_capture_cnt++; } jack_free(ports_system_capture); } ports_system_playback = jack_get_ports(client, "system:.*", NULL, JackPortIsPhysical | JackPortIsInput); if (ports_system_playback != NULL) { for (j = 0; j < fPlaybackPorts && ports_system_playback[j]; j++, i++) { sprintf(port_name, "playback_%d", j + 1); fInputPorts[i] = jack_port_register(client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); sprintf(port_name, "__system_playback_%d", j + 1); fOutputPorts[i] = jack_port_register(client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); ports_system_playback_cnt++; } jack_free(ports_system_playback); } //store actual number of system ports fCapturePorts = ports_system_capture_cnt; fPlaybackPorts = ports_system_playback_cnt; jack_set_process_callback(client, Process, this); jack_activate(client); //conenct between sapaproxy and system ports for (unsigned int i = 0; i < ports_system_capture_cnt; i++) { sprintf(port_name, "system:capture_%d", i + 1); jack_connect(client, port_name, jack_port_name(fInputPorts[i])); } for (unsigned int i = 0; i < ports_system_playback_cnt; i++) { sprintf(port_name, "system:playback_%d", i + 1); jack_connect(client, jack_port_name(fOutputPorts[ports_system_capture_cnt + i]), port_name); } return 0; }
process_info_t * process_info_new (ui_t* ui, unsigned long rack_channels) { process_info_t* procinfo; int err; procinfo = g_malloc (sizeof (process_info_t)); procinfo->chain = NULL; procinfo->chain_end = NULL; procinfo->jack_client = NULL; procinfo->port_count = 0; procinfo->jack_input_ports = NULL; procinfo->jack_output_ports = NULL; procinfo->channels = rack_channels; procinfo->time_runs = time_runs; /* sort out the client name */ jack_client_name = g_strdup ( client_name->str ); sanitize_client_name ( jack_client_name ); err = process_info_connect_jack (procinfo, ui); if (err == -1) { g_free (jack_client_name); g_free (procinfo); return NULL; } err = process_info_set_port_count (procinfo, ui, rack_channels); if (err) return NULL; sample_rate = jack_get_sample_rate (procinfo->jack_client); buffer_size = jack_get_sample_rate (procinfo->jack_client); jack_set_process_callback (procinfo->jack_client, process, procinfo); jack_on_shutdown (procinfo->jack_client, jack_shutdown_cb, ui); #if HAVE_JACK_SESSION if( jack_set_session_callback ) jack_set_session_callback (procinfo->jack_client, jack_session_cb_aux, ui); #endif procinfo->ui_to_process = ui->ui_to_process; procinfo->process_to_ui = ui->process_to_ui; jack_activate (procinfo->jack_client); #ifdef HAVE_LASH /* sort out LASH stuff */ lash_jack_client_name (global_lash_client, jack_client_name); #endif return procinfo; }
void JackSequencerController::init() { if( !( m_client = jack_client_open( "sequencer", JackNullOption, NULL ) ) ) { std::cout << "could not open client." << std::endl; } if( ( jack_set_process_callback( m_client, &JackSequencerController::doProcess, this ) ) != 0 ) { std::cout << "could not set the process callback." << std::endl; } m_port = jack_port_register( m_client, "play", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0 ); }
void open_client(std::string const & server_name, std::string const & name, uint32_t input_port_count, uint32_t output_port_count, uint32_t blocksize) { blocksize_ = blocksize; /* open client */ client = server_name.empty() ? jack_client_open(name.c_str(), JackNoStartServer, &status) : jack_client_open(name.c_str(), jack_options_t(JackNoStartServer | JackServerName), &status, server_name.c_str()); boost::atomic_thread_fence(boost::memory_order_release); // ensure visibility on other threads if (status & JackServerFailed) throw std::runtime_error("Unable to connect to JACK server"); if (status & JackNameNotUnique) { const char * client_name = jack_get_client_name(client); std::cout << "unique client name: " << client_name << std::endl; } /* initialize callbacks */ jack_set_thread_init_callback (client, jack_thread_init_callback, this); jack_set_process_callback (client, jack_process_callback, this); jack_set_xrun_callback(client, jack_xrun_callback, this); jack_on_info_shutdown(client, (JackInfoShutdownCallback)jack_on_info_shutdown_callback, NULL); /* register ports */ input_ports.clear(); for (uint32_t i = 0; i != input_port_count; ++i) { std::string portname ("input_"); portname += std::to_string(i+1); jack_port_t * port = jack_port_register(client, portname.c_str(), JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); input_ports.push_back(port); } input_channels = input_port_count; super::input_samples.resize(input_port_count); output_ports.clear(); for (uint32_t i = 0; i != output_port_count; ++i) { std::string portname ("output_"); portname += std::to_string(i+1); jack_port_t * port = jack_port_register(client, portname.c_str(), JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); output_ports.push_back(port); } output_channels = output_port_count; super::output_samples.resize(output_port_count); samplerate_ = jack_get_sample_rate(client); jack_frames = jack_get_buffer_size(client); if (jack_frames % blocksize_) throw std::runtime_error("Jack buffer size is not a multiple of blocksize"); }
jack_raw_output::jack_raw_output (const char* client, const char* server, int rate, int channels, callback_type cb) : detail::async_base_impl (cb) , _out_ports (channels) , _buffer_size (0) { jack_set_error_function (log_jack_error); jack_set_info_function (log_jack_info); jack_options_t options = !server ? JackNullOption : JackServerName; _client = jack_client_open (client, options, 0, server); if (!_client) throw jack_open_error (); auto grd_client = base::make_guard ([&] { jack_client_close (_client); }); PSYNTH_JACK_CHECK (jack_set_process_callback ( _client, &jack_raw_output::_process_cb, this), jack_param_error); PSYNTH_JACK_CHECK (jack_set_sample_rate_callback ( _client, &jack_raw_output::_sample_rate_cb, this), jack_param_error); jack_on_shutdown (_client, &jack_raw_output::_shutdown_cb, this); _actual_rate = jack_get_sample_rate (_client); if (_actual_rate != rate) PSYNTH_LOG << base::log::warning << "Jackd sample rate and application sample rate mismatch." << "Better sound quality is achieved if both are the same."; _buffer_size = jack_get_buffer_size (_client); PSYNTH_LOG << base::log::info << "Jackd buffer size is: " << _buffer_size; for (size_t i = 0; i < _out_ports.size(); ++i) { std::string port_name = std::string ("out_") + boost::lexical_cast<std::string> (i); _out_ports [i] = jack_port_register ( _client, port_name.c_str (), JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); if (_out_ports [i] == 0) throw jack_param_error (); } grd_client.dismiss (); }
int JackAudioSystem::set_process_callback(process_callback_t cb, void* arg, QString* err_msg) { assert(_client); int rv = jack_set_process_callback( _client, cb, arg ); if(rv && err_msg) { *err_msg = "Could not set up jack callback."; } return rv; }
bool JACKaudiooutputinit(Master *master_){ jackmaster=master_; jackclient=0; char tmpstr[100]; jackoutl=new REALTYPE [SOUND_BUFFER_SIZE]; jackoutr=new REALTYPE [SOUND_BUFFER_SIZE]; int rbbufsize=SOUND_BUFFER_SIZE*sizeof (REALTYPE)*2*2; printf("%d\n",rbbufsize); rb=jack_ringbuffer_create(rbbufsize); for (int i=0;i<rbbufsize;i++) rb->buf[i]=0.0; for (int i=0;i<15;i++){ if (i!=0) snprintf(tmpstr,100,"ZynAddSubFX_%d",i); else snprintf(tmpstr,100,"ZynAddSubFX"); jackclient=jack_client_new(tmpstr); if (jackclient!=0) break; }; if (jackclient==0) { fprintf(stderr,"\nERROR: Cannot make a jack client (possible reasons: JACK server is not running or jackd is launched by root and zynaddsubfx by another user.).\n\n\n"); return(false); }; fprintf(stderr,"Internal SampleRate = %d\nJack Output SampleRate= %d\n",SAMPLE_RATE,jack_get_sample_rate(jackclient)); if ((unsigned int)jack_get_sample_rate(jackclient)!=(unsigned int) SAMPLE_RATE) fprintf(stderr,"It is recomanded that the both samplerates to be equal.\n"); jack_set_process_callback(jackclient,jackprocess,0); jack_set_sample_rate_callback(jackclient,jacksrate,0); jack_on_shutdown(jackclient,jackshutdown,0); outport_left=jack_port_register(jackclient,"out_1", JACK_DEFAULT_AUDIO_TYPE,JackPortIsOutput|JackPortIsTerminal,0); outport_right=jack_port_register(jackclient,"out_2", JACK_DEFAULT_AUDIO_TYPE,JackPortIsOutput|JackPortIsTerminal,0); if (jack_activate(jackclient)){ fprintf(stderr,"Cannot activate jack client\n"); return(false); }; pthread_create(&bthr,NULL,thread_blocked,NULL); /* jack_connect(jackclient,jack_port_name(outport_left),"alsa_pcm:out_1"); jack_connect(jackclient,jack_port_name(outport_right),"alsa_pcm:out_2"); */ return(true); };
bool JackClient::setup(volatile bool* p_runFlag, uint32_t nrOfFramesInRingBuffer) { m_p_runFlag = p_runFlag; const char *server_name = NULL; jack_options_t options = JackNoStartServer; jack_status_t status; // create a jack client m_p_jackClient = jack_client_open(s_jackClientName.c_str(), options, &status, server_name); if (m_p_jackClient == NULL) { DEBUG_PRINT("jack_client_open() failed, status = 0x%2.0x", status); if (status & JackServerFailed) { DEBUG_PRINT("unable to connect to JACK server"); } return false; } if (status & JackServerStarted) { DEBUG_PRINT("jack server up and running"); } if (status & JackNameNotUnique) { char* client_name = jack_get_client_name(m_p_jackClient); DEBUG_PRINT("unique name `%s' assigned", client_name); } // create ringbuffer m_p_ringBuffer = jack_ringbuffer_create(sizeof(jack_default_audio_sample_t) * jack_get_buffer_size(m_p_jackClient) * nrOfFramesInRingBuffer); if (m_p_ringBuffer == NULL) { DEBUG_PRINT("failed to create ringbuffer"); return false; } // setup callbacks int check; if ((check = jack_set_process_callback(m_p_jackClient, JackClient::processJackCallback, this))) { return false; } jack_on_shutdown(m_p_jackClient, JackClient::shutdownJackCallback, this); if ((check = jack_set_port_connect_callback(m_p_jackClient, JackClient::connectionJackCallback, this))) { return false; } if (!registerPorts()) { return false; } return true; }
void jack_client_init(long rb_size) { jack_client_t *client; char *client_name; double aFreq = 440.0; pthread_attr_t attr; fftInit(latency); /* Initialize tuning */ int i; freqs[0]=aFreq; lfreqs[0]=log(freqs[0]); for (i=1; i<12; i++) { freqs[i] = freqs[i-1] * D_NOTE; lfreqs[i] = lfreqs[i-1] + LOG_D_NOTE; } client_name = g_strdup_printf("show_note_%u", getpid()); if ((client = jack_client_new(client_name)) == 0) { fprintf (stderr, "jack server not running?\n"); exit (1); } /* try and run detect_note thread in realtime */ pthread_attr_init(&attr); /* pthread_attr_setscope(&attr, PTHREAD_EXPLICIT_SCHED); pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); */ memset (&thread_info, 0, sizeof (thread_info)); thread_info.rb_size = rb_size; thread_info.client = client; thread_info.channels = 1; thread_info.can_process = 0; if (pthread_create (&thread_info.thread_id, &attr, detect_note, &thread_info)) { fprintf(stderr, "Error creating realtime thread!\n"); abort(); } jack_set_process_callback(client, jack_process, &thread_info); jack_on_shutdown(client, jack_shutdown, &thread_info); rate = jack_get_sample_rate(client); if (jack_activate(client)) { fprintf(stderr, "cannot activate client"); } }
aubio_jack_t * new_aubio_jack(uint_t ichan, uint_t ochan, aubio_process_func_t callback) { aubio_jack_t * jack_setup = aubio_jack_alloc (ichan, ochan); uint_t i; char * client_name = "aubio"; char name[64]; /* initial jack client setup */ if ((jack_setup->client = jack_client_new (client_name)) == 0) { AUBIO_ERR ("jack server not running?\n"); AUBIO_QUIT(AUBIO_FAIL); } /* set callbacks */ jack_set_process_callback (jack_setup->client, aubio_jack_process, (void*) jack_setup); jack_on_shutdown (jack_setup->client, aubio_jack_shutdown, (void*) jack_setup); /* register jack output ports */ for (i = 0; i < ochan; i++) { AUBIO_SPRINTF(name, "out_%d", i+1); AUBIO_MSG("%s\n", name); if ((jack_setup->oports[i] = jack_port_register (jack_setup->client, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0)) == 0) { AUBIO_ERR("failed registering output port \"%s\"!\n", name); jack_client_close (jack_setup->client); AUBIO_QUIT(AUBIO_FAIL); } } /* register jack input ports */ for (i = 0; i < ichan; i++) { AUBIO_SPRINTF(name, "in_%d", i+1); AUBIO_MSG("%s\n", name); if ((jack_setup->iports[i] = jack_port_register (jack_setup->client, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0)) == 0) { AUBIO_ERR("failed registering input port \"%s\"!\n", name); jack_client_close (jack_setup->client); AUBIO_QUIT(AUBIO_FAIL); } } /* set processing callback */ jack_setup->callback = callback; return jack_setup; }
bool SoundDevice::open(bool read, bool write) { // notice("detecting sound device"); #ifdef HAVE_JACK // we try to open up a jack client jack_sample_size = sizeof(jack_default_audio_sample_t); if(!jack) // check if it is not allready on if( (jack_client = jack_client_new("MuSE")) !=0 ) { notice("jack audio daemon detected"); act("hooking in/out sound channels"); warning("this feature is still experimental and won't work!"); warning("you need to stop jack and free the audio card"); jack = true; jack_samplerate = jack_get_sample_rate(jack_client); jack_set_process_callback(jack_client, dev_jack_process, this); jack_on_shutdown(jack_client,dev_jack_shutdown,this); jack_in_pipe = new Pipe(); jack_in_pipe->set_output_type("copy_float_to_int16"); jack_in_pipe->set_block(false,true); jack_out_pipe = new Pipe(); jack_out_pipe->set_input_type("copy_int16_to_float"); jack_in_pipe->set_block(true,false); // open the jack input channel jack_in_port = jack_port_register(jack_client, "capture", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); // open the jack output channel jack_out_port = jack_port_register(jack_client, "playback", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); jack_activate(jack_client); return true; } #endif if( ! output(write) ) return false; if(info_output) func("output device: %s",info_output->name); else error("output device not available"); if( ! input(read) ) return false; if(info_input) func("input device: %s",info_input->name); else error("input device not available"); return true; }
int Server_jack_start(Server *self) { PyoJackBackendData *be_data = (PyoJackBackendData *) self->audio_be_data; jack_set_process_callback(be_data->jack_client, jack_callback, (void *) self); if (jack_activate(be_data->jack_client)) { Server_error(self, "Jack error: cannot activate jack client.\n"); jack_client_close(be_data->jack_client); Server_shut_down(self); return -1; } Server_jack_autoconnect(self); return 0; }
int connect_to_jack(char *_str,int stereo) { if (debug) fprintf(stderr,"connect_to_jack(%s)",_str); if ((client=jack_client_open(_str,0,NULL)) == 0) { if (debug) fprintf (stderr, " [FAIL]\n"); return 1; } else if (debug) fprintf(stderr," [OK]\n"); jack_buf_size=jack_get_buffer_size(client); if (debug) fprintf(stderr,"jack buf_size=%lu\n",(unsigned long)jack_buf_size); jack_sample_rate=jack_get_sample_rate(client); if (debug) fprintf(stderr,"jack rate=%lu\n",(unsigned long)jack_sample_rate); if ((!jack_buf_size) || (!jack_sample_rate)) { fprintf(stderr,"bad buf_size or sample rate!\n"); exit(13); } if (stereo) jack_set_process_callback(client,output_mix_frame_stereo,0); else jack_set_process_callback(client,output_mix_frame_mono,0); jack_on_shutdown(client,jack_shutdown,0); // zero out audio buffers memset(audio_inp,0,sizeof(audio_inp)); memset(audio_out,0,sizeof(audio_out)); memset(mmdata,0,sizeof(mmdata)); audio_ird=(0-fft_size/2+MAX_SFRAG_SIZE)%MAX_SFRAG_SIZE; if (debug) printf("AUDIO LAG IN: audio_ird=%d = %d samples\n",audio_ird,fft_size/2); audio_ord=(0-fft_size/4+MAX_SFRAG_SIZE)%MAX_SFRAG_SIZE; if (debug) printf("AUDIO LAG OUT: audio_ord=%d = %d samples\n",audio_ord,fft_size/4); audio_roff=fft_size/2; if (debug) printf("AUDIO LAG REC: audio_roff=%d samples\n",audio_roff); load_data_window(audio_data_window); return 0; }
void init_jack (void) { int err; #ifdef WITH_LASH lash_event_t *event; #endif jack_client = jack_client_open(PROGRAM_NAME, JackNullOption, NULL); if (jack_client == NULL) { g_critical("Could not connect to the JACK server; run jackd first?"); exit(EX_UNAVAILABLE); } #ifdef WITH_LASH event = lash_event_new_with_type(LASH_Client_Name); // assert(event); /* Documentation does not say anything about return value. */ lash_event_set_string(event, jack_get_client_name(jack_client)); lash_send_event(lash_client, event); lash_jack_client_name(lash_client, jack_get_client_name(jack_client)); #endif err = jack_set_process_callback(jack_client, process_callback, 0); if (err) { g_critical("Could not register JACK process callback."); exit(EX_UNAVAILABLE); } /* * The above is pretty close to COMMON CODE. */ input_port = jack_port_register ( jack_client, INPUT_PORT_NAME, JACK_DEFAULT_MIDI_TYPE, JackPortIsInput, 0 ); if (input_port == NULL) { g_critical("Could not register JACK input port."); exit(EX_UNAVAILABLE); } if (jack_activate(jack_client)) { g_critical("Cannot activate JACK client."); exit(EX_UNAVAILABLE); } }
/** * This required entry point is called after the client is loaded by * jack_internal_client_load(). * * @param client pointer to JACK client structure. * @param load_init character string passed to the load operation. * * @return 0 if successful; otherwise jack_finish() will be called and * the client terminated immediately. */ int jack_initialize (jack_client_t *client, const char *load_init) { port_pair_t *pp = malloc (sizeof (port_pair_t)); const char **ports; if (pp == NULL) return 1; /* heap exhausted */ jack_set_process_callback (client, inprocess, pp); /* create a pair of ports */ pp->input_port = jack_port_register (client, "input", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); pp->output_port = jack_port_register (client, "output", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); /* join the process() cycle */ jack_activate (client); ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical|JackPortIsOutput); if (ports == NULL) { fprintf(stderr, "no physical capture ports\n"); return 1; /* terminate client */ } if (jack_connect (client, ports[0], jack_port_name (pp->input_port))) { fprintf (stderr, "cannot connect input ports\n"); } free (ports); ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical|JackPortIsInput); if (ports == NULL) { fprintf(stderr, "no physical playback ports\n"); return 1; /* terminate client */ } if (jack_connect (client, jack_port_name (pp->output_port), ports[0])) { fprintf (stderr, "cannot connect output ports\n"); } free (ports); return 0; /* success */ }
void AudioReader::start(char* llabel = "cloop:capture_1", char* rlabel = "cloop:capture_2") { if(running) return; running = true; // set up the history head = 0; history_length = 0; sounds = new Sound[max_history_length]; if((client = jack_client_open("AudioReader", JackNoStartServer, NULL)) == 0){ fprintf(stderr, "jack server not running?\n"); exit(EXIT_FAILURE); } pthread_mutex_lock(&reading_mutex); // jack_client_open() links the process() callback and if process() runs before the ports are connected this will break jack_set_process_callback(client, audio_reader_process_callback, (void *) this); jack_on_shutdown(client, audio_reader_shutdown_callback, this); if (jack_activate(client)) { fprintf(stderr, "Cannot activate client"); exit(EXIT_FAILURE); } // register the ports to capture data on, in this case set with the JACK audio GUI output_left = jack_port_by_name(client, llabel); output_right = jack_port_by_name(client, rlabel); if (output_left == NULL || output_right == NULL) { fprintf(stderr, "Can't get ports from Jack server"); jack_client_close(client); exit(EXIT_FAILURE); } // allocate space for the main audio buffer that will continuously be written to buffer = new jack_default_audio_sample_t[nports * maxframes]; // register this program's loopback ports input_left = jack_port_register(client, "AudioReaderLeft", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); input_right = jack_port_register(client, "AudioReaderRight", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); if (input_left == 0 || input_right == 0) { fprintf(stderr, "Cannot register loopback port\n"); stop(); exit(EXIT_FAILURE); } // create the new connections to route all audio to system out through this program int left_con = jack_connect(client, jack_port_name(output_left), jack_port_name(input_left)); int right_con = jack_connect(client, jack_port_name(output_right), jack_port_name(input_right)); if (left_con != 0 || right_con != 0) { fprintf(stderr, "Cannot connect input to output\n"); stop(); exit(EXIT_FAILURE); } pthread_mutex_unlock(&reading_mutex); // allocate the space for the fft if ((cfg = kiss_fftr_alloc(maxframes, 0, NULL, NULL)) == NULL) fprintf(stderr, "Out of memory!\n"); }
int main(int argc, char *argv[]) { jack_client_t *client; const char **ports; const char* name = (argc>1) ? argv[1] : "StereoDecoder"; char s[63]; int i; if ((client = jack_client_open(name, JackNullOption, NULL)) == 0) { fprintf(stderr, "jack server not running?\n"); return 1; } jack_set_process_callback(client, process, 0); jack_on_shutdown(client, jack_shutdown, 0); for(i=0; i<INPORTS; i++) { sprintf(s, "input_%d", i); input_ports[i] = jack_port_register(client, s, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); } for(i=0; i<OUTPORTS; i++) { sprintf(s, "output_%d", i); output_ports[i] = jack_port_register(client, s, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); } if (jack_activate(client)) { fprintf(stderr, "cannot activate client"); return 1; } if ((ports = jack_get_ports(client, NULL, NULL, JackPortIsPhysical|JackPortIsInput)) == NULL) { fprintf(stderr, "Cannot find any physical playback ports\n"); return 1; } for(i=0; i<OUTPORTS; i++) { if (ports[i]==NULL || jack_connect(client, jack_port_name(output_ports[i]), ports[i])) { fprintf(stderr, "cannot connect output ports\n"); } } free(ports); while (1) { sleep(10); } }
//------------------------------------------------------------------------------------------------------- bool JackVST::CheckClient() { if (JackVST::fJackClient) { return true; }else{ JackVST::fJackClient = jack_client_new("JACK-ASinsert"); if (JackVST::fJackClient){ jack_set_process_callback(JackVST::fJackClient,JackProcess,NULL); return true; }else{ return false; } } }
MidiJack::MidiJack() : MidiClientRaw(), m_input_port( NULL ), m_output_port( NULL ), m_quit( false ) { // if jack is used for audio then we share the connection // AudioJack creates and maintains the jack connection // and also handles the callback, we pass it our address // so that we can also process during the callback if(Engine::mixer()->audioDevName() == AudioJack::name() ) { // if a jack connection has been created for audio we use that m_jackAudio = dynamic_cast<AudioJack*>(Engine::mixer()->audioDev())->addMidiClient(this); }else{ m_jackAudio = NULL; m_jackClient = jack_client_open(probeDevice().toLatin1().data(), JackNoStartServer, NULL); if(m_jackClient) { jack_set_process_callback(m_jackClient, JackMidiProcessCallback, this); jack_on_shutdown(m_jackClient, JackMidiShutdown, 0); } } if(jackClient()) { /* jack midi out not implemented JackMidiWrite and sendByte needs to be functional before enabling this m_output_port = jack_port_register( jackClient(), "MIDI out", JACK_DEFAULT_MIDI_TYPE, JackPortIsOutput, 0); */ m_input_port = jack_port_register( jackClient(), "MIDI in", JACK_DEFAULT_MIDI_TYPE, JackPortIsInput, 0); if(jack_activate(jackClient()) == 0 ) { // only start thread, if we have an active jack client. start( QThread::LowPriority ); } } }
static int _jack_init(prog_t *handle, const char *id) { jack_options_t opts = JackNullOption | JackNoStartServer; if(handle->server_name) opts |= JackServerName; if(handle->session_id) opts |= JackSessionID; jack_status_t status; if(!(handle->client = jack_client_open(id, opts, &status, handle->server_name ? handle->server_name : handle->session_id, handle->server_name ? handle->session_id : NULL))) { return -1; } //TODO check status // set client pretty name #if defined(JACK_HAS_METADATA_API) jack_uuid_t uuid; const char *client_name = jack_get_client_name(handle->client); const char *uuid_str = jack_get_uuid_for_client_name(handle->client, client_name); if(uuid_str) jack_uuid_parse(uuid_str, &uuid); else jack_uuid_clear(&uuid); if(!jack_uuid_empty(uuid)) { jack_set_property(handle->client, uuid, JACK_METADATA_PRETTY_NAME, "Synthpod", "text/plain"); } #endif // set client process callback if(jack_set_process_callback(handle->client, _process, handle)) return -1; if(jack_set_session_callback(handle->client, _session, handle)) return -1; if(jack_set_sample_rate_callback(handle->client, _sample_rate, handle)) return -1; if(jack_set_buffer_size_callback(handle->client, _buffer_size, handle)) return -1; jack_on_shutdown(handle->client, _shutdown, handle); jack_set_xrun_callback(handle->client, _xrun, handle); return 0; }