Browse Source

Merge 10792865e7 into 9ba44b14b8

pull/7/merge
Erik de Castro Lopo GitHub 6 years ago
parent
commit
631219c35e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 234 additions and 248 deletions
  1. +8
    -14
      alsa_in.c
  2. +8
    -14
      alsa_out.c
  3. +4
    -4
      evmon.c
  4. +214
    -216
      property.c

+ 8
- 14
alsa_in.c View File

@@ -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) {
@@ -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;
@@ -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 );
@@ -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++ )
@@ -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;
@@ -488,7 +482,7 @@ again:
//printf( "putback = %d\n", put_back_samples );
snd_pcm_rewind( alsa_handle, put_back_samples );

return 0;
return 0;
}

/**
@@ -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 )
@@ -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 );


+ 8
- 14
alsa_out.c View File

@@ -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) {
@@ -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;
}
@@ -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++ )
@@ -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;
@@ -466,7 +460,7 @@ again:
goto again;
}

return 0;
return 0;
}

/**
@@ -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 )
@@ -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 );


+ 4
- 4
evmon.c View File

@@ -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
@@ -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);
}
@@ -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 {
@@ -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;


+ 214
- 216
property.c View File

@@ -24,8 +24,8 @@ show_usage (void)
fprintf (stderr, " -d, --delete Remove/delete property \"key\" for \"UUID\"\n");
fprintf (stderr, " -d, --delete UUID Remove/delete all properties for \"UUID\"\n");
fprintf (stderr, " -D, --delete-all Remove/delete all properties\n");
fprintf (stderr, " --client Interpret UUID as a client name, not a UUID\n");
fprintf (stderr, " --port \tInterpret UUID as a port name, not a UUID\n");
fprintf (stderr, " --client Interpret UUID as a client name, not a UUID\n");
fprintf (stderr, " --port \tInterpret UUID as a port name, not a UUID\n");
fprintf (stderr, "\nDisplay options:\n");
fprintf (stderr, " -l Show all properties\n");
fprintf (stderr, " -l, --list UUID \tShow value all properties of UUID\n");
@@ -44,7 +44,7 @@ get_subject (jack_client_t* client, char* argv[], int* optind)
fprintf (stderr, "cannot get UUID for client named %s\n", cstr);
return -1;
}
if (jack_uuid_parse (ustr, &uuid)) {
fprintf (stderr, "cannot parse client UUID as UUID\n");
return -1;
@@ -61,13 +61,13 @@ get_subject (jack_client_t* client, char* argv[], int* optind)
fprintf (stderr, "cannot find port name %s\n", pstr);
return -1;
}
uuid = jack_port_uuid (port);
subject = pstr;

} else {
char* str = argv[(*optind)++];
if (jack_uuid_parse (str, &uuid)) {
fprintf (stderr, "cannot parse subject as UUID\n");
return -1;
@@ -81,7 +81,7 @@ get_subject (jack_client_t* client, char* argv[], int* optind)

int main (int argc, char* argv[])
{
jack_client_t* client = NULL;
jack_client_t* client = NULL;
jack_options_t options = JackNoStartServer;
char* key = NULL;
char* value = NULL;
@@ -89,7 +89,6 @@ int main (int argc, char* argv[])
int set = 1;
int delete = 0;
int delete_all = 0;
int list_all = 0;
int c;
int option_index;
extern int optind;
@@ -99,238 +98,237 @@ int main (int argc, char* argv[])
{ "delete-all", 0, 0, 'D' },
{ "list", 0, 0, 'l' },
{ "all", 0, 0, 'a' },
{ "client", 0, 0, 'c' },
{ "port", 0, 0, 'p' },
{ "client", 0, 0, 'c' },
{ "port", 0, 0, 'p' },
{ 0, 0, 0, 0 }
};

if (argc < 2) {
show_usage ();
exit (1);
}
if (argc < 2) {
show_usage ();
exit (1);
}

while ((c = getopt_long (argc, argv, "sdDlaApc", long_options, &option_index)) >= 0) {
switch (c) {
case 's':
if (argc < 5) {
show_usage ();
exit (1);
}
if (argc < 5) {
show_usage ();
exit (1);
}
set = 1;
break;
case 'd':
if (argc < 3) {
show_usage ();
return 1;
}
set = 0;
delete = 1;
break;

case 'D':
delete = 0;
set = 0;
delete_all = 1;
break;

case 'l':
set = 0;
delete = 0;
delete_all = 0;
break;

case 'a':
list_all = 1;
set = 0;
delete = 0;
delete_all = 0;
break;

case 'p':
subject_is_port = 1;
break;

case 'c':
subject_is_client = 1;
break;

case '?':
default:
show_usage ();
exit (1);
}
}
case 'd':
if (argc < 3) {
show_usage ();
return 1;
}
set = 0;
delete = 1;
break;

if ((client = jack_client_open ("jack-property", options, NULL)) == 0) {
fprintf (stderr, "Cannot connect to JACK server\n");
exit (1);
}
case 'D':
delete = 0;
set = 0;
delete_all = 1;
break;

if (delete_all) {
case 'l':
set = 0;
delete = 0;
delete_all = 0;
break;

if (jack_remove_all_properties (client) == 0) {
printf ("JACK metadata successfully delete\n");
exit (0);
}
exit (1);
}
case 'a':
set = 0;
delete = 0;
delete_all = 0;
break;

if (delete) {
case 'p':
subject_is_port = 1;
break;

int args_left = argc - optind;
case 'c':
subject_is_client = 1;
break;

if (args_left < 1) {
show_usage ();
exit (1);
}
case '?':
default:
show_usage ();
exit (1);
}
}

/* argc == 3: delete all properties for a subject
argc == 4: delete value of key for subject
*/

