Git Product home page Git Product logo

resample's Introduction

resample

-- import "github.com/zaf/resample"

Package resample implements resampling of PCM-encoded audio. It uses the SoX Resampler library `libsoxr'.

To install make sure you have libsoxr installed, then run:

go get -u github.com/zaf/resample

The package warps an io.Reader in a Resampler that resamples and writes all input data. Input should be RAW PCM encoded audio samples.

For usage details please see the code snippet in the cmd folder.

Usage

const (
	// Quality settings
	Quick     = 0 // Quick cubic interpolation
	LowQ      = 1 // LowQ 16-bit with larger rolloff
	MediumQ   = 2 // MediumQ 16-bit with medium rolloff
	HighQ     = 4 // High quality
	VeryHighQ = 6 // Very high quality

	// Input formats
	F32 = 0 // 32-bit floating point PCM
	F64 = 1 // 64-bit floating point PCM
	I32 = 2 // 32-bit signed linear PCM
	I16 = 3 // 16-bit signed linear PCM

)

type Resampler

type Resampler struct {
}

Resampler resamples PCM sound data.

func New

func New(writer io.Writer, inputRate, outputRate float64, channels, format, quality int) (*Resampler, error)

New returns a pointer to a Resampler that implements an io.WriteCloser. It takes as parameters the destination data Writer, the input and output sampling rates, the number of channels of the input data, the input format and the quality setting.

func (*Resampler) Close

func (r *Resampler) Close() (err error)

Close clean-ups and frees memory. Should always be called when finished using the resampler.

func (*Resampler) Reset

func (r *Resampler) Reset(writer io.Writer) (err error)

Reset permits reusing a Resampler rather than allocating a new one.

func (*Resampler) Write

func (r *Resampler) Write(p []byte) (i int, err error)

Write resamples PCM sound data. Writes len(p) bytes from p to the underlying data stream, returns the number of bytes written from p (0 <= n <= len(p)) and any error encountered that caused the write to stop early.

resample's People

Contributors

zaf avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.