aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2016-06-18 19:33:08 +0200
committerAndreas Eversberg <jolly@eversberg.eu>2016-06-18 19:33:08 +0200
commit4d52f955b3aba7451e9349d38ae361e6823f1f4f (patch)
tree81649fb60c5da40db201a4a585aba55a7a04c22c
parente10898c1e8702488d2d03acc28faf528be157c98 (diff)
common code: Add processing interval option to decrese CPU usage
-rw-r--r--src/amps/main.c2
-rw-r--r--src/anetz/main.c2
-rw-r--r--src/bnetz/main.c2
-rw-r--r--src/cnetz/main.c2
-rw-r--r--src/common/main.h3
-rw-r--r--src/common/main_common.c22
-rw-r--r--src/nmt/main.c2
7 files changed, 25 insertions, 10 deletions
diff --git a/src/amps/main.c b/src/amps/main.c
index 65912fc..9cf18df 100644
--- a/src/amps/main.c
+++ b/src/amps/main.c
@@ -354,7 +354,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "Error setting SCHED_RR with prio %d\n", rt_prio);
}
- main_loop(&quit, latency);
+ main_loop(&quit, latency, interval);
if (rt_prio > 0) {
struct sched_param schedp;
diff --git a/src/anetz/main.c b/src/anetz/main.c
index 4e73f0a..f67abbe 100644
--- a/src/anetz/main.c
+++ b/src/anetz/main.c
@@ -193,7 +193,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "Error setting SCHED_RR with prio %d\n", rt_prio);
}
- main_loop(&quit, latency);
+ main_loop(&quit, latency, interval);
if (rt_prio > 0) {
struct sched_param schedp;
diff --git a/src/bnetz/main.c b/src/bnetz/main.c
index c625672..44379bb 100644
--- a/src/bnetz/main.c
+++ b/src/bnetz/main.c
@@ -208,7 +208,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "Error setting SCHED_RR with prio %d\n", rt_prio);
}
- main_loop(&quit, latency);
+ main_loop(&quit, latency, interval);
if (rt_prio > 0) {
struct sched_param schedp;
diff --git a/src/cnetz/main.c b/src/cnetz/main.c
index 0410e87..1027b34 100644
--- a/src/cnetz/main.c
+++ b/src/cnetz/main.c
@@ -313,7 +313,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "Error setting SCHED_RR with prio %d\n", rt_prio);
}
- main_loop(&quit, latency);
+ main_loop(&quit, latency, interval);
if (rt_prio > 0) {
struct sched_param schedp;
diff --git a/src/common/main.h b/src/common/main.h
index cc50013..6a67717 100644
--- a/src/common/main.h
+++ b/src/common/main.h
@@ -5,6 +5,7 @@ extern int num_sounddev;
extern const char *sounddev[];
extern const char *call_sounddev;
extern int samplerate;
+extern int interval;
extern int latency;
extern int cross_channels;
extern int do_pre_emphasis;
@@ -36,5 +37,5 @@ void opt_switch_common(int c, char *arg0, int *skip_args);
extern int quit;
void sighandler(int sigset);
-void main_loop(int *quit, int latency);
+void main_loop(int *quit, int latency, int interval);
diff --git a/src/common/main_common.c b/src/common/main_common.c
index 9820c1a..aef582e 100644
--- a/src/common/main_common.c
+++ b/src/common/main_common.c
@@ -39,6 +39,7 @@ int num_sounddev = 0;
const char *sounddev[MAX_SENDER] = { "hw:0,0" };
const char *call_sounddev = "";
int samplerate = 48000;
+int interval = 1;
int latency = 50;
int cross_channels = 0;
int do_pre_emphasis = 0;
@@ -69,8 +70,12 @@ void print_help_common(const char *arg0, const char *ext_usage)
printf(" Sound card and device number (default = '%s')\n", sounddev[0]);
printf(" -s --samplerate <rate>\n");
printf(" Sample rate of sound device (default = '%d')\n", samplerate);
+ printf(" -i --interval 1..25\n");
+ printf(" Interval of processing loop in ms (default = '%d' ms)\n", interval);
+ printf(" Use 25 to drastically reduce CPU usage. In case of buffer underrun,\n");
+ printf(" increase latency accordingly.\n");
printf(" -l --latency <delay>\n");
- printf(" How many milliseconds processed in advance (default = '%d')\n", latency);
+ printf(" How many milliseconds processed in advance (default = '%d')\n", latency);
printf(" -x --cross\n");
printf(" Cross channels on sound card. 1st channel (right) is swapped with\n");
printf(" second channel (left)\n");
@@ -107,6 +112,7 @@ static struct option long_options_common[] = {
{"device", 1, 0, 'd'},
{"call-device", 1, 0, 'c'},
{"samplerate", 1, 0, 's'},
+ {"interval", 1, 0, 'i'},
{"latency", 1, 0, 'l'},
{"cross", 0, 0, 'x'},
{"pre-emphasis", 0, 0, 'E'},
@@ -121,7 +127,7 @@ static struct option long_options_common[] = {
{0, 0, 0, 0}
};
-const char *optstring_common = "hD:k:d:s:c:l:xEeG:mp:L:r:W:R:";
+const char *optstring_common = "hD:k:d:s:c:i:l:xEeG:mp:L:r:W:R:";
struct option *long_options;
char *optstring;
@@ -176,6 +182,14 @@ void opt_switch_common(int c, char *arg0, int *skip_args)
call_sounddev = strdup(optarg);
*skip_args += 2;
break;
+ case 'i':
+ interval = atoi(optarg);
+ *skip_args += 2;
+ if (interval < 1)
+ interval = 1;
+ if (interval > 25)
+ interval = 25;
+ break;
case 'l':
latency = atoi(optarg);
*skip_args += 2;
@@ -263,7 +277,7 @@ static int get_char()
}
/* Loop through all transceiver instances of one network. */
-void main_loop(int *quit, int latency)
+void main_loop(int *quit, int latency, int interval)
{
int latspl;
sender_t *sender;
@@ -318,7 +332,7 @@ void main_loop(int *quit, int latency)
}
/* sleep a while */
- usleep(1000);
+ usleep(interval * 1000);
}
/* reset terminal */
diff --git a/src/nmt/main.c b/src/nmt/main.c
index afd049c..e19a937 100644
--- a/src/nmt/main.c
+++ b/src/nmt/main.c
@@ -286,7 +286,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "Error setting SCHED_RR with prio %d\n", rt_prio);
}
- main_loop(&quit, latency);
+ main_loop(&quit, latency, interval);
if (rt_prio > 0) {
struct sched_param schedp;