interpolators

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2025 License: MIT Imports: 1 Imported by: 1

README

interpolation

CI codecov Go Reference Release

A Go package with an array of polynomial interpolators for resampling audio.

newplot(1)

Available Interpolators

This package includes 20 different interpolation methods:

Basic Interpolators
  • None - Returns input data as-is
  • DropSample - 0th-order B-spline (nearest neighbor/sample-and-hold)
  • Linear - 1st-order B-spline (linear interpolation)
B-Spline Interpolators
  • BSpline3 - 3rd-order B-spline (4-point)
  • BSpline5 - 5th-order B-spline (6-point)
Lagrange Interpolators
  • Lagrange4 - 4-point, 3rd-order Lagrange interpolator
  • Lagrange6 - 6-point, 5th-order Lagrange interpolator
Hermite Interpolators
  • Hermite4 - 4-point, 3rd-order Hermite (Catmull-Rom spline)
  • Hermite6_3 - 6-point, 3rd-order Hermite interpolator
  • Hermite6_5 - 6-point, 5th-order Hermite interpolator
Osculating Interpolators
  • Osculating4 - 4-point, 5th-order 2nd-order-osculating interpolator
  • Osculating6 - 6-point, 5th-order 2nd-order-osculating interpolator
Specialized Interpolators
  • Watte - 4-point, 2nd-order Watte tri-linear interpolator
  • Parabolic2x - 4-point, 2nd-order parabolic 2x interpolator
Spline Interpolators
  • CubicSpline - Natural cubic spline with C² continuity
  • MonotonicCubic - Fritsch-Carlson monotonic cubic (preserves monotonicity)
  • Akima - Akima spline (robust to outliers)
Windowed Sinc Interpolators
  • Lanczos2 - Windowed sinc with a=2 (4-point, high quality)
  • Lanczos3 - Windowed sinc with a=3 (6-point, highest quality)
Other
  • Bezier - Cubic Bezier curve interpolation

Benchmarks

goos: linux
goarch: amd64
pkg: github.com/schollz/interpolation
cpu: 13th Gen Intel(R) Core(TM) i9-13900K
BenchmarkResampleWAVFile/Linear-32                  1552            835038 ns/op
BenchmarkResampleWAVFile/DropSample-32              1537            849516 ns/op
BenchmarkResampleWAVFile/BSpline3-32                 685           1671143 ns/op
BenchmarkResampleWAVFile/BSpline5-32                 462           2531651 ns/op
BenchmarkResampleWAVFile/Lagrange4-32                679           1730536 ns/op
BenchmarkResampleWAVFile/Lagrange6-32                444           2796961 ns/op
BenchmarkResampleWAVFile/Watte-32                    896           1488571 ns/op
BenchmarkResampleWAVFile/Parabolic2x-32              784           1468642 ns/op
BenchmarkResampleWAVFile/Osculating4-32              646           1990904 ns/op
BenchmarkResampleWAVFile/Osculating6-32              427           2525010 ns/op
BenchmarkResampleWAVFile/Hermite4-32                 570           2215825 ns/op
BenchmarkResampleWAVFile/Hermite6_3-32               411           2687895 ns/op
BenchmarkResampleWAVFile/Hermite6_5-32               403           3145303 ns/op
BenchmarkResampleWAVFile/Lanczos2-32                 213           5560200 ns/op
BenchmarkResampleWAVFile/Lanczos3-32                 147           8437112 ns/op
BenchmarkResampleWAVFile/Bezier-32                   556           2163774 ns/op

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Interpolate

func Interpolate(in []float64, outSamples int, interpolatorType InterpolatorType) (out []float64, err error)

Interpolate performs interpolation on the input data based on the specified type

func InterpolateInt

func InterpolateInt(in []int, outSamples int, interpolatorType InterpolatorType) (out []int, err error)

InterpolateInt performs interpolation on integer input data and returns integer output This function minimizes conversions by converting to float64 only once at the start and back to int only once at the end (with rounding)

Types

type InterpolatorType

type InterpolatorType int

InterpolatorType defines the type of interpolation to use

const (
	// None returns the input data as-is without any interpolation
	None InterpolatorType = iota
	// DropSample is the 0th-order B-spline (1-point)
	DropSample
	// Linear is the 1st-order B-spline (2-point)
	Linear
	// BSpline3 is the 3rd-order B-spline (4-point)
	BSpline3
	// BSpline5 is the 5th-order B-spline (6-point)
	BSpline5
	// Lagrange4 is the 4-point, 3rd-order Lagrange interpolator
	Lagrange4
	// Lagrange6 is the 6-point, 5th-order Lagrange interpolator
	Lagrange6
	// Watte is the 4-point, 2nd-order Watte tri-linear interpolator
	Watte
	// Parabolic2x is the 4-point, 2nd-order parabolic 2x interpolator
	Parabolic2x
	// Osculating4 is the 4-point, 5th-order 2nd-order-osculating interpolator
	Osculating4
	// Osculating6 is the 6-point, 5th-order 2nd-order-osculating interpolator
	Osculating6
	// Hermite4 is the 4-point, 3rd-order Hermite interpolator (Catmull-Rom spline)
	Hermite4
	// Hermite6_3 is the 6-point, 3rd-order Hermite interpolator
	Hermite6_3
	// Hermite6_5 is the 6-point, 5th-order Hermite interpolator
	Hermite6_5
	// CubicSpline is the natural cubic spline interpolator with C² continuity
	CubicSpline
	// MonotonicCubic is the Fritsch-Carlson monotonic cubic interpolator (preserves monotonicity)
	MonotonicCubic
	// Lanczos2 is the windowed sinc interpolator with a=2 (4-point)
	Lanczos2
	// Lanczos3 is the windowed sinc interpolator with a=3 (6-point)
	Lanczos3
	// Bezier is the cubic Bezier curve interpolator
	Bezier
	// Akima is the Akima spline interpolator (robust to outliers)
	Akima
)

Directories

Path Synopsis
examples
interpolate_int command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL