Skip to content

About

A resampler port based on SpeexDSP

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

SpeexResamplerSharp

SpeexResamplerSharp is an optimized, pure-managed C# port of the SpeexDSP audio resampler. It targets netstandard2.1, net8.0, and net10.0 and preserves the floating-point SSE/SSE2 implementation's output bit for bit on x64.

The library supports floating-point and signed 16-bit PCM, independent or interleaved channels, integer and rational rate changes, all Speex quality levels, streaming history, non-unit strides, latency queries, initial-delay skipping, reset, and explicit zero-input draining.

Example

using SpeexResamplerSharp;

var resampler = new SpeexResampler(channelCount: 2, inputRate: 48_000, outputRate: 44_100,
    quality: ResamplerQuality.Desktop);
short[] input = GetInterleavedStereoPcm();
short[] output = new short[44_100 * 2];

ResamplerProcessResult progress = resampler.ProcessInterleaved(input, output);
Console.WriteLine($"Consumed {progress.InputConsumed} frames; produced {progress.OutputProduced} frames.");

Processing methods do not allocate after warm-up. A resampler is mutable and not thread-safe; use a separate instance for each concurrently processed stream.

The netstandard2.1 build uses an unsafe four-lane scalar-vector kernel that preserves the upstream SSE operation order. The net8.0 and net10.0 builds use explicit SSE/SSE2 intrinsics when the processor supports them and fall back to the portable bit-compatible kernel otherwise. Filter and history arrays are retained across calls and only grow when a rate or quality change requires more capacity.

Verification

The test suite builds the pinned speexdsp submodule as a strict floating-point SSE/SSE2 native reference and compares every managed output bit, progress count, and state transition. Tests also use a checked-in CC0 real-music excerpt; see THIRD_PARTY_NOTICES.md and the asset provenance for details.

Build before running tests so no stale binaries are exercised:

dotnet build SpeexResamplerSharp.sln -c Release -m:1
dotnet test --solution SpeexResamplerSharp.sln -c Release --no-build --max-parallel-test-modules 1 `
    --minimum-expected-tests 104

Run the real-music performance workloads separately for each runtime:

dotnet run --project SpeexResamplerSharp.Benchmarks -c Release -f net8.0 -- --filter "*" --job short
dotnet run --project SpeexResamplerSharp.Benchmarks -c Release -f net10.0 -- --filter "*" --job short

License

BSD 3-Clause. See LICENSE and THIRD_PARTY_NOTICES.md.

About

A resampler port based on SpeexDSP

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages