예제 #1
0
static int audio_read_header(AVFormatContext *context, AVFormatParameters *params)
{
    JackData *self = context->priv_data;
    AVStream *stream;
    int test;

    if (params->sample_rate <= 0 || params->channels <= 0)
        return -1;

    if ((test = start_jack(context, params)))
        return test;

    stream = av_new_stream(context, 0);
    if (!stream) {
        stop_jack(self);
        return AVERROR(ENOMEM);
    }

    stream->codec->codec_type   = CODEC_TYPE_AUDIO;
#if HAVE_BIGENDIAN
    stream->codec->codec_id     = CODEC_ID_PCM_F32BE;
#else
    stream->codec->codec_id     = CODEC_ID_PCM_F32LE;
#endif
    stream->codec->sample_rate  = self->sample_rate;
    stream->codec->channels     = self->nports;

    av_set_pts_info(stream, 64, 1, 1000000);  /* 64 bits pts in us */
    return 0;
}
예제 #2
0
파일: perform.hpp 프로젝트: EQ4/sequencer64
 void start_playing (bool flag = false)
 {
     position_jack(flag);
     start_jack();
     start(flag);
     g_rc_settings.is_pattern_playing(true);
 }
예제 #3
0
int jack_play_alloc(struct auplay_st **stp, const struct auplay *ap,
		    struct auplay_prm *prm, const char *device,
		    auplay_write_h *wh, void *arg)
{
	struct auplay_st *st;
	int err = 0;

	if (!stp || !ap || !prm || !wh)
		return EINVAL;

	info("jack: play %uHz,%uch\n", prm->srate, prm->ch);

	if (prm->ch > ARRAY_SIZE(st->portv))
		return EINVAL;

	st = mem_zalloc(sizeof(*st), auplay_destructor);
	if (!st)
		return ENOMEM;

	st->prm = *prm;
	st->ap  = ap;
	st->wh  = wh;
	st->arg = arg;

	err = start_jack(st);
	if (err)
		goto out;

	st->sampc = st->nframes * prm->ch;
	st->sampv = mem_alloc(st->sampc * sizeof(int16_t), NULL);
	if (!st->sampv) {
		err = ENOMEM;
		goto out;
	}

	info("jack: sampc=%zu\n", st->sampc);

 out:
	if (err)
		mem_deref(st);
	else
		*stp = st;

	return err;
}
예제 #4
0
파일: main.c 프로젝트: Prichy/SoundDesk
static bool
init_all()
/*
 * Master initialisation routine (calls all of the others)
 */
{
	int	i;

	bool	(* init_func[])(void) =		 /* List of init routines     */
			{
				init_objects,
				init_config,
				init_global_vars,
				init_triggers,
				init_automators,
				init_cues,
				init_actions,
				init_keyhooks,
				init_midihooks,
				init_mixers,
				init_decks,
				init_devices,
				init_midi,
				init_cables,
				load_config,
				init_guilib,
				init_gui,
				init_samples,
				init_runtime_layout,
				init_jack,
				NULL
			};

	for(i=0; init_func[i]; i++)		 /* For each init routine ... */
		if(!init_func[i]())		 /* ... call it!	      */
			return FALSE;		 /* ... if it failed	      */

	start_jack();				 /* Don't care if this fails  */

	return TRUE;				 /* Everything worked!	      */
}						 /* init_all()		      */
예제 #5
0
파일: main.c 프로젝트: pmyadlowsky/qmx
int main(int argc, char **argv) {
	struct pollfd polls[MAX_POLL_ITEMS];
	int opt, background, fdin, nfds, watch_alsa;
	int con_in, msg_in;
	background = 0;
	watch_alsa = 0;
	client_name = DEFAULT_CLIENT_NAME;
	server_name = DEFAULT_SERVER_NAME;
	msg_port = DEFAULT_MSG_PORT;
	sampling_rate = DEFAULT_SAMPLING_RATE;
	period_frames = DEFAULT_PERIOD_SIZE;
	while ((opt = getopt(argc, argv, "adn:p:P:r:s:")) != -1) {
		switch (opt) {
			case 'a': watch_alsa = 1; break;
			case 'd': background = 1; break;
			case 'j': use_jack = 1; break;
			case 'n': client_name = optarg; break;
			case 'P': msg_port = atoi(optarg); break;
			case 'p': period_frames = atoi(optarg); break;
			case 'r': sampling_rate = atoi(optarg); break;
			case 's': server_name = optarg; break;
			default:
				fprintf(stderr, "invalid option: %c", opt);
				exit(1);
			}
		}
	if (background) {
		set_handler(SIGCHLD, sigsnag);
		if (fork() > 0) _exit(0);
		}
	set_handler(SIGINT, sigsnag);
	set_handler(SIGTERM, sigsnag);
	set_handler(SIGABRT, sigsnag);
	set_handler(SIGHUP, sigsnag);
	set_handler(SIGQUIT, sigsnag);
	scm_init_guile();
	init_env();
	if (use_jack) start_jack(NULL);
	else {
		size_t memsize = QMX_CHANNELS * period_frames * sizeof(sample_t);
		fixed_cauldron = (sample_t *)malloc(memsize);
		int ret = mlock(fixed_cauldron, memsize);
		if (ret == 0) log_msg("MIXMEM locked: %lu\n", memsize);
		else log_msg("MIXMEM not locked: %s\n", strerror(errno));
		}
	start_outbuffer();
	scm_c_define("jack-sampling-rate", scm_from_int(sampling_rate));
	while (optind < argc) {
		log_msg("load %s\n", argv[optind]);
		scm_c_primitive_load(argv[optind]);
		optind++;
		}
	fdin = fileno(stdin);
	nfds = 0;
	con_in = -1;
	if (!background) {
		con_in = nfds;
		polls[nfds].fd = fdin;
		polls[nfds].events = POLLIN;
		nfds++;
		}
	msg_in = -1;
	if (msg_socket() >= 0) {
		msg_in = nfds;
		polls[nfds].fd = msg_socket();
		polls[nfds].events = POLLIN;
		nfds++;
		}
	if (isatty(fdin)) rl_callback_handler_install(prompt, line_handler);
	running = 1;
	if (!use_jack) spawn_detached_thread(mix_thread_abs, NULL);
	while (running) {
		if (watch_alsa) check_card_event();
		if (poll(polls, nfds, POLL_TIMEOUT) < 1) continue;
		if ((con_in >= 0) && (polls[con_in].revents & POLLIN))
			process_line(fdin);
		if ((msg_in >= 0) && (polls[msg_in].revents & POLLIN))
			msg_process();
		}
	if (isatty(fdin)) rl_callback_handler_remove();
	shutdown_env();
	log_msg("bye!\n");
	cleanup();
	return 0;
	}
