Commit 095ef5ef authored by Emily's avatar Emily
Browse files

libresample: 0.1.3 -> 0.1.4-unstable-2024-08-23

The Debian CMake build system rewrite patch was broken and generated
an unusable `.pc` file, so I rewrote it again in Meson. This was
accepted upstream, but is still awaiting a final release.

The licence also changed to BSD-2-Clause OR LGPL-2.1-or-later in 2013.
parent 7ca429f2
Loading
Loading
Loading
Loading
+108 −0
Original line number Diff line number Diff line
From fb8e3c74d582038a358936d827f53c4c0c43d4e6 Mon Sep 17 00:00:00 2001
From: Matt Harvey <mattharvey@google.com>
Date: Mon, 27 Nov 2023 16:28:53 -0800
Subject: [PATCH] Fix testresample.c output span; add exit code

Prior to this chance, the "Resample with different factors" test only
passed for 60 of the 63 factors, with the 3 failing ones being the
largest.

1. Since only 63 distinct factors were being considered, 100 random
   samples was overkill.
2. To support noticing failure in continuous build systems, it's nice if
   the test exit()s with nonzero when there are failures.
3. The root cause was a formula error when determining which indices in
   the resampled output ought be compared. Details are explained in a
   comment.
---
 tests/testresample.c | 32 ++++++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 8 deletions(-)

diff --git a/tests/testresample.c b/tests/testresample.c
index aa83a46..640df5a 100644
--- a/tests/testresample.c
+++ b/tests/testresample.c
@@ -19,6 +19,8 @@
 
 #define MIN(A, B) (A) < (B)? (A) : (B)
 
+int global_error;
+
 void runtest(int srclen, double freq, double factor,
              int srcblocksize, int dstblocksize)
 {
@@ -65,10 +67,12 @@ void runtest(int srclen, double freq, double factor,
 
    if (o < 0) {
       printf("Error: resample_process returned an error: %d\n", o);
+      global_error = 1;
    }
 
    if (out <= 0) {
       printf("Error: resample_process returned %d samples\n", out);
+      global_error = 1;
       free(src);
       free(dst);
       return;
@@ -79,15 +83,16 @@ void runtest(int srclen, double freq, double factor,
       printf("   Expected ~%d, got %d samples out\n",
              expectedlen, out);
    }
-   
+
    sum = 0.0;
    sumsq = 0.0;
    errcount = 0.0;
 
-   /* Don't compute statistics on all output values; the last few
-      are guaranteed to be off because it's based on far less
-      interpolation. */
-   statlen = out - fwidth;
+   /* Don't compute statistics on all output values; the last small fraction
+      are guaranteed to be off since they are interpolated based on far fewer
+      values. When upsampling, the length of the range where this concern
+      applies is in direct proportion to the upsampling factor. */
+   statlen = out - ((int)round(fwidth * factor));
 
    for(i=0; i<statlen; i++) {
       double diff = sin((i/freq)/factor) - dst[i];
@@ -117,6 +122,7 @@ void runtest(int srclen, double freq, double factor,
       printf("   i=%d:  expected %.3f, got %.3f\n",
              i, sin((i/freq)/factor), dst[i]);
       printf("   At least %d samples had significant error.\n", errcount);
+      global_error = 1;
    }
    err = sum / statlen;
    rmserr = sqrt(sumsq / statlen);
@@ -130,6 +136,8 @@ int main(int argc, char **argv)
    int i, srclen, dstlen, ifreq;
    double factor;
 
+   global_error = 0;
+
    printf("\n*** Vary source block size*** \n\n");
    srclen = 10000;
    ifreq = 100;
@@ -172,11 +180,19 @@ int main(int argc, char **argv)
    printf("\n*** Resample with different factors ***\n\n");
    srclen = 10000;
    ifreq = 100;
-   for(i=0; i<100; i++) {
-      factor = ((rand() % 64) + 1) / 4.0;
+   for (i = 1; i < 64; i++) {
+      factor = i / 4.0;
+      dstlen = (int)(srclen * factor + 10);
+      runtest(srclen, (double)ifreq, factor, srclen, dstlen);
+   }
+
+   printf("\n*** Resample with large factors ***\n\n");
+   srclen = 200;
+   ifreq = 100;
+   for (factor = 25.0; factor < 1000.0; factor *= 1.7) {
       dstlen = (int)(srclen * factor + 10);
       runtest(srclen, (double)ifreq, factor, srclen, dstlen);
    }
 
-   return 0;
+   return global_error;
 }
+52 −21
Original line number Diff line number Diff line
{
  lib,
  stdenv,
  fetchurl,
  fetchFromGitHub,
  cmake,
  meson,
  ninja,
  pkg-config,
  libsndfile,
  libsamplerate,
}:

let
  patch = fetchurl {
    url = "mirror://debian/pool/main/libr/libresample/libresample_0.1.3-3.diff.gz";
    sha256 = "063w8rqxw87fc89gas47vk0ll7xl8cy7d8g70gm1l62bqkkajklx";
  };
in
stdenv.mkDerivation rec {
stdenv.mkDerivation (finalAttrs: {
  pname = "libresample";
  version = "0.1.3";
  src = fetchurl {
    url = "mirror://debian/pool/main/libr/libresample/libresample_${version}.orig.tar.gz";
    sha256 = "05a8mmh1bw5afqx0kfdqzmph4x2npcs4idx0p0v6q95lwf22l8i0";
  version = "0.1.4-unstable-2024-08-23";

  outputs = [
    "bin"
    "dev"
    "out"
  ];

  src = fetchFromGitHub {
    owner = "minorninth";
    repo = "libresample";
    rev = "7cb7f9c3f72d4e6774d964dc324af827192df7c3";
    hash = "sha256-8gyGZVblqeHYXKFM79AcfX455+l3Tsoq3xQse5nrKAo=";
  };
  patches = [ patch ];
  preConfigure = ''
    cat debian/patches/1001_shlib-cmake.patch | patch -p1
  '';
  nativeBuildInputs = [ cmake ];

  patches = [
    # Fix testresample.c output span; add exit code
    # https://github.com/minorninth/libresample/pull/7
    ./fix-test.patch
  ];

  nativeBuildInputs = [
    meson
    ninja
    pkg-config
  ];

  buildInputs =
    [
      # For `resample-sndfile`
      libsndfile
    ]
    ++ lib.optionals (!libsamplerate.meta.broken) [
      # For `compareresample`
      libsamplerate
    ];

  mesonFlags = [ (lib.mesonEnable "compareresample" (!libsamplerate.meta.broken)) ];

  doCheck = true;

  meta = {
    description = "Real-time library for sampling rate conversion library";
    license = lib.licenses.lgpl2Plus;
    homepage = "https://ccrma.stanford.edu/~jos/resample/Free_Resampling_Software.html";
    homepage = "https://github.com/minorninth/libresample";
    license = lib.licenses.bsd2; # OR LGPL-2.1-or-later
    sourceProvenance = [ lib.sourceTypes.fromSource ];
    platforms = lib.platforms.all;
    maintainers = [
      lib.maintainers.sander
      lib.maintainers.emily
    ];
    platforms = lib.platforms.unix;
    mainProgram = "resample-sndfile";
  };
}
})