diff options
author | David Henningsson <david.henningsson@canonical.com> | 2014-09-10 14:52:01 +0200 |
---|---|---|
committer | David Henningsson <david.henningsson@canonical.com> | 2014-09-18 11:51:47 +0200 |
commit | f8aa823998f3b75691b67f032320cb4bf228f313 (patch) | |
tree | d4ae556821f68296e36abd5b480e173d4a28c862 /src/tests | |
parent | c9e8c0703fd8900ac5513ddb66206cbcbaf1da5c (diff) | |
download | pulseaudio-f8aa823998f3b75691b67f032320cb4bf228f313.tar.gz |
alsa-time-test: Make constants for channels and rate
Hard-coding constants on several places is bad coding practice.
Signed-off-by: David Henningsson <david.henningsson@canonical.com>
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/alsa-time-test.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/tests/alsa-time-test.c b/src/tests/alsa-time-test.c index 20f16ccb6..b4eedaba2 100644 --- a/src/tests/alsa-time-test.c +++ b/src/tests/alsa-time-test.c @@ -10,6 +10,9 @@ #include <alsa/asoundlib.h> +#define SAMPLE_RATE 44100 +#define CHANNELS 2 + static uint64_t timespec_us(const struct timespec *ts) { return ts->tv_sec * 1000000LLU + @@ -23,9 +26,9 @@ int main(int argc, char *argv[]) { snd_pcm_sw_params_t *swparams; snd_pcm_status_t *status; snd_pcm_t *pcm; - unsigned rate = 44100; + unsigned rate = SAMPLE_RATE; unsigned periods = 2; - snd_pcm_uframes_t boundary, buffer_size = 44100/10; /* 100s */ + snd_pcm_uframes_t boundary, buffer_size = SAMPLE_RATE/10; /* 100s */ int dir = 1; int fillrate; struct timespec start, last_timestamp = { 0, 0 }; @@ -58,7 +61,7 @@ int main(int argc, char *argv[]) { cap = argc > 2 ? atoi(argv[2]) : 0; fillrate = argc > 3 ? atoi(argv[3]) : 1; - samples = calloc(fillrate, 2*sizeof(uint16_t)); + samples = calloc(fillrate, CHANNELS*sizeof(uint16_t)); assert(samples); if (cap == 0) @@ -82,7 +85,7 @@ int main(int argc, char *argv[]) { r = snd_pcm_hw_params_set_rate_near(pcm, hwparams, &rate, NULL); assert(r == 0); - r = snd_pcm_hw_params_set_channels(pcm, hwparams, 2); + r = snd_pcm_hw_params_set_channels(pcm, hwparams, CHANNELS); assert(r == 0); r = snd_pcm_hw_params_set_periods_integer(pcm, hwparams); @@ -216,9 +219,9 @@ int main(int argc, char *argv[]) { timestamp_us = timespec_us(×tamp); if (cap == 0) - pos = (unsigned long long) ((sample_count - handled - delay) * 1000000LU / 44100); + pos = (unsigned long long) ((sample_count - handled - delay) * 1000000LU / SAMPLE_RATE); else - pos = (unsigned long long) ((sample_count - handled + delay) * 1000000LU / 44100); + pos = (unsigned long long) ((sample_count - handled + delay) * 1000000LU / SAMPLE_RATE); if (count++ % 50 == 0) printf("Elapsed\tCPU\tALSA\tPos\tSamples\tavail\tdelay\trevents\thandled\tstate\n"); |