Ejemplo n.º 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;
}
Ejemplo n.º 2
0
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
	}
}
Ejemplo n.º 3
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");
    }
Ejemplo n.º 4
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);
}
Ejemplo n.º 5
0
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;
}
bool JackAudioInterface::open_jack_client()
{
    // open a client connection to the JACK server
    jack_status_t status;
    m_client = jack_client_open(m_clientName, JackUseExactName, &status);
    if (m_client == NULL)
    {
        qWarning("JackAudioInterface::open_jack_client(): jack_client_open() failed, status = 0x%2.0x", status);
        if (status & JackServerFailed)
        {
            qWarning("JackAudioInterface::open_jack_client(): Unable to connect to JACK server");
        }
        return false;
    }
    if (status & JackServerStarted)
    {
        qDebug("JackAudioInterface::open_jack_client(): Started new JACK server");
    }
    if (status & JackNameNotUnique)
    {
        qWarning("JackAudioInterface::open_jack_client(): unique client name `%s' assigned", jack_get_client_name(m_client));
        // TODO: this should actually be an error: since our client name includes our port #, we should already be unique
    }
    
    return true;
}
Ejemplo n.º 7
0
DSP::DSP()
{
  cout << "DSP()" << endl;
  
  // open the client
  client = jack_client_open ( "showcase-2", JackNullOption , 0 , 0 );
  
  // register two output ports
  out_left  = jack_port_register( client,
                                  "out_left",
                                  JACK_DEFAULT_AUDIO_TYPE,
                                  JackPortIsOutput,
                                  0 );
  
  out_right = jack_port_register( client,
                                  "out_right",
                                  JACK_DEFAULT_AUDIO_TYPE,
                                  JackPortIsOutput,
                                  0 );
  
  // register the static DSP callback
  jack_set_process_callback( client,
                             static_process,
                             static_cast<void*>(this) );
  
  // sample counter for playback
  playbackIndex = 0;
}
Ejemplo n.º 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);
    }

}
Ejemplo n.º 9
0
int main (int ac, char *av [])
{
    float          t;
    jack_status_t  s;

    jack_handle = jack_client_open ("jack_delay", JackNoStartServer, &s);
    if (jack_handle == 0)
    {
        fprintf (stderr, "Can't connect to Jack, is the server running ?\n");
        exit (1);
    }

    mtdm = mtdm_new(jack_get_sample_rate(jack_handle));

    jack_set_process_callback (jack_handle, jack_callback, 0);

    if (jack_set_latency_callback)
	    jack_set_latency_callback (jack_handle, latency_cb, 0);

    jack_capt = jack_port_register (jack_handle, "in",  JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
    jack_play = jack_port_register (jack_handle, "out", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);

    t = 1000.0f / jack_get_sample_rate (jack_handle);

    if (jack_activate (jack_handle))
    {
        fprintf(stderr, "Can't activate Jack");
        return 1;
    }

    while (1)
    {
 
    #ifdef WIN32 
        Sleep (250); 
    #else 
        usleep (250000); 
 	#endif        
        if (mtdm_resolve (mtdm) < 0) printf ("Signal below threshold...\n");
        else 
        {
            jack_nframes_t systemic_latency;

            if (mtdm->_err > 0.3) 
            {
                mtdm_invert ( mtdm );
                mtdm_resolve ( mtdm );
            }
            systemic_latency = (jack_nframes_t) floor (mtdm->_del - (capture_latency.max + playback_latency.max));

            printf ("%10.3lf frames %10.3lf ms total roundtrip latency\n\textra loopback latency: %u frames\n\tuse %u for the backend arguments -I and -O", mtdm->_del, mtdm->_del * t, 
                    systemic_latency, systemic_latency/2);
            if (mtdm->_err > 0.2) printf (" ??");
                if (mtdm->_inv) printf (" Inv");
            printf ("\n");
        }
    }

    return 0;
}
Ejemplo n.º 10
0
FXbool JackOutput::open() {
  jack = jack_client_open("gap",JackNoStartServer,NULL);
  if (jack==NULL) {
    return false;
    }
  return false;
  }
Ejemplo n.º 11
0
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;
}
Ejemplo n.º 12
0
/* connect to jack server */
static int jack_transport_connect(jack_transport_t * x)
{
	char port_name[80] = "";

	static int client = 0;
	do 
	{
		sprintf(port_name,"pure_data_jack_transport_%d",client);
		client++;
	} 
	while (((x->x_jack_client = jack_client_open(port_name,0,0)) == 0) &&
		   client < 100);
	client = 0;

	if (!x->x_jack_client)
	{
		post("jack_transport: can't connect to jack server");
		return 1;
	}

	post("jack_transport: connecting as %s", port_name);
	
	jack_activate(x->x_jack_client);
	
	return 0;
}
Ejemplo n.º 13
0
// 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;
}
int JackSimpleClient::setUp (int argc, char *argv[])
{
	LOGD("setUp argc %d", argc);
	for(int i = 0;i< argc; i++){
		LOGD("setup argv %s", argv[i]);
	}

	// You have to use argv[0] as the jack client name like below.
	jackClient = jack_client_open (argv[0], JackNullOption, NULL, NULL);
	if (jackClient == NULL) {
		return APA_RETURN_ERROR;
	}

	bufferSize = jack_get_buffer_size(jackClient);

	// init the sine table
	for(int i=0; i<bufferSize; i++ )
	{
		sineTable[i] = (float) sin( ((double)i*8/(double)bufferSize) * 2. * 3.14159265 );
	}

	jack_set_process_callback (jackClient, processSine, this);

	outPort = jack_port_register (jackClient, "out",
					  JACK_DEFAULT_AUDIO_TYPE,
					  JackPortIsOutput, 0);
	if(outPort == NULL){
		return APA_RETURN_ERROR;
	}

	return APA_RETURN_SUCCESS;
}
Ejemplo n.º 15
0
int
main (int argc, char *argv[])
{
	jack_client_t *client;
	char *my_name = strrchr(argv[0], '/');

	if (my_name == 0) {
		my_name = argv[0];
	} else {
		my_name ++;
	}

	if (argc != 2) {
		fprintf (stderr, "Usage: %s client\n", my_name);
		return 1;
	}

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

	if (jack_port_request_monitor_by_name (client, argv[1], TRUE)) {
		fprintf (stderr, "could not enable monitoring for %s\n", argv[1]);
		jack_client_close (client);
		return 1;
	}
	sleep (30);
	if (jack_port_request_monitor_by_name (client, argv[1], FALSE)) {
		fprintf (stderr, "could not disable monitoring for %s\n", argv[1]);
	}
	jack_client_close (client);
	exit (0);
}
Ejemplo n.º 16
0
    JackAudioProvider(Synth *synth, const std::string &name)
      : synth_(synth)
    {
      SampleBufferAllocator::reset();
      client_ = jack_client_open(name.c_str(), JackNoStartServer, 0);
      if (client_ == NULL) {
	throw JackClientOpenError();
      }
      std::cout << "connected to jackd as client `" << name << "`\n";
      sl::sampleRate(jack_get_sample_rate(client_));
      jack_set_sample_rate_callback(client_, jackSampleRateCallback, 0);
      sl::bufferSize(jack_get_buffer_size(client_));
      jack_set_buffer_size_callback(client_, jackBufferSizeCallback, 0);
      jack_set_process_callback(client_, jackProcessCallback, this);
      midiInPort_ = jack_port_register(client_, "midi_in", JACK_DEFAULT_MIDI_TYPE, JackPortIsInput, 0);
      std::cout << "registered midi port: midi_in\n";
      char portName[64];
      for (int i=0; i<Synth::InputBuffer::nChannels; i++) {
	snprintf(portName, sizeof(portName), "in_%u", i+1);
	inputPorts_[i] = jack_port_register(client_, portName, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
        std::cout << "registered audio port: " << portName << "\n";
      }
      for (int i=0; i<Synth::OutputBuffer::nChannels; i++) {
	snprintf(portName, sizeof(portName), "out_%u", i+1);
	outputPorts_[i] = jack_port_register(client_, portName, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
        std::cout << "registered audio port: " << portName << "\n";
      }
      for (int i=0; i<128; i++) {
        midiCtrlMap_[i] = i;
      }
      for (int i=11; i<=19; i++) {
        midiCtrlMap_[i] = i-10;
      }
      midiCtrlMap_[1] = 129; // modwheel
    }
Ejemplo n.º 17
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;
}
Ejemplo n.º 18
0
Archivo: jack.c Proyecto: 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;
}
Ejemplo n.º 19
0
int main (int argc, char* argv[]) {
  jack_client_t* client;
  char const default_name[] = "connector";

  // this is moderately retarded
  aliases[0] = (char *) malloc (jack_port_name_size());
  aliases[1] = (char *) malloc (jack_port_name_size());

  client = jack_client_open(default_name, JackNullOption, NULL);

  while (1) {
    const char **portnames;
    const char **orig;
    orig = portnames = jack_get_ports(client, "", "", 0);

    desired_connection *desired = desired_connections;
    while (desired->from_port) {
      ensure_connected(client, orig, desired);
      desired++;
    }
    printf("\n");
    sleep(5);
    jack_free(orig);
  }
}
Ejemplo n.º 20
0
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);
}
Ejemplo n.º 21
0
static void rtJack_CopyDevParams(RtJackGlobals *p, char **devName,
                                 const csRtAudioParams *parm, int isOutput)
{
    CSOUND  *csound;
    char    *s;
    size_t  nBytes;

    csound = p->csound;
    *devName = (char*) NULL;
    if (parm->devNum != 1024) {
      jack_client_t *client_;
      int           useTmpClient = 0;
      /* FIXME: a temporary JACK client is created if there is no */
      /* connection yet; this is a somewhat hackish solution... */
      if (p->client == (jack_client_t*) NULL) {
        useTmpClient = 1;
        client_ = jack_client_open(&(p->clientName[0]), JackNoStartServer, NULL);
      }
      else
        client_ = p->client;
      if (client_ != (jack_client_t*) NULL) {
        rtJack_ListPorts(csound, client_, &(p->clientName[0]), isOutput);
        if (useTmpClient)
          jack_client_close(client_);
      }
      rtJack_Error(csound, -1, Str("must specify a device name, not a number"));
    }
    if (parm->devName != NULL && parm->devName[0] != (char) 0) {
      /* NOTE: this assumes max. 999 channels (the current limit is 255) */
      nBytes = strlen(parm->devName) + 4;
      if (UNLIKELY(nBytes > (size_t) jack_port_name_size()))
        rtJack_Error(csound, -1, Str("device name is too long"));
      s = (char*) malloc(nBytes+1);
      if (UNLIKELY(s == NULL))
        rtJack_Error(csound, CSOUND_MEMORY, Str("memory allocation failure"));
      strcpy(s, parm->devName);

      *devName = s;
    }
    if (isOutput && p->inputEnabled) {
      /* full duplex audio I/O: check consistency of parameters */
      if (UNLIKELY(p->nChannels != parm->nChannels ||
                   (unsigned int)p->bufSize != parm->bufSamp_SW))
        rtJack_Error(csound, -1,
                     Str("input and output parameters are not consistent"));
      if (UNLIKELY((unsigned int)((parm->bufSamp_SW / csound->GetKsmps(csound)) *
                                  csound->GetKsmps(csound)) != parm->bufSamp_SW))
        rtJack_Error(csound, -1,
                     Str("period size (-b) must be an integer multiple of ksmps"));
    }
    p->sampleRate = (int) parm->sampleRate;
    if (UNLIKELY((float) p->sampleRate != parm->sampleRate))
      rtJack_Error(csound, -1, Str("sample rate must be an integer"));
    p->nChannels = parm->nChannels;
    p->bufSize = parm->bufSamp_SW;
    p->nBuffers = (parm->bufSamp_HW + parm->bufSamp_SW - 1) / parm->bufSamp_SW;

}
Ejemplo n.º 22
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;

}
Ejemplo n.º 23
0
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;
}
Ejemplo n.º 24
0
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;
}
Ejemplo n.º 25
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");
}
Ejemplo n.º 26
0
Archivo: ipload.c Proyecto: 7890/tools
int
main (int argc, char *argv[])
{
	jack_status_t status;

	/* parse and validate command arguments */
	if (parse_args (argc, argv))
		exit (1);		/* invalid command line */

	/* first, become a JACK client */
	client = jack_client_open (client_name, JackServerName,
				   &status, server_name);
	if (client == NULL) {
		fprintf (stderr, "jack_client_open() failed, "
			 "status = 0x%2.0x\n", status);
		if (status & JackServerFailed) {
			fprintf (stderr, "Unable to connect to JACK server\n");
		}
		exit (1);
	}

	/* then, load the internal client */
	jack_internal_client_load (client, intclient_name,
                                   (JackLoadName|JackLoadInit),
                                   &status, intclient, load_name, load_init);

        if (status & JackNameNotUnique) {
                fprintf (stderr, "unique internal client name `%s' assigned\n",
                         load_name);
                return 3;
        }

        if (status & JackFailure) {
                fprintf (stderr, "could not load %s, status = 0x%x\n",
                         client_name, status);
                return 2;
        }
        
        
	fprintf (stdout, "%s is running.\n", load_name);

	if (wait_opt) {
		/* define a signal handler to unload the client, then
		 * wait for it to exit */
		signal (SIGQUIT, signal_handler);
		signal (SIGTERM, signal_handler);
		signal (SIGHUP, signal_handler);
		signal (SIGINT, signal_handler);

		while (1) {
			sleep (1);
		}
	}

	return 0;
}
Ejemplo n.º 27
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);
}
Ejemplo n.º 28
0
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;

};
Ejemplo n.º 29
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;
}
Ejemplo n.º 30
0
void jack_init(NextFrameCb nfc)
{
	// connect to jack
	if (!(jack = jack_client_open("mousemidi", JackNoStartServer, NULL)))
		err(1, "unable to connect to jack");

	// register callbacks
	jack_on_shutdown(jack, $(void, () {
		exit(0);
	}), NULL);