bool Out_JACK::Go() { SampleRate = 0; // Create a new JACK client. JackClient = jack_client_new("Sinospan"); if(JackClient == NULL) { printf("FATAL: out_jack: Couldn't make JACK client\n"); return false; } // Associate our render function as the JACK process callback if(jack_set_process_callback(JackClient, R_pRender, (void*) this) != 0) { printf("ERROR: out_jack: Couldn't register processing callback\n"); } // Set our sample rate change handler if(jack_set_sample_rate_callback(JackClient, R_pNewSrate, (void*) this) != 0) { printf("WARNING: out_jack: Couldn't register sample rate callback.\n"); } // Make our output port JackOut1 = jack_port_register(JackClient, "Out", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); if(JackOut1 == NULL) { printf("FATAL: out_jack: Couldn't register an output port.\n"); return false; } // Get the sample rate from the JACK server. R_pNewSrate(jack_get_sample_rate(JackClient), (void*) this); // It's go-time! if(jack_activate(JackClient) != 0) { printf("ERROR: out_jack: Couldn't activate JACK client.\n"); return false; } return true; }
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); }
void jack_begin() { // try to become a client of the JACK server if ((jack_client = jack_client_new (JACK_CLIENT_NAME)) == 0) { fprintf (stderr, "jack server not running?\n"); exit(1); } }
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); };
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; }
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"); } }
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; }
//------------------------------------------------------------------------------------------------------- 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; } } }
/* jack_detect: * Detects driver presence. */ static int jack_detect(int input) { if (input) { ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text( "Input is not supported")); return FALSE; } if (!jack_client) { jack_client_name = get_config_string("sound", "jack_client_name", jack_client_name); jack_client = jack_client_new(jack_client_name); if (!jack_client) return FALSE; } return TRUE; }
gint jack_card_manager_init(SndCardManager *m, gint index) { jack_client_t *client = NULL; char* client_name; client_name=g_strdup_printf("linphone-%u", g_random_int()); if ((client = jack_client_new (client_name))!= NULL) { g_message("Found Jack Daemon"); g_free(client_name); m->cards[index]=jack_card_new(client); m->cards[index]->index=index; return 1; } else { g_free(client_name); return 0; } }
int main() { /* setup our signal handler signalled() above, so * we can exit cleanly (see end of main()) */ signal(SIGINT, signalled); /* naturally we need to become a jack client :) */ client = jack_client_new("foobar"); if (!client) { printf("couldn't connect to jack server. Either it's not running or the client name is already taken\n"); exit(1); } /* we register an output port and tell jack it's a * terminal port which means we don't * have any input ports from which we could somhow * feed our output */ port = jack_port_register(client, "output", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput|JackPortIsTerminal, 0); /* jack is callback based. That means we register * a callback function (see process() above) * which will then get called by jack once per process cycle */ jack_set_process_callback(client, process, 0); /* tell jack that we are ready to do our thing */ jack_activate(client); /* wait until this app receives a SIGINT (i.e. press * ctrl-c in the terminal) see signalled() above */ while(!quit) /* let's not waste cycles by busy waiting */ sleep(1); /* so we shall quit, eh? ok, cleanup time. otherwise * jack would probably produce an xrun * on shutdown */ jack_deactivate(client); /* shutdown cont. */ jack_client_close(client); /* done !! */ return 0; }
//------------------------------------------------------------------------ bool TJackSynchro::Open() { OSStatus err; if ((fClient = jack_client_new("JackSynchro")) == 0) { fprintf (stderr, "jack server not running?\n"); return false; } jack_set_process_callback(fClient, Process, this); jack_set_sync_callback(fClient, SyncCallback, this); jack_on_shutdown(fClient, Shutdown, 0); if (jack_activate(fClient)) { fprintf (stderr, "cannot activate client"); return false; } DBUG(("MIDIClientCreate \n")); err = MIDIClientCreate(CFSTR("JAS Sync"), NotifyProc, NULL, &fMidiClient); if (!fClient) { printf("Can not open Midi client\n"); goto error; } err = MIDIDestinationCreate(fMidiClient, CFSTR("Jack Sync In"), ReadSyncProc, this, &fDestination); if (!fDestination) { printf("Can not open create destination \n"); goto error; } DBUG(("MIDIDestinationCreate OK\n")); DBUG(("MIDISourceCreate \n")); err = MIDISourceCreate(fMidiClient, CFSTR("Jack Sync Out"), &fSource); if (!fSource) { printf("Can not open create source \n"); goto error; } return true; error: Close(); return false; }
int main (int argc, char *argv[]) { int retval; jack_client_t *client; QApplication app(argc, argv); OutputSettings settings; cfg = &settings.cfg; if ((client = jack_client_new ("output")) == 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_x = jack_port_register (client, "in_x", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); in_y = jack_port_register (client, "in_y", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); in_g = jack_port_register (client, "in_g", 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_g = jack_port_register (client, "out_g", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); out_e = jack_port_register (client, "out_e", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); if (jack_activate (client)) { fprintf (stderr, "cannot activate client"); return 1; } settings.show(); retval = app.exec(); jack_client_close (client); return retval; }
/** * Open and initialize connection to the JACK system. * * @param Parameters - optional parameters * @throws AudioOutputException on error * @see AcquireChannels() */ AudioOutputDeviceJack::AudioOutputDeviceJack(std::map<String,DeviceCreationParameter*> Parameters) : AudioOutputDevice(Parameters) { if (((DeviceCreationParameterString*)Parameters["NAME"])->ValueAsString().size() >= jack_client_name_size()) throw Exception("JACK client name too long"); if ((hJackClient = jack_client_new(((DeviceCreationParameterString*)Parameters["NAME"])->ValueAsString().c_str())) == 0) throw AudioOutputException("Seems Jack server not running."); existingJackDevices++; jack_set_process_callback(hJackClient, __libjack_process_callback, this); jack_on_shutdown(hJackClient, __libjack_shutdown_callback, this); if (jack_activate(hJackClient)) throw AudioOutputException("Jack: Cannot activate Jack client."); uiMaxSamplesPerCycle = jack_get_buffer_size(hJackClient); // create audio channels AcquireChannels(((DeviceCreationParameterInt*)Parameters["CHANNELS"])->ValueAsInt()); // finally activate device if desired if (((DeviceCreationParameterBool*)Parameters["ACTIVE"])->ValueAsBool()) Play(); }
int main (int argc, char *argv[]) { if ((client = jack_client_new ("simulator")) == 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_x = jack_port_register (client, "in_x", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); in_y = jack_port_register (client, "in_y", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); in_g = jack_port_register (client, "in_g", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH); glutInitWindowSize(640, 640); glutInitWindowPosition(0, 0); window = glutCreateWindow("OpenLase Simulator"); glutDisplayFunc(&draw_gl); glutIdleFunc(&draw_gl); glutReshapeFunc(&resize_gl); glutKeyboardFunc(&key_gl); init_gl(640, 640); if (jack_activate (client)) { fprintf (stderr, "cannot activate client"); return 1; } glutMainLoop(); return 0; }
int driver_jack_open_vio (struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh, struct roar_stream_server * sstream) { struct driver_jack * self; // we are not FH Safe, return error if fh != -1: if ( fh != -1 ) return -1; // set up VIO: memset(inst, 0, sizeof(struct roar_vio_calls)); inst->read = driver_jack_read; inst->write = driver_jack_write; inst->lseek = NULL; // no seeking on this device inst->nonblock = driver_jack_nonblock; inst->sync = driver_jack_sync; inst->ctl = driver_jack_ctl; inst->close = driver_jack_close; // set up internal struct: if ( (self = roar_mm_malloc(sizeof(struct driver_jack))) == NULL ) return -1; memset(self, 0, sizeof(struct driver_jack)); inst->inst = self; if ( (self->client = jack_client_new("roard")) == NULL ) { roar_mm_free(self); return -1; } // return -1 on error or 0 on no error. return 0; }
int engine_jack_initialize(engine_t* engine){ if (!engine->device_name){ if (!(engine->device_name = strdup("soundtank"))){ printf("memory error allocating string\n"); return -1; } } /*try to become a client of the JACK server*/ if ((client = jack_client_new(engine->device_name)) == 0){ printf ("jack engine error: couldn't make jack client, jack server not running?\n"); return -1; } /*get sample rate*/ engine->sample_rate = jack_get_sample_rate(client); /*get period size (TODO: JACK does not guarantee a static period size however the current Soundtank code can't handle a change in the period size and will crash)*/ engine->period_size = jack_get_buffer_size(client); /*set callbacks used by jack server*/ if (jack_set_process_callback(client, soundtank_jack_process_callback, 0) < 0){ printf("jack engine error: could not set processing callback function\n"); return -1; } jack_on_shutdown(client, soundtank_jack_shutdown_callback, 0); /*engine is ready to go, set state variable to indicate so*/ engine->state = ENGINE_STATE_INACTIVE; return 0; }
int main (int argc, char *argv[]) { jack_client_t *client; const char **ports; if (argc < 2) { fprintf (stderr, "usage: jack_simple_client <name>n"); return 1; } /* try to become a client of the JACK server */ if ((client = jack_client_new (argv[1])) == 0) { fprintf (stderr, "jack server not running?n"); return 1; } /* tell the JACK server to call `process()' whenever there is work to be done. */ jack_set_process_callback (client, process, 0); /* 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); /* display the current sample rate. */ printf ("engine sample rate: %" PRIu32 "n", jack_get_sample_rate (client)); /* create two ports */ input_port = jack_port_register (client, "input", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); output_port = jack_port_register (client, "output", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); /* tell the JACK server that we are ready to roll */ if (jack_activate (client)) { fprintf (stderr, "cannot activate client"); return 1; } /* connect the ports. Note: you can't do this before the client is activated, because we can't allow connections to be made to clients that aren't running. */ if ((ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical|JackPortIsOutput)) == NULL) { fprintf(stderr, "Cannot find any physical capture portsn"); exit(1); } if (jack_connect (client, ports[0], jack_port_name (input_port))) { fprintf (stderr, "cannot connect input portsn"); } free (ports); if ((ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical|JackPortIsInput)) == NULL) { fprintf(stderr, "Cannot find any physical playback portsn"); exit(1); } if (jack_connect (client, jack_port_name (output_port), ports[0])) { fprintf (stderr, "cannot connect output portsn"); } free (ports); /* Since this is just a toy, run for a few seconds, then finish */ while(1) { sleep (10); } jack_client_close (client); exit (0); }
/* initialize JACK audio */ u8 j_init(void){ jack_client_t *client; const intptr_t **ports; fprintf(stderr, "Trying jack....\n"); // tell the JACK server to call error() whenever it //experiences an error. Notice that this callback is // global to this process, not specific to each client. // // This is set here so that it can catch errors in the // connection process jack_set_error_function(j_error); // try to become a client of the JACK server if((client = jack_client_new("pineappletracker")) == 0){ fprintf(stderr, "jack server not running?\n"); return 1; } // tell the JACK server to call `process()' whenever // there is work to be done. jack_set_process_callback(client, j_process, 0); // 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, j_shutdown, 0); // display the current sample rate. once the client is activated // (see below), you should rely on your own sample rate // callback (see above) for this value. fprintf(stderr, "engine sample rate: %d\n", jack_get_sample_rate (client)); sr=jack_get_sample_rate(client); output_port = jack_port_register(client, "output", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); // tell the JACK server that we are ready to roll if(jack_activate(client)){ fprintf (stderr, "cannot activate client"); return 1; } // connect the ports if((ports = jack_get_ports(client, NULL, NULL, JackPortIsPhysical|JackPortIsInput)) == NULL){ fprintf(stderr, "Cannot find any physical playback ports\n"); return 1; } int i=0; while(ports[i]!=NULL){ if(jack_connect(client, jack_port_name (output_port), ports[i])) fprintf(stderr, "cannot connect output ports\n"); i++; } return 0; }
int main (int argc, char *argv[]) { jack_client_t *client; jack_thread_info_t thread_info; int c; char jackClientName[1024] = ""; int ret = 0; struct stat buf; int i; int longopt_index = 0; extern int optind, opterr; int show_usage = 0; char *optstring = "p:n:c:d:f:b:B:h"; struct option long_options[] = { { "portmatch", 1, 0, 'p' }, { "name", 1, 0, 'n' }, { "config", 1, 0, 'c' }, { "help", 0, 0, 'h' }, { "duration", 1, 0, 'd' }, { "file", 1, 0, 'f' }, { "bitdepth", 1, 0, 'b' }, { "bufsize", 1, 0, 'B' }, { 0, 0, 0, 0 } }; signal(SIGINT, sigHandler); memset (&thread_info, 0, sizeof (thread_info)); thread_info.rb_size = DEFAULT_RB_SIZE; opterr = 0; memset(&g, '\000', sizeof(g)); setServerStatusCallback(&g, serverStatusCallback); setGeneralStatusCallback(&g, generalStatusCallback); setWriteBytesCallback(&g, writeBytesCallback); addBasicEncoderSettings(&g); strcpy(jackClientName, "edcast"); while ((c = getopt_long (argc, argv, optstring, long_options, &longopt_index)) != -1) { switch (c) { case 1: /* getopt signals end of '-' options */ break; case 'p': strcpy(portMatch, optarg); getFirstTwo = 1; break; case 'n': strcpy(jackClientName, optarg); break; case 'c': i = stat (optarg, &buf ); if ( i != 0 ) { printf("Cannot open config file (%s)\n", optarg); exit(1); } setConfigFileName(&g, optarg); readConfigFile(&g, 1); break; case 'h': show_usage++; break; case 'd': thread_info.duration = atoi (optarg); break; case 'f': thread_info.path = optarg; break; case 'b': thread_info.bitdepth = atoi (optarg); break; case 'B': thread_info.rb_size = atoi (optarg); break; default: fprintf (stderr, "error\n"); show_usage++; break; } } if (show_usage || ((optind == argc) && (!getFirstTwo))) { fprintf (stderr, "usage: edcast -c configfile [ -n jack_client_name ] [ -p portmatch ] [ jackport1 [ jackport2 ... ]]\n"); fprintf(stderr, "Where:\n"); fprintf(stderr, "-c : config file that specified encoding settings\n"); fprintf(stderr, "-n : name used to register with jackd\n"); fprintf(stderr, "-p : if specified, edcast will connect to the first two output ports matching this name.\n"); fprintf(stderr, "jackportX : explicitly specify a jack port name\n"); exit (1); } if ((client = jack_client_new (jackClientName)) == 0) { fprintf (stderr, "jack server not running?\n"); exit (1); } thread_info.client = client; if (getFirstTwo) { thread_info.channels = 2; } else { thread_info.channels = argc - optind; } thread_info.can_process = 0; setLogFlags(); setup_edcast_thread (&thread_info); jack_set_process_callback (client, process, &thread_info); jack_on_shutdown (client, jack_shutdown, &thread_info); if (jack_activate (client)) { fprintf (stderr, "cannot activate client"); } setup_ports (thread_info.channels, &argv[optind], &thread_info); run_edcast_thread (&thread_info); jack_client_close (client); jack_ringbuffer_free (rb[0]); jack_ringbuffer_free (rb[1]); exit (0); }
int main (int narg, char * args []) { SNDFILE *sndfile ; SF_INFO sndfileinfo ; jack_client_t *client ; thread_info_t info ; int i, jack_sr ; if (narg < 2) { fprintf (stderr, "no soundfile given\n") ; return 1 ; } ; // create jack client if ((client = jack_client_new ("jackplay")) == 0) { fprintf (stderr, "Jack server not running?\n") ; return 1 ; } ; jack_sr = jack_get_sample_rate (client) ; /* Open the soundfile. */ sndfileinfo.format = 0 ; sndfile = sf_open (args [1], SFM_READ, &sndfileinfo) ; if (sndfile == NULL) { fprintf (stderr, "Could not open soundfile '%s'\n", args [1]) ; return 1 ; } ; fprintf (stderr, "Channels : %d\nSample rate : %d Hz\nDuration : ", sndfileinfo.channels, sndfileinfo.samplerate) ; print_time (sndfileinfo.frames, sndfileinfo.samplerate) ; fprintf (stderr, "\n") ; if (sndfileinfo.samplerate != jack_sr) fprintf (stderr, "Warning: samplerate of soundfile (%d Hz) does not match jack server (%d Hz).\n", sndfileinfo.samplerate, jack_sr) ; /* Init the thread info struct. */ memset (&info, 0, sizeof (info)) ; info.can_process = 0 ; info.read_done = 0 ; info.play_done = 0 ; info.sndfile = sndfile ; info.channels = sndfileinfo.channels ; info.client = client ; info.pos = 0 ; /* Set up callbacks. */ jack_set_process_callback (client, process, &info) ; jack_on_shutdown (client, jack_shutdown, 0) ; /* Allocate output ports. */ output_port = calloc (sndfileinfo.channels, sizeof (jack_port_t *)) ; outs = calloc (sndfileinfo.channels, sizeof (jack_default_audio_sample_t *)) ; for (i = 0 ; i < sndfileinfo.channels ; i++) { char name [16] ; snprintf (name, sizeof (name), "out_%d", i + 1) ; output_port [i] = jack_port_register (client, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0) ; } ; /* Allocate and clear ringbuffer. */ ringbuf = jack_ringbuffer_create (sizeof (jack_default_audio_sample_t) * RB_SIZE) ; memset (ringbuf->buf, 0, ringbuf->size) ; /* Activate client. */ if (jack_activate (client)) { fprintf (stderr, "Cannot activate client.\n") ; return 1 ; } ; /* Auto connect all channels. */ for (i = 0 ; i < sndfileinfo.channels ; i++) { char name [64] ; snprintf (name, sizeof (name), "alsa_pcm:playback_%d", i + 1) ; if (jack_connect (client, jack_port_name (output_port [i]), name)) fprintf (stderr, "Cannot connect output port %d (%s).\n", i, name) ; } ; /* Start the disk thread. */ pthread_create (&info.thread_id, NULL, disk_thread, &info) ; /* Sit in a loop, displaying the current play position. */ while (! info.play_done) { fprintf (stderr, "\r-> ") ; print_time (info.pos, jack_sr) ; fflush (stdout) ; usleep (50000) ; } ; /* Clean up. */ jack_client_close (client) ; jack_ringbuffer_free (ringbuf) ; sf_close (sndfile) ; free (outs) ; free (output_port) ; puts ("") ; return 0 ; } /* main */
/***************************************************************************** * Open: create a JACK client *****************************************************************************/ static int Open( vlc_object_t *p_this ) { char psz_name[32]; aout_instance_t *p_aout = (aout_instance_t *)p_this; struct aout_sys_t *p_sys = NULL; int status = VLC_SUCCESS; unsigned int i; int i_error; /* Allocate structure */ p_sys = calloc( 1, sizeof( aout_sys_t ) ); if( p_sys == NULL ) { status = VLC_ENOMEM; goto error_out; } p_aout->output.p_sys = p_sys; /* Connect to the JACK server */ snprintf( psz_name, sizeof(psz_name), "vlc_%d", getpid()); psz_name[sizeof(psz_name) - 1] = '\0'; p_sys->p_jack_client = jack_client_new( psz_name ); if( p_sys->p_jack_client == NULL ) { msg_Err( p_aout, "failed to connect to JACK server" ); status = VLC_EGENERIC; goto error_out; } /* Set the process callback */ jack_set_process_callback( p_sys->p_jack_client, Process, p_aout ); p_aout->output.pf_play = Play; aout_VolumeSoftInit( p_aout ); /* JACK only supports fl32 format */ p_aout->output.output.i_format = VLC_CODEC_FL32; // TODO add buffer size callback p_aout->output.i_nb_samples = jack_get_buffer_size( p_sys->p_jack_client ); p_aout->output.output.i_rate = jack_get_sample_rate( p_sys->p_jack_client ); p_sys->i_channels = aout_FormatNbChannels( &p_aout->output.output ); p_sys->p_jack_ports = malloc( p_sys->i_channels * sizeof(jack_port_t *) ); if( p_sys->p_jack_ports == NULL ) { status = VLC_ENOMEM; goto error_out; } p_sys->p_jack_buffers = malloc( p_sys->i_channels * sizeof(jack_sample_t *) ); if( p_sys->p_jack_buffers == NULL ) { status = VLC_ENOMEM; goto error_out; } /* Create the output ports */ for( i = 0; i < p_sys->i_channels; i++ ) { snprintf( psz_name, sizeof(psz_name), "out_%d", i + 1); psz_name[sizeof(psz_name) - 1] = '\0'; p_sys->p_jack_ports[i] = jack_port_register( p_sys->p_jack_client, psz_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0 ); if( p_sys->p_jack_ports[i] == NULL ) { msg_Err( p_aout, "failed to register a JACK port" ); status = VLC_EGENERIC; goto error_out; } } /* Tell the JACK server we are ready */ i_error = jack_activate( p_sys->p_jack_client ); if( i_error ) { msg_Err( p_aout, "failed to activate JACK client (error %d)", i_error ); status = VLC_EGENERIC; goto error_out; } /* Auto connect ports if we were asked to */ if( config_GetInt( p_aout, AUTO_CONNECT_OPTION ) ) { unsigned int i_in_ports; char *psz_regex = config_GetPsz( p_aout, CONNECT_REGEX_OPTION ); const char **pp_in_ports = jack_get_ports( p_sys->p_jack_client, psz_regex, NULL, JackPortIsInput ); free( psz_regex ); /* Count the number of returned ports */ i_in_ports = 0; while( pp_in_ports && pp_in_ports[i_in_ports] ) { i_in_ports++; } /* Tie the output ports to JACK input ports */ for( i = 0; i_in_ports > 0 && i < p_sys->i_channels; i++ ) { const char* psz_in = pp_in_ports[i % i_in_ports]; const char* psz_out = jack_port_name( p_sys->p_jack_ports[i] ); i_error = jack_connect( p_sys->p_jack_client, psz_out, psz_in ); if( i_error ) { msg_Err( p_aout, "failed to connect port %s to port %s (error %d)", psz_out, psz_in, i_error ); } else { msg_Dbg( p_aout, "connecting port %s to port %s", psz_out, psz_in ); } } free( pp_in_ports ); } msg_Dbg( p_aout, "JACK audio output initialized (%d channels, buffer " "size=%d, rate=%d)", p_sys->i_channels, p_aout->output.i_nb_samples, p_aout->output.output.i_rate ); error_out: /* Clean up, if an error occurred */ if( status != VLC_SUCCESS && p_sys != NULL) { if( p_sys->p_jack_client ) { jack_deactivate( p_sys->p_jack_client ); jack_client_close( p_sys->p_jack_client ); } free( p_sys->p_jack_ports ); free( p_sys->p_jack_buffers ); free( p_sys ); } return status; }
/*------------------------------------------------------------------------------ * Open the audio source *----------------------------------------------------------------------------*/ bool JackDspSource :: open ( void ) throw ( Exception ) { char client_name[255]; size_t rb_size; unsigned int c; if ( isOpen() ) { return false; } // Register client with Jack if ( jack_client_name != NULL ) { snprintf(client_name, 255, "%s", jack_client_name); } else { snprintf(client_name, 255, "darkice-%d", getpid()); } if ((client = jack_client_new(client_name)) == NULL) { throw Exception( __FILE__, __LINE__, "JACK server not running?"); } Reporter::reportEvent( 1, "Registering as JACK client", client_name); // Check the sample rate is correct if (jack_get_sample_rate( client ) != (jack_nframes_t)getSampleRate()) { throw Exception( __FILE__, __LINE__, "JACK server sample rate is different than " "sample rate in darkice config file"); } // Register ports with Jack if (getChannel() == 1) { if (!(ports[0] = jack_port_register(client, "mono", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0))) { throw Exception( __FILE__, __LINE__, "Cannot register input port", "mono"); } } else if (getChannel() == 2) { if (!(ports[0] = jack_port_register(client, "left", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0))) { throw Exception( __FILE__, __LINE__, "Cannot register input port", "left"); } if (!(ports[1] = jack_port_register(client, "right", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0))) { throw Exception( __FILE__, __LINE__, "Cannot register input port", "right"); } } else { throw Exception( __FILE__, __LINE__, "Invalid number of channels", getChannel()); } // Create a ring buffer for each channel rb_size = 2 * jack_get_sample_rate(client) * sizeof (jack_default_audio_sample_t); for (c=0; c<getChannel(); c++) { rb[c] = jack_ringbuffer_create(rb_size); if (!rb[c]) { throw Exception( __FILE__, __LINE__, "Failed to create ringbuffer for", "channel", c); } } // Set the callbacks jack_on_shutdown(client, JackDspSource::shutdown_callback, (void*)this); if (jack_set_process_callback(client, JackDspSource::process_callback, (void*)this)) { throw Exception( __FILE__, __LINE__, "Failed to set process callback"); } // Activate client if (jack_activate(client)) { throw Exception( __FILE__, __LINE__, "Can't activate client"); } // Attempt to automatically connect up our input ports to something ? if (auto_connect) { do_auto_connect(); } return true; }
// On error return a negative value // If the requested buffer size can be served return 0, // otherwise return the number of 16 bit words contained in the obtained buffer mp_sint32 AudioDriver_JACK::initDevice(mp_sint32 bufferSizeInWords, mp_uint32 mixFrequency, MasterMixer* mixer) { // First load libjack libJack = dlopen("libjack.so", RTLD_LAZY); if(!libJack) { fprintf(stderr, "JACK: Can't load libjack (is it installed?)\n"); return -1; } // Get function addresses // Each function has to be cast.. surely there must be an easier way? dlerror(); jack_port_get_buffer = (void* (*)(jack_port_t*, jack_nframes_t)) dlsym(libJack, "jack_port_get_buffer"); jack_client_new = (jack_client_t* (*)(const char*)) dlsym(libJack, "jack_client_new"); jack_port_register = (jack_port_t* (*)(jack_client_t*, const char*, const char*, long unsigned int, long unsigned int)) dlsym(libJack, "jack_port_register"); jack_set_process_callback = (int (*)(jack_client_t*, int (*)(jack_nframes_t, void*), void*)) dlsym(libJack, "jack_set_process_callback"); jack_get_buffer_size = (jack_nframes_t (*)(jack_client_t*)) dlsym(libJack, "jack_get_buffer_size"); jack_deactivate = (int (*)(jack_client_t*)) dlsym(libJack, "jack_deactivate"); jack_client_close = (int (*)(jack_client_t*)) dlsym(libJack, "jack_client_close"); jack_activate = (int (*)(jack_client_t*)) dlsym(libJack, "jack_activate"); jack_get_sample_rate = (jack_nframes_t (*)(jack_client_t *)) dlsym(libJack, "jack_get_sample_rate"); if(dlerror()) { fprintf(stderr, "JACK: An error occured whilst loading symbols, aborting.\n"); return -1; } mp_sint32 res = AudioDriverBase::initDevice(bufferSizeInWords, mixFrequency, mixer); if (res < 0) return res; // Connect to JACK hJack = jack_client_new("Milkytracker"); if (!hJack) { fprintf(stderr, "JACK: Can't connect to JACK (is it running?)\n"); return -1; } // Register ports leftPort = jack_port_register(hJack, "Left", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); rightPort = jack_port_register(hJack, "Right", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); if(!leftPort || !rightPort) { fprintf(stderr, "JACK: Failed to register ports\n"); return -1; } // Set callback jack_set_process_callback(hJack, jackProcess, (void *) this); // Get buffer-size jackFrames = jack_get_buffer_size(hJack); bufferSize = jackFrames * 2; this->mixFrequency = jack_get_sample_rate(hJack); printf("JACK: Mixer frequency: %i\n", this->mixFrequency); //delete[] rawStream; // pailes: make sure this isn't allocated yet assert(!rawStream); // If it is allocated, something went wrong and we need to know about it rawStream = new mp_sword[bufferSize]; printf("JACK: Latency = %i frames\n", jackFrames); return bufferSize; }
bool SC_JackDriver::DriverSetup(int* outNumSamples, double* outSampleRate) { char* clientName = 0; char* serverName = 0; if (mWorld->hw->mInDeviceName && (strlen(mWorld->hw->mInDeviceName) > 0)) { // parse string <serverName>:<clientName> SC_StringParser sp(mWorld->hw->mInDeviceName, ':'); if (!sp.AtEnd()) serverName = strdup(sp.NextToken()); if (!sp.AtEnd()) clientName = strdup(sp.NextToken()); if (clientName == 0) { // no semicolon found clientName = serverName; serverName = 0; } else if (strlen(clientName) == 0) { free(clientName); clientName = 0; } } #ifdef SC_USE_JACK_CLIENT_NEW // old style client startup for Jack <0.100 -- AG if (clientName) { mClient = jack_client_new(clientName); } else { clientName = strdup("SuperCollider"); mClient = jack_client_new(clientName); if (mClient == 0) { char uniqueName[64]; sprintf(uniqueName, "SuperCollider-%d", getpid()); clientName = strdup(uniqueName); mClient = jack_client_new(uniqueName); } } if (mClient) scprintf("%s: client name is '%s'\n", kJackDriverIdent, clientName); if (serverName) free(serverName); if (clientName) free(clientName); if (mClient == 0) return false; #else mClient = jack_client_open( clientName ? clientName : kJackDefaultClientName, serverName ? JackServerName : JackNullOption, NULL, serverName); if (serverName) free(serverName); if (clientName) free(clientName); if (mClient == 0) return false; scprintf("%s: client name is '%s'\n", kJackDriverIdent, jack_get_client_name(mClient)); #endif // create jack I/O ports mInputList = new SC_JackPortList(mClient, mWorld->mNumInputs, JackPortIsInput); mOutputList = new SC_JackPortList(mClient, mWorld->mNumOutputs, JackPortIsOutput); // register callbacks jack_set_process_callback(mClient, sc_jack_process_cb, this); jack_set_buffer_size_callback(mClient, sc_jack_bufsize_cb, this); jack_set_sample_rate_callback(mClient, sc_jack_srate_cb, this); jack_set_graph_order_callback(mClient, sc_jack_graph_order_cb, this); jack_set_xrun_callback(mClient, sc_jack_xrun_cb, this); jack_on_shutdown(mClient, sc_jack_shutdown_cb, mWorld); *outNumSamples = (int)jack_get_buffer_size(mClient); *outSampleRate = (double)jack_get_sample_rate(mClient); return true; }
int main (int argc, char *argv[]) { fprintf(stderr, "tmrd v%s\n", VERSION); parseArgs(argc, argv); attach_sig_handler(); jack_client_t *client; const char **ports; /* init jack */ if ((client = jack_client_new ("smp")) == 0) { fprintf (stderr, "jack server not running?\n"); return 1; } jack_set_process_callback (client, process, 0); jack_on_shutdown (client, jack_shutdown, 0); sample_rate = jack_get_sample_rate (client); printf ("engine sample rate: %u\n", sample_rate); /* create a delay buffer for each channel */ buffer = (jack_default_audio_sample_t**)malloc(2*sizeof(jack_default_audio_sample_t**)); /* div by 10 since time is in tenths of secs */ buf_frames = max_delay_time*sample_rate/10; buffer[0] = (jack_default_audio_sample_t*)malloc(buf_frames*sizeof(jack_default_audio_sample_t)); buffer[1] = (jack_default_audio_sample_t*)malloc(buf_frames*sizeof(jack_default_audio_sample_t)); memset(buffer[0], 0, buf_frames*sizeof(jack_default_audio_sample_t)); memset(buffer[1], 0, buf_frames*sizeof(jack_default_audio_sample_t)); printf("buffer frames: %d\n", buf_frames); /* create two input ports and two output ports */ input_port = (jack_port_t**)malloc(2*sizeof(jack_port_t**)); output_port = (jack_port_t**)malloc(2*sizeof(jack_port_t**)); input_port[0] = jack_port_register (client, "input0", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); input_port[1] = jack_port_register (client, "input1", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); output_port[0] = jack_port_register (client, "output0", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); output_port[1] = jack_port_register (client, "output1", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); /* start jack */ if (jack_activate (client)) { fprintf (stderr, "cannot activate client"); return 1; } if ((ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical|JackPortIsOutput)) == NULL) { fprintf(stderr, "Cannot find any physical capture ports\n"); exit(1); } if (jack_connect (client, ports[0], jack_port_name (input_port[0]))) fprintf (stderr, "cannot connect input ports\n"); if (jack_connect (client, ports[1], jack_port_name (input_port[1]))) fprintf (stderr, "cannot connect input ports\n"); free (ports); if ((ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical|JackPortIsInput)) == NULL) { fprintf(stderr, "Cannot find any physical playback ports\n"); exit(1); } if (jack_connect (client, jack_port_name (output_port[0]), ports[0])) fprintf (stderr, "cannot connect output ports\n"); if (jack_connect (client, jack_port_name (output_port[1]), ports[1])) fprintf (stderr, "cannot connect output ports\n"); free (ports); run_ui(); /* start the ui, listen for keyboard input */ jack_client_close (client); exit (0); }
void *JackOpenPlay(struct FFTSound *fftsound){ int lokke; static char *outnames[MAX_SAMPS_PER_FRAME]={"output1","output2","output3","output4","output5","output6","output7","output8"}; struct Jackplay *jackplay; jackplay=calloc(1,sizeof(struct Jackplay)); jackplay->fftsound=fftsound; jackplay->buffersize=BUFFERSIZE; // fprintf(stderr,"Open jack play.\n"); #if 1 if(globalclient==NULL){ // Hack to get around a bug in jack. if (CONFIG_getBool("jack_client_name_is_ceres_plus_pid")==true){ sprintf(clientname,"ceres-%d",getpid()); }else{ sprintf(clientname,"ceres"); } if ((jackplay->client=globalclient = jack_client_new (clientname)) == 0) { fprintf(stderr,"Failed. Jack server not running?\n"); goto failed; } atexit(jackCleanUp); } jackplay->client=globalclient; #else if ((jackplay->client=globalclient=jack_client_new ("ceres")) == 0) { fprintf(stderr,"Failed. Jack server not running?\n"); goto failed; } #endif if(fftsound->R!=jack_get_sample_rate(jackplay->client)){ fprintf( stderr, "Warning, sample rate is %d, while jacks sample rate is %lu.\n", fftsound->R, jack_get_sample_rate(jackplay->client) ); } jack_set_process_callback (jackplay->client, jackprocess, jackplay); for(lokke=0;lokke<fftsound->samps_per_frame;lokke++){ jackplay->jpc[lokke].output_port = jack_port_register( jackplay->client, outnames[lokke], JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0 ); } if (jack_activate (jackplay->client)) { fprintf (stderr, "Error. Cannot activate jack client.\n"); goto failed_activate; } for(lokke=0;lokke<fftsound->samps_per_frame;lokke++){ if ( jack_connect( jackplay->client, jack_port_name(jackplay->jpc[lokke].output_port), outportnames[lokke] ) ) { fprintf (stderr, "Error. Cannot connect jack output port %d: \"%s\".\n",lokke,outportnames[lokke]); goto failed_connect; } } return jackplay; failed_connect: for(lokke=0;lokke<jackplay->fftsound->samps_per_frame;lokke++){ jack_disconnect( jackplay->client, jack_port_name(jackplay->jpc[lokke].output_port), outportnames[lokke] ); jack_port_unregister( jackplay->client,jackplay->jpc[lokke].output_port ); } failed_activate: jack_deactivate(jackplay->client); // jack_client_close (jackplay->client); failed: free(jackplay); return NULL; }
PaError PaJack_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiIndex hostApiIndex ) { PaError result = paNoError; PaJackHostApiRepresentation *jackHostApi; jackHostApi = (PaJackHostApiRepresentation*) PaUtil_AllocateMemory( sizeof(PaJackHostApiRepresentation) ); if( !jackHostApi ) { result = paInsufficientMemory; goto error; } jackHostApi->deviceInfoMemory = NULL; /* Try to become a client of the JACK server. If we cannot do * this, than this API cannot be used. */ jackHostApi->jack_client = jack_client_new( "PortAudio client" ); if( jackHostApi->jack_client == 0 ) { /* the V19 development docs say that if an implementation * detects that it cannot be used, it should return a NULL * interface and paNoError */ result = paNoError; *hostApi = NULL; goto error; } jackHostApi->deviceInfoMemory = PaUtil_CreateAllocationGroup(); if( !jackHostApi->deviceInfoMemory ) { result = paInsufficientMemory; goto error; } jackHostApi->hostApiIndex = hostApiIndex; *hostApi = &jackHostApi->commonHostApiRep; (*hostApi)->info.structVersion = 1; (*hostApi)->info.type = paInDevelopment; (*hostApi)->info.name = "JACK Audio Connection Kit"; (*hostApi)->info.defaultInputDevice = paNoDevice; /* set in BuildDeviceList() */ (*hostApi)->info.defaultOutputDevice = paNoDevice; /* set in BuildDeviceList() */ (*hostApi)->info.deviceCount = 0; /* set in BuildDeviceList() */ /* Build a device list by querying the JACK server */ result = BuildDeviceList( jackHostApi ); if( result != paNoError ) goto error; /* Register functions */ (*hostApi)->Terminate = Terminate; (*hostApi)->OpenStream = OpenStream; (*hostApi)->IsFormatSupported = IsFormatSupported; PaUtil_InitializeStreamInterface( &jackHostApi->callbackStreamInterface, CloseStream, StartStream, StopStream, AbortStream, IsStreamStopped, IsStreamActive, GetStreamTime, GetStreamCpuLoad, PaUtil_DummyRead, PaUtil_DummyWrite, PaUtil_DummyGetReadAvailable, PaUtil_DummyGetWriteAvailable ); return result; error: if( jackHostApi ) { if( jackHostApi->deviceInfoMemory ) { PaUtil_FreeAllAllocations( jackHostApi->deviceInfoMemory ); PaUtil_DestroyAllocationGroup( jackHostApi->deviceInfoMemory ); } PaUtil_FreeMemory( jackHostApi ); } return result; }
bool audioStreamer_JACK::init(const char* clientName, int nInputChannels, int nOutputChannels, SPLPROC proc) { njc = NULL; splproc = proc; if (client) { jack_client_close(client); client = NULL; } if ((client = jack_client_new(clientName)) == 0) { fprintf (stderr, "jack server not running?\n"); return false; // exit(20); } jack_set_process_callback (client, (JackProcessCallback) process_cb, this); jack_set_timebase_callback( client, 0, (JackTimebaseCallback) jack_timebase_cb, this ); if (_out) { delete[] _out; _out = NULL; } _out = new jack_port_t*[nOutputChannels]; if (_outports) { delete[] _outports; _outports = NULL; } _outports = new float*[nOutputChannels]; for (unsigned i=0; i<nOutputChannels; i++) { char name[10]; snprintf(name, sizeof(name), "out%d", i+1); _out[i] = jack_port_register (client, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); } if (_in) { delete[] _in; _in = NULL; } _in = new jack_port_t*[nInputChannels]; if (_inports) { delete[] _inports; _inports = NULL; } _inports = new float*[nInputChannels]; for (unsigned i=0; i<nInputChannels; i++) { char name[10]; snprintf(name, sizeof(name), "in%d", i+1); _in[i] = jack_port_register (client, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); } if (jack_activate (client)) { fprintf (stderr, "cannot activate client\n"); return false; //exit(20); } m_innch = nInputChannels; m_outnch = nOutputChannels; m_srate = jack_get_sample_rate( client ); m_bps = 32; return true; }
int jack_init(JackCard* obj) { char* client_name; int error; if (!obj->jack_running) { obj->client = NULL; client_name = g_strdup_printf("linphone-%u", g_random_int()); if ((obj->client = jack_client_new (client_name)) == NULL) { g_warning("cannot create jack client"); g_free(client_name); return -1; } g_message("Found Jack Daemon"); g_free(client_name); /* tell the JACK server to call `process()' whenever there is work to be done. */ jack_set_process_callback (obj->client, process, obj); /* 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 (obj->client, jack_shutdown, obj); jack_set_sample_rate_callback (obj->client, samplerate, obj); obj->rate = jack_get_sample_rate (obj->client); if (obj->rate == 0) { g_warning ("rate is 0???"); if (jack_client_close(obj->client) != 0) g_warning("could not close client"); return -1; } obj->buffer_size = jack_get_buffer_size(obj->client); obj->jack_running = TRUE; } if (!obj->jack_active) { if (jack_activate (obj->client)) { g_warning("cannot activate jack client"); return -1; } else obj->jack_active = TRUE; } if (obj->read.init) { if (!obj->read.port && (obj->read.port = jack_port_register (obj->client, "input", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0))==NULL) { g_warning("error while trying to register input port"); return -1; } if (!obj->read.phys_ports && (obj->read.phys_ports = jack_get_ports (obj->client, NULL, NULL, JackPortIsPhysical|JackPortIsOutput)) == NULL) { g_warning("Cannot find any physical capture ports\n"); jack_port_unregister(obj->client, obj->read.port); obj->read.port = NULL; return -1; } if (!jack_port_connected(obj->read.port)) if ((error = jack_connect (obj->client, obj->read.phys_ports[0], jack_port_name (obj->read.port))) != 0) { g_warning("cannot connect input ports: %s -> %s\n", jack_port_name (obj->read.port), obj->read.phys_ports[0]); if (error == EEXIST) g_warning("connection already made"); else { jack_port_unregister(obj->client, obj->read.port); obj->read.port = NULL; return -1; } } obj->read.init = FALSE; } if (obj->write.init) { if (!obj->write.port && (obj->write.port = jack_port_register (obj->client, "output", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0))==NULL) { g_warning("error while trying to register output port"); return -1; } if (!obj->write.phys_ports && (obj->write.phys_ports = jack_get_ports (obj->client, NULL, NULL, JackPortIsPhysical|JackPortIsInput)) == NULL) { g_warning("Cannot find any physical playback ports\n"); jack_port_unregister(obj->client, obj->write.port); obj->write.port = NULL; return -1; } if (!jack_port_connected(obj->write.port)) { if ((error = jack_connect (obj->client, jack_port_name (obj->write.port), obj->write.phys_ports[0])) != 0) { g_warning("cannot connect output ports: %s -> %s\n", jack_port_name (obj->write.port), obj->write.phys_ports[0]); if (error == EEXIST) g_warning("connection already made"); else { jack_port_unregister(obj->client, obj->write.port); obj->write.port = NULL; return -1; } } if ((error = jack_connect (obj->client, jack_port_name (obj->write.port), obj->write.phys_ports[1])) != 0) { g_warning("cannot connect output ports: %s -> %s\n", jack_port_name (obj->write.port), obj->write.phys_ports[1]); if (error == EEXIST) g_warning("connection already made"); else { jack_port_unregister(obj->client, obj->write.port); obj->write.port = NULL; return -1; } } } obj->write.init = FALSE; } return 0; }