James Courtier-Dutton <James@superbug.demon.co.uk>

I attach a patch that updates the speaker-test program.
It corrects a few minor bugs as well as add a new -s option.
This commit is contained in:
Jaroslav Kysela 2004-05-16 13:43:29 +00:00
parent e4d3e84845
commit 2db52ba839
2 changed files with 41 additions and 17 deletions

View file

@ -9,4 +9,6 @@ To test: -
./speaker-test -Dsurround40 -c4
3) A 5.1 speaker setup from three stereo jacks: -
./speaker-test -Dsurround51 -c6
4) To send a nice low 75Hz tone to the Woofer and then exit without touching any other speakers: -
./speaker-test -Dplug:surround51 -c6 -s1 -f75

View file

@ -10,7 +10,7 @@
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* xine is distributed in the hope that it will be useful,
* speaker-test is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
@ -40,8 +40,9 @@
static char *device = "plughw:0,0"; /* playback device */
static snd_pcm_format_t format = SND_PCM_FORMAT_S16; /* sample format */
static unsigned int rate = 44100; /* stream rate */
static unsigned int rate = 48000; /* stream rate */
static unsigned int channels = 1; /* count of channels */
static unsigned int speaker = 0; /* count of channels */
static unsigned int buffer_time = 500000; /* ring buffer length in us */
static unsigned int period_time = 100000; /* period time in us */
static double freq = 440; /* sinusoidal wave frequency in Hz */
@ -307,10 +308,9 @@ static int write_loop(snd_pcm_t *handle, int channel, int periods, signed short
}
static void help(void) {
int k;
printf(
"Usage: latency [OPTION]... [FILE]...\n"
"Usage: speaker-test [OPTION]... \n"
"-h,--help help\n"
"-D,--device playback device\n"
"-r,--rate stream rate in Hz\n"
@ -318,8 +318,9 @@ static void help(void) {
"-f,--frequency sine wave frequency in Hz\n"
"-b,--buffer ring buffer size in us\n"
"-p,--period period size in us\n"
"-s,--speaker single speaker test. Values 1=Left or 2=right\n"
"\n");
#if 0
printf("Recognized sample formats are:");
for (k = 0; k < SND_PCM_FORMAT_LAST; ++k) {
const char *s = snd_pcm_format_name(k);
@ -328,6 +329,8 @@ static void help(void) {
}
printf("\n\n");
#endif
}
int main(int argc, char *argv[]) {
@ -345,6 +348,7 @@ int main(int argc, char *argv[]) {
{"frequency", 1, NULL, 'f'},
{"buffer", 1, NULL, 'b'},
{"period", 1, NULL, 'p'},
{"speaker", 1, NULL, 's'},
{NULL, 0, NULL, 0 },
};
@ -357,7 +361,7 @@ int main(int argc, char *argv[]) {
while (1) {
int c;
if ((c = getopt_long(argc, argv, "hD:r:c:f:b:p:m:", long_option, NULL)) < 0)
if ((c = getopt_long(argc, argv, "hD:r:c:f:b:p:s:", long_option, NULL)) < 0)
break;
switch (c) {
@ -392,6 +396,15 @@ int main(int argc, char *argv[]) {
period_time = period_time < 1000 ? 1000 : period_time;
period_time = period_time > 1000000 ? 1000000 : period_time;
break;
case 's':
speaker = atoi(optarg);
speaker = speaker < 1 ? 0 : speaker;
speaker = speaker > channels ? 0 : speaker;
if (speaker==0) {
printf("Invalid parameter for -s option.\n");
exit(EXIT_FAILURE);
}
break;
default:
printf("Unknown option '%c'\n", c);
exit(EXIT_FAILURE);
@ -433,7 +446,7 @@ int main(int argc, char *argv[]) {
printf("No enough memory\n");
exit(EXIT_FAILURE);
}
if (speaker==0) {
while (1) {
for(chn = 0; chn < channels; chn++) {
@ -447,6 +460,15 @@ int main(int argc, char *argv[]) {
}
}
}
} else {
printf(" - %s\n", channel_name[speaker-1]);
err = write_loop(handle, speaker-1, ((rate*5)/period_size), samples);
if (err < 0) {
printf("Transfer failed: %s\n", snd_strerror(err));
}
}
free(samples);
snd_pcm_close(handle);