sox

package module
v0.0.0-...-7d2f8ae Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2018 License: MIT Imports: 3 Imported by: 13

README

gosox

"SoX − Sound eXchange, the Swiss Army knife of audio manipulation"

Go bindings for the libsox sound library

Description

libsox is a library of sound sample file format readers/writers and sound effects processors. It is mainly developed for use by SoX but is useful for any sound application.

SoX reads and writes audio files in most popular formats and can optionally apply effects to them. It can combine multiple input sources, synthesise audio, and, on many systems, act as a general purpose audio player or a multi-track audio recorder. It also has limited ability to split the input into multiple output files.

Documentation

Overview

Package sox is a set of bindings for the libSoX sound library. LibSoX is a library of sound sample file format readers/writers and sound effects processors. It is mainly developed for use by SoX but is useful for any sound application.

Index

Constants

View Source
const (
	// no, yes, or default (default usually implies some kind of auto-detect logic).
	NO      = C.sox_option_no
	YES     = C.sox_option_yes
	DEFAULT = C.sox_option_default

	// The libSoX-specific error codes.
	SUCCESS = C.SOX_SUCCESS // Function succeeded
	EOF     = C.SOX_EOF     // End Of File or other error
	EHDR    = C.SOX_EHDR    // Invalid Audio Header
	EFMT    = C.SOX_EFMT    // Unsupported data format
	ENOMEM  = C.SOX_ENOMEM  // Can't alloc memory
	EPERM   = C.SOX_EPERM   // Operation not permitted
	ENOTSUP = C.SOX_ENOTSUP // Operation not supported
	EINVAL  = C.SOX_EINVAL  // Invalid argument

	// Flags indicating whether optional features are present in this build of libSoX.
	HAVE_POPEN   = C.sox_version_have_popen
	HAVE_MAGIC   = C.sox_version_have_magic
	HAVE_THREADS = C.sox_version_have_threads
	HAVE_MEMOPEN = C.sox_version_have_memopen

	// Format of sample data.
	ENCODING_UNKNOWN    = C.SOX_ENCODING_UNKNOWN    // encoding has not yet been determined
	ENCODING_SIGN2      = C.SOX_ENCODING_SIGN2      // signed linear 2's comp: Mac
	ENCODING_UNSIGNED   = C.SOX_ENCODING_UNSIGNED   // unsigned linear: Sound Blaster
	ENCODING_FLOAT      = C.SOX_ENCODING_FLOAT      // floating point (binary format)
	ENCODING_FLOAT_TEXT = C.SOX_ENCODING_FLOAT_TEXT // floating point (text format)
	ENCODING_FLAC       = C.SOX_ENCODING_FLAC       // FLAC compression
	ENCODING_HCOM       = C.SOX_ENCODING_HCOM       // Mac FSSD files with Huffman compression
	ENCODING_WAVPACK    = C.SOX_ENCODING_WAVPACK    // WavPack with integer samples
	ENCODING_WAVPACKF   = C.SOX_ENCODING_WAVPACKF   // WavPack with float samples
	ENCODING_ULAW       = C.SOX_ENCODING_ULAW       // u-law signed logs: US telephony SPARC
	ENCODING_ALAW       = C.SOX_ENCODING_ALAW       // A-law signed logs: non-US telephony Psion
	ENCODING_G721       = C.SOX_ENCODING_G721       // G.721 4-bit ADPCM
	ENCODING_G723       = C.SOX_ENCODING_G723       // G.723 3 or 5 bit ADPCM
	ENCODING_CL_ADPCM   = C.SOX_ENCODING_CL_ADPCM   // Creative Labs 8 --> 234 bit Compressed PCM
	ENCODING_CL_ADPCM16 = C.SOX_ENCODING_CL_ADPCM16 // Creative Labs 16 --> 4 bit Compressed PCM
	ENCODING_MS_ADPCM   = C.SOX_ENCODING_MS_ADPCM   // Microsoft Compressed PCM
	ENCODING_IMA_ADPCM  = C.SOX_ENCODING_IMA_ADPCM  // IMA Compressed PCM
	ENCODING_OKI_ADPCM  = C.SOX_ENCODING_OKI_ADPCM  // Dialogic/OKI Compressed PCM
	ENCODING_DPCM       = C.SOX_ENCODING_DPCM       // Differential PCM: Fasttracker 2 (xi)
	ENCODING_DWVW       = C.SOX_ENCODING_DWVW       // Delta Width Variable Word
	ENCODING_DWVWN      = C.SOX_ENCODING_DWVWN      // Delta Width Variable Word N-bit
	ENCODING_GSM        = C.SOX_ENCODING_GSM        // GSM 6.10 33byte frame lossy compression
	ENCODING_MP3        = C.SOX_ENCODING_MP3        // MP3 compression
	ENCODING_VORBIS     = C.SOX_ENCODING_VORBIS     // Vorbis compression
	ENCODING_AMR_WB     = C.SOX_ENCODING_AMR_WB     // AMR-WB compression
	ENCODING_AMR_NB     = C.SOX_ENCODING_AMR_NB     // AMR-NB compression
	ENCODING_CVSD       = C.SOX_ENCODING_CVSD       // Continuously Variable Slope Delta modulation
	ENCODING_LPC10      = C.SOX_ENCODING_LPC10      // Linear Predictive Coding

	// Flags for EncodingsInfo: lossless/lossy1/lossy2
	LOSSLESS = C.sox_encodings_none   // No flags specified (implies lossless encoding).
	LOSSY1   = C.sox_encodings_lossy1 // Encode, decode: lossy once.
	LOSSY2   = C.sox_encodings_lossy2 // Encode, decode, encode, decode: lossy twice.

	// Type of plot.
	PLOT_OFF     = C.sox_plot_off     // No plot.
	PLOT_OCTAVE  = C.sox_plot_octave  // Octave plot.
	PLOT_GNUPLOT = C.sox_plot_gnuplot // Gnuplot plot.
	PLOT_DATA    = C.sox_plot_data    // Plot data.

	// Loop modes.
	LOOP_NONE          = C.sox_loop_none          // single-shot
	LOOP_FORWARD       = C.sox_loop_forward       // forward loop
	LOOP_FORWARD_BACK  = C.sox_loop_forward_back  // forward/back loop
	LOOP_8             = C.sox_loop_8             // 8 loops (??)
	LOOP_SUSTAIN_DECAY = C.sox_loop_sustain_decay // AIFF style, one sustain & one decay loop

	DEFAULT_CHANNELS  = C.SOX_DEFAULT_CHANNELS
	DEFAULT_RATE      = C.SOX_DEFAULT_RATE
	DEFAULT_PRECISION = C.SOX_DEFAULT_PRECISION
	DEFAULT_ENCODING  = C.SOX_DEFAULT_ENCODING

	// Maximum number of loops supported by sox_oob_t
	MAX_NLOOPS = C.SOX_MAX_NLOOPS

	FILE_NOSTDIO = C.SOX_FILE_NOSTDIO
	FILE_DEVICE  = C.SOX_FILE_DEVICE
	FILE_PHONY   = C.SOX_FILE_PHONY
	FILE_REWIND  = C.SOX_FILE_REWIND
)

