示例#1
0
static int
process_info_connect_jack (process_info_t * procinfo, ui_t * ui)
{
  _update_status ( _("Connecting to JACK server with client name '%s'"), jack_client_name );

#if HAVE_JACK_SESSION
  if (strlen (session_uuid->str))
    procinfo->jack_client = jack_client_open (jack_client_name, JackSessionID, NULL, session_uuid->str);
  else
#endif
    procinfo->jack_client = jack_client_open (jack_client_name, JackNullOption, NULL);

  if (!procinfo->jack_client)
        return -1;
  
  _update_status ( _status_cb_data, _("Connected to JACK server") );

  jack_set_process_callback (procinfo->jack_client, process, procinfo);
  jack_on_shutdown (procinfo->jack_client, jack_shutdown_cb, ui); /* FIXME: need a generic callback for this, too */

#if HAVE_JACK_SESSION
  if( jack_set_session_callback )
	  jack_set_session_callback (procinfo->jack_client, jack_session_cb_aux, ui);
#endif
                                            
  return 0;
}
示例#2
0
PRIVATE void clock_handler(AClock *clock, AClockReason reason) {

    switch (reason) {
	case CLOCK_DISABLE:
	    jack_deactivate( jack_client );
	    break;

	case CLOCK_ENABLE:
	    jack_set_process_callback( jack_client, (JackProcessCallback) process_callback, NULL ); 
	    jack_on_shutdown (jack_client, jack_shutdown, 0);

	    jack_activate( jack_client );

	    lash_event_t *event;
	    if( lash_enabled( galan_lash_get_client() ) ) {
		event = lash_event_new_with_type(LASH_Jack_Client_Name);
		lash_event_set_string(event, jack_get_client_name( jack_client ) );
		lash_send_event( galan_lash_get_client(), event);
	    }
	    break;

	default:
	    g_message("Unreachable code reached (jack_output)... reason = %d", reason);
	    break;
    }
}
示例#3
0
文件: freewheel.c 项目: johnsen/jack2
int 
main (int argc, char *argv[])
{
	parse_arguments (argc, argv);

	/* become a JACK client */
	if ((client = jack_client_open ("freewheel", JackNullOption, NULL)) == 0) {
		fprintf (stderr, "JACK server not running?\n");
		exit(1);
	}

	signal (SIGQUIT, signal_handler);
	signal (SIGTERM, signal_handler);
	signal (SIGHUP, signal_handler);
	signal (SIGINT, signal_handler);

	jack_on_shutdown (client, jack_shutdown, 0);

	if (jack_set_freewheel (client, onoff)) {
		fprintf (stderr, "failed to reset freewheel mode\n");
	}

	jack_client_close(client);
	return 0;
}
示例#4
0
文件: pyjack.c 项目: egasimus/pyjack
// Attempt to connect to the Jack server
static PyObject* attach(PyObject* self, PyObject* args)
{
    char* cname;
    if (! PyArg_ParseTuple(args, "s", &cname))
        return NULL;

    pyjack_client_t * client = self_or_global_client(self);
    if(client->pjc != NULL) {
        PyErr_SetString(JackUsageError, "A connection is already established.");
        return NULL;
    }

    jack_status_t status;
    client->pjc = jack_client_open(cname, JackNoStartServer, &status);
    if(client->pjc == NULL) {
        //TODO check status
        PyErr_SetString(JackNotConnectedError, "Failed to connect to Jack audio server.");
        return NULL;
    }

    jack_on_shutdown(client->pjc, pyjack_shutdown, client);
    signal(SIGHUP, pyjack_hangup); // TODO: This just works with global clients

    if(jack_set_process_callback(client->pjc, pyjack_process, client) != 0) {
        PyErr_SetString(JackError, "Failed to set jack process callback.");
        return NULL;
    }

    if(jack_set_buffer_size_callback(client->pjc, pyjack_buffer_size_changed, client) != 0) {
        PyErr_SetString(JackError, "Failed to set jack buffer size callback.");
        return NULL;
    }

    if(jack_set_sample_rate_callback(client->pjc, pyjack_sample_rate_changed, client) != 0) {
        PyErr_SetString(JackError, "Failed to set jack sample rate callback.");
        return NULL;
    }

    if(jack_set_port_registration_callback(client->pjc, pyjack_port_registration, client) != 0) {
        PyErr_SetString(JackError, "Failed to set jack port registration callback.");
        return NULL;
    }

    if(jack_set_graph_order_callback(client->pjc, pyjack_graph_order, client) != 0) {
        PyErr_SetString(JackError, "Failed to set jack graph order callback.");
        return NULL;
    }

    if(jack_set_xrun_callback(client->pjc, pyjack_xrun, client) != 0) {
        PyErr_SetString(JackError, "Failed to set jack xrun callback.");
        return NULL;
    }

    // Get buffer size
    client->buffer_size = jack_get_buffer_size(client->pjc);

    // Success!
    Py_INCREF(Py_None);
    return Py_None;
}
示例#5
0
文件: bufsize.c 项目: HI-CARL/jack2
int main(int argc, char *argv[])
{
	int rc;

	parse_arguments(argc, argv);

	/* become a JACK client */
    if ((client = jack_client_open(package, JackNullOption, NULL)) == 0) {
		fprintf(stderr, "JACK server not running?\n");
		exit(1);
	}

#ifndef WIN32
	signal(SIGQUIT, signal_handler);
	signal(SIGHUP, signal_handler);
#endif
	signal(SIGTERM, signal_handler);
	signal(SIGINT, signal_handler);

	jack_on_shutdown(client, jack_shutdown, 0);

	if (just_print_bufsize) {
		fprintf(stdout, "buffer size = %d  sample rate = %d\n", jack_get_buffer_size(client), jack_get_sample_rate(client));
		rc=0;
	}
	else
	{
		rc = jack_set_buffer_size(client, nframes);
		if (rc)
			fprintf(stderr, "jack_set_buffer_size(): %s\n", strerror(rc));
	}
	jack_client_close(client);

	return rc;
}
示例#6
0
    String open (const BigInteger& inputChannels, const BigInteger& outputChannels,
                 double /* sampleRate */, int /* bufferSizeSamples */)
    {
        jack_Log ("opening client");
        lastError = client.open (KV_JACK_NAME, 0);
        if (lastError.isNotEmpty())
        {
            jack_Log (lastError);
            return lastError;
        }

        DBG("num inputs: " << inputChannels.getHighestBit());
        DBG("num outputs: " << outputChannels.getHighestBit());


        jack_on_shutdown (client, JackDevice::shutdownCallback, this);
        jack_set_error_function (JackDevice::errorCallback);
        jack_set_port_connect_callback (client, JackDevice::portConnectCallback, this);
        jack_set_process_callback (client, JackDevice::processCallback, this);
        jack_set_thread_init_callback (client, JackDevice::threadInitCallback, this);
        jack_set_port_registration_callback (client, JackDevice::_portRegistration, this);

        client.registerPort ("audio_1", Jack::audioPort, JackPortIsOutput);
        client.registerPort ("audio_2", Jack::audioPort, JackPortIsOutput);

        return lastError;
    }
