lame

package module
v0.0.0-...-189b4ae Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2023 License: MIT Imports: 7 Imported by: 0

README

go-lame

Yet another simple wrapper of libmp3lame for golang. It focuses on converting raw PCM, and WAV files into mp3.

Examples

PCM to MP3

Assuming the sample rate of the PCM file is 44100, and the output's is the same.


func PcmToMp3(pcmFileName, mp3FileName string) {
	pcmFile, _ := os.OpenFile(pcmFileName, os.O_RDONLY, 0555)
	mp3File, _ := os.OpenFile(mp3FileName, os.O_CREATE | os.O_WRONLY | os.O_TRUNC, 0755)
	defer mp3File.Close()
	wr, err := lame.NewWriter(mp3File)
	if err != nil {
		panic("cannot create lame writer, err: " + err.Error())
	}
	io.Copy(wr, pcmFile)
	wr.Close()
}

PCM to MP3 (Customize params)

Assuming here goes some properties of the PCM file:

- SampleRate: 16000,
- Number of Channel: 1 (single),

and the output (.mp3) is expected to meet demands below:

- SampleRate: 8000
- Quality: 9 (lowest)
- Mode: Stereo (2 channels)
func PcmToMp3Customize(pcmFileName, mp3FileName string) {
	pcmFile, _ := os.OpenFile(pcmFileName, os.O_RDONLY, 0555)
	mp3File, _ := os.OpenFile(mp3FileName, os.O_CREATE | os.O_WRONLY | os.O_TRUNC, 0755)
	defer mp3File.Close()
	wr, err := lame.NewWriter(mp3File)
	if err != nil {
		panic("cannot create lame writer, err: " + err.Error())
	}
	wr.InSampleRate = 44100  // input sample rate
	wr.InNumChannels = 1     // number of channels: 1
	wr.OutMode = lame.MODE_STEREO // common, 2 channels
	wr.OutQuality = 9        // 0: highest; 9: lowest 
	wr.OutSampleRate = 8000  // output sample rate
	
	io.Copy(wr, pcmFile)
	wr.Close()
}

WAV to MP3

func WavToMp3(wavFileName, mp3FileName string) {
	// open files
	wavFile, _ := os.OpenFile(wavFileName, os.O_RDONLY, 0555)
	mp3File, _ := os.OpenFile(mp3FileName, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0755)
	defer mp3File.Close()

	// parsing wav info
	// NOTE: reader position moves even if it is not a wav file
	wavHdr, err := lame.ReadWavHeader(wavFile)
	if err != nil {
		panic("not a wav file, err=" + err.Error())
	}

	wr, _ := lame.NewWriter(mp3File)
	wr.EncodeOptions = wavHdr.ToEncodeOptions()
	io.Copy(wr, wavFile) // wavFile's pos has been changed!
	wr.Close()
}

Roadmap

  • Wrapping functions from libmp3lame
  • WavFile parsing support
  • Shortcut to using wrapped functions
  • Supporting parsing both little-endian and big-endian PCM files
  • Thorough tests
  • Supporting bit depth other than 16

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInsufficientMemory = errors.New("cannot allocate memory for Lame")
	ErrCannotInitParams   = errors.New("cannot init params, most likely invalid params, especially sample rates")
	ErrParamsNotInit      = errors.New("params not initialized")
	ErrTooSmallBuffer     = errors.New("too small buffer")
	ErrUnknown            = errors.New("unknown")
	ErrEmptyArguments     = errors.New("some arguments are empty")
	ErrInvalidSampleRate  = errors.New("invalid sample rate, supports only 8, 12, 16, 22, 32, 44.1, 48k")
)
View Source
var (
	// ChunkId is invalid
	ErrInvalidWavChunkId = errors.New("invalid wav chunk id, expected RIFF or RIFX")
	// Cannot read ChunkId at all
	ErrCannotReadChunkId = errors.New("cannot read chunkId")
	// Cannot read header at all
	ErrCannotReadHeader = errors.New("cannot read headers")
)
View Source
var ErrUnsupportedChannelNum = errors.New("only 1 and 2 channels are supported")

Functions

This section is empty.

Types

type AsmOptimizations

type AsmOptimizations int

asm_optimizations_e

const (
	AO_INVALID AsmOptimizations = iota
	AO_MMX
	AO_AMD_3DNOW
	AO_SSE
)

let us define asm optimizations

type EncodeOptions

