Exemplo n.º 1
0
    /* open audio using whatever parameters were last used */
void sys_reopen_audio( void)
{
    int naudioindev, audioindev[MAXAUDIOINDEV], chindev[MAXAUDIOINDEV];
    int naudiooutdev, audiooutdev[MAXAUDIOOUTDEV], choutdev[MAXAUDIOOUTDEV];
    int rate, advance, callback, blocksize, outcome = 0;
    sys_get_audio_params(&naudioindev, audioindev, chindev,
        &naudiooutdev, audiooutdev, choutdev, &rate, &advance, &callback,
            &blocksize);
    sys_setchsr(audio_nextinchans, audio_nextoutchans, rate);
    if (!naudioindev && !naudiooutdev)
    {
        sched_set_using_audio(SCHED_AUDIO_NONE);
        return;
    }
#ifdef USEAPI_PORTAUDIO
    if (sys_audioapi == API_PORTAUDIO)
    {
        int blksize = (audio_blocksize ? audio_blocksize : 64);
        if (sys_verbose)
            fprintf(stderr, "blksize %d, advance %d\n", blksize, sys_advance_samples/blksize);
        outcome = pa_open_audio((naudioindev > 0 ? chindev[0] : 0),
        (naudiooutdev > 0 ? choutdev[0] : 0), rate, STUFF->st_soundin,
            STUFF->st_soundout, blksize, sys_advance_samples/blksize,
             (naudioindev > 0 ? audioindev[0] : 0),
              (naudiooutdev > 0 ? audiooutdev[0] : 0),
               (callback ? sched_audio_callbackfn : 0));
    }
    else
#endif
#ifdef USEAPI_JACK
    if (sys_audioapi == API_JACK)
        outcome = jack_open_audio((naudioindev > 0 ? chindev[0] : 0),
            (naudiooutdev > 0 ? choutdev[0] : 0), rate,
                (callback ? sched_audio_callbackfn : 0));

    else
#endif
#ifdef USEAPI_OSS
    if (sys_audioapi == API_OSS)
        outcome = oss_open_audio(naudioindev, audioindev, naudioindev,
            chindev, naudiooutdev, audiooutdev, naudiooutdev, choutdev, rate,
                audio_blocksize);
    else
#endif
#ifdef USEAPI_ALSA
        /* for alsa, only one device is supported; it may
        be open for both input and output. */
    if (sys_audioapi == API_ALSA)
        outcome = alsa_open_audio(naudioindev, audioindev, naudioindev,
            chindev, naudiooutdev, audiooutdev, naudiooutdev, choutdev, rate,
                audio_blocksize);
    else
#endif
#ifdef USEAPI_MMIO
    if (sys_audioapi == API_MMIO)
        outcome = mmio_open_audio(naudioindev, audioindev, naudioindev,
            chindev, naudiooutdev, audiooutdev, naudiooutdev, choutdev, rate,
                audio_blocksize);
    else
#endif
#ifdef USEAPI_AUDIOUNIT
    if (sys_audioapi == API_AUDIOUNIT)
        outcome = audiounit_open_audio((naudioindev > 0 ? chindev[0] : 0),
            (naudioindev > 0 ? choutdev[0] : 0), rate);
    else
#endif
#ifdef USEAPI_ESD
    if (sys_audioapi == API_ALSA)
        outcome = esd_open_audio(naudioindev, audioindev, naudioindev,
            chindev, naudiooutdev, audiooutdev, naudiooutdev, choutdev, rate);
    else
#endif
#ifdef USEAPI_DUMMY
    if (sys_audioapi == API_DUMMY)
        outcome = dummy_open_audio(naudioindev, naudiooutdev, rate);
    else
#endif
    if (sys_audioapi == API_NONE)
        ;
    else post("unknown audio API specified");
    if (outcome)    /* failed */
    {
        audio_state = 0;
        sched_set_using_audio(SCHED_AUDIO_NONE);
        sys_audioapiopened = -1;
        audio_callback_is_open = 0;
    }
    else
    {
                /* fprintf(stderr, "started w/callback %d\n", callback); */
        audio_state = 1;
        sched_set_using_audio(
            (callback ? SCHED_AUDIO_CALLBACK : SCHED_AUDIO_POLL));
        sys_audioapiopened = sys_audioapi;
        audio_callback_is_open = callback;
    }
    sys_vgui("set pd_whichapi %d\n",  (outcome == 0 ? sys_audioapi : 0));
}
Exemplo n.º 2
0
void sys_open_audio(int naudioindev, int *audioindev, int nchindev,
    int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev,
    int *choutdev, int rate, int advance, int enable)
{
#ifdef ROCKBOX
    int i;
#else
    int i, *ip;
#endif
    int defaultchannels = SYS_DEFAULTCH;
    int inchans, outchans;
    if (rate < 1)
    	rate = SYS_DEFAULTSRATE;
#ifdef ROCKBOX
    pd_audio_init();
#else
    audio_init();
#endif
    	/* Since the channel vector might be longer than the
	audio device vector, or vice versa, we fill the shorter one
	in to match the longer one.  Also, if both are empty, we fill in
	one device (the default) and two channels. */ 
    if (naudioindev == -1)
    { 	    	/* no input audio devices specified */
	if (nchindev == -1)
	{
	    nchindev=1;
	    chindev[0] = defaultchannels;
	    naudioindev = 1;
	    audioindev[0] = DEFAULTAUDIODEV;
	}
	else
	{
	    for (i = 0; i < MAXAUDIOINDEV; i++)
      	        audioindev[i] = i;
	    naudioindev = nchindev;
	}
    }
    else
    {
	if (nchindev == -1)
	{
	    nchindev = naudioindev;
	    for (i = 0; i < naudioindev; i++)
	    	chindev[i] = defaultchannels;
	}
	else if (nchindev > naudioindev)
	{
	    for (i = naudioindev; i < nchindev; i++)
	    {
	    	if (i == 0)
		    audioindev[0] = DEFAULTAUDIODEV;
		else audioindev[i] = audioindev[i-1] + 1;
    	    }
	    naudioindev = nchindev;
	}
	else if (nchindev < naudioindev)
	{
	    for (i = nchindev; i < naudioindev; i++)
	    {
	    	if (i == 0)
		    chindev[0] = defaultchannels;
		else chindev[i] = chindev[i-1];
    	    }
	    naudioindev = nchindev;
	}
    }

    if (naudiooutdev == -1)
    { 	    	/* not set */
	if (nchoutdev == -1)
	{
	    nchoutdev=1;
	    choutdev[0]=defaultchannels;
	    naudiooutdev=1;
	    audiooutdev[0] = DEFAULTAUDIODEV;
	}
	else
	{
	    for (i = 0; i < MAXAUDIOOUTDEV; i++)
      	        audiooutdev[i] = i;
	    naudiooutdev = nchoutdev;
	}
    }
    else
    {
	if (nchoutdev == -1)
	{
	    nchoutdev = naudiooutdev;
	    for (i = 0; i < naudiooutdev; i++)
	    	choutdev[i] = defaultchannels;
	}
	else if (nchoutdev > naudiooutdev)
	{
	    for (i = naudiooutdev; i < nchoutdev; i++)
	    {
	    	if (i == 0)
		    audiooutdev[0] = DEFAULTAUDIODEV;
		else audiooutdev[i] = audiooutdev[i-1] + 1;
    	    }
	    naudiooutdev = nchoutdev;
	}
	else if (nchoutdev < naudiooutdev)
	{
	    for (i = nchoutdev; i < naudiooutdev; i++)
	    {
	    	if (i == 0)
		    choutdev[0] = defaultchannels;
		else choutdev[i] = choutdev[i-1];
    	    }
	    naudiooutdev = nchoutdev;
	}
    }

    	/* count total number of input and output channels */
    for (i = inchans = 0; i < naudioindev; i++)
    	inchans += chindev[i];
    for (i = outchans = 0; i < naudiooutdev; i++)
    	outchans += choutdev[i];
    	/* if no input or output devices seem to have been specified,
	this really means just disable audio, which we now do.  Meanwhile,
	we can set audio input and output devices to their defaults. */
    if (!inchans && !outchans)
    {
    	enable = 0;
	naudioindev = nchindev = naudiooutdev = nchoutdev = 1;
	audioindev[0] = audiooutdev[0] = DEFAULTAUDIODEV;
	chindev[0] = choutdev[0] = 0;
    }
    sys_schedadvance = advance * 1000;
    sys_setchsr(inchans, outchans, rate);
    sys_log_error(ERR_NOTHING);

    if (enable && (inchans > 0 || outchans > 0))
    {
#ifdef USEAPI_PORTAUDIO
	if (sys_audioapi == API_PORTAUDIO)
	{
    	    int blksize = (sys_blocksize ? sys_blocksize : 64);
	    pa_open_audio(inchans, outchans, rate, sys_soundin, sys_soundout,
		blksize, sys_advance_samples/blksize,
		    (naudiooutdev > 0 ? audioindev[0] : 0),
			(naudiooutdev > 0 ? audiooutdev[0] : 0));
	}
else
#endif
#ifdef USEAPI_JACK
	if (sys_audioapi == API_JACK) 
	    jack_open_audio((naudioindev > 0 ? chindev[0] : 0),
			    (naudiooutdev > 0 ? choutdev[0] : 0), rate);

	else
#endif	  
#ifdef USEAPI_OSS
	if (sys_audioapi == API_OSS)
	    oss_open_audio(naudioindev, audioindev, nchindev, chindev,
    		    naudiooutdev, audiooutdev, nchoutdev, choutdev, rate);
	else
#endif
#ifdef USEAPI_ALSA
    	    /* for alsa, only one device is supported; it may
	    be open for both input and output. */
	if (sys_audioapi == API_ALSA)
	    alsa_open_audio(naudioindev, audioindev, nchindev, chindev,
    		    naudiooutdev, audiooutdev, nchoutdev, choutdev, rate);
	else 
#endif
#ifdef USEAPI_MMIO
	if (sys_audioapi == API_MMIO)
	    mmio_open_audio(naudioindev, audioindev, nchindev, chindev,
    		    naudiooutdev, audiooutdev, nchoutdev, choutdev, rate);
	else
#endif
#ifdef USEAPI_ROCKBOX
        if (sys_audioapi == API_ROCKBOX)
            rockbox_open_audio(rate);
        else
#endif
    	    post("unknown audio API specified");
    }
    sys_save_audio_params(naudioindev, audioindev, chindev,
    	naudiooutdev, audiooutdev, choutdev, rate, advance);
    if (sys_inchannels == 0 && sys_outchannels == 0)
    	enable = 0;
    audio_state = enable;
#ifndef ROCKBOX
    sys_vgui("set pd_whichapi %d\n",  (audio_isopen() ? sys_audioapi : 0));
#endif
    sched_set_using_dacs(enable);
}