示例#7
0
文件: jack.c 项目: huuh/huuwax
static int start_jack_client(void)
{
    const char *server_name;
    jack_status_t status;

    client = jack_client_open("xwax", JackNullOption, &status, &server_name);
    if (client == NULL) {
        if (status & JackServerFailed)
            fprintf(stderr, "JACK: Failed to connect\n");
        else
            fprintf(stderr, "jack_client_open: Failed (0x%x)\n", status);
        return -1;
    }

    if (jack_set_process_callback(client, process_callback, NULL) != 0) {
        fprintf(stderr, "JACK: Failed to set process callback\n");
        return -1;
    }

    jack_on_shutdown(client, shutdown_callback, NULL);

    rate = jack_get_sample_rate(client);
    fprintf(stderr, "JACK: %dHz\n", rate);

    return 0;
}
示例#8
0
// ========================
// = INITIALIZE AUDIO I/O =
// ========================
void initJackAudioIO() {
    // Create client:
    if((client = jack_client_open("xooky_nabox", JackNullOption, NULL)) == NULL) {
        std::cout << "jack server not running?\n";
        exit(1);
    }

    // Register callbacks:
    jack_on_shutdown(client, jack_shutdown, 0);
    jack_set_process_callback(client, process, 0);

    // Register io ports:
    portO1 = jack_port_register(client, "out1", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
    portO2 = jack_port_register(client, "out2", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
    portI1 = jack_port_register(client, "in1", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
    portI2 = jack_port_register(client, "in2", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);

    // Get sample rate from server
    sampleRate = jack_get_sample_rate(client);
    std::cout << "Sample rate:" << sampleRate << "\n";

    //Go!
    if (jack_activate (client)) {
        std::cout << "Cannot activate client";
        exit(1);
    }

}
示例#9
0
DspAudioJackOut::DspAudioJackOut( DspOutRtp *inrtp, const QString &name )
{
	jack_clientName = name;
	audio_stereo = false;
	input = inrtp;

	if ((jack_client = jack_client_new( jack_clientName )) == 0 ) {
		printf( "CallAudioJackOut: Error, jack server not running?\n" );
		return;
	}
	
	jack_thread_info_t thread_info;
	
	thread_info.client = jack_client;
	thread_info.channels = 1;
	thread_info.ready = 0;
	thread_info.running = 0;
	jack_set_process_callback( jack_client, jack_callaudio_process, &thread_info );
	jack_on_shutdown( jack_client, jack_callaudio_shutdown, &thread_info );

	if (jack_activate( jack_client )) {
		fprintf (stderr, "cannot activate client");
	}
	setup_port_out( 1, "alsa_pcm:playback_1", &thread_info);

}
示例#10
0
// Device initialization method.
bool qmidinetJackMidiDevice::open ( const QString& sClientName, int iNumPorts )
{
	// Close if already open.
	close();

	// Open new JACK client...
	const QByteArray aClientName = sClientName.toLocal8Bit();
	m_pJackClient = jack_client_open(
		aClientName.constData(), JackNullOption, NULL);
	if (m_pJackClient == NULL)
		return false;

	m_nports = iNumPorts;

	int i;

	// Create duplex ports.
	m_ppJackPortIn  = new jack_port_t * [m_nports];
	m_ppJackPortOut = new jack_port_t * [m_nports];

	for (i = 0; i < m_nports; ++i) {
		m_ppJackPortIn[i] = NULL;
		m_ppJackPortOut[i] = NULL;
	}

	const QString sPortNameIn("in_%1");
	const QString sPortNameOut("out_%1");
	for (i = 0; i < m_nports; ++i) {
		m_ppJackPortIn[i] = jack_port_register(m_pJackClient,
			sPortNameIn.arg(i + 1).toLocal8Bit().constData(),
			JACK_DEFAULT_MIDI_TYPE,
			JackPortIsInput, 0);
		m_ppJackPortOut[i] = jack_port_register(m_pJackClient,
			sPortNameOut.arg(i + 1).toLocal8Bit().constData(),
			JACK_DEFAULT_MIDI_TYPE,
			JackPortIsOutput, 0);
	}

	// Create transient buffers.
	m_pJackBufferIn  = jack_ringbuffer_create(1024 * m_nports);
	m_pJackBufferOut = jack_ringbuffer_create(1024 * m_nports);

	// Prepare the queue sorter stuff...
	m_pQueueIn = new qmidinetJackMidiQueue(1024 * m_nports, 8);
	
	// Set and go usual callbacks...
	jack_set_process_callback(m_pJackClient,
		qmidinetJackMidiDevice_process, this);
	jack_on_shutdown(m_pJackClient,
		qmidinetJackMidiDevice_shutdown, this);

	jack_activate(m_pJackClient);

	// Start listener thread...
	m_pRecvThread = new qmidinetJackMidiThread();
	m_pRecvThread->start();

	// Done.
	return true;
}
示例#11
0
文件: jack.c 项目: lgarrido/xjadeo
void open_jack(void ) 
{
	if (jack_client) {
		fprintf (stderr, "xjadeo is alredy connected to jack.\n");
		return;
	}

	int i = 0;
	do {
		snprintf(jackid,16,"xjadeo-%i",i);
#ifdef JACK_SESSION
		if (jack_uuid) 
			jack_client = jack_client_open (jackid, JackUseExactName|JackSessionID, NULL, jack_uuid);
		else
#endif
		  jack_client = jack_client_open (jackid, JackUseExactName, NULL);
	} while (jack_client == 0 && i++<16);

	if (!jack_client) {
		fprintf(stderr, "could not connect to jack server.\n");
	} else { 
#ifdef JACK_SESSION
		jack_set_session_callback (jack_client, jack_session_cb, NULL);
#endif
#ifndef HAVE_WINDOWS
		jack_on_shutdown (jack_client, jack_shutdown, 0);
		jack_activate(jack_client);
#endif
		if (!want_quiet) 
			fprintf(stdout, "connected as jack client '%s'\n",jackid);
#ifdef HAVE_LASH
		lash_jack_client_name(lash_client, jackid);
#endif
	}
}
示例#12
0
文件: scope.c 项目: UIKit0/openlase-1
int main (int argc, char *argv[])
{
	jack_client_t *client;
	char jack_client_name[] = "scope";
	jack_status_t jack_status;
	jack_options_t  jack_options = JackNullOption;		

	if ((client = jack_client_open(jack_client_name, jack_options, &jack_status)) == 0) {
		fprintf (stderr, "jack server not running?\n");
		return 1;
	}

	jack_set_process_callback (client, process, 0);
	jack_set_buffer_size_callback (client, bufsize, 0);
	jack_set_sample_rate_callback (client, srate, 0);
	jack_on_shutdown (client, jack_shutdown, 0);

	in_l = jack_port_register (client, "in_l", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
	in_r = jack_port_register (client, "in_r", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
	out_x = jack_port_register (client, "out_x", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
	out_y = jack_port_register (client, "out_y", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
	out_w = jack_port_register (client, "out_w", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);

	if (jack_activate (client)) {
		fprintf (stderr, "cannot activate client");
		return 1;
	}

	while (1)
		sleep(1);
	jack_client_close (client);
	exit (0);
}
示例#13
0
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;

}
示例#14
0
文件: jack.c 项目: GerryKurz/Open-AVB
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;
}
示例#15
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;
}
示例#16
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");
}
示例#17
0
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;
}
示例#18
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;
}
示例#19
0
int main(int argc, char *argv[]) {
	/* try to become a client of the JACK server */
	int c;

	while ((c = getopt(argc, argv, "a:p:f:")) != -1)
		switch (c) {
		case 'a':
			udp_ip = optarg;
			break;
		case 'p':
			udp_port = atoi(optarg);
			break;
		case 'f':
			framerate_out=atoi(optarg);
			break;
		default:
			abort();
			break;
		}

	framerate_out_delay=(int)(((float)1/(float)framerate_out)*(float)1000000);
	printf("Starting..\n");

	if ((client = jack_client_open("showtime", JackNullOption, NULL)) == 0) {
		fprintf(stderr, "JACK server not running?\n");
		return 1;
	}

	signal(SIGQUIT, signal_handler);
	signal(SIGTERM, signal_handler);
	signal(SIGHUP, signal_handler);
	signal(SIGINT, signal_handler);

	/* tell the JACK server to call `jack_shutdown()' if
	 it ever shuts down, either entirely, or if it
	 just decides to stop calling us.
	 */

	jack_on_shutdown(client, jack_shutdown, 0);

	/* tell the JACK server that we are ready to roll */

	if (jack_activate(client)) {
		fprintf(stderr, "cannot activate client");
		return 1;
	}

	while (1) {
		usleep(framerate_out_delay);
		showtime();
	}

	jack_client_close(client);
	exit(0);
}
示例#20
0
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 ();
}
示例#21
0
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;
}
示例#22
0
JackLayer::JackLayer(const AudioPreference &p) :
    AudioLayer(p),
    captureClient_(nullptr),
    playbackClient_(nullptr),
    out_ports_(),
    in_ports_(),
    out_ringbuffers_(),
    in_ringbuffers_(),
    ringbuffer_thread_(),
    //workerAlive_(false),
    ringbuffer_thread_mutex_(),
    data_ready_(),
    playbackBuffer_(0, audioFormat_),
    playbackFloatBuffer_(),
    captureBuffer_(0, audioFormat_),
    captureFloatBuffer_(),
    hardwareBufferSize_(0),
    mainRingBuffer_(Manager::instance().getRingBufferPool().getRingBuffer(RingBufferPool::DEFAULT_ID))
{
    playbackClient_ = jack_client_open(PACKAGE_NAME,
            (jack_options_t) (JackNullOption | JackNoStartServer), NULL);
    if (!playbackClient_)
        throw std::runtime_error("Could not open JACK client");

    captureClient_ = jack_client_open(PACKAGE_NAME,
            (jack_options_t) (JackNullOption | JackNoStartServer), NULL);
    if (!captureClient_)
        throw std::runtime_error("Could not open JACK client");

    jack_set_process_callback(captureClient_, process_capture, this);
    jack_set_process_callback(playbackClient_, process_playback, this);

    createPorts(playbackClient_, out_ports_, true, out_ringbuffers_);
    createPorts(captureClient_, in_ports_, false, in_ringbuffers_);

    const auto playRate = jack_get_sample_rate(playbackClient_);
    const auto captureRate = jack_get_sample_rate(captureClient_);
    if (playRate != captureRate)
        RING_ERR("Mismatch between capture rate %u and playback rate %u", playRate, captureRate);

    hardwareBufferSize_ = jack_get_buffer_size(playbackClient_);

    auto update_buffer = [] (AudioBuffer &buf, size_t size, unsigned rate, unsigned nbChannels) {
        buf.setSampleRate(rate);
        buf.resize(size);
        buf.setChannelNum(nbChannels);
    };

    update_buffer(playbackBuffer_, hardwareBufferSize_, playRate, out_ports_.size());
    update_buffer(captureBuffer_, hardwareBufferSize_, captureRate, in_ports_.size());

    jack_on_shutdown(playbackClient_, onShutdown, this);
}
示例#23
0
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);
};
示例#24
0
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");
	}
}
示例#25
0
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;
}
示例#26
0
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;
}
示例#27
0
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);
  }
}
示例#29
0
文件: MidiJack.cpp 项目: BaraMGB/lmms
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 );
		}
	}
}
示例#30
0
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;
}