From 2db52ba839050636f3352e612629f46368ae8f56 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Sun, 16 May 2004 13:43:29 +0000 Subject: [PATCH] James Courtier-Dutton I attach a patch that updates the speaker-test program. It corrects a few minor bugs as well as add a new -s option. --- speaker-test/readme.txt | 8 +++--- speaker-test/speaker-test.c | 50 ++++++++++++++++++++++++++----------- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/speaker-test/readme.txt b/speaker-test/readme.txt index f96c9f1..cee78ba 100644 --- a/speaker-test/readme.txt +++ b/speaker-test/readme.txt @@ -4,9 +4,11 @@ make To test: - 1) Just stereo sound from one stereo jack: - -./speaker-test -Dfront -c 2 +./speaker-test -Dfront -c2 2) A 4 speaker setup from two stereo jacks: - -./speaker-test -Dsurround40 -c 4 +./speaker-test -Dsurround40 -c4 3) A 5.1 speaker setup from three stereo jacks: - -./speaker-test -Dsurround51 -c 6 +./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 diff --git a/speaker-test/speaker-test.c b/speaker-test/speaker-test.c index 5447601..6f930c4 100644 --- a/speaker-test/speaker-test.c +++ b/speaker-test/speaker-test.c @@ -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,21 +446,30 @@ int main(int argc, char *argv[]) { printf("No enough memory\n"); exit(EXIT_FAILURE); } + if (speaker==0) { + while (1) { - while (1) { + for(chn = 0; chn < channels; chn++) { + printf(" - %s\n", channel_name[chn]); - for(chn = 0; chn < channels; chn++) { - printf(" - %s\n", channel_name[chn]); + err = write_loop(handle, chn, ((rate*5)/period_size), samples); - err = write_loop(handle, chn, ((rate*5)/period_size), samples); - - if (err < 0) { - printf("Transfer failed: %s\n", snd_strerror(err)); - exit(EXIT_FAILURE); + if (err < 0) { + printf("Transfer failed: %s\n", snd_strerror(err)); + exit(EXIT_FAILURE); + } } } + } 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);