gosamplerate

package module
Version: v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2020 License: BSD-2-Clause Imports: 4 Imported by: 3

README

libsamplerate binding for Golang

Go Report Card Build Status Coverage Status

This is a Golang binding for libsamplerate (written in C), probably the best audio Sample Rate Converter available to today.

A classical use case is converting audio from a CD sample rate of 44.1kHz to the 48kHz sample rate used by DAT players.

libsamplerate is capable of arbitrary and time varying conversions (max sampling / upsampling by factor 256) and comes with 5 converters, allowing quality to be traded off against computation cost.

API implementations

gosamplerate implements the following libsamplerate API calls:

not (yet) implemented is:

License

This library (gosamplerate) is published under the the permissive BSD license. You can find a good comparison of Open Source Software licenses, including the BSD license at choosealicense.com

libsamplerate has been republished in 2016 under the 2-clause BSD license.

How to install samplerate

Make sure that you have libsamplerate installed on your system.

On Mac or Linux it can be installed conveniently through your distro's packet manager.

Linux:

using apt (Ubuntu), yum (Centos)...etc.

    $ sudo apt install libsamplerate0
MacOS

using Homebrew:

    $ brew install libsamplerate
Install gosamplerate
    $ go get github.com/dh1tw/gosamplerate

Documentation

The API of gosamplerate can be found at godoc.org. The documentation of libsamplerate (necessary in order to fully understand the API) can be found here.

Tests & Examples

The test coverage is close to 100%. The tests contain various examples on how to use gosamplerate.

Documentation

Overview

Package gosamplerate is a golang binding for libsamplerate (audio sample rate converter)

Index

Constants

View Source
const (
	SRC_SINC_BEST_QUALITY   = C.SRC_SINC_BEST_QUALITY
	SRC_SINC_MEDIUM_QUALITY = C.SRC_SINC_MEDIUM_QUALITY
	SRC_SINC_FASTEST        = C.SRC_SINC_FASTEST
	SRC_ZERO_ORDER_HOLD     = C.SRC_ZERO_ORDER_HOLD
	SRC_LINEAR              = C.SRC_LINEAR
)

Variables

This section is empty.

Functions

func Delete

func Delete(src Src) error

Delete cleans up all internal allocations.

func Error

func Error(errNo int) string

Error Convert the error number into a string.

func GetDescription

func GetDescription(converter C.int) (string, error)

GetDescription returns the description of a sample rate converter

func GetName

func GetName(converter C.int) (string, error)

GetName returns the name of a sample rate converter

func GetVersion

func GetVersion() string

GetVersion returns the version number of libsamplerate

func IsValidRatio

func IsValidRatio(ratio float64) bool

IsValidRatio returns True is ratio is a valid conversion ratio, False otherwise.

func Simple

func Simple(dataIn []float32, ratio float64, channels int, converterType int) ([]float32, error)

Simple converts a single block of samples (one or more channels) in one go. The simple API is less capable than the full API (Process()). It must not be used if Audio shall be converted in chunks. For full documentation see: http://www.mega-nerd.com/SRC/api_simple.html

Types

type Src

type Src struct {
	// contains filtered or unexported fields
}

Src struct holding the data for the full API

func New

func New(converterType int, channels int, bufferLen int) (Src, error)

New initializes the converter object and returns a reference to it.

func (*Src) ErrorNo

func (src *Src) ErrorNo() int

ErrorNo return an error number

func (*Src) GetChannels

func (src *Src) GetChannels() (int, error)

GetChannels gets the current channel count.

func (*Src) Process

func (src *Src) Process(dataIn []float32, ratio float64, endOfInput bool) ([]float32, error)

Process is known as the full API. It allows time varying sample rate conversion on streaming data on one or more channels. For full documentation see: http://www.mega-nerd.com/SRC/api_full.html

func (*Src) Reset

func (src *Src) Reset() error

Reset the internal SRC state. It does not modify the quality settings. It does not free any memory allocations.

func (*Src) SetRatio

func (src *Src) SetRatio(ratio float64) error

SetRatio sets the samplerate conversion ratio between input and output samples. Normally, when using (src *SRC) Process or the callback, the library will try to smoothly transition between the conversion ratio of the last call and the conversion ratio of the next call. This function bypasses this behaviour and achieves a step response in the conversion rate.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto