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
PATCH 1/3 speaker-test: allow frequency to be floating point
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.
--- speaker-test/speaker-test.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
speaker-test/speaker-test.c +4 -4
@@ -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);
Signature · 1 line
1.6.2.4
PATCH 2/3 Allow frequencies down to 30 Hz
---
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(-)
speaker-test/speaker-test.c +1 -1
@@ -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' :
Signature · 1 line
1.6.2.4
PATCH 3/3 Remove dead/commented out code
--- speaker-test/speaker-test.c | 15 --------------- 1 files changed, 0 insertions(+), 15 deletions(-)
speaker-test/speaker-test.c +0 -15
@@ -142,17 +142,6 @@ static void generate_sine(uint8_t *frames, int channel, int count, double *_phasfloat *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 ;
Signature · 1 line
1.6.2.4
Jaroslav Kysela
AppliedQuoted 3 lines · Dan McGee
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 <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, Red Hat, Inc.