[alsa-devel] speaker-test cleanups and fixes
This is a series of 3 (mostly unrelated) patches to clean up and fix up a few shortcomings I found in the speaker-test program. Please let me know of any concerns or comments on the patches.
-Dan
Use atof() rather than atoi() to store the frequency- we were already using a floating point value internally but did not let the user specify one from the command line.
Signed-off-by: Dan McGee dpmcgee@gmail.com --- speaker-test/speaker-test.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/speaker-test/speaker-test.c b/speaker-test/speaker-test.c index 63a7151..5e00ea4 100644 --- a/speaker-test/speaker-test.c +++ b/speaker-test/speaker-test.c @@ -76,7 +76,7 @@ static unsigned int speaker = 0; /* count of channels */ static unsigned int buffer_time = 0; /* ring buffer length in us */ static unsigned int period_time = 0; /* period time in us */ static unsigned int nperiods = 4; /* number of periods */ -static double freq = 440; /* sinusoidal wave frequency in Hz */ +static double freq = 440.0; /* sinusoidal wave frequency in Hz */ static int test_type = TEST_PINK_NOISE; /* Test type. 1 = noise, 2 = sine wave */ static pink_noise_t pink; static snd_pcm_uframes_t buffer_size; @@ -860,9 +860,9 @@ int main(int argc, char *argv[]) { channels = channels > 1024 ? 1024 : channels; break; case 'f': - freq = atoi(optarg); - freq = freq < 50 ? 50 : freq; - freq = freq > 5000 ? 5000 : freq; + freq = atof(optarg); + freq = freq < 50.0 ? 50.0 : freq; + freq = freq > 5000.0 ? 5000.0 : freq; break; case 'b': buffer_time = atoi(optarg);
Signed-off-by: Dan McGee dpmcgee@gmail.com ---
This patch is partially an RFC- it seems odd that we limit the frequency at all. I proposed lowering it to 30 here only because that is what my subwoofer can handle, but it may be better to just accept anything above zero, or choose something like 20.
-Dan
speaker-test/speaker-test.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/speaker-test/speaker-test.c b/speaker-test/speaker-test.c index 5e00ea4..38e5462 100644 --- a/speaker-test/speaker-test.c +++ b/speaker-test/speaker-test.c @@ -861,7 +861,7 @@ int main(int argc, char *argv[]) { break; case 'f': freq = atof(optarg); - freq = freq < 50.0 ? 50.0 : freq; + freq = freq < 30.0 ? 30.0 : freq; freq = freq > 5000.0 ? 5000.0 : freq; break; case 'b':
Signed-off-by: Dan McGee dpmcgee@gmail.com --- speaker-test/speaker-test.c | 15 --------------- 1 files changed, 0 insertions(+), 15 deletions(-)
diff --git a/speaker-test/speaker-test.c b/speaker-test/speaker-test.c index 38e5462..d983a4f 100644 --- a/speaker-test/speaker-test.c +++ b/speaker-test/speaker-test.c @@ -142,17 +142,6 @@ static void generate_sine(uint8_t *frames, int channel, int count, double *_phas float *samp_f = (float*) frames;
while (count-- > 0) { - //res = sin((phase * 2 * M_PI) / max_phase - M_PI) * 32767; - //res = sin((phase * 2 * M_PI) / max_phase - M_PI) * 32767; - //res = (sin((phase * 2 * M_PI) / max_phase - M_PI)) * 0x03fffffff; /* Don't use MAX volume */ - //if (res > 0) res = 10000; - //if (res < 0) res = -10000; - - /* printf("%e\n",res); */ - //ires = res; - //ires = ((16 - (count & 0xf)) <<24); - //ires = 0; - for(chn=0;chn<channels;chn++) { switch (format) { case SND_PCM_FORMAT_S8: @@ -195,11 +184,7 @@ static void generate_sine(uint8_t *frames, int channel, int count, double *_phas res = (sin((phase * 2 * M_PI) / max_phase - M_PI)) * 0.75 ; /* Don't use MAX volume */ fres = res; *samp_f++ = fres; - //*samp32++ = 0xF2345678; - //printf("res=%lf, ires=%d 0x%x, samp32=0x%x\n",res,ires, ires, samp32[-1]); } else { - //*samp32++ = ires+0x10000; - //*samp32++ = ires; *samp_f++ = 0.0; } break;
On Sat, 9 May 2009, Dan McGee wrote:
This is a series of 3 (mostly unrelated) patches to clean up and fix up a few shortcomings I found in the speaker-test program. Please let me know of any concerns or comments on the patches.
Hi,
I applied all 5 patches to our git repo. Thanks for your code.
Jaroslav
----- Jaroslav Kysela perex@perex.cz Linux Kernel Sound Maintainer ALSA Project, Red Hat, Inc.
participants (2)
-
Dan McGee
-
Jaroslav Kysela