type EncodeOptions struct {
	InBigEndian     bool // true if it is in big-endian
	InSampleRate    int  // Hz, e.g., 8000, 16000, 12800, 44100, etc.
	InBitsPerSample int  // typically 16 should be working fine. the bit count of each sample, e.g., 2Bytes/sample->16bits
	InNumChannels   int  // count of channels, for mono ones, please remain 1, and 2 if stereo

	OutSampleRate int  // Hz
	OutMode       Mode // MODE_MONO, MODE_STEREO, etc.
	OutQuality    int  // quality: 0-highest, 9-lowest
}

options for encoder

type Lame

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

Bridge towards lame_global_struct

func NewLame

func NewLame() (l *Lame, err error)

create and init a lame struct

func (*Lame) EncodeFlush

func (l *Lame) EncodeFlush() (residual []byte, err error)

* NOTE: MUST BE CALLED AFTER CONVERSION * returns the length of trailing bytes

func (*Lame) EncodeInt16

func (l *Lame) EncodeInt16(dataLeft, dataRight []int16, mp3Buf []byte) (int, error)
  • BELOW ARE <CONVERT> FUNCTIONS

encode pcm to mp3, given buffer according to LAME, there is a loose bound for the buf, len=1.25*numSamped + 7200

func (*Lame) EncodeInt16Interleaved

func (l *Lame) EncodeInt16Interleaved(data []int16, mp3Buf []byte) (int, error)

encode pcm to mp3, given buffer. same with encodeInt64, except data for left and right channels being interleaved according to LAME, there is a loose bound for the buf, len=1.25*numSamped + 7200

func (*Lame) EncodeInt32

func (l *Lame) EncodeInt32(dataLeft, dataRight []int32, mp3Buf []byte) (int, error)

func (*Lame) EncodeInt64

func (l *Lame) EncodeInt64(dataLeft, dataRight []int32, mp3Buf []byte) (int, error)

func (*Lame) GetATHlower

func (l *Lame) GetATHlower() float32

func (*Lame) GetATHonly

func (l *Lame) GetATHonly() int

func (*Lame) GetATHshort

func (l *Lame) GetATHshort() int

func (*Lame) GetATHtype

func (l *Lame) GetATHtype() int

func (*Lame) GetAllowDiffShort

func (l *Lame) GetAllowDiffShort() int

func (*Lame) GetAnalysis

func (l *Lame) GetAnalysis() int

func (*Lame) GetAthaaSensitivity

func (l *Lame) GetAthaaSensitivity() float32

func (*Lame) GetAthaaType

func (l *Lame) GetAthaaType() int

func (*Lame) GetAudiophileGain

func (l *Lame) GetAudiophileGain() int

AudiophileGain value. Multipled by 10 and rounded to the nearest.

func (*Lame) GetBWriteVbrTag

func (l *Lame) GetBWriteVbrTag() int

func (*Lame) GetBrate

func (l *Lame) GetBrate() int

func (*Lame) GetCompressionRatio

func (l *Lame) GetCompressionRatio() float32

func (*Lame) GetCopyright

func (l *Lame) GetCopyright() int

func (*Lame) GetDecodeOnTheFly

func (l *Lame) GetDecodeOnTheFly() int

func (*Lame) GetDecodeOnly

func (l *Lame) GetDecodeOnly() int

func (*Lame) GetDisableReservoir

func (l *Lame) GetDisableReservoir() int

func (*Lame) GetEmphasis

func (l *Lame) GetEmphasis() int

func (*Lame) GetEncoderDelay

func (l *Lame) GetEncoderDelay() int

encoder delay

func (*Lame) GetEncoderPadding

func (l *Lame) GetEncoderPadding() int

padding appended to the input to make sure decoder can fully decode all input. Note that this value can only be calculated during the call to lame_encoder_flush(). Before lame_encoder_flush() has been called, the value of encoder_padding = 0.

func (*Lame) GetErrorProtection

func (l *Lame) GetErrorProtection() int

func (*Lame) GetExpNspsytune

func (l *Lame) GetExpNspsytune() int

func (*Lame) GetExperimentalX

func (l *Lame) GetExperimentalX() int

compatibility

func (*Lame) GetExperimentalY

func (l *Lame) GetExperimentalY() int

func (*Lame) GetExperimentalZ

func (l *Lame) GetExperimentalZ() int

func (*Lame) GetExtension

func (l *Lame) GetExtension() int