bool JackAudioInterface::go()
{
    // start JACK
    if (jack_server_is_running())
    {
        qDebug() << "JackAudioInterface::start Warning: JACK was already running" << endl;
    }
    else
    {
        qDebug() << "JackAudioInterface::start Starting JACK:" << endl;
        pid_t jackPID = start_jack(m_sampleRate, m_bufferSamples);
        qDebug() << "JackAudioInterface::start Finished starting JACK" << endl;
        if (jackPID >= 0)
        {
            qDebug() << "JackAudioInterface::start: Successfully started the JACK server with PID " << QString::number(jackPID) << endl;
        }
        else
        {
            qWarning() << "JackAudioInterface::start: Couldn't start JACK server" << endl;
            return false;
        }
    }
    
    // create a jack client
    if (!open_jack_client())
    {
        qWarning() << "JackAudioInterface::start Couldn't open JACK client" << endl;
        return false;
    }

    qDebug() << "JackAudioInterface::start opened JACK client" << endl;

    // check that buffer size and sample rate are correct
    if (jack_get_buffer_size(m_client) != m_bufferSamples || jack_get_sample_rate(m_client) != m_sampleRate)
    {
        qWarning() << "JackAudioInterface::start ERROR: JACK is running with incorrect parameters: sample rate = " << jack_get_sample_rate(m_client) << ", buffer size = " << jack_get_buffer_size(m_client) << endl;
        // TODO: how to communicate this error back to the app?
        return false;
    }
    
    qDebug() << "JackAudioInterface::start checked JACK parameters" << endl;

    // register jack callbacks
    jack_set_buffer_size_callback(m_client, JackAudioInterface::jack_buffer_size_changed, this);
    jack_set_process_callback(m_client, JackAudioInterface::jack_process, this);
    jack_set_sample_rate_callback(m_client, JackAudioInterface::jack_sample_rate_changed, this);
    jack_on_shutdown(m_client, JackAudioInterface::jack_shutdown, this);
    jack_set_xrun_callback(m_client, JackAudioInterface::jack_xrun, this);

    qDebug() << "JackAudioInterface::start registered JACK callbacks" << endl;

     // activate client (starts processing)
    if (jack_activate(m_client) != 0)
    {
        qDebug() << "JackAudioInterface::start Couldn't activate JACK client" << endl;
        return false;
    }

    qDebug() << "JackAudioInterface::start activated JACK client" << endl;
    return true;
}