Variables

This section is empty.

Functions

func FormatInit

func FormatInit() bool

FormatInit finds and loads format handler plugins. Returns true if successful.

func FormatQuit

func FormatQuit()

FormatQuit unloads the format handler plugins.

func FormatSupportsEncoding

func FormatSupportsEncoding(path string, encoding *EncodingInfo) bool

FormatSupportsEncoding returns true if the format handler for the specified file type supports the specified encoding.

func FormatSupportsEncoding2

func FormatSupportsEncoding2(path, filetype string, encoding *EncodingInfo) bool

FormatSupportsEncoding2 returns true if the format handler for the specified file type supports the specified encoding.

func Init

func Init() bool

Init initializes the libsox effects library.

func Precision

func Precision(encoding int, bits_per_sample uint) uint

Precision: Given an encoding (for example, SIGN2) and the encoded bits_per_sample (for example, 16), returns the number of useful bits per sample in the decoded data (for example, 16), or returns 0 to indicate that the value returned by the format handler should be used instead of a pre-determined precision. @returns the number of useful bits per sample in the decoded data (for example 16), or returns 0 to indicate that the value returned by the format handler should be used instead of a pre-determined precision.

func Quit

func Quit() bool

Quit closes the effects library and unloads the format handler plugins.

func SampleToFloat64

func SampleToFloat64(d Sample) float64

SampleToFloat64 converts sox.Sample to a float64

func SampleToInt32

func SampleToInt32(d Sample) int32

SampleToInt32 converts sox.Sample to a signed 32-bit integer

func SampleToUInt32

func SampleToUInt32(d Sample) uint32

SampleToUInt32 converts sox.Sample to an unsigned 32-bit integer

func StrError

func StrError(errno int) string

func Version

func Version() string

Version returns the version number string of libSoX, for example, "14.4.0".

Types

type Comments

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

Comments holds file's metadata, access via sox_*_comments functions.

func (*Comments) Append

func (c *Comments) Append(item string)

Append adds an "id=value" item to the metadata block.

func (*Comments) AppendN

func (c *Comments) AppendN(item string)

AppendN adds a newline-delimited list of "id=value" items to the metadata block.

func (*Comments) Find

func (c *Comments) Find(id string) interface{}

Find returns value if "id=value" is found, else nil