func (*Lame) GetFindReplayGain

func (l *Lame) GetFindReplayGain() int

func (*Lame) GetForceMs

func (l *Lame) GetForceMs() int

func (*Lame) GetForceShortBlocks

func (l *Lame) GetForceShortBlocks() int

func (*Lame) GetFrameNum

func (l *Lame) GetFrameNum() int

number of frames encoded so far

func (*Lame) GetFramesize

func (l *Lame) GetFramesize() int

size of MPEG frame

func (*Lame) GetFreeFormat

func (l *Lame) GetFreeFormat() int

func (*Lame) GetHighpassfreq

func (l *Lame) GetHighpassfreq() int

func (*Lame) GetHighpasswidth

func (l *Lame) GetHighpasswidth() int

func (*Lame) GetInSampleRate

func (l *Lame) GetInSampleRate() int

get input sample rate

func (*Lame) GetInterChRatio

func (l *Lame) GetInterChRatio() float32

func (*Lame) GetLowpassfreq

func (l *Lame) GetLowpassfreq() int

func (*Lame) GetLowpasswidth

func (l *Lame) GetLowpasswidth() int

func (*Lame) GetMfSamplesToEncode

func (l *Lame) GetMfSamplesToEncode() int

number of PCM samples buffered, but not yet encoded to mp3 data.

func (*Lame) GetMode

func (l *Lame) GetMode() Mode

func (*Lame) GetMsfix

func (l *Lame) GetMsfix() float32

func (*Lame) GetNoATH

func (l *Lame) GetNoATH() int

func (*Lame) GetNoShortBlocks

func (l *Lame) GetNoShortBlocks() int

func (*Lame) GetNoclipGainChange

func (l *Lame) GetNoclipGainChange() int

Gain change required for preventing clipping.

ref: https://github.com/gypified/libmp3lame/blob/master/include/lame.h#L623

func (*Lame) GetNogapCurrentindex

func (l *Lame) GetNogapCurrentindex() int

func (*Lame) GetNogapTotal

func (l *Lame) GetNogapTotal() int

func (*Lame) GetNumChannels

func (l *Lame) GetNumChannels() int

get the number of channels

func (*Lame) GetOriginal

func (l *Lame) GetOriginal() int

func (*Lame) GetOutSampleRate

func (l *Lame) GetOutSampleRate() int

func (*Lame) GetPeakSample

func (l *Lame) GetPeakSample() float32

the peak sample

func (*Lame) GetQuality

func (l *Lame) GetQuality() int

func (*Lame) GetQuantComp

func (l *Lame) GetQuantComp() int

func (*Lame) GetQuantCompShort

func (l *Lame) GetQuantCompShort() int

func (*Lame) GetRadioGain

func (l *Lame) GetRadioGain() int

RadioGain value. Multiplied by 10 and rounded to the nearest.

func (*Lame) GetScale

func (l *Lame) GetScale() float32

func (*Lame) GetScaleRight

func (l *Lame) GetScaleRight() float32

func (*Lame) GetSizeMp3buffer

func (l *Lame) GetSizeMp3buffer() int

size (bytes) of mp3 data buffered, but not yet encoded. ref: https://github.com/gypified/libmp3lame/blob/master/include/lame.h#L594

func (*Lame) GetStrictISO

func (l *Lame) GetStrictISO() int

func (*Lame) GetTotalframes

func (l *Lame) GetTotalframes() int

lame's estimate of the total number of frames to be encoded

only valid if calling program set num_samples

func (*Lame) GetUseTemporal

func (l *Lame) GetUseTemporal() int

func (*Lame) GetVBR

func (l *Lame) GetVBR() VBRMode

func (*Lame) GetVBRHardMin

func (l *Lame) GetVBRHardMin() int

func (*Lame) GetVBRMaxBitrateKbps

func (l *Lame) GetVBRMaxBitrateKbps() int

func (*Lame) GetVBRMeanBitrateKbps

func (l *Lame) GetVBRMeanBitrateKbps() int

func (*Lame) GetVBRMinBitrateKbps

func (l *Lame) GetVBRMinBitrateKbps() int

func (*Lame) GetVBRQ

func (l *Lame) GetVBRQ() int

func (*Lame) GetVBRQuality

func (l *Lame) GetVBRQuality() float32

func (*Lame) GetVersion

func (l *Lame) GetVersion() int

mp3 version 0=MPEG-2 1=MPEG-1 (2=MPEG-2.5)

