{"id":45920517,"url":"https://github.com/tphakala/go-audio-resampler","last_synced_at":"2026-03-15T17:00:05.699Z","repository":{"id":326102559,"uuid":"1103227751","full_name":"tphakala/go-audio-resampler","owner":"tphakala","description":"High-quality audio resampling library for Go, based on libsoxr. Polyphase FIR filtering with Kaiser window design, SIMD acceleration, and professional-grade quality.","archived":false,"fork":false,"pushed_at":"2026-02-13T17:57:31.000Z","size":2311,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-02-13T20:35:29.413Z","etag":null,"topics":["audio","audio-processing","dsp","fir-filter","golang","resampling","sample-rate-conversion","simd","soxr"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tphakala.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-24T15:41:26.000Z","updated_at":"2026-02-13T17:57:34.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/tphakala/go-audio-resampler","commit_stats":null,"previous_names":["tphakala/go-audio-resampler"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/tphakala/go-audio-resampler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tphakala%2Fgo-audio-resampler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tphakala%2Fgo-audio-resampler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tphakala%2Fgo-audio-resampler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tphakala%2Fgo-audio-resampler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tphakala","download_url":"https://codeload.github.com/tphakala/go-audio-resampler/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tphakala%2Fgo-audio-resampler/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29929091,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-27T19:37:42.220Z","status":"online","status_checked_at":"2026-02-28T02:00:07.010Z","response_time":90,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["audio","audio-processing","dsp","fir-filter","golang","resampling","sample-rate-conversion","simd","soxr"],"created_at":"2026-02-28T08:41:16.942Z","updated_at":"2026-03-15T17:00:05.683Z","avatar_url":"https://github.com/tphakala.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-audio-resampler\n\n[![CI](https://github.com/tphakala/go-audio-resampler/actions/workflows/ci.yml/badge.svg)](https://github.com/tphakala/go-audio-resampler/actions/workflows/ci.yml)\n[![codecov](https://codecov.io/gh/tphakala/go-audio-resampler/branch/master/graph/badge.svg)](https://codecov.io/gh/tphakala/go-audio-resampler)\n[![Go Reference](https://pkg.go.dev/badge/github.com/tphakala/go-audio-resampler.svg)](https://pkg.go.dev/github.com/tphakala/go-audio-resampler)\n[![Go Report Card](https://goreportcard.com/badge/github.com/tphakala/go-audio-resampler)](https://goreportcard.com/report/github.com/tphakala/go-audio-resampler)\n[![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/tphakala/go-audio-resampler/badge)](https://scorecard.dev/viewer/?uri=github.com/tphakala/go-audio-resampler)\n\nThe **only pure Go** high-quality audio resampling library (that I know of) - **no CGO dependencies** required.\n\nBased on [libsoxr](https://sourceforge.net/projects/soxr/) (the SoX Resampler library) by Rob Sykes, this is a complete Go reimplementation delivering professional-grade quality without any C code or external dependencies.\n\nThe library implements polyphase FIR filtering with Kaiser window design for professional-grade sample rate conversion, following the multi-stage architecture that makes libsoxr one of the highest-quality resamplers available.\n\n## Features\n\n- **100% Pure Go** - No CGO, no external C libraries, no build complexity. Just `go get` and build anywhere\n- **Cross-platform** - Works on Linux, macOS, Windows, ARM, WebAssembly - anywhere Go runs\n- **Multiple quality presets** - From quick/low-latency to very high quality mastering (8-bit to 32-bit precision)\n- **Selectable precision** - Generic float32/float64 processing paths with type-safe SIMD operations\n- **Polyphase FIR filtering** - Efficient multi-stage resampling architecture with cubic coefficient interpolation\n- **Kaiser window design** - Optimal stopband attenuation with configurable parameters\n- **SIMD acceleration** - AVX2/SSE optimizations via [tphakala/simd](https://github.com/tphakala/simd) for both float32 and float64\n- **Multi-channel support** - Process stereo, surround, and multi-channel audio (up to 256 channels)\n- **Parallel channel processing** - ~1.7x speedup for stereo, up to 8x for 7.1 surround audio\n- **Streaming API** - Process audio in chunks with proper state management\n- **soxr-quality algorithms** - Implements libsoxr's multi-stage architecture for professional-grade quality\n\n## Installation\n\n```bash\ngo get github.com/tphakala/go-audio-resampler\n```\n\nRequires Go 1.25 or later.\n\n## Quick Start\n\n### Simple One-Shot Resampling\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"log\"\n\n    resampling \"github.com/tphakala/go-audio-resampler\"\n)\n\nfunc main() {\n    // Resample mono audio from 44.1kHz to 48kHz\n    input := generateSineWave(44100, 1000, 1.0) // 1 second of 1kHz sine\n\n    output, err := resampling.ResampleMono(input, 44100, 48000, resampling.QualityHigh)\n    if err != nil {\n        log.Fatal(err)\n    }\n\n    fmt.Printf(\"Resampled %d samples to %d samples\\n\", len(input), len(output))\n}\n```\n\n### Streaming Resampling\n\n```go\npackage main\n\nimport (\n    \"log\"\n\n    resampling \"github.com/tphakala/go-audio-resampler\"\n)\n\nfunc main() {\n    // Create a resampler for CD to DAT conversion\n    config := \u0026resampling.Config{\n        InputRate:  44100,\n        OutputRate: 48000,\n        Channels:   2,\n        Quality:    resampling.QualitySpec{Preset: resampling.QualityHigh},\n    }\n\n    r, err := resampling.New(config)\n    if err != nil {\n        log.Fatal(err)\n    }\n\n    // Process audio in chunks\n    for chunk := range audioChunks {\n        output, err := r.Process(chunk)\n        if err != nil {\n            log.Fatal(err)\n        }\n        writeOutput(output)\n    }\n\n    // Flush remaining samples\n    final, _ := r.Flush()\n    writeOutput(final)\n}\n```\n\n### Convenience Functions\n\n```go\n// Common sample rate conversions\nr, _ := resampling.NewCDtoDAT(resampling.QualityHigh)    // 44.1kHz -\u003e 48kHz\nr, _ := resampling.NewDATtoCD(resampling.QualityHigh)    // 48kHz -\u003e 44.1kHz\nr, _ := resampling.NewCDtoHiRes(resampling.QualityHigh)  // 44.1kHz -\u003e 88.2kHz\n\n// Simple mono/stereo resamplers\nr, _ := resampling.NewSimple(inputRate, outputRate)\nr, _ := resampling.NewStereo(inputRate, outputRate, resampling.QualityMedium)\nr, _ := resampling.NewMultiChannel(inputRate, outputRate, 6, resampling.QualityHigh)\n\n// Direct engine access for maximum performance\nr, _ := resampling.NewEngine(44100, 48000, resampling.QualityHigh)\n```\n\n### Stereo Processing\n\n```go\n// Process stereo as separate channels\nleftOut, rightOut, err := resampling.ResampleStereo(\n    leftChannel, rightChannel,\n    44100, 48000,\n    resampling.QualityHigh,\n)\n\n// Interleave/deinterleave helpers\ninterleaved := resampling.InterleaveToStereo(left, right)\nleft, right := resampling.DeinterleaveFromStereo(interleaved)\n```\n\n## Quality Presets\n\n| Preset            | Precision | Attenuation | Use Case                        |\n| ----------------- | --------- | ----------- | ------------------------------- |\n| `QualityQuick`    | 8-bit     | ~54 dB      | Preview, real-time with low CPU |\n| `QualityLow`      | 16-bit    | ~102 dB     | Speech, low-bandwidth audio     |\n| `QualityMedium`   | 16-bit    | ~102 dB     | General music playback          |\n| `QualityHigh`     | 20-bit    | ~126 dB     | Studio production, streaming    |\n| `QualityVeryHigh` | 28-bit    | ~175 dB     | Mastering, archival             |\n\n### Quality Validation vs libsoxr\n\nThe following THD (Total Harmonic Distortion) measurements compare this library against libsoxr reference implementation for 44.1kHz → 48kHz conversion at 1kHz test tone:\n\n| Preset   | libsoxr THD | Go THD     | Difference |\n| -------- | ----------- | ---------- | ---------- |\n| Low      | -146.25 dB  | -145.17 dB | +1.1 dB    |\n| Medium   | -130.61 dB  | -145.17 dB | -14.6 dB ✓ |\n| High     | -155.19 dB  | -156.73 dB | -1.5 dB ✓  |\n| VeryHigh | -162.22 dB  | -162.19 dB | +0.03 dB   |\n\n_Negative difference means Go implementation has better THD (lower distortion)._\n\n**Key findings:**\n\n- **High and VeryHigh presets match or exceed libsoxr quality** with THD differences under 2 dB\n- All presets achieve SNR (Signal-to-Noise Ratio) matching libsoxr within measurement tolerance\n- Downsampling (e.g., 48kHz → 32kHz) often shows even better performance due to optimized anti-aliasing filters\n\n### Custom Quality Settings\n\n```go\nconfig := \u0026resampling.Config{\n    InputRate:  44100,\n    OutputRate: 48000,\n    Channels:   1,\n    Quality: resampling.QualitySpec{\n        Preset:        resampling.QualityCustom,\n        Precision:     24,          // Bits of precision\n        PhaseResponse: 50,          // 0=minimum, 50=linear, 100=maximum\n        PassbandEnd:   0.95,        // Preserve up to 95% of Nyquist\n        StopbandBegin: 0.99,        // Attenuate above 99% of Nyquist\n    },\n}\n```\n\n## Precision Modes (float32 vs float64)\n\nThe library supports both float32 and float64 processing through Go generics:\n\n```go\n// float64 for maximum precision (default)\nr64, _ := engine.NewResampler[float64](44100, 48000, engine.QualityHigh)\noutput64, _ := r64.Process(input64)\n\n// float32 for ~2x SIMD throughput\nr32, _ := engine.NewResampler[float32](44100, 48000, engine.QualityHigh)\noutput32, _ := r32.Process(input32)\n```\n\n**Precision comparison (44.1kHz → 48kHz, High quality):**\n\n| Mode    | THD @ 1kHz | Use Case                          |\n| ------- | ---------- | --------------------------------- |\n| float64 | -144.95 dB | Maximum precision, critical audio |\n| float32 | -144.96 dB | Higher throughput, general use    |\n\nBoth modes achieve equivalent quality for most use cases. Use float32 when processing large amounts of audio data where throughput is more important than theoretical precision limits.\n\n## Architecture\n\nThe library implements a multi-stage resampling architecture similar to libsoxr:\n\n```text\nInput -\u003e [DFT Pre-Stage] -\u003e [Polyphase FIR] -\u003e Output\n              (2x)            (fine ratio)\n```\n\n- **Integer ratios** (2x, 3x, etc.): Single DFT stage for efficiency\n- **Non-integer ratios** (44.1kHz→48kHz): DFT pre-upsampling + polyphase stage\n- **Polyphase decomposition**: Reduces computation by processing only needed output phases\n- **Cubic coefficient interpolation**: Sub-phase interpolation for excellent high-frequency THD\n- **Kaiser window**: Optimal FIR filter design with configurable stopband attenuation\n\n## API Reference\n\n### Core Types\n\n```go\n// Main resampler interface\ntype Resampler interface {\n    Process(input []float64) ([]float64, error)\n    ProcessFloat32(input []float32) ([]float32, error)\n    ProcessMulti(input [][]float64) ([][]float64, error)\n    Flush() ([]float64, error)\n    GetLatency() int\n    Reset()\n    GetRatio() float64\n}\n\n// Configuration\ntype Config struct {\n    InputRate      float64      // Input sample rate in Hz\n    OutputRate     float64      // Output sample rate in Hz\n    Channels       int          // Number of audio channels\n    Quality        QualitySpec  // Quality settings\n    MaxInputSize   int          // Optional buffer size hint\n    EnableSIMD     bool         // Enable SIMD optimizations\n    EnableParallel bool         // Enable parallel channel processing\n}\n```\n\n### Getting Resampler Info\n\n```go\nr, _ := resampling.New(config)\ninfo := resampling.GetInfo(r)\n\nfmt.Printf(\"Algorithm: %s\\n\", info.Algorithm)\nfmt.Printf(\"Filter length: %d taps\\n\", info.FilterLength)\nfmt.Printf(\"Latency: %d samples\\n\", info.Latency)\nfmt.Printf(\"Memory: %d bytes\\n\", info.MemoryUsage)\nfmt.Printf(\"SIMD: %v (%s)\\n\", info.SIMDEnabled, info.SIMDType)\n```\n\n## Command-Line Tools\n\n### resample-wav\n\nResample WAV audio files:\n\n```bash\n# Build\ngo build -o bin/resample-wav ./cmd/resample-wav\n\n# Usage\nresample-wav -rate 48 input.wav output.wav              # Resample to 48kHz\nresample-wav -rate 16 -quality high speech.wav out.wav  # Downsample speech\nresample-wav -rate 96 music.wav hires.wav               # Upsample to hi-res\nresample-wav -rate 48 -fast input.wav output.wav        # Float32 precision (~40% faster)\nresample-wav -rate 48 -parallel=false input.wav out.wav # Disable parallel processing\n```\n\nParallel channel processing is enabled by default for stereo/multichannel files.\n\n### resample (demo)\n\nInteractive demo showing library capabilities:\n\n```bash\ngo build -o bin/resample ./cmd/resample\n./bin/resample -demo\n```\n\n## Performance\n\nFilter complexity comparison for 44.1kHz → 48kHz conversion:\n\n| Quality  | DFT Stage          | Polyphase Stage     | Total Taps |\n| -------- | ------------------ | ------------------- | ---------- |\n| Low      | 132 taps × 2 phase | 32 taps × 80 phase  | ~2820      |\n| Medium   | 132 taps × 2 phase | 32 taps × 80 phase  | ~2820      |\n| High     | 166 taps × 2 phase | 64 taps × 80 phase  | ~5452      |\n| VeryHigh | 166 taps × 2 phase | 100 taps × 80 phase | ~8332      |\n\n_Actual performance varies by CPU. The [simd](https://github.com/tphakala/simd) library automatically uses AVX2/SSE when available. Setting `GOAMD64=v3` can provide minor additional speedup for non-SIMD code paths._\n\n### Parallel Channel Processing\n\nFor multi-channel audio, enabling parallel processing provides significant speedup:\n\n```go\nconfig := \u0026resampling.Config{\n    InputRate:      44100,\n    OutputRate:     48000,\n    Channels:       2,\n    Quality:        resampling.QualitySpec{Preset: resampling.QualityHigh},\n    EnableParallel: true,  // Process channels concurrently\n}\n```\n\n| Configuration | Processing Time | Speedup |\n| ------------- | --------------- | ------- |\n| Stereo (sequential) | 15.7 ms | 1.0x |\n| Stereo (parallel) | 9.4 ms | 1.67x |\n| 5.1 Surround (parallel) | ~17.1 ms | ~5.5x vs sequential |\n| 7.1 Surround (parallel) | ~20.0 ms | ~7.0x vs sequential |\n\n_Benchmark: 1 second of audio, 44.1kHz → 48kHz, High quality, Intel i7-1260P_\n\nParallel processing is safe because each channel maintains independent filter state. Mono audio is unaffected (no channels to parallelize).\n\n## Dependencies\n\n- [github.com/tphakala/simd](https://github.com/tphakala/simd) - SIMD operations for filter convolution\n- [gonum.org/v1/gonum](https://gonum.org) - FFT for DFT stages\n- [github.com/go-audio/wav](https://github.com/go-audio/wav) - WAV file I/O (CLI tools only)\n\n## Contributing\n\nContributions are welcome! Please:\n\n1. Fork the repository\n2. Create a feature branch\n3. Add tests for new functionality\n4. Ensure `go test ./...` passes\n5. Submit a pull request\n\n## License\n\nThis library is licensed under the **GNU Lesser General Public License v2.1 (LGPL-2.1)**.\n\nSee the [LICENSE](LICENSE) file for the full license text.\n\n## Acknowledgments\n\nThis library is based on [libsoxr](https://sourceforge.net/projects/soxr/) by Rob Sykes (licensed under LGPL-2.1). The following were derived from libsoxr:\n\n- Multi-stage resampling pipeline (DFT pre-stage + polyphase)\n- Polyphase filter bank decomposition\n- Quality preset parameters and filter specifications\n- Integer phase arithmetic for polyphase interpolation\n\nThe Kaiser window filter design follows well-established DSP literature, particularly the work of James Kaiser on optimal window functions.\n\nWe gratefully acknowledge Rob Sykes' excellent work on libsoxr.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftphakala%2Fgo-audio-resampler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftphakala%2Fgo-audio-resampler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftphakala%2Fgo-audio-resampler/lists"}