[pulseaudio-commits] 3 commits - src/tests

David Henningsson diwic at kemper.freedesktop.org
Thu Sep 18 02:52:21 PDT 2014


 src/tests/alsa-time-test.c |   37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)

New commits:
commit f8aa823998f3b75691b67f032320cb4bf228f313
Author: David Henningsson <david.henningsson at canonical.com>
Date:   Wed Sep 10 14:52:01 2014 +0200

    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 at canonical.com>

diff --git a/src/tests/alsa-time-test.c b/src/tests/alsa-time-test.c
index 20f16cc..b4eedab 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(&timestamp);
 
         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");

commit c9e8c0703fd8900ac5513ddb66206cbcbaf1da5c
Author: David Henningsson <david.henningsson at canonical.com>
Date:   Wed Sep 10 14:45:01 2014 +0200

    alsa-time-test: Do not use Lennart's card by default
    
    Lennart probably had a card with a specific name. It is not a
    common name anymore.
    
    Signed-off-by: David Henningsson <david.henningsson at canonical.com>

diff --git a/src/tests/alsa-time-test.c b/src/tests/alsa-time-test.c
index 5d75756..20f16cc 100644
--- a/src/tests/alsa-time-test.c
+++ b/src/tests/alsa-time-test.c
@@ -54,7 +54,7 @@ int main(int argc, char *argv[]) {
 
     start_us = timespec_us(&start);
 
-    dev = argc > 1 ? argv[1] : "front:AudioPCI";
+    dev = argc > 1 ? argv[1] : "front:0";
     cap = argc > 2 ? atoi(argv[2]) : 0;
     fillrate = argc > 3 ? atoi(argv[3]) : 1;
 

commit d303489ef0b4908815bea1e0e7329b5f45e7340f
Author: David Henningsson <david.henningsson at canonical.com>
Date:   Wed Sep 10 14:43:19 2014 +0200

    alsa-time-test: Add fillrate parameter
    
    As a third parameter, add the number of samples to read/write in
    every iteration. This will help slow CPUs.
    
    Signed-off-by: David Henningsson <david.henningsson at canonical.com>

diff --git a/src/tests/alsa-time-test.c b/src/tests/alsa-time-test.c
index 3c82fdc..5d75756 100644
--- a/src/tests/alsa-time-test.c
+++ b/src/tests/alsa-time-test.c
@@ -27,12 +27,14 @@ int main(int argc, char *argv[]) {
     unsigned periods = 2;
     snd_pcm_uframes_t boundary, buffer_size = 44100/10; /* 100s */
     int dir = 1;
+    int fillrate;
     struct timespec start, last_timestamp = { 0, 0 };
     uint64_t start_us, last_us = 0;
     snd_pcm_sframes_t last_avail = 0, last_delay = 0;
     struct pollfd *pollfds;
     int n_pollfd;
     int64_t sample_count = 0;
+    uint16_t *samples;
     struct sched_param sp;
 
     r = -1;
@@ -54,6 +56,10 @@ int main(int argc, char *argv[]) {
 
     dev = argc > 1 ? argv[1] : "front:AudioPCI";
     cap = argc > 2 ? atoi(argv[2]) : 0;
+    fillrate = argc > 3 ? atoi(argv[3]) : 1;
+
+    samples = calloc(fillrate, 2*sizeof(uint16_t));
+    assert(samples);
 
     if (cap == 0)
       r = snd_pcm_open(&pcm, dev, SND_PCM_STREAM_PLAYBACK, 0);
@@ -108,7 +114,7 @@ int main(int argc, char *argv[]) {
 
     r = snd_pcm_hw_params_get_buffer_size(hwparams, &buffer_size);
     assert(r == 0);
-    r = snd_pcm_sw_params_set_start_threshold(pcm, swparams, buffer_size);
+    r = snd_pcm_sw_params_set_start_threshold(pcm, swparams, buffer_size - (buffer_size % fillrate));
     assert(r == 0);
 
     r = snd_pcm_sw_params_get_boundary(swparams, &boundary);
@@ -185,19 +191,17 @@ int main(int argc, char *argv[]) {
 
         assert(!revents || avail > 0);
 
-        if ((!cap && avail) || (cap && (unsigned)avail >= buffer_size)) {
+        if ((!cap && (avail >= fillrate)) || (cap && (unsigned)avail >= buffer_size)) {
             snd_pcm_sframes_t sframes;
-            static const uint16_t psamples[2] = { 0, 0 };
-            uint16_t csamples[2];
 
             if (cap == 0)
-              sframes = snd_pcm_writei(pcm, psamples, 1);
+              sframes = snd_pcm_writei(pcm, samples, fillrate);
             else
-              sframes = snd_pcm_readi(pcm, csamples, 1);
-            assert(sframes == 1);
+              sframes = snd_pcm_readi(pcm, samples, fillrate);
+            assert(sframes == fillrate);
 
-            handled = 1;
-            sample_count++;
+            handled = fillrate;
+            sample_count += fillrate;
         }
 
         if (!handled &&



More information about the pulseaudio-commits mailing list