func (*Lame) InitParams

func (l *Lame) InitParams() error

* NOTE: MUST BE CALLED BEFORE CONVERSION * sets more internal configuration based on data provided above.

func (*Lame) SetATHlower

func (l *Lame) SetATHlower(ATHlower float32) error

lower ATH by this many db

func (*Lame) SetATHonly

func (l *Lame) SetATHonly(ATHonly int) error

only use ATH for masking

func (*Lame) SetATHshort

func (l *Lame) SetATHshort(ATHshort int) error

only use ATH for short blocks

func (*Lame) SetATHtype

func (l *Lame) SetATHtype(ATHtype int) error

select ATH formula

func (*Lame) SetAllowDiffShort

func (l *Lame) SetAllowDiffShort(allowDiffShort int) error

allow blocktypes to differ between channels? default: 0 for jstereo, 1 for stereo

func (*Lame) SetAnalysis

func (l *Lame) SetAnalysis(analysis int) error
  below are general control parameters
	default: 0
	set to 1 if you need LAME to ollect data for an MP3 frame analyzer

func (*Lame) SetAsmOptimizations

func (l *Lame) SetAsmOptimizations(optim AsmOptimizations, mode int) error

func (*Lame) SetAthaaSensitivity

func (l *Lame) SetAthaaSensitivity(athaaSensitivity float32) error

adjust (in dB) the point below which adaptive ATH level adjustment occurs

func (*Lame) SetAthaaType

func (l *Lame) SetAthaaType(athaaType int) error

select ATH adaptive adjustment type

func (*Lame) SetBWriteVbrTag

func (l *Lame) SetBWriteVbrTag(bWriteVbrTag int) error

1 = write a Xing VBR header frame. default = 1 this variable must have been added by a Hungarian notation Windows programmer :-)

func (*Lame) SetBrate

func (l *Lame) SetBrate(brate int) error

set one of brate compression ratio. default is compression ratio of 11.

func (*Lame) SetCompressionRatio

func (l *Lame) SetCompressionRatio(compressionRatio float32) error

func (*Lame) SetCopyright

func (l *Lame) SetCopyright(copyright int) error

*******************************************************************

  • frame params ********************************************************************** mark as copyright. default=0

func (*Lame) SetDecodeOnTheFly

func (l *Lame) SetDecodeOnTheFly(decode_on_the_fly int) error

decode on the fly. Search for the peak sample. If the ReplayGain * analysis is enabled then perform the analysis on the decoded data * stream. default = 0 (disabled) * NOTE: if this option is set the build-in decoder should not be used

func (*Lame) SetDecodeOnly

func (l *Lame) SetDecodeOnly(decodeOnly int) error

1=decode only. use lame/mpglib to convert mp3/ogg to wav. default=0

func (*Lame) SetDisableReservoir

func (l *Lame) SetDisableReservoir(disable_reservoir int) error

disable the bit reservoir. For testing only. default=0

func (*Lame) SetEmphasis

func (l *Lame) SetEmphasis(emphasis int) error

Input PCM is emphased PCM (for instance from one of the rarely

emphased CDs), it is STRONGLY not recommended to use this, because
psycho does not take it into account, and last but not least many decoders
ignore these bits

func (*Lame) SetErrorProtection

func (l *Lame) SetErrorProtection(errorProtection int) error

error_protection. Use 2 bytes from each frame for CRC checksum. default=0

func (*Lame) SetExpNspsytune

func (l *Lame) SetExpNspsytune(expNspsytune int) error

Naoki's psycho acoustic model. default=0

func (*Lame) SetExperimentalX

func (l *Lame) SetExperimentalX(experimentalX int) error

func (*Lame) SetExperimentalY

func (l *Lame) SetExperimentalY(experimentalY int) error

another experimental option. for testing only

func (*Lame) SetExperimentalZ

func (l *Lame) SetExperimentalZ(experimentalZ int) error

another experimental option. for testing only

func (*Lame) SetExtension

func (l *Lame) SetExtension(extension int) error

MP3 'private extension' bit Meaningless. default=0

func (*Lame) SetFindReplayGain

func (l *Lame) SetFindReplayGain(findReplayGain int) error

perform ReplayGain analysis? default = 0 (disabled)

func (*Lame) SetForceMs

func (l *Lame) SetForceMs(forceMs int) error

force_ms. Force M/S for all frames. For testing only. default = 0 (disabled)

