Skip to content
This repository has been archived by the owner on Apr 20, 2022. It is now read-only.

Minor fixes #7

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions alsa_in.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,6 @@ static int set_swparams(snd_pcm_t *handle, snd_pcm_sw_params_t *swparams, int pe
printf("Unable to set avail min for capture: %s\n", snd_strerror(err));
return err;
}
/* align all transfers to 1 sample */
err = snd_pcm_sw_params_set_xfer_align(handle, swparams, 1);
if (err < 0) {
printf("Unable to set transfer align for capture: %s\n", snd_strerror(err));
return err;
}
/* write the parameters to the playback device */
err = snd_pcm_sw_params(handle, swparams);
if (err < 0) {
Expand Down Expand Up @@ -312,7 +306,7 @@ void freewheel (int freewheel_starting, void *ignored_arg)
if( freewheel_starting ) {
snd_pcm_close( alsa_handle );
alsa_handle = 0;
// reset resampling parameters
// reset resampling parameters
resample_mean = 1.0;
static_resample_factor = 1.0;
resample_lower_limit = 0.25;
Expand Down Expand Up @@ -342,7 +336,7 @@ int process (jack_nframes_t nframes, void *arg) {
/* freewheeling, or some other error */
return 0;
}

delay = snd_pcm_avail( alsa_handle );

delay -= jack_frames_since_cycle_start( client );
Expand All @@ -363,7 +357,7 @@ int process (jack_nframes_t nframes, void *arg) {

// Set the resample_rate... we need to adjust the offset integral, to do this.
// first look at the PI controller, this code is just a special case, which should never execute once
// everything is swung in.
// everything is swung in.
offset_integral = - (resample_mean - static_resample_factor) * catch_factor * catch_factor2;
// Also clear the array. we are beginning a new control cycle.
for( i=0; i<smooth_size; i++ )
Expand Down Expand Up @@ -408,7 +402,7 @@ int process (jack_nframes_t nframes, void *arg) {
if( fabs( smooth_offset ) < pclamp )
smooth_offset = 0.0;

// ok. now this is the PI controller.
// ok. now this is the PI controller.
// u(t) = K * ( e(t) + 1/T \int e(t') dt' )
// K = 1/catch_factor and T = catch_factor2
double current_resample_factor = static_resample_factor - smooth_offset / (double) catch_factor - offset_integral / (double) catch_factor / (double)catch_factor2;
Expand Down Expand Up @@ -488,7 +482,7 @@ int process (jack_nframes_t nframes, void *arg) {
//printf( "putback = %d\n", put_back_samples );
snd_pcm_rewind( alsa_handle, put_back_samples );

return 0;
return 0;
}

/**
Expand Down Expand Up @@ -720,7 +714,7 @@ int main (int argc, char *argv[]) {
jack_set_latency_callback (client, latency_cb, 0);

// get jack sample_rate

jack_sample_rate = jack_get_sample_rate( client );

if( !sample_rate )
Expand Down Expand Up @@ -756,11 +750,11 @@ int main (int argc, char *argv[]) {

jack_buffer_size = jack_get_buffer_size( client );
// Setup target delay and max_diff for the normal user, who does not play with them...
if( !target_delay )
if( !target_delay )
target_delay = (num_periods*period_size / 2) + jack_buffer_size/2;

if( !max_diff )
max_diff = num_periods*period_size - target_delay ;
max_diff = num_periods*period_size - target_delay ;

if( max_diff > target_delay ) {
fprintf( stderr, "target_delay (%d) cant be smaller than max_diff(%d)\n", target_delay, max_diff );
Expand Down
22 changes: 8 additions & 14 deletions alsa_out.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,6 @@ static int set_swparams(snd_pcm_t *handle, snd_pcm_sw_params_t *swparams, int pe
printf("Unable to set avail min for capture: %s\n", snd_strerror(err));
return err;
}
/* align all transfers to 1 sample */
err = snd_pcm_sw_params_set_xfer_align(handle, swparams, 1);
if (err < 0) {
printf("Unable to set transfer align for capture: %s\n", snd_strerror(err));
return err;
}
/* write the parameters to the playback device */
err = snd_pcm_sw_params(handle, swparams);
if (err < 0) {
Expand Down Expand Up @@ -298,10 +292,10 @@ static snd_pcm_t *open_audiofd( char *device_name, int capture, int rate, int ch
//snd_pcm_start( handle );
//snd_pcm_wait( handle, 200 );
int num_null_samples = nperiods * period * channels;
char *tmp = alloca( num_null_samples * formats[format].sample_size );
char *tmp = alloca( num_null_samples * formats[format].sample_size );
memset( tmp, 0, num_null_samples * formats[format].sample_size );
snd_pcm_writei( handle, tmp, num_null_samples );


return handle;
}
Expand Down Expand Up @@ -336,7 +330,7 @@ int process (jack_nframes_t nframes, void *arg) {

// Set the resample_rate... we need to adjust the offset integral, to do this.
// first look at the PI controller, this code is just a special case, which should never execute once
// everything is swung in.
// everything is swung in.
offset_integral = - (resample_mean - static_resample_factor) * catch_factor * catch_factor2;
// Also clear the array. we are beginning a new control cycle.
for( i=0; i<smooth_size; i++ )
Expand Down Expand Up @@ -388,7 +382,7 @@ int process (jack_nframes_t nframes, void *arg) {
if( fabs( smooth_offset ) < pclamp )
smooth_offset = 0.0;

// ok. now this is the PI controller.
// ok. now this is the PI controller.
// u(t) = K * ( e(t) + 1/T \int e(t') dt' )
// K = 1/catch_factor and T = catch_factor2
double current_resample_factor = static_resample_factor - smooth_offset / (double) catch_factor - offset_integral / (double) catch_factor / (double)catch_factor2;
Expand Down Expand Up @@ -466,7 +460,7 @@ int process (jack_nframes_t nframes, void *arg) {
goto again;
}

return 0;
return 0;
}

/**
Expand Down Expand Up @@ -695,7 +689,7 @@ int main (int argc, char *argv[]) {
jack_set_latency_callback (client, latency_cb, 0);

// get jack sample_rate

jack_sample_rate = jack_get_sample_rate( client );

if( !sample_rate )
Expand Down Expand Up @@ -724,11 +718,11 @@ int main (int argc, char *argv[]) {

jack_buffer_size = jack_get_buffer_size( client );
// Setup target delay and max_diff for the normal user, who does not play with them...
if( !target_delay )
if( !target_delay )
target_delay = (num_periods*period_size / 2) - jack_buffer_size/2;

if( !max_diff )
max_diff = target_delay;
max_diff = target_delay;

if( max_diff > target_delay ) {
fprintf( stderr, "target_delay (%d) cant be smaller than max_diff(%d)\n", target_delay, max_diff );
Expand Down
8 changes: 4 additions & 4 deletions evmon.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright (C) 2007 Paul Davis

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
Expand All @@ -27,7 +27,7 @@
#include <jack/uuid.h>

void
port_rename_callback (jack_port_id_t port, const char* old_name, const char* new_name)
port_rename_callback (jack_port_id_t port, const char* old_name, const char* new_name, void * ptr)
{
printf ("Port %d renamed from %s to %s\n", port, old_name, new_name);
}
Expand Down Expand Up @@ -82,7 +82,7 @@ propchange (jack_uuid_t subject, const char* key, jack_property_change_t change)
printf ("All properties changed!\n");
} else {
jack_uuid_unparse (subject, buf);

if (key) {
printf ("key [%s] for %s %s\n", key, buf, action);
} else {
Expand All @@ -106,7 +106,7 @@ main (int argc, char *argv[])
}
return 1;
}

if (jack_set_port_registration_callback (client, port_callback, NULL)) {
fprintf (stderr, "cannot set port registration callback\n");
return 1;
Expand Down
Loading