func (*Comments) Num

func (c *Comments) Num() int

Num returns the number of items in the metadata block.

type Effect

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

Effect holds effect information.

func CreateEffect

func CreateEffect(handler *EffectHandler) *Effect

CreateEffect creates an effect using the given handler.

func (*Effect) Options

func (e *Effect) Options(args ...interface{}) int

Options applies the given command-line options to the effect.

func (*Effect) Release

func (e *Effect) Release()

Release the memory held by the effect.

func (*Effect) Stop

func (e *Effect) Stop()

Stop an effect (calls stop on each of its flows).

type EffectHandler

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

EffectHandler holds effect handler information.

func FindEffect

func FindEffect(name string) *EffectHandler

FindEffect finds the effect handler with the given name.

func GetEffectHandlers

func GetEffectHandlers() (handlers []EffectHandler)

GetEffectHandlers returns an array containing the known effect handlers.

func (*EffectHandler) Flags

func (h *EffectHandler) Flags() uint

Flags returns the combination of effect flags

func (*EffectHandler) Name

func (h *EffectHandler) Name() string

Name returns the effect name

func (*EffectHandler) Usage

func (h *EffectHandler) Usage() string

Usage returns a short explanation of the parameters accepted by the effect

type EffectsChain

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

EffectsChain holds a chain of effects to be applied to a stream.

func CreateEffectsChain

func CreateEffectsChain(in *EncodingInfo, out *EncodingInfo) *EffectsChain

CreateEffectsChain initializes an effects chain. Returned handle must be closed with .Release().

func (*EffectsChain) Add

func (c *EffectsChain) Add(effect *Effect, in, out *SignalInfo) bool

Add the given effect to the effects chain. Returns true if successful.

func (*EffectsChain) Clips

func (c *EffectsChain) Clips() uint64

Clips returns the number of clips that occurred while running an effects chain.

func (*EffectsChain) DeleteAll

func (c *EffectsChain) DeleteAll()

DeleteAll shuts down and deletes all effects in the chain.

func (*EffectsChain) DeleteLast

func (c *EffectsChain) DeleteLast()

DeleteLast shuts down and deletes the last effect in the chain.

func (*EffectsChain) Flow

func (c *EffectsChain) Flow() bool

Flow runs the effects chain, returns true if successful.

func (*EffectsChain) FlowCallback

func (c *EffectsChain) FlowCallback(fn func(all_done bool) int) bool

func (*EffectsChain) PopLast

func (c *EffectsChain) PopLast() *Effect

PopLast removes and returns an effect from the end of the chain.

func (*EffectsChain) PushLast

func (c *EffectsChain) PushLast(effect *Effect)

PushLast adds an already-initialized effect to the end of the chain.

func (*EffectsChain) Release

func (c *EffectsChain) Release()

Release the memory used by the effects chain.

type EffectsGlobals

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

EffectsGlobals holds global parameters for effects.

func GetEffectsGlobals

func GetEffectsGlobals() *EffectsGlobals

GetEffectsGlobals returns global parameters for effects.

type EncodingInfo

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

EncodingInfo holds encoding parameters.

func NewEncodingInfo

func NewEncodingInfo(encoding int, bitsPerSample uint, compression float64, oppositeEndian bool) *EncodingInfo

type EncodingsInfo

type EncodingsInfo struct {
	Flags      int // lossy once, lossy twice or lossless
	Name, Desc string
}

EncodingsInfo holds basic information about an encoding.

func GetEncodingsInfo

func GetEncodingsInfo() (info []EncodingsInfo)

GetEncodingsInfo returns an array of available encodings.

type Format

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

Format holds data passed to/from the format handler

func OpenMemRead

func OpenMemRead(buffer interface{}) *Format

OpenMemRead opens a decoding session for a memory buffer. Returned handle must be closed with (*Format).Release(). Returns the handle for the new session, or nil on failure.

func OpenMemRead0

func OpenMemRead0(buffer interface{}, signal *SignalInfo, encoding *EncodingInfo, filetype interface{}) *Format

OpenMemRead opens a decoding session for a memory buffer. accepting SignalInfo, EncodingInfo and file type parameters. Returned handle must be closed with (*Format).Release(). Returns the handle for the new session, or nil on failure.

func OpenMemWrite

func OpenMemWrite(buffer []byte, signal *SignalInfo, encoding *EncodingInfo, filetype interface{}) *Format

OpenMemWrite opens an encoding session for a memory buffer. Returned handle must be closed with .Release().

func OpenMemstreamWrite

func OpenMemstreamWrite(memstream *Memstream, signal *SignalInfo, encoding *EncodingInfo, filetype interface{}) *Format

OpenMemstreamWrite opens an encoding session for a memstream buffer. Returned handle must be closed with .Release()

func OpenRead