if (args_left >= 2) {
if (get_subject (client, argv, &optind)) {
return 1;
}

key = argv[optind++];

if (jack_remove_property (client, uuid, key)) {
fprintf (stderr, "\"%s\" property not removed for %s\n", key, subject);
exit (1);
}

} else {
if (get_subject (client, argv, &optind)) {
return 1;
}
if (jack_remove_properties (client, uuid) < 0) {
fprintf (stderr, "cannot remove properties for UUID %s\n", subject);
exit (1);
}
}
if ((client = jack_client_open ("jack-property", options, NULL)) == 0) {
fprintf (stderr, "Cannot connect to JACK server\n");
exit (1);
}

} else if (set) {
if (delete_all) {

int args_left = argc - optind;
if (jack_remove_all_properties (client) == 0) {
printf ("JACK metadata successfully delete\n");
exit (0);
}
exit (1);
}

if (get_subject (client, argv, &optind)) {
return -1;
}
if (delete) {

key = argv[optind++];
value = argv[optind++];
int args_left = argc - optind;

if (args_left >= 3) {
type = argv[optind++];
} else {
type = "";
}
if (args_left < 1) {
show_usage ();
exit (1);
}

if (jack_set_property (client, uuid, key, value, type)) {
fprintf (stderr, "cannot set value for key %s of %s\n", value, subject);
exit (1);
}
} else {
/* argc == 3: delete all properties for a subject
argc == 4: delete value of key for subject
*/

/* list properties */
int args_left = argc - optind;

if (args_left >= 2) {

/* list properties for a UUID/key pair */

if (get_subject (client, argv, &optind)) {
return -1;
}

key = argv[optind++];

if (jack_get_property (uuid, key, &value, &type) == 0) {
printf ("%s\n", value);
free (value);
if (type) {
free (type);
}
} else {
fprintf (stderr, "Value not found for %s of %s\n", key, subject);
exit (1);
}

} else if (args_left == 1) {

/* list all properties for a given UUID */

jack_description_t description;
size_t cnt, n;

if (get_subject (client, argv, &optind)) {
return -1;
}
if ((cnt = jack_get_properties (uuid, &description)) < 0) {
fprintf (stderr, "could not retrieve properties for %s\n", subject);
exit (1);
}

for (n = 0; n < cnt; ++n) {
if (description.properties[n].type) {
printf ("key: %s value: %s type: %s\n",
description.properties[n].key,
description.properties[n].data,
description.properties[n].type);
} else {
printf ("key: %s value: %s\n",
description.properties[n].key,
description.properties[n].data);
}
}

jack_free_description (&description, 0);

} else {

/* list all properties */

jack_description_t* description;
size_t cnt;
size_t p;
size_t n;
char buf[JACK_UUID_STRING_SIZE];

if ((cnt = jack_get_all_properties (&description)) < 0) {
fprintf (stderr, "could not retrieve properties for %s\n", subject);
exit (1);
}

for (n = 0; n < cnt; ++n) {
jack_uuid_unparse (description[n].subject, buf);
printf ("%s\n", buf);
for (p = 0; p < description[n].property_cnt; ++p) {
if (description[n].properties[p].type) {
printf ("key: %s value: %s type: %s\n",
description[n].properties[p].key,
description[n].properties[p].data,
description[n].properties[p].type);
} else {
printf ("key: %s value: %s\n",
description[n].properties[p].key,
description[n].properties[p].data);
}
}
jack_free_description (&description[n], 0);
}

free (description);
}
}
if (args_left >= 2) {

if (get_subject (client, argv, &optind)) {
return 1;
}

(void) jack_client_close (client);
return 0;
key = argv[optind++];

if (jack_remove_property (client, uuid, key)) {
fprintf (stderr, "\"%s\" property not removed for %s\n", key, subject);
exit (1);
}

} else {

if (get_subject (client, argv, &optind)) {
return 1;
}

if (jack_remove_properties (client, uuid) < 0) {
fprintf (stderr, "cannot remove properties for UUID %s\n", subject);
exit (1);
}
}

} else if (set) {

int args_left = argc - optind;

if (get_subject (client, argv, &optind)) {
return -1;
}

key = argv[optind++];
value = argv[optind++];

if (args_left >= 3) {
type = argv[optind++];
} else {
type = "";
}

if (jack_set_property (client, uuid, key, value, type)) {
fprintf (stderr, "cannot set value for key %s of %s\n", value, subject);
exit (1);
}

} else {

/* list properties */

int args_left = argc - optind;

if (args_left >= 2) {

/* list properties for a UUID/key pair */

if (get_subject (client, argv, &optind)) {
return -1;
}

key = argv[optind++];

if (jack_get_property (uuid, key, &value, &type) == 0) {
printf ("%s\n", value);
free (value);
if (type) {
free (type);
}
} else {
fprintf (stderr, "Value not found for %s of %s\n", key, subject);
exit (1);
}

} else if (args_left == 1) {

/* list all properties for a given UUID */

jack_description_t description;
size_t cnt, n;

if (get_subject (client, argv, &optind)) {
return -1;
}

if ((cnt = jack_get_properties (uuid, &description)) < 0) {
fprintf (stderr, "could not retrieve properties for %s\n", subject);
exit (1);
}

for (n = 0; n < cnt; ++n) {
if (description.properties[n].type) {
printf ("key: %s value: %s type: %s\n",
description.properties[n].key,
description.properties[n].data,
description.properties[n].type);
} else {
printf ("key: %s value: %s\n",
description.properties[n].key,
description.properties[n].data);
}
}

jack_free_description (&description, 0);

} else {

/* list all properties */

jack_description_t* description;
size_t cnt;
size_t p;
size_t n;
char buf[JACK_UUID_STRING_SIZE];

if ((cnt = jack_get_all_properties (&description)) < 0) {
fprintf (stderr, "could not retrieve properties for %s\n", subject);
exit (1);
}

for (n = 0; n < cnt; ++n) {
jack_uuid_unparse (description[n].subject, buf);
printf ("%s\n", buf);
for (p = 0; p < description[n].property_cnt; ++p) {
if (description[n].properties[p].type) {
printf ("key: %s value: %s type: %s\n",
description[n].properties[p].key,
description[n].properties[p].data,
description[n].properties[p].type);
} else {
printf ("key: %s value: %s\n",
description[n].properties[p].key,
description[n].properties[p].data);
}
}
jack_free_description (&description[n], 0);
}

free (description);
}
}


(void) jack_client_close (client);
return 0;
}

Loading…
Cancel
Save