func (*Lame) SetForceShortBlocks

func (l *Lame) SetForceShortBlocks(forceShortBlocks int) error

force short blocks

func (*Lame) SetFreeFormat

func (l *Lame) SetFreeFormat(freeFormat int) error

use free_format? default = 0 (disabled)

func (*Lame) SetHighpassfreq

func (l *Lame) SetHighpassfreq(highpassfreq int) error

freq in Hz to apply highpass. Default = 0 = lame chooses. -1 = disabled

func (*Lame) SetHighpasswidth

func (l *Lame) SetHighpasswidth(highpasswidth int) error

width of transition band, in Hz. Default = one polyphase filter band

func (*Lame) SetInSampleRate

func (l *Lame) SetInSampleRate(sampleRate int) error

set input sample rate

func (*Lame) SetInterChRatio

func (l *Lame) SetInterChRatio(interChRatio float32) error

use temporal masking effect (default = 1)

func (*Lame) SetLowpassfreq

func (l *Lame) SetLowpassfreq(lowpassfreq int) error

filtering... freq in Hz to apply lowpass. Default = 0 = lame chooses. -1 = disabled

func (*Lame) SetLowpasswidth

func (l *Lame) SetLowpasswidth(lowpasswidth int) error

width of transition band, in Hz. Default = one polyphase filter band

func (*Lame) SetMode

func (l *Lame) SetMode(mode Mode) error

mode = 0,1,2,3 = stereo, jstereo, dual channel (not supported), mono default: lame picks based on compression ration and input channels

func (*Lame) SetMsfix

func (l *Lame) SetMsfix(msfix float32)

void lame_set_msfix(lame_global_flags *, double);

func (*Lame) SetNoATH

func (l *Lame) SetNoATH(noATH int) error

disable ATH

func (*Lame) SetNoShortBlocks

func (l *Lame) SetNoShortBlocks(noShortBlocks int) error

disable short blocks

func (*Lame) SetNogapCurrentindex

func (l *Lame) SetNogapCurrentindex(nogapCurrentindex int) error

func (*Lame) SetNogapTotal

func (l *Lame) SetNogapTotal(nogapTotal int) error

counters for gapless encoding

func (*Lame) SetNumChannels

func (l *Lame) SetNumChannels(numChannels int) error
number of channels in input stream. default=2

set number of channels

func (*Lame) SetOriginal

func (l *Lame) SetOriginal(original int) error

mark as original. default=1

func (*Lame) SetOutSampleRate

func (l *Lame) SetOutSampleRate(outSampleRate int) error

output sample rate in Hz. default = 0, which means LAME picks best value based on the amount of compression. MPEG only allows: MPEG1 32, 44.1, 48khz MPEG2 16, 22.05, 24 MPEG2.5 8, 11.025, 12 (not used by decoding routines)

func (*Lame) SetPreset

func (l *Lame) SetPreset(preset int) error

func (*Lame) SetQuality

func (l *Lame) SetQuality(quality int) error

internal algorithm selection. True quality is determined by the bitrate but this variable will effect quality by selecting expensive or cheap algorithms. quality=0..9. 0=best (very slow). 9=worst. recommended: 2 near-best quality, not too slow

5     good quality, fast
7     ok quality, really fast

func (*Lame) SetQuantComp

func (l *Lame) SetQuantComp(quantComp int) error

select a different "best quantization" function. default=0

func (*Lame) SetQuantCompShort

func (l *Lame) SetQuantCompShort(quantCompShort int) error

func (*Lame) SetScale

func (l *Lame) SetScale(scale float32) error

scale the input by this amount before encoding. default=1 (not used by decoding routines)

func (*Lame) SetScaleLeft

func (l *Lame) SetScaleLeft(scale float32) error

scale the channel 0 (left) input by this amount before encoding. default=1 (not used by decoding routines) ref: https://github.com/gypified/libmp3lame/blob/master/include/lame.h#L206

func (*Lame) SetScaleRight

func (l *Lame) SetScaleRight(scaleRight float32) error

scale the channel 1 (right) input by this amount before encoding. default=1 (not used by decoding routines)

func (*Lame) SetStrictISO

func (l *Lame) SetStrictISO(strictISO int) error

enforce strict ISO compliance. default=0

func (*Lame) SetUseTemporal

func (l *Lame) SetUseTemporal(useTemporal int) error

use temporal masking effect (default = 1)

