Example #1
0
  JucePlayer(PropertiesFile *propertiesfile)
  {
    this->propertiesfile=propertiesfile;

    jp_isplaying=false;
    isreadingdata=false;
    pleasestop=false;
    isinitialized=false;
    isusingjack=false;

    {
      num_src_states=0;
      src_states=NULL;
    }

    {
      ov_callbacks ov_cb={oggread_func,oggseek_func,oggclose_func,oggtell_func};
      lastreadoggpos=-1;
      nextreadoggpos=-1;      
      if(ov_open_callbacks(&oggvorbisfile,&oggvorbisfile,NULL,0,ov_cb)==0)
	isplaying_ogg=true;
      else
	isplaying_ogg=false;
      N=getSourceLength();
      R=44100;
      oggsrc_state=src_callback_new(audio_getOggResampledData_callback,SRC_QUALITY,2,NULL,NULL);
    }


#ifdef HAVE_JACK
    samplerate=init_jack(audio_jack_callback);

    if(samplerate!=-1){
      isinitialized=true;
      isusingjack=true;
    }else
#endif
      initJuceAudio();


    audioDeviceManager.addChangeListener(this);
  }
Example #2
0
int main(int argc, char **argv)
{
	MastSendTool *tool = NULL;
	jack_client_t* client = NULL;


	// Create the send tool object
	tool = new MastSendTool( MAST_TOOL_NAME );


	// Parse the command line arguments 
	// and configure the session
	parse_cmd_line( argc, argv, tool );


	// Initialise Jack
	client = init_jack( tool );
	if (client==NULL) MAST_FATAL( "Failed to initialise JACK client" );
	
	// Get the samplerate of the JACK Router
	tool->set_input_samplerate( jack_get_sample_rate( client ) );
	
	// Setup signal handlers
	mast_setup_signals();

	// Run the main loop
	tool->run();
	
	// Clean up
	delete tool;
	

	// Shut down JACK
	deinit_jack( client );

	
	// Success !
	return 0;
}
Example #3
0
int main(int argc, char *argv[])
{
	int ret;

	char* dev = NULL;
	char errbuf[PCAP_ERRBUF_SIZE];
	struct bpf_program comp_filter_exp;		/** The compiled filter expression */
	char filter_exp[] = "ether dst 91:E0:F0:00:0e:80";	/** The filter expression */
	struct pcap_pkthdr header;	/** header pcap gives us */
	const u_char* packet;		/** actual packet */
	
	signal(SIGINT, shutdown_all);
	
	int c;
	while((c = getopt(argc, argv, "hi:")) > 0) 
	{
		switch (c) 
		{
		case 'h': 
			help();
			break;
		case 'i':
			dev = strdup(optarg);
			break;
		default:
          		fprintf(stderr, "Unrecognized option!\n");
		}
	}

	if (NULL == dev) {
		help();
	}

	if (create_socket()) {
		fprintf(stderr, "Socket creation failed.\n");
		return (errno);
	}

	send_process('D'); /** report domain status */

	init_jack();
	
	fprintf(stdout,"Waiting for talker...\n");
	await_talker();	

	send_process('R'); /** send_ready */

#ifdef LIBSND
	char* filename = "listener.wav";
	SF_INFO* sf_info = (SF_INFO*)malloc(sizeof(SF_INFO));

	memset(sf_info, 0, sizeof(SF_INFO));

	sf_info->samplerate = SAMPLES_PER_SECOND;
	sf_info->channels = CHANNELS;
	sf_info->format = SF_FORMAT_WAV | SF_FORMAT_PCM_24;

	if (0 == sf_format_check(sf_info)) {
		fprintf(stderr, "Wrong format.\n");
		shutdown_all(0);
		return -1;
	}

	if (NULL == (snd_file = sf_open(filename, SFM_WRITE, sf_info))) {
		fprintf(stderr, "Could not create file %s.\n", filename);
		shutdown_all(0);
		return -1;
	}
#endif

	/** session, get session handler */
	handle = pcap_open_live(dev, BUFSIZ, 1, -1, errbuf);
	if (NULL == handle) {
		fprintf(stderr, "Could not open device %s: %s.\n", dev, errbuf);
		shutdown_all(0);
		return -1;
	}

	/** compile and apply filter */
	if (-1 == pcap_compile(handle, &comp_filter_exp, filter_exp, 0, PCAP_NETMASK_UNKNOWN)) {
		fprintf(stderr, "Could not parse filter %s: %s.\n", filter_exp, pcap_geterr(handle));
		shutdown_all(0);
		return -1;
	}

	if (-1 == pcap_setfilter(handle, &comp_filter_exp)) {
		fprintf(stderr, "Could not install filter %s: %s.\n", filter_exp, pcap_geterr(handle));
		shutdown_all(0);
		return -1;
	}
	
	/** loop forever and call callback-function for every received packet */
	pcap_loop(handle, -1, pcap_callback, NULL);

	usleep(-1);
	return 0;
}
int
main (int argc, char * argv [])
{
   int ch, i;
   char * file_name, * autoconnect_port_name = NULL;
   g_thread_init(NULL);

#ifdef WITH_LASH
   lash_args_t * lash_args = lash_extract_args(&argc, &argv);
#endif

   g_log_set_default_handler(log_handler, NULL);
   while ((ch = getopt(argc, argv, "a:V")) != -1)
   {
      switch (ch)
      {
         case 'a':
            autoconnect_port_name = strdup(optarg);
            break;

         case 'V':
            show_version();
            break;

         case '?':
         default:
            usage();
      }
   }
   argc -= optind;
   argv += optind;
   if (argc == 0)
      usage();

   file_name = argv[0];
   smf = smf_new();
   if (smf == NULL)
      exit(-1);

   for (i = 0; i < 16; ++i)
   {
      tracks[i] = smf_track_new();
      if (tracks[i] == NULL)
         exit(-1);

      smf_add_track(smf, tracks[i]);
   }

#ifdef WITH_LASH
   init_lash(lash_args);
#endif

   init_jack();
   if (autoconnect_port_name)
   {
      if (connect_to_output_port(autoconnect_port_name))
      {
         g_critical("Couldn't connect to '%s', exiting.", autoconnect_port_name);
         exit(EX_UNAVAILABLE);
      }
   }
   g_timeout_add(100, writer_timeout, (gpointer)argv[0]);
   signal(SIGINT, ctrl_c_handler);
   g_message
   (
      "Recording will start at the first received note; "
      "press ^C to write the file and exit."
   );
   g_main_loop_run(g_main_loop_new(NULL, TRUE));

   /* Not reached. */

   return 0;
}
Example #5
0
int main(int argc, char *argv[])
{
  int autoconnect = 0;
  jack_options_t jack_opt = JackNullOption;
  char *client_name = DEFAULT_CLIENT_NAME;
  char *connect_left = NULL;
  char *connect_right = NULL;
  const char *format_name = NULL;
  int bitrate = DEFAULT_BITRATE;
  int sync_period = DEFAULT_SYNC_PERIOD;
  float sleep_time = 0;
  time_t next_sync = 0;
  int i,opt;

  // Make STDOUT unbuffered
  setbuf(stdout, NULL);

  // Parse Switches
  while ((opt = getopt(argc, argv, "al:r:n:N:O:p:jf:b:Q:d:c:R:L:s:uvqh")) != -1) {
    switch (opt) {
      case 'a':  autoconnect = 1; break;
      case 'l':  connect_left = optarg; break;
      case 'r':  connect_right = optarg; break;
      case 'n':  client_name = optarg; break;
      case 'N':  archive_name = optarg; break;
      case 'O':  originator = strdup(optarg); break;
      case 'p':  archive_period_seconds = atol(optarg); break;
      case 'j':  jack_opt |= JackNoStartServer; break;
      case 'f':  format_name = rotter_str_tolower(optarg); break;
      case 'b':  bitrate = atoi(optarg); break;
      case 'Q':  vbr_quality = atof(optarg); break;
      case 'd':  delete_hours = atoi(optarg); break;
      case 'c':  channels = atoi(optarg); break;
      case 'R':  rb_duration = atof(optarg); break;
      case 'L':  file_layout = optarg; break;
      case 's':  sync_period = atoi(optarg); break;
      case 'u':  utc = 1; break;
      case 'v':  verbose = 1; break;
      case 'q':  quiet = 1; break;
      default:  usage(); break;
    }
  }

  // Validate parameters
  if (quiet && verbose) {
    rotter_error("Can't be quiet and verbose at the same time.");
    usage();
  }

  // Check the number of channels
  if (channels!=1 && channels!=2) {
    rotter_error("Number of channels should be either 1 or 2.");
    usage();
  }

  // Check remaining arguments
    argc -= optind;
    argv += optind;
    if (argc!=1) {
      rotter_error("%s requires a root directory argument.", PACKAGE_NAME);
      usage();
  } else {
    root_directory = argv[0];
    if (root_directory[strlen(root_directory)-1] == '/')
      root_directory[strlen(root_directory)-1] = 0;

    if (rotter_directory_exists(root_directory)) {
      rotter_debug("Root directory: %s", root_directory);
    } else {
      rotter_fatal("Root directory does not exist: %s", root_directory);
      goto cleanup;
    }
  }

  // Search for the selected output format
  if (format_name) {
    for(i=0; format_list[i].name; i++) {
      if (strcmp( format_list[i].name, format_name ) == 0) {
        // Found desired format
        output_format = &format_list[i];
        rotter_debug("User selected [%s] '%s'.",  output_format->name,  output_format->desc);
        break;
      }
    }
    if (output_format==NULL) {
      rotter_fatal("Failed to find format [%s], please check the supported format list.", format_name);
      goto cleanup;
    }
  } else {
    output_format = &format_list[0];
  }

  // No originator defined?
  if (!originator) {
    originator = rotter_get_hostname();
  }

  // Initialise JACK
  if (init_jack( client_name, jack_opt )) {
    rotter_debug("Failed to initialise Jack client.");
    goto cleanup;
  }

  // Create ring buffers
  if (init_ringbuffers()) {
    rotter_debug("Failed to initialise ring buffers.");
    goto cleanup;
  }

  // Create temporary buffer for reading samples into
  if (init_tmpbuffers(output_format->samples_per_frame)) {
    rotter_debug("Failed to initialise temporary buffers.");
    goto cleanup;
  }

  // Initialise encoder
  encoder = output_format->initfunc(output_format, channels, bitrate);
  if (encoder==NULL) {
    rotter_debug("Failed to initialise encoder.");
    goto cleanup;
  }

  // Activate JACK
  if (jack_activate(client)) {
    rotter_fatal("Cannot activate JACK client.");
    goto cleanup;
  }

  // Setup signal handlers
  signal(SIGTERM, rotter_termination_handler);
  signal(SIGINT, rotter_termination_handler);
  signal(SIGHUP, rotter_termination_handler);

  // Auto-connect our input ports ?
  if (autoconnect) autoconnect_jack_ports( client );
  if (connect_left) connect_jack_port( connect_left, inport[0] );
  if (connect_right && channels == 2) connect_jack_port( connect_right, inport[1] );

  // Calculate period to wait when there is no audio to process
  sleep_time = (2.0f * output_format->samples_per_frame / jack_get_sample_rate( client ));
  rotter_debug("Sleep period is %dms.", (int)(sleep_time * 1000));

  while( rotter_run_state == ROTTER_STATE_RUNNING ) {
    time_t now = time(NULL);
    int samples_processed = rotter_process_audio();
    if (samples_processed <= 0) {
      usleep(sleep_time * 1000000);
    }

    // Is it time to sync the encoded audio to disk?
    if (next_sync < now) {
      rotter_sync_to_disk();
      next_sync = now + sync_period;
    }

    deletefiles_cleanup_child();
  }


cleanup:

  // Clean up JACK
  deinit_jack();

  // Free buffers and close files
  deinit_tmpbuffers();
  deinit_ringbuffers();

  // Shut down encoder
  if (encoder)
    encoder->deinit();

  // Free the originator string
  if (originator)
    free(originator);

  // Did something go wrong?
  if (rotter_run_state == ROTTER_STATE_QUITING) {
    return EXIT_SUCCESS;
  } else {
    return EXIT_FAILURE;
  }
}
Example #6
0
int 
main(int argc, char *argv[])
{
	int		ch;
	char		*file_name, *autoconnect_port_name = NULL;


#ifdef WITH_LASH
	lash_args_t *lash_args;
#endif

	g_thread_init(NULL);

#ifdef WITH_LASH
	lash_args = lash_extract_args(&argc, &argv);
#endif

	g_log_set_default_handler(log_handler, NULL);

	while ((ch = getopt(argc, argv, "a:dnqr:stVx")) != -1) {
		switch (ch) {
			case 'a':
				autoconnect_port_name = strdup(optarg);
				break;

			case 'd':
				debug = 1;
				break;

			case 'n':
				start_stopped = 1;
				break;

			case 'q':
				be_quiet = 1;
				break;

			case 'r':
				rate_limit = strtod(optarg, NULL);
				if (rate_limit <= 0.0) {
					g_critical("Invalid rate limit specified.\n");

					exit(EX_USAGE);
				}

				break;

			case 's':
				just_one_output = 1;
				break;

			case 't':
				use_transport = 0;
				break;

            case 'x':
                    remote_control = 1;
                    break;

			case 'V':
				show_version();
				break;

			case '?':
			default:
				usage();
				break;
		}
	}

	argc -= optind;
	argv += optind;

	if (argv[0] == NULL) {
		g_critical("No file name given.");
		usage();
	}

	file_name = argv[0];

	if (!remote_control) {
	smf_vol = smf = smf_load(file_name);

	if (smf == NULL) {
		g_critical("Loading SMF file failed.");

		exit(-1);
	}

	if (!be_quiet)
		g_message("%s.", smf_decode(smf));

	if (smf->number_of_tracks > MAX_NUMBER_OF_TRACKS) {
		g_warning("Number of tracks (%d) exceeds maximum for per-track output; implying '-s' option.", smf->number_of_tracks);
		just_one_output = 1;
	}
	}

#ifdef WITH_LASH
	init_lash(lash_args);
#endif

	g_timeout_add(1000, emergency_exit_timeout, (gpointer)0);
	signal(SIGINT, ctrl_c_handler);

	init_jack();

	if (autoconnect_port_name) {
		if (connect_to_input_port(autoconnect_port_name)) {
			g_critical("Couldn't connect to '%s', exiting.", autoconnect_port_name);
			exit(EX_UNAVAILABLE);
		}
	}

	if (use_transport && !start_stopped) {
		jack_transport_locate(jack_client, 0);
		jack_transport_start(jack_client);
	}

	if (!use_transport)
		playback_started = jack_frame_time(jack_client);

	if (remote_control)
		remote_control_start(argv[0]);

	g_main_loop_run(g_main_loop_new(NULL, TRUE));

	/* Not reached. */

	return 0;
}
Example #7
0
int main(int argc, char **argv){	
	struct 				tm start_time_tm;
	int outputPorts;

	pthread_t *audioThreads;
	pthread_attr_t custom_sched_attr;	
	int fifo_max_prio = 0;
	int fifo_min_prio = 0;
	int fifo_mid_prio = 0;	
	struct sched_param fifo_param;

	syncbuffer = 0;
	normalbuffer = 0;

	if(argc < 3){
		printf("./<audio_decoder> udp://[IP]:[PORT] [ptsDelay] [Amount of channel] [Channel 0] [Channel n]\n");
		return 0;
	}

	if(argc != 3){

	}

	
	ff_ctx = malloc(sizeof(ff_ctx_t));

	av_register_all();
	avformat_network_init();

	InitFF(ff_ctx, argv[1], argv[2]);
	

	if (avformat_open_input (&ff_ctx->avInputCtx, ff_ctx->udp_address, NULL , &ff_ctx->avDic) != 0) {
		printf ("Cloud not open UDP input stream at %s\n", ff_ctx->udp_address);
		return -1;
	}

	if (avformat_find_stream_info(ff_ctx->avInputCtx, NULL) < 0) {
		printf ("Cloud not get stream info\n");
		return -1;
	}

	if (ff_ctx->audioIndexStream = av_find_best_stream(ff_ctx->avInputCtx, AVMEDIA_TYPE_AUDIO, -1, -1, &ff_ctx->avCodec, 0) < 0) {
		printf ("No audio streams found\n");
		return -1;
	}

	printf ("Audio stream found at %d\n", ff_ctx->audioIndexStream);

	ff_ctx->avDicentry = av_dict_get(ff_ctx->avInputCtx->metadata, "service_name", NULL, 0);

	if(ff_ctx->avDicentry != NULL){
		strptime( ff_ctx->avDicentry->value, "%Y-%m-%d %H:%M:%S", &start_time_tm);
		start_time = mktime(&start_time_tm);
	}
	else {
		start_time = getSystemTime(NULL);
	}
	
	ff_ctx->avCodecCtx = ff_ctx->avInputCtx->streams[ff_ctx->audioIndexStream]->codec;
	ff_ctx->avCodec = avcodec_find_decoder(ff_ctx->avCodecCtx->codec_id);

	av_dump_format(ff_ctx->avInputCtx, 0, ff_ctx->udp_address, 0);

	if (avcodec_open2 (ff_ctx->avCodecCtx, ff_ctx->avCodec, NULL) < 0) {
		return -1;
	}

	outputPorts = ff_ctx->avCodecCtx->channels;
	InitBF(ff_ctx->avCodecCtx->channels, &to_audio_buffer, TO_AUDIO_BUFFER_SIZE);
	InitBF(ff_ctx->avCodecCtx->channels, &to_jack_buffer, TO_JACK_BUFFER_SIZE);

	//One thread for each channel
	audioThreads = malloc (sizeof(pthread_t)*outputPorts);

	pthread_attr_init(&custom_sched_attr);	
 	pthread_attr_setinheritsched(&custom_sched_attr, PTHREAD_INHERIT_SCHED /* PTHREAD_EXPLICIT_SCHED */);

 	//Options below only are applied when PTHREAD_EXPLICIT_SCHED is used!
 	pthread_attr_setscope(&custom_sched_attr, PTHREAD_SCOPE_SYSTEM );	
 	pthread_attr_setschedpolicy(&custom_sched_attr, SCHED_FIFO);	

 	fifo_max_prio = sched_get_priority_max(SCHED_FIFO);	
 	fifo_min_prio = sched_get_priority_min(SCHED_FIFO);	
 	fifo_mid_prio = (fifo_min_prio + fifo_max_prio) / 2;	
 	fifo_param.sched_priority = fifo_mid_prio;	
 	pthread_attr_setschedparam(&custom_sched_attr, &fifo_param);

 	int i;
 	threadArgs_t args[outputPorts];
 	for (i = 0; i < outputPorts; i++) {
 		args[i].channel = i;
 		args[i].process_block_size = AUDIO_PROCESS_BLOCK_SIZE;
 		if (pthread_create(&audioThreads[i], &custom_sched_attr, audioThreadFunction, &args[i])) {
 			printf ("Unable to create audio_thread %d\n", i);
 			return 0;
 		}
 	}
    
    av_init_packet(&ff_ctx->avPacket);

	static AVFrame frame;
	int frameFinished;
	int nb, ch;

	char samplebuf[30];
	av_get_sample_fmt_string (samplebuf, 30, ff_ctx->avCodecCtx->sample_fmt);
	printf ("Audio sample format is %s\n", samplebuf);

	audio_sync_sample_t **sync_samples;
	sync_samples = malloc (outputPorts*sizeof(audio_sync_sample_t*));

	long double initPTS, PTS, frame_pts_offset;
	unsigned long int frame_count, framePTS, sample_count;

	int sample_rate = ff_ctx->avCodecCtx->sample_rate;

	if (init_jack(&jackCtx, outputPorts)) {
		return 1;
	}

	while(av_read_frame (ff_ctx->avInputCtx, &ff_ctx->avPacket)>=0) {

		if(ff_ctx->avPacket.stream_index == ff_ctx->audioIndexStream ) {
			int contador = 0;
			long double time_1 = getSystemTime(NULL);

			int len = avcodec_decode_audio4 (ff_ctx->avCodecCtx, &frame, &frameFinished, &ff_ctx->avPacket);

			if (frameFinished) {
				int data_size = frame.nb_samples * av_get_bytes_per_sample(frame.format);
				int sync_size = frame.nb_samples * sizeof (audio_sync_sample_t);

				framePTS = av_frame_get_best_effort_timestamp (&frame);

				frame_count = framePTS - ff_ctx->avInputCtx->streams[ff_ctx->audioIndexStream]->start_time;
				frame_pts_offset = frame_count * av_q2d(ff_ctx->avInputCtx->streams[ff_ctx->audioIndexStream]->time_base) ;

				initPTS = start_time + frame_pts_offset + ff_ctx->ptsDelay;

#ifdef _DBG_PTS
				printf ("frame decoded PTS %lu, frame count %lu, TB %d/%d, PTS %Lf\n", framePTS, frame_count, ff_ctx->avInputCtx->streams[ff_ctx->audioIndexStream]->time_base.num, ff_ctx->avInputCtx->streams[ff_ctx->audioIndexStream]->time_base.den, initPTS);
#endif

				//Build sync info data, sample timing
				for (ch = 0; ch < ff_ctx->avCodecCtx->channels; ch++) {
					sync_samples[ch] =  malloc(sync_size);

					PTS = initPTS;

					for (sample_count = 0; sample_count < frame.nb_samples; sample_count++) {
						PTS += (1/(float) sample_rate);
						sync_samples[ch][sample_count].samplePTS = PTS;
					}
				}

#ifdef _DBG_PTS
				printf ("ended samples PTS %Lf\n", PTS);
#endif
				for (ch = 0; ch < ff_ctx->avCodecCtx->channels; ch++) {
					ProduceSyncToBuffer (&to_audio_buffer, ch, (uint8_t*) sync_samples[ch], sync_size);
					ProduceAudioToBuffer(&to_audio_buffer, ch, (uint8_t*) frame.extended_data[ch], data_size);

					free(sync_samples[ch]);
				}
			}

	       	long double time_2 = getSystemTime(NULL);
	       	adaptativeSleep( (1/READ_INPUT_FRAME_RATE) - (time_2 - time_1));
		}
	}
}
Example #8
0
File: main.c Project: LADI/ladish
int main(int argc, char** argv)
{
  #if ENABLE_NLS
    bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR);
    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
    textdomain (GETTEXT_PACKAGE);
  #endif

  gtk_init(&argc, &argv);

  if (!dbus_init())
  {
    return 1;
  }

  if (!conf_proxy_init())
  {
    return 1;
  }

  if (!canvas_init())
  {
    log_error("Canvas initialization failed.");
    return 1;
  }

  if (!init_gtk_builder())
  {
    return 1;
  }

  g_main_win = get_gtk_builder_widget("main_win");

  init_dialogs();

  if (!create_studio_lists())
  {
    return 1;
  }

  init_statusbar();
  init_jack_widgets();

  create_room_dialog_init();

  world_tree_init();
  view_init();

  init_actions_and_accelerators();

  if (!menu_init())
  {
    return 1;
  }

  buffer_size_clear();

  if (!toolbar_init())
  {
    return 1;
  }

  if (!conf_register(LADISH_CONF_KEY_DAEMON_NOTIFY, NULL, NULL))
  {
    return 1;
  }

  if (!conf_register(LADISH_CONF_KEY_DAEMON_SHELL, NULL, NULL))
  {
    return 1;
  }

  if (!conf_register(LADISH_CONF_KEY_DAEMON_TERMINAL, NULL, NULL))
  {
    return 1;
  }

  if (!conf_register(LADISH_CONF_KEY_DAEMON_STUDIO_AUTOSTART, NULL, NULL))
  {
    return 1;
  }

  if (!conf_register(LADISH_CONF_KEY_DAEMON_JS_SAVE_DELAY, NULL, NULL))
  {
    return 1;
  }

  if (!conf_register(LADISH_CONF_KEY_JACK_CONF_TOOL, NULL, NULL))
  {
    return 1;
  }

  if (!init_jack())
  {
    return 1;
  }

  if (!a2j_proxy_init())
  {
    return 1;
  }

  if (!control_proxy_init())
  {
    return 1;
  }

  if (!studio_proxy_init())
  {
    return 1;
  }

  set_studio_callbacks();
  set_room_callbacks();

  g_signal_connect(G_OBJECT(g_main_win), "destroy", G_CALLBACK(gtk_main_quit), NULL);
  g_signal_connect(G_OBJECT(get_gtk_builder_widget("menu_item_quit")), "activate", G_CALLBACK(gtk_main_quit), NULL);
  g_signal_connect(G_OBJECT(get_gtk_builder_widget("menu_item_view_arrange")), "activate", G_CALLBACK(arrange), NULL);
  g_signal_connect(G_OBJECT(get_gtk_builder_widget("menu_item_help_about")), "activate", G_CALLBACK(show_about), NULL);

  gtk_widget_show(g_main_win);

  gtk_main();

  studio_proxy_uninit();
  control_proxy_uninit();
  a2j_proxy_uninit();
  uninit_jack();
  menu_uninit();
  create_room_dialog_uninit();
  destroy_studio_lists();
  uninit_gtk_builder();

  conf_proxy_uninit();
  dbus_uninit();

  return 0;
}
Example #9
0
int main(int argc, char *argv[])
{
	jack_client_t *client = NULL;
	const char* client_name = DEFAULT_CLIENT_NAME;
	const char* connect_port = NULL;
	float peakdb = 0.0f;			// The current peak signal level (in dB)
	float last_peakdb = 0.0f;		// The previous peak signal level (in dB)
	int silence_period = 1;			// Required period of silence for trigger
	int nodynamic_period = 10;		// Required period of no-dynamic for trigger
	int grace_period = 0;			// Period to wait before triggering again
	float silence_theshold = -40;	// Level considered silent (in dB)
	float nodynamic_theshold = 0;	// Minimum allowed delta between peaks (in dB)
	int silence_count = 0;			// Number of seconds of silence detected
	int nodynamic_count = 0;		// Number of seconds of no-dynamic detected
	int in_grace = 0;				// Number of seconds left in grace
	int opt;

	// Make STDOUT unbuffered
	setbuf(stdout, NULL);

	// Parse command line arguments
	while ((opt = getopt(argc, argv, "c:n:l:p:P:d:g:vqh")) != -1) {
		switch (opt) {
			case 'c': connect_port = optarg; break;
			case 'n': client_name = optarg; break;
			case 'l': silence_theshold = atof(optarg); break;
			case 'p': silence_period = fabs(atoi(optarg)); break;
			case 'd': nodynamic_theshold = atof(optarg); break;
			case 'P': nodynamic_period = atof(optarg); break;
			case 'g': grace_period = fabs(atoi(optarg)); break;
			case 'v': verbose = 1; break;
			case 'q': quiet = 1; break;
			case 'h':
			default:
				/* Show usage information */
				usage();
				break;
		}
	}
    argc -= optind;
    argv += optind;

	
	// Validate parameters
	if (quiet && verbose) {
    	fprintf(stderr, "Can't be quiet and verbose at the same time.\n");
    	usage();
	}

	// Initialise Jack
	client = init_jack( client_name, connect_port );
	
	
	// Main loop
	while (running) {
	
		// Sleep for 1 second
		usleep( 1000000 );
		
		// Are we in grace period ?
		if (in_grace) {
			in_grace--;
			if (verbose) printf("%d seconds left in grace period.\n", in_grace);
			continue;
		}

		// Check we are connected to something
		if (jack_port_connected(input_port)==0) {
			if (verbose) printf("Input port isn't connected to anything.\n");
			continue;
		}
	
	
		// Read the recent peak (in decibels)
		last_peakdb = peakdb;
		peakdb = read_peak();
		
		
		// Do silence detection?
		if (silence_theshold) {
			if (verbose) printf("peak: %2.2fdB", peakdb);
		
			// Is peak too low?
			if (peakdb < silence_theshold) {
				silence_count++;
				if (verbose) printf(" (%d seconds of silence)\n", silence_count);
			} else {
				if (verbose) printf(" (not silent)\n");
				silence_count=0;
			}
	
			// Have we had enough seconds of silence?
			if (silence_count >= silence_period) {
				if (!quiet) printf("**SILENCE**\n");
				run_command( argc, argv );
				silence_count = 0;
				in_grace = grace_period;
			}
			
		}
		
		
		// Do no-dynamic detection
		if (nodynamic_theshold) {
			
			if (verbose) printf("delta: %2.2fdB", fabs(last_peakdb-peakdb));
			
			// Check the dynamic/delta between peaks
			if (fabs(last_peakdb-peakdb) < nodynamic_theshold) {
				nodynamic_count++;
				if (verbose) printf(" (%d seconds of no dynamic)\n", nodynamic_count);
			} else {
				if (verbose) printf(" (dynamic)\n");
				nodynamic_count=0;
			}
	
			// Have we had enough seconds of no dynamic?
			if (nodynamic_count >= nodynamic_period) {
				if (!quiet) printf("**NO DYNAMIC**\n");
				run_command( argc, argv );
				nodynamic_count = 0;
				in_grace = grace_period;
			}
	
		}



		
	}


	// Clean up
	finish_jack( client );


	return 0;
}