[pulseaudio-discuss] [PATCH 1/4] resampler-test: Add zero padding.

poljar (Damir Jelić) poljarinho at gmail.com
Tue Dec 10 16:42:48 PST 2013


For the resampler test we create 10 samples and run them through a
resampler and then we try to run run the resampler backwards. This
crashes if our original 10 samples are not enough to produce any output
on the original run.

This patch adds additional zero padding to our original 10 samples. This
way all resample methods produce enough output to run the resampler
backwards.
---
 src/tests/resampler-test.c | 40 ++++++++++++++++++++++++++++++++--------
 1 file changed, 32 insertions(+), 8 deletions(-)

diff --git a/src/tests/resampler-test.c b/src/tests/resampler-test.c
index 566b69f..84c21ad 100644
--- a/src/tests/resampler-test.c
+++ b/src/tests/resampler-test.c
@@ -40,6 +40,12 @@
 #include <pulsecore/sample-util.h>
 #include <pulsecore/core-util.h>
 
+/* The size of the padding is determined by running the resampler
+ * test with different padding values and watching if it crashes.
+ * As it turns out src-sinc-best-quality needs a huge amount of
+ * samples. At least 278 samples are needed so round it up to 280 */
+#define PADDING 280
+
 static void dump_block(const char *label, const pa_sample_spec *ss, const pa_memchunk *chunk) {
     void *d;
     unsigned i;
@@ -57,7 +63,7 @@ static void dump_block(const char *label, const pa_sample_spec *ss, const pa_mem
         case PA_SAMPLE_ALAW: {
             uint8_t *u = d;
 
-            for (i = 0; i < chunk->length / pa_frame_size(ss); i++)
+            for (i = 0; i < 10; i++)
                 printf("      0x%02x ", *(u++));
 
             break;
@@ -67,7 +73,7 @@ static void dump_block(const char *label, const pa_sample_spec *ss, const pa_mem
         case PA_SAMPLE_S16RE: {
             uint16_t *u = d;
 
-            for (i = 0; i < chunk->length / pa_frame_size(ss); i++)
+            for (i = 0; i < 10; i++)
                 printf("    0x%04x ", *(u++));
 
             break;
@@ -77,7 +83,7 @@ static void dump_block(const char *label, const pa_sample_spec *ss, const pa_mem
         case PA_SAMPLE_S32RE: {
             uint32_t *u = d;
 
-            for (i = 0; i < chunk->length / pa_frame_size(ss); i++)
+            for (i = 0; i < 10; i++)
                 printf("0x%08x ", *(u++));
 
             break;
@@ -87,7 +93,7 @@ static void dump_block(const char *label, const pa_sample_spec *ss, const pa_mem
         case PA_SAMPLE_S24_32RE: {
             uint32_t *u = d;
 
-            for (i = 0; i < chunk->length / pa_frame_size(ss); i++)
+            for (i = 0; i < 10; i++)
                 printf("0x%08x ", *(u++));
 
             break;
@@ -97,7 +103,7 @@ static void dump_block(const char *label, const pa_sample_spec *ss, const pa_mem
         case PA_SAMPLE_FLOAT32RE: {
             float *u = d;
 
-            for (i = 0; i < chunk->length / pa_frame_size(ss); i++) {
+            for (i = 0; i < 10; i++) {
                 printf("%4.3g ", ss->format == PA_SAMPLE_FLOAT32NE ? *u : PA_FLOAT32_SWAP(*u));
                 u++;
             }
@@ -109,7 +115,7 @@ static void dump_block(const char *label, const pa_sample_spec *ss, const pa_mem
         case PA_SAMPLE_S24BE: {
             uint8_t *u = d;
 
-            for (i = 0; i < chunk->length / pa_frame_size(ss); i++) {
+            for (i = 0; i < 10; i++) {
                 printf("  0x%06x ", PA_READ24NE(u));
                 u += pa_frame_size(ss);
             }
@@ -131,7 +137,7 @@ static pa_memblock* generate_block(pa_mempool *pool, const pa_sample_spec *ss) {
     void *d;
     unsigned i;
 
-    pa_assert_se(r = pa_memblock_new(pool, pa_frame_size(ss) * 10));
+    pa_assert_se(r = pa_memblock_new(pool, pa_frame_size(ss) * (10 + PADDING)));
     d = pa_memblock_acquire(r);
 
     switch (ss->format) {
@@ -151,6 +157,10 @@ static pa_memblock* generate_block(pa_mempool *pool, const pa_sample_spec *ss) {
             u[7] = 0xF0;
             u[8] = 0x20;
             u[9] = 0x21;
+
+            for (i = 10; i < 10 + PADDING; i++)
+                u[i] = 0x00;
+
             break;
         }
 
@@ -168,6 +178,9 @@ static pa_memblock* generate_block(pa_mempool *pool, const pa_sample_spec *ss) {
             u[7] = 0xF000;
             u[8] = 0x20;
             u[9] = 0x21;
+
+            for (i = 10; i < 10 + PADDING; i++)
+                u[i] = 0x0000;
             break;
         }
 
@@ -185,6 +198,10 @@ static pa_memblock* generate_block(pa_mempool *pool, const pa_sample_spec *ss) {
             u[7] = 0xF0000008;
             u[8] =   0x200009;
             u[9] =   0x21000A;
+
+            for (i = 10; i < 10 + PADDING; i++)
+                u[i] = 0x00000000;
+
             break;
         }
 
@@ -220,8 +237,11 @@ static pa_memblock* generate_block(pa_mempool *pool, const pa_sample_spec *ss) {
             u[8] = -0.555f;
             u[9] = -.123f;
 
+            for (i = 10; i < 10 + PADDING; i++)
+                u[i] = 0.0f;
+
             if (ss->format == PA_SAMPLE_FLOAT32RE)
-                for (i = 0; i < 10; i++)
+                for (i = 0; i < 10 + PADDING; i++)
                     u[i] = PA_FLOAT32_SWAP(u[i]);
 
             break;
@@ -241,6 +261,10 @@ static pa_memblock* generate_block(pa_mempool *pool, const pa_sample_spec *ss) {
             PA_WRITE24NE(u+21, 0xF00008);
             PA_WRITE24NE(u+24,   0x2009);
             PA_WRITE24NE(u+27,   0x210A);
+
+            for (i = 30; i < 30 + (PADDING * 3); i+=3)
+                PA_WRITE24NE(u+i, 0x000000);
+
             break;
         }
 
-- 
1.8.4.2



More information about the pulseaudio-discuss mailing list