func (*Lame) SetVBR

func (l *Lame) SetVBR(vbr VBRMode) error

VBR stuff Types of VBR. default = VBR_OFF = CBR

func (*Lame) SetVBRHardMin

func (l *Lame) SetVBRHardMin(VBRHardMin int) error

1=strictly enforce VBR_min_bitrate. Normally it will be violated for analog silence

func (*Lame) SetVBRMaxBitrateKbps

func (l *Lame) SetVBRMaxBitrateKbps(VBRMaxBitrateKbps int) error

func (*Lame) SetVBRMeanBitrateKbps

func (l *Lame) SetVBRMeanBitrateKbps(VBRMeanBitrateKbps int) error

Ignored except for VBR=vbr_abr (ABR mode)

func (*Lame) SetVBRMinBitrateKbps

func (l *Lame) SetVBRMinBitrateKbps(VBRMinBitrateKbps int) error

func (*Lame) SetVBRQ

func (l *Lame) SetVBRQ(VBR_q int) error

VBR quality level. 0=highest 9=lowest

func (*Lame) SetVBRQuality

func (l *Lame) SetVBRQuality(VBRQuality float32) error

VBR quality level. 0=highest 9=lowest, Range [0,...,10[

type Mode

type Mode int

MPEG_mode_e

const (
	MODE_STEREO Mode = iota
	MODE_JOINT_STEREO
	MODE_DUAL_CHANNEL /* LAME doesn't supports this! */
	MODE_MONO
	MODE_NOT_SET /* Don't use this! It's used for sanity checks. */
	MODE_MAX_INDICATOR
)

let us define modes here

type VBRMode

type VBRMode int

the VBR mode vbr_mode_e

const (
	VBR_OFF VBRMode = iota
	VBR_MT
	VBR_RH
	VBR_ABR
	VBR_MTRH
	VBR_MAX_INDICATOR
	VBR_DEFAULT = VBR_MTRH
)

let us define vbr mode here

type WavHeader

type WavHeader struct {
	// RIFF Header
	ChunkId [4]byte // fixed "RIFF" or "RIFX" if the file is big-endian
	WavHeaderRemaining
}

The header of a common wav file, length=44B

func ReadWavHeader

func ReadWavHeader(reader io.Reader) (hdr *WavHeader, err error)

Try to read the wav header from the given reader returns non-nil err if error occurs NOTE: the reader's position would be permanently changed, even if the given data is corrupted

func (*WavHeader) IsBigEndian

func (hdr *WavHeader) IsBigEndian() bool

func (*WavHeader) ToEncodeOptions

func (hdr *WavHeader) ToEncodeOptions() EncodeOptions

build an encodeOptions object by wavHeader

type WavHeaderRemaining

type WavHeaderRemaining struct {
	ChunkSize int32   //  Size of the overall file - 8 bytes, in bytes (32-bit integer). Typically, you'd fill this in after creation.
	Format    [4]byte // fixed "WAVE"

	// Format Header
	SubChunk1Id   [4]byte // fixed "fmt\0"
	SubChunk1Size int32   // Length of format data as listed above
	AudioFormat   int16   // Type of format (1 is PCM) - 2 byte integer
	NumChannels   int16   // Number of Channels - 2 byte integer
	SampleRate    int32   // Sample Rate - 32 byte integer. Common values are 44100 (CD), 48000 (DAT). Sample Rate = Number of Samples per second, or Hertz.
	ByteRate      int32   // *NOT BIT RATE*, but byte rate (Sample Rate * BitsPerSample * Channels) / 8.
	BlockAlign    int16   //
	BitsPerSample int16   // Bits per sample

	// Data
	SubChunk2Id   [4]byte // Contains "data"
	SubChunk2Size int32   // Number of bytes in data. Number of samples * num_channels * sample byte size
}

type Writer

type Writer struct {
	EncodeOptions
	// contains filtered or unexported fields
}

func NewWriter

func NewWriter(output io.Writer) (*Writer, error)

create a new writer, without initializing the Lame

func (*Writer) Close

func (w *Writer) Close() error

func (*Writer) ForceUpdateParams

func (w *Writer) ForceUpdateParams() (err error)

forced to init the params inside NOT NECESSARY

func (*Writer) Write

func (w *Writer) Write(p []byte) (n int, err error)

NOT thread-safe! will check if we have lame object inside first! TODO: support 8bit/32bit! currently, we support 16bit depth only

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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