mirror of
https://github.com/alsa-project/alsa-utils
synced 2025-01-05 12:56:42 +01:00
- added --buffer-size and --period-size options.
- accept -h as the help :) - fixed VU meter for 8 bit and negative values. - updated man page.
This commit is contained in:
parent
271d3b0fa1
commit
cb8494d8d4
2 changed files with 59 additions and 20 deletions
|
@ -25,7 +25,7 @@ If filename is not specified, the standard output or input is used. The \fBaplay
|
||||||
|
|
||||||
.SS Options
|
.SS Options
|
||||||
.TP
|
.TP
|
||||||
\fI--help\fP
|
\fI-h, --help\fP
|
||||||
Help: show syntax.
|
Help: show syntax.
|
||||||
.TP
|
.TP
|
||||||
\fI--version\fP
|
\fI--version\fP
|
||||||
|
@ -86,6 +86,12 @@ Distance between interrupts is # microseconds
|
||||||
\fI-B, --buffer-time=#\fP
|
\fI-B, --buffer-time=#\fP
|
||||||
Buffer duration is # microseconds
|
Buffer duration is # microseconds
|
||||||
.TP
|
.TP
|
||||||
|
\fI--period-size=#\fP
|
||||||
|
Distance between interrupts is # frames
|
||||||
|
.TP
|
||||||
|
\fI--buffer-size=#\fP
|
||||||
|
Buffer duration is # frames
|
||||||
|
.TP
|
||||||
\fI-A, --avail-min=#\fP
|
\fI-A, --avail-min=#\fP
|
||||||
Min available space for wakeup is # microseconds
|
Min available space for wakeup is # microseconds
|
||||||
.TP
|
.TP
|
||||||
|
@ -97,11 +103,12 @@ Delay for automatic PCM start is # microseconds
|
||||||
Delay for automatic PCM stop is # microseconds from xrun
|
Delay for automatic PCM stop is # microseconds from xrun
|
||||||
.TP
|
.TP
|
||||||
\fI-v, --verbose\fP
|
\fI-v, --verbose\fP
|
||||||
Show PCM structure and setup
|
Show PCM structure and setup.
|
||||||
|
This option is accumulative. The VU meter is displayed when this
|
||||||
|
is given twice.
|
||||||
.TP
|
.TP
|
||||||
\fI-I, --separate-channels\fP
|
\fI-I, --separate-channels\fP
|
||||||
One file for each channel
|
One file for each channel
|
||||||
.TP
|
|
||||||
|
|
||||||
.SS
|
.SS
|
||||||
Example:
|
Example:
|
||||||
|
|
|
@ -83,6 +83,8 @@ static char *audiobuf = NULL;
|
||||||
static snd_pcm_uframes_t chunk_size = 0;
|
static snd_pcm_uframes_t chunk_size = 0;
|
||||||
static unsigned period_time = 0;
|
static unsigned period_time = 0;
|
||||||
static unsigned buffer_time = 0;
|
static unsigned buffer_time = 0;
|
||||||
|
static snd_pcm_uframes_t period_frames = 0;
|
||||||
|
static snd_pcm_uframes_t buffer_frames = 0;
|
||||||
static int avail_min = -1;
|
static int avail_min = -1;
|
||||||
static int start_delay = 0;
|
static int start_delay = 0;
|
||||||
static int stop_delay = 0;
|
static int stop_delay = 0;
|
||||||
|
@ -142,8 +144,8 @@ static void usage(char *command)
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Usage: %s [OPTION]... [FILE]...\n"
|
"Usage: %s [OPTION]... [FILE]...\n"
|
||||||
"\n"
|
"\n"
|
||||||
"--help help\n"
|
"-h, --help help\n"
|
||||||
"--version print current version\n"
|
" --version print current version\n"
|
||||||
"-l, --list-devices list all soundcards and digital audio devices\n"
|
"-l, --list-devices list all soundcards and digital audio devices\n"
|
||||||
"-L, --list-pcms list all PCMs defined\n"
|
"-L, --list-pcms list all PCMs defined\n"
|
||||||
"-D, --device=NAME select PCM by name\n"
|
"-D, --device=NAME select PCM by name\n"
|
||||||
|
@ -158,6 +160,8 @@ static void usage(char *command)
|
||||||
"-N, --nonblock nonblocking mode\n"
|
"-N, --nonblock nonblocking mode\n"
|
||||||
"-F, --period-time=# distance between interrupts is # microseconds\n"
|
"-F, --period-time=# distance between interrupts is # microseconds\n"
|
||||||
"-B, --buffer-time=# buffer duration is # microseconds\n"
|
"-B, --buffer-time=# buffer duration is # microseconds\n"
|
||||||
|
" --period-size=# distance between interrupts is # frames\n"
|
||||||
|
" --buffer-size=# buffer duration is # frames\n"
|
||||||
"-A, --avail-min=# min available space for wakeup is # microseconds\n"
|
"-A, --avail-min=# min available space for wakeup is # microseconds\n"
|
||||||
"-R, --start-delay=# delay for automatic PCM start is # microseconds \n"
|
"-R, --start-delay=# delay for automatic PCM start is # microseconds \n"
|
||||||
" (relative to buffer size if <= 0)\n"
|
" (relative to buffer size if <= 0)\n"
|
||||||
|
@ -287,15 +291,18 @@ static void signal_handler(int sig)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define OPT_HELP 1
|
enum {
|
||||||
#define OPT_VERSION 2
|
OPT_VERSION = 1,
|
||||||
|
OPT_PERIOD_SIZE,
|
||||||
|
OPT_BUFFER_SIZE
|
||||||
|
};
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int option_index;
|
int option_index;
|
||||||
char *short_options = "lLD:qt:c:f:r:d:s:MNF:A:X:R:T:B:vIPC";
|
char *short_options = "hlLD:qt:c:f:r:d:s:MNF:A:X:R:T:B:vIPC";
|
||||||
static struct option long_options[] = {
|
static struct option long_options[] = {
|
||||||
{"help", 0, 0, OPT_HELP},
|
{"help", 0, 0, 'h'},
|
||||||
{"version", 0, 0, OPT_VERSION},
|
{"version", 0, 0, OPT_VERSION},
|
||||||
{"list-devices", 0, 0, 'l'},
|
{"list-devices", 0, 0, 'l'},
|
||||||
{"list-pcms", 0, 0, 'L'},
|
{"list-pcms", 0, 0, 'L'},
|
||||||
|
@ -310,10 +317,12 @@ int main(int argc, char *argv[])
|
||||||
{"mmap", 0, 0, 'M'},
|
{"mmap", 0, 0, 'M'},
|
||||||
{"nonblock", 0, 0, 'N'},
|
{"nonblock", 0, 0, 'N'},
|
||||||
{"period-time", 1, 0, 'F'},
|
{"period-time", 1, 0, 'F'},
|
||||||
|
{"period-size", 1, 0, OPT_PERIOD_SIZE},
|
||||||
{"avail-min", 1, 0, 'A'},
|
{"avail-min", 1, 0, 'A'},
|
||||||
{"start-delay", 1, 0, 'R'},
|
{"start-delay", 1, 0, 'R'},
|
||||||
{"stop-delay", 1, 0, 'T'},
|
{"stop-delay", 1, 0, 'T'},
|
||||||
{"buffer-time", 1, 0, 'B'},
|
{"buffer-time", 1, 0, 'B'},
|
||||||
|
{"buffer-size", 1, 0, OPT_BUFFER_SIZE},
|
||||||
{"verbose", 0, 0, 'v'},
|
{"verbose", 0, 0, 'v'},
|
||||||
{"separate-channels", 0, 0, 'I'},
|
{"separate-channels", 0, 0, 'I'},
|
||||||
{"playback", 0, 0, 'P'},
|
{"playback", 0, 0, 'P'},
|
||||||
|
@ -350,7 +359,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, short_options, long_options, &option_index)) != -1) {
|
while ((c = getopt_long(argc, argv, short_options, long_options, &option_index)) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case OPT_HELP:
|
case 'h':
|
||||||
usage(command);
|
usage(command);
|
||||||
return 0;
|
return 0;
|
||||||
case OPT_VERSION:
|
case OPT_VERSION:
|
||||||
|
@ -435,6 +444,12 @@ int main(int argc, char *argv[])
|
||||||
case 'B':
|
case 'B':
|
||||||
buffer_time = atoi(optarg);
|
buffer_time = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
|
case OPT_PERIOD_SIZE:
|
||||||
|
period_frames = atoi(optarg);
|
||||||
|
break;
|
||||||
|
case OPT_BUFFER_SIZE:
|
||||||
|
buffer_frames = atoi(optarg);
|
||||||
|
break;
|
||||||
case 'A':
|
case 'A':
|
||||||
avail_min = atoi(optarg);
|
avail_min = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
|
@ -829,15 +844,28 @@ static void set_params(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rate = hwparams.rate;
|
rate = hwparams.rate;
|
||||||
|
if (buffer_time == 0 && buffer_frames > 0) {
|
||||||
|
err = snd_pcm_hw_params_set_buffer_size_near(handle, params,
|
||||||
|
&buffer_frames);
|
||||||
|
} else {
|
||||||
if (buffer_time == 0)
|
if (buffer_time == 0)
|
||||||
buffer_time = 500000;
|
buffer_time = 500000;
|
||||||
err = snd_pcm_hw_params_set_buffer_time_near(handle, params,
|
err = snd_pcm_hw_params_set_buffer_time_near(handle, params,
|
||||||
&buffer_time, 0);
|
&buffer_time, 0);
|
||||||
|
}
|
||||||
assert(err >= 0);
|
assert(err >= 0);
|
||||||
if (period_time == 0)
|
if (period_time == 0 && period_frames == 0) {
|
||||||
|
if (buffer_time > 0)
|
||||||
period_time = buffer_time / 4;
|
period_time = buffer_time / 4;
|
||||||
|
else
|
||||||
|
period_frames = buffer_frames / 4;
|
||||||
|
}
|
||||||
|
if (period_time > 0)
|
||||||
err = snd_pcm_hw_params_set_period_time_near(handle, params,
|
err = snd_pcm_hw_params_set_period_time_near(handle, params,
|
||||||
&period_time, 0);
|
&period_time, 0);
|
||||||
|
else
|
||||||
|
err = snd_pcm_hw_params_set_period_size_near(handle, params,
|
||||||
|
&period_frames, 0);
|
||||||
assert(err >= 0);
|
assert(err >= 0);
|
||||||
err = snd_pcm_hw_params(handle, params);
|
err = snd_pcm_hw_params(handle, params);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
|
@ -1006,6 +1034,7 @@ static void compute_max_peak(u_char *data, size_t count)
|
||||||
default: val = 0; step = 1; break;
|
default: val = 0; step = 1; break;
|
||||||
}
|
}
|
||||||
data += step;
|
data += step;
|
||||||
|
val = abs(val);
|
||||||
if (max_peak < val)
|
if (max_peak < val)
|
||||||
max_peak = val;
|
max_peak = val;
|
||||||
}
|
}
|
||||||
|
@ -1013,7 +1042,10 @@ static void compute_max_peak(u_char *data, size_t count)
|
||||||
if (max <= 0)
|
if (max <= 0)
|
||||||
max = 0x7fffffff;
|
max = 0x7fffffff;
|
||||||
printf("Max peak (%li samples): %05i (0x%04x) ", (long)ocount, max_peak, max_peak);
|
printf("Max peak (%li samples): %05i (0x%04x) ", (long)ocount, max_peak, max_peak);
|
||||||
|
if (bits_per_sample > 16)
|
||||||
perc = max_peak / (max / 100);
|
perc = max_peak / (max / 100);
|
||||||
|
else
|
||||||
|
perc = max_peak * 100 / max;
|
||||||
for (val = 0; val < 20; val++)
|
for (val = 0; val < 20; val++)
|
||||||
if (val <= perc / 5)
|
if (val <= perc / 5)
|
||||||
putc('#', stdout);
|
putc('#', stdout);
|
||||||
|
|
Loading…
Reference in a new issue