mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-06 13:29:56 -05:00
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>
This commit is contained in:
parent
c9e8c0703f
commit
f8aa823998
1 changed files with 9 additions and 6 deletions
|
|
@ -10,6 +10,9 @@
|
||||||
|
|
||||||
#include <alsa/asoundlib.h>
|
#include <alsa/asoundlib.h>
|
||||||
|
|
||||||
|
#define SAMPLE_RATE 44100
|
||||||
|
#define CHANNELS 2
|
||||||
|
|
||||||
static uint64_t timespec_us(const struct timespec *ts) {
|
static uint64_t timespec_us(const struct timespec *ts) {
|
||||||
return
|
return
|
||||||
ts->tv_sec * 1000000LLU +
|
ts->tv_sec * 1000000LLU +
|
||||||
|
|
@ -23,9 +26,9 @@ int main(int argc, char *argv[]) {
|
||||||
snd_pcm_sw_params_t *swparams;
|
snd_pcm_sw_params_t *swparams;
|
||||||
snd_pcm_status_t *status;
|
snd_pcm_status_t *status;
|
||||||
snd_pcm_t *pcm;
|
snd_pcm_t *pcm;
|
||||||
unsigned rate = 44100;
|
unsigned rate = SAMPLE_RATE;
|
||||||
unsigned periods = 2;
|
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 dir = 1;
|
||||||
int fillrate;
|
int fillrate;
|
||||||
struct timespec start, last_timestamp = { 0, 0 };
|
struct timespec start, last_timestamp = { 0, 0 };
|
||||||
|
|
@ -58,7 +61,7 @@ int main(int argc, char *argv[]) {
|
||||||
cap = argc > 2 ? atoi(argv[2]) : 0;
|
cap = argc > 2 ? atoi(argv[2]) : 0;
|
||||||
fillrate = argc > 3 ? atoi(argv[3]) : 1;
|
fillrate = argc > 3 ? atoi(argv[3]) : 1;
|
||||||
|
|
||||||
samples = calloc(fillrate, 2*sizeof(uint16_t));
|
samples = calloc(fillrate, CHANNELS*sizeof(uint16_t));
|
||||||
assert(samples);
|
assert(samples);
|
||||||
|
|
||||||
if (cap == 0)
|
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);
|
r = snd_pcm_hw_params_set_rate_near(pcm, hwparams, &rate, NULL);
|
||||||
assert(r == 0);
|
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);
|
assert(r == 0);
|
||||||
|
|
||||||
r = snd_pcm_hw_params_set_periods_integer(pcm, hwparams);
|
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);
|
timestamp_us = timespec_us(×tamp);
|
||||||
|
|
||||||
if (cap == 0)
|
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
|
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)
|
if (count++ % 50 == 0)
|
||||||
printf("Elapsed\tCPU\tALSA\tPos\tSamples\tavail\tdelay\trevents\thandled\tstate\n");
|
printf("Elapsed\tCPU\tALSA\tPos\tSamples\tavail\tdelay\trevents\thandled\tstate\n");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue