Skip to content

Commit

Permalink
Add soxr to packages (pyodide#5150)
Browse files Browse the repository at this point in the history
  • Loading branch information
swnf authored Nov 5, 2024
1 parent 4f7e0df commit a5386c8
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/development/new-packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ from pytest_pyodide import run_in_pyodide
@run_in_pyodide(packages=["<package-name>-tests", "pytest"])
def test_mytestname(selenium):
import pytest
pytest.main(["--pyargs", "<package-name>", "-k", "some_filter", ...])
assert pytest.main(["--pyargs", "<package-name>", "-k", "some_filter", ...]) == 0
```

you can put whatever command line arguments you would pass to `pytest` as
Expand Down
3 changes: 2 additions & 1 deletion docs/project/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ myst:
- Upgraded `pydantic_core` to 2.25.1 {pr}`5151`
- Upgraded `pydantic` to 2.9.2 {pr}`5151`
- Upgraded `msgpack` to 1.1.0 {pr}`5144`
- Added `tiktoken` v0.8.0 in {pr}`5147`
- Upgraded `protobuf` to 5.28.3 {pr}`5136`
- Upgraded `scikit-learn` to 1.5.2 {pr}`4823`, {pr}`5016`, {pr}`5072`
- Upgraded `libcst` to 1.4.0 {pr}`4856`
Expand All @@ -89,6 +88,8 @@ myst:
- Upgraded `tree-sitter` to 0.23.1 {pr}`5110`
- Upgraded `PyYAML` to 6.0.2 {pr}`5137`
- Upgraded `duckdb` to 1.1.2 {pr}`5142`
- Added `soxr` 0.5.0.post1 {pr}`5150`
- Added `tiktoken` v0.8.0 in {pr}`5147`
- Added `casadi` 3.6.6 {pr}`4936`, {pr}`5057`
- Added `pyarrow` 17.0.0 {pr}`4950`
- Added `rasterio` 1.13.10, `affine` 2.4.0 {pr}`4983`
Expand Down
25 changes: 25 additions & 0 deletions packages/soxr/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package:
name: soxr
version: 0.5.0.post1
top-level:
- soxr
source:
url: https://files.pythonhosted.org/packages/02/c0/4429bf9b3be10e749149e286aa5c53775399ec62891c6b970456c6dca325/soxr-0.5.0.post1.tar.gz
sha256: 7092b9f3e8a416044e1fa138c8172520757179763b85dc53aa9504f4813cff73
patches:
# Can be removed once the PR chirlu/soxr#13 (dead upstream) or dofuuz/soxr#3 (python soxr fork) is merged and released
- patches/0001-Fix-function-signatures.patch
requirements:
run:
- numpy
about:
home: https://github.com/dofuuz/python-soxr
PyPI: https://pypi.org/project/soxr
summary: High quality, one-dimensional sample-rate conversion library
license: LGPLv2+
test:
imports:
- soxr
extra:
recipe-maintainers:
- swnf
99 changes: 99 additions & 0 deletions packages/soxr/patches/0001-Fix-function-signatures.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
From 983ea3d49b2834e044ca5b492cfb80181e49666f Mon Sep 17 00:00:00 2001
From: swnf <[email protected]>
Date: Sun, 3 Nov 2024 10:36:47 +0100
Subject: [PATCH] Fix function signature mismatches


diff --git a/libsoxr/src/fft4g32.c b/libsoxr/src/fft4g32.c
index 7a31ba4..31aebca 100644
--- a/libsoxr/src/fft4g32.c
+++ b/libsoxr/src/fft4g32.c
@@ -9,11 +9,12 @@

#if WITH_CR32
#include "rdft_t.h"
-static void * null(void) {return 0;}
-static void forward (int length, void * setup, double * H) {lsx_safe_rdft_f(length, 1, H); (void)setup;}
-static void backward(int length, void * setup, double * H) {lsx_safe_rdft_f(length, -1, H); (void)setup;}
+static void * null(int length) {return 0; (void)length;}
+static void nothing(void * setup) {(void)setup;}
+static void forward(int length, void * setup, void * H, void * scratch) {lsx_safe_rdft_f(length, 1, (double * ) H); (void)setup; (void)scratch;}
+static void backward(int length, void * setup, void * H, void * scratch) {lsx_safe_rdft_f(length, -1, (double * ) H); (void)setup; (void)scratch;}
static int multiplier(void) {return 2;}
-static void nothing(void) {}
+static void nothing2(int length, void * setup, void * H, void * scratch) {(void)length; (void)setup; (void)H; (void)scratch;}
static int flags(void) {return 0;}

fn_t _soxr_rdft32_cb[] = {
@@ -27,7 +28,7 @@ fn_t _soxr_rdft32_cb[] = {
(fn_t)_soxr_ordered_convolve_f,
(fn_t)_soxr_ordered_partial_convolve_f,
(fn_t)multiplier,
- (fn_t)nothing,
+ (fn_t)nothing2,
(fn_t)malloc,
(fn_t)calloc,
(fn_t)free,
diff --git a/libsoxr/src/fft4g32s.c b/libsoxr/src/fft4g32s.c
index 8ce9726..f00c97c 100644
--- a/libsoxr/src/fft4g32s.c
+++ b/libsoxr/src/fft4g32s.c
@@ -5,11 +5,12 @@
#include "util32s.h"
#include "rdft_t.h"

-static void * null(void) {return 0;}
-static void nothing(void) {}
-static void forward (int length, void * setup, float * H) {lsx_safe_rdft_f(length, 1, H); (void)setup;}
-static void backward(int length, void * setup, float * H) {lsx_safe_rdft_f(length, -1, H); (void)setup;}
+static void * null(int length) {return 0; (void)length;}
+static void nothing(void * setup) {(void)setup;}
+static void forward (int length, void * setup, void * H, void * scratch) {lsx_safe_rdft_f(length, 1, (float*)H); (void)setup; (void)scratch;}
+static void backward(int length, void * setup, void * H, void * scratch) {lsx_safe_rdft_f(length, -1, (float*)H); (void)setup; (void)scratch;}
static int multiplier(void) {return 2;}
+static void nothing2(int length, void * setup, void * H, void * scratch) {(void)length; (void)setup; (void)H; (void)scratch;}
static int flags(void) {return RDFT_IS_SIMD;}

fn_t _soxr_rdft32s_cb[] = {
@@ -23,7 +24,7 @@ fn_t _soxr_rdft32s_cb[] = {
(fn_t)ORDERED_CONVOLVE_SIMD,
(fn_t)ORDERED_PARTIAL_CONVOLVE_SIMD,
(fn_t)multiplier,
- (fn_t)nothing,
+ (fn_t)nothing2,
(fn_t)SIMD_ALIGNED_MALLOC,
(fn_t)SIMD_ALIGNED_CALLOC,
(fn_t)SIMD_ALIGNED_FREE,
diff --git a/libsoxr/src/fft4g64.c b/libsoxr/src/fft4g64.c
index 0018516..5798fd7 100644
--- a/libsoxr/src/fft4g64.c
+++ b/libsoxr/src/fft4g64.c
@@ -7,11 +7,12 @@
#include "soxr-config.h"

#if WITH_CR64
-static void * null(void) {return 0;}
-static void nothing(void) {}
-static void forward (int length, void * setup, double * H) {lsx_safe_rdft(length, 1, H); (void)setup;}
-static void backward(int length, void * setup, double * H) {lsx_safe_rdft(length, -1, H); (void)setup;}
+static void * null(int length) {return 0; (void)length;}
+static void nothing(void * setup) {(void)setup;}
+static void forward (int length, void * setup, void * H, void * scratch) {lsx_safe_rdft(length, 1, (double*)H); (void)setup; (void)scratch;}
+static void backward(int length, void * setup, void * H, void * scratch) {lsx_safe_rdft(length, -1, (double*)H); (void)setup; (void)scratch;}
static int multiplier(void) {return 2;}
+static void nothing2(int length, void * setup, void * H, void * scratch) {(void)length; (void)setup; (void)H; (void)scratch;}
static int flags(void) {return 0;}

typedef void (* fn_t)(void);
@@ -26,7 +27,7 @@ fn_t _soxr_rdft64_cb[] = {
(fn_t)_soxr_ordered_convolve,
(fn_t)_soxr_ordered_partial_convolve,
(fn_t)multiplier,
- (fn_t)nothing,
+ (fn_t)nothing2,
(fn_t)malloc,
(fn_t)calloc,
(fn_t)free,
--
2.43.0

24 changes: 24 additions & 0 deletions packages/soxr/test_soxr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import pytest
from pytest_pyodide import run_in_pyodide


@pytest.mark.parametrize("input_sr, output_sr", [(44100, 22050), (22050, 44100)])
@run_in_pyodide(packages=["soxr", "numpy"])
def test_resample(selenium, input_sr, output_sr):
import numpy as np
import soxr

# Signal length in seconds
length = 5.0
# Frequency in Hz
frequency = 42

input_sample_positions = np.arange(0, length, 1 / input_sr)
output_sample_positions = np.arange(0, length, 1 / output_sr)

input_signal = np.sin(2 * np.pi * frequency * input_sample_positions)
predicted_output_signal = np.sin(2 * np.pi * frequency * output_sample_positions)

output_signal = soxr.resample(input_signal, input_sr, output_sr)

np.testing.assert_allclose(predicted_output_signal, output_signal, atol=0.0015)

0 comments on commit a5386c8

Please sign in to comment.