func OpenRead(path string) *Format

OpenRead opens a decoding session for a file. Returned handle must be closed with (*Format).Release(). Returns the handle for the new session, or nil on failure.

func OpenRead0

func OpenRead0(path string, signal *SignalInfo, encoding *EncodingInfo, filetype interface{}) *Format

OpenRead0 opens a decoding session for a file, accepting SignalInfo, EncodingInfo and file type parameters. Returned handle must be closed with (*Format).Release(). Returns the handle for the new session, or nil on failure.

func OpenWrite

func OpenWrite(path string, signal *SignalInfo, encoding *EncodingInfo, filetype interface{}) *Format

OpenWrite opens an encoding session for a file. Returned handle must be closed with .Release().

func (*Format) Comments

func (f *Format) Comments() *Comments

Comments returns out-of-band metadata

func (*Format) DeleteComments

func (f *Format) DeleteComments()

DeleteComments deletes all out-of-band metadata

func (*Format) Encoding

func (f *Format) Encoding() *EncodingInfo

Encoding specifications for reader (decoder) or writer (encoder):

encoding (sample format), bits per sample, compression rate, endianness.
Should be filled in by startread. Values specified should be used
by startwrite when it is configuring the encoding parameters.

func (*Format) Filename

func (f *Format) Filename() string

Filename.

func (*Format) Read

func (f *Format) Read(buffer []Sample, num uint) int64

Read reads samples from a decoding session into a sample buffer.

func (*Format) Release

func (f *Format) Release()

Release closes an encoding or decoding session.

func (*Format) Seek

func (f *Format) Seek(offset uint64) bool

Seek sets the location at which next samples will be decoded. Returns true if successful.

func (*Format) Seekable

func (f *Format) Seekable() bool

Seekable returns true if seek can be used on this file.

func (*Format) Signal

func (f *Format) Signal() *SignalInfo

Signal specifications for reader (decoder) or writer (encoder): sample rate, number of channels, precision, length, headroom multiplier. Any info specified by the user is here on entry to startread or startwrite. Info will be SOX_UNSPEC if the user provided no info. At exit from startread, should be completely filled in, using either data from the file's headers (if available) or whatever the format is guessing/assuming (if header data is not available). At exit from startwrite, should be completely filled in, using either the data that was specified, or values chosen by the format based on the format's defaults or capabilities.

func (*Format) Type

func (f *Format) Type() string

Type of file, as determined by header inspection or libmagic.

func (*Format) Write

func (f *Format) Write(buffer []Sample, num uint) int64

Write writes samples to an encoding session from a sample buffer.

type FormatHandler

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

FormatHandler structure defined by each format.

func FindFormat

func FindFormat(name string, ignore_devices bool) *FormatHandler

FindFormat finds a format handler by name.

type Memstream

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

Memstream is a holder for memory buffer information filled in by OpenMemstreamWrite. It can be passed directly to OpenMemRead().

func NewMemstream

func NewMemstream() *Memstream

NewMemstream creates a new memory buffer holder.

func (*Memstream) Bytes

func (m *Memstream) Bytes() []byte

Bytes returns a copy of the written memory buffer as a Go byte array.

func (*Memstream) Release

func (m *Memstream) Release()

Release the memstream and free the allocated memory

type Sample

type Sample int32

Sample is the native SoX audio sample type (int32)

type SignalInfo

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

SignalInfo holds signal parameters; members should be set to SOX_UNSPEC (= 0) if unknown.

func NewSignalInfo

func NewSignalInfo(rate float64, channels, precision uint, length uint64, mult *float64) *SignalInfo

func (*SignalInfo) Channels

func (s *SignalInfo) Channels() uint

Channels = number of sound channels, 0 if unknown

func (*SignalInfo) Copy

func (s *SignalInfo) Copy() *SignalInfo

Returns a copy of the signalinfo

func (*SignalInfo) Length

func (s *SignalInfo) Length() uint64

Length = samples * chans in file, 0 if unknown, -1 if unspecified

func (*SignalInfo) Mult

func (s *SignalInfo) Mult() (float64, bool)

Mult = Effects headroom multiplier; (value, set/not set)

func (*SignalInfo) Precision

func (s *SignalInfo) Precision() uint

Precision = bits per sample, 0 if unknown

func (*SignalInfo) Rate

func (s *SignalInfo) Rate() float64

Rate = samples per second, 0 if unknown

Directories

Path Synopsis
A simple example of using SoX libraries A simple example of using SoX libraries A simple example of using SoX libraries A simple example of using SoX libraries Simple example of using SoX libraries.
A simple example of using SoX libraries A simple example of using SoX libraries A simple example of using SoX libraries A simple example of using SoX libraries Simple example of using SoX libraries.

Jump to

Keyboard shortcuts

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