Browse Source

alsa_in/alsa_out should be aware of freewheeling mode

alsa_in/alsa_out need to close the ALSA device they use when freewheeling starts and then reopen it, along with reset resampling parameters, when it ends. this avoids bizarre behaviour during freewheeling as they try to do audio i/o with a still open PCM device
tags/0.124.0
Paul Davis 13 years ago
parent
commit
0179013e7e
1 changed files with 23 additions and 3 deletions
  1. +23
    -3
      alsa_in.c

+ 23
- 3
alsa_in.c View File

@@ -48,6 +48,7 @@ double offset_integral = 0;

// ------------------------------------------------------ commandline parameters

const char* alsa_device = "hw:0";
int sample_rate = 0; /* stream rate */
int num_channels = 2; /* count of channels */
int period_size = 1024;
@@ -272,7 +273,7 @@ static int set_swparams(snd_pcm_t *handle, snd_pcm_sw_params_t *swparams, int pe

// ok... i only need this function to communicate with the alsa bloat api...

static snd_pcm_t *open_audiofd( char *device_name, int capture, int rate, int channels, int period, int nperiods ) {
static snd_pcm_t *open_audiofd( const char *device_name, int capture, int rate, int channels, int period, int nperiods ) {
int err;
snd_pcm_t *handle;
snd_pcm_hw_params_t *hwparams;
@@ -306,6 +307,17 @@ double hann( double x )
return 0.5 * (1.0 - cos( 2*M_PI * x ) );
}

void freewheel (int freewheel_starting, void *ignored_arg)
{
if( freewheel_starting ) {
snd_pcm_close( alsa_handle );
} else {
alsa_handle = open_audiofd( alsa_device, 1, sample_rate, num_channels, period_size, num_periods);
if( alsa_handle == 0 )
exit(20);
}
}

/**
* The process callback for this JACK application.
* It is called by JACK at the appropriate times.
@@ -318,6 +330,11 @@ int process (jack_nframes_t nframes, void *arg) {
int put_back_samples=0;
int i;

if (alsa_handle == 0) {
/* freewheeling, or some other error */
return 0;
}
delay = snd_pcm_avail( alsa_handle );

delay -= jack_frames_since_cycle_start( client );
@@ -593,7 +610,6 @@ sigterm_handler( int signal )

int main (int argc, char *argv[]) {
char jack_name[30] = "alsa_in";
char alsa_device[30] = "hw:0";

extern char *optarg;
extern int optind, optopt;
@@ -618,7 +634,7 @@ int main (int argc, char *argv[]) {
num_periods = atoi(optarg);
break;
case 'd':
strcpy(alsa_device,optarg);
alsa_device = strdup (optarg);
break;
case 't':
target_delay = atoi(optarg);
@@ -681,6 +697,10 @@ int main (int argc, char *argv[]) {

jack_set_process_callback (client, process, 0);

/* handle freewheeling */

jack_set_freewheel_callback (client, freewheel, 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.


Loading…
Cancel
Save