audio

package
v0.0.0-...-fd00b2c Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const MP3EncoderDelay = time.Millisecond * 1000.0 / 44100.0 * 576.0

Variables

View Source
var ErrBufferFull = errors.New("buffer full")

ErrBufferFull is returned when using MP3Buffer.SetCap and a Write exceeding said cap occurs.

Functions

func ProbeDuration

func ProbeDuration(ctx context.Context, filename string) (time.Duration, error)

ProbeDuration attempts to call ffprobe on the file given and returns the duration as returned by it. Requires ffprobe findable in the PATH.

func Spectrum

func Spectrum(ctx context.Context, fs afero.Fs, filename string) (string, error)

Types

type AudioFormat

type AudioFormat struct {
	ChannelCount   int
	BytesPerSample int
	SampleRate     int
}

type Buffer

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

func NewBuffer

func NewBuffer(initialSize int) *Buffer

func (*Buffer) Close

func (b *Buffer) Close() error

Close closes the buffer, any writes will return an error and any readers that are blocked will receive an EOF

func (*Buffer) Error

func (b *Buffer) Error() (err error)

Error returns error set previously or nil

func (*Buffer) Reader

func (b *Buffer) Reader() *BufferReader

Reader returns a reader over the data contained in the buffer

func (*Buffer) SetError

func (b *Buffer) SetError(err error)

SetError sets an error that is returned by all Readers when Read is called. An error set this way does not wait for readers to finish reading data. After setting the error, Close is called.

Passing in a nil error is a no-op

func (*Buffer) Wait

func (b *Buffer) Wait() error

Wait waits until Close is called and returns with any error that occured.

func (*Buffer) Write

func (b *Buffer) Write(p []byte) (n int, err error)

type BufferReader

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

BufferReader is an io.Reader on top of a Buffer, multiple readers per Buffer can be created

func (*BufferReader) Read

func (br *BufferReader) Read(p []byte) (n int, err error)

type DecodeError

type DecodeError struct {
	Err       error
	ExtraInfo string
}

DecodeError is returned when a non-zero exit code is returned by the decoder

The ExtraInfo field contains stderr of the decoder process.

func (*DecodeError) Error

func (e *DecodeError) Error() string

type FormatInfo

type FormatInfo struct {
	BitRate        string          `json:"bit_rate"`
	Duration       string          `json:"duration"`
	Filename       string          `json:"filename"`
	FormatLongName string          `json:"format_long_name"`
	FormatName     string          `json:"format_name"`
	NbStreams      int             `json:"nb_streams"`
	Size           string          `json:"size"`
	StartTime      string          `json:"start_time"`
	Tags           *FormatTagsInfo `json:"tags"`
}

type FormatTagsInfo

type FormatTagsInfo struct {
	Anime         string `json:"ANIME"`
	Compilation   string `json:"COMPILATION,omitempty"`
	Originaldate  string `json:"ORIGINALDATE,omitempty"`
	R128AlbumGain string `json:"R128_ALBUM_GAIN,omitempty"`
	R128TrackGain string `json:"R128_TRACK_GAIN,omitempty"`
	Tbpm          string `json:"TBPM,omitempty"`
	Year          string `json:"YEAR,omitempty"`
	Album         string `json:"album"`
	AlbumArtist   string `json:"album_artist,omitempty"`
	Artist        string `json:"artist"`
	Date          string `json:"date,omitempty"`
	Disc          string `json:"disc,omitempty"`
	Title         string `json:"title"`
	Track         string `json:"track,omitempty"`
}

type Info

type Info struct {
	Duration   time.Duration
	FormatName string
	Title      string
	Artist     string
	Album      string
	Bitrate    int
}

func ProbeText

func ProbeText(ctx context.Context, filename string) (*Info, error)

type LAME

type LAME struct {
	AudioFormat
	// contains filtered or unexported fields
}

func NewLAME

func NewLAME(opt AudioFormat) (*LAME, error)

func (*LAME) Close

func (l *LAME) Close() error

Close frees C resources associated with this instance

func (*LAME) Encode

func (l *LAME) Encode(in []byte) (out []byte, err error)

Encode encodes in and returns available mp3 data, out is only valid until the next call to Encode

func (*LAME) Flush

func (l *LAME) Flush() []byte

Flush flushes internal buffers and returns any mp3 data found

type MP3Buffer

type MP3Buffer struct {
	*Buffer
	// contains filtered or unexported fields
}

MP3Buffer is a Buffer that is mp3-aware

func NewMP3Buffer

func NewMP3Buffer() *MP3Buffer

NewMP3Buffer returns a Buffer that is mp3-aware to calculate playback duration and frame validation.

func (*MP3Buffer) BufferBytes

func (mb *MP3Buffer) BufferBytes() []byte

BufferBytes returns unwritten bytes in the internal buffer. return value is only valid until next Write call.

func (*MP3Buffer) Length

func (mb *MP3Buffer) Length() time.Duration

Length returns the playback duration of the contents of the buffer. i.e. calling Write increases the duration

func (*MP3Buffer) Reader

func (mb *MP3Buffer) Reader() *MP3BufferReader

Reader returns a reader over the buffer

func (*MP3Buffer) SetCap

func (mb *MP3Buffer) SetCap(dur time.Duration)

SetCap sets a length cap, this means any writes past this cap will fail with a BufferFull error. Short-writes can occur when using SetCap.

func (*MP3Buffer) Write

func (mb *MP3Buffer) Write(p []byte) (n int, err error)

type MP3BufferReader

type MP3BufferReader struct {
	*BufferReader
	// contains filtered or unexported fields
}

func (*MP3BufferReader) Length

func (mbr *MP3BufferReader) Length() time.Duration

Length returns the playback duration of the contents of the buffer. i.e. calling Read lowers the duration of the buffer.

func (*MP3BufferReader) Progress

func (mbr *MP3BufferReader) Progress() time.Duration

func (*MP3BufferReader) Read

func (mbr *MP3BufferReader) Read(p []byte) (n int, err error)

func (*MP3BufferReader) Sleep

func (mbr *MP3BufferReader) Sleep()

type PCMBuffer

type PCMBuffer struct {
	AudioFormat

	*Buffer
	// contains filtered or unexported fields
}

PCMBuffer is a pcm-aware Buffer

func DecodeFile

func DecodeFile(path string) (*PCMBuffer, error)

DecodeFile decodes the audio filepath given and returns a PCMBuffer

func DecodeFileGain

func DecodeFileGain(path string) (*PCMBuffer, error)

func NewPCMBuffer

func NewPCMBuffer(f AudioFormat) *PCMBuffer

NewPCMBuffer returns a new PCMBuffer with the Format given.

func (*PCMBuffer) Length

func (pb *PCMBuffer) Length() time.Duration

Length returns the playback length of the data in the buffer

func (*PCMBuffer) ReadFrom

func (pb *PCMBuffer) ReadFrom(src io.Reader) (n int64, err error)

ReadFrom implements io.ReaderFrom

func (*PCMBuffer) Reader

func (pb *PCMBuffer) Reader() *PCMBufferReader

Reader returns a reader over the buffer

func (*PCMBuffer) Write

func (pb *PCMBuffer) Write(p []byte) (n int, err error)

Write implements io.Writer

type PCMBufferReader

type PCMBufferReader struct {
	*BufferReader
	// contains filtered or unexported fields
}

PCMBufferReader is a buffer aware of its contents

func (*PCMBufferReader) Length

func (pbr *PCMBufferReader) Length() time.Duration

Length returns the playback duration of the contents of the buffer. i.e. calling Read lowers the duration of the buffer.

func (*PCMBufferReader) Progress

func (pbr *PCMBufferReader) Progress() time.Duration

type ProbeInfo

type ProbeInfo struct {
	Format  *FormatInfo   `json:"format,omitempty"`
	Streams []StreamsInfo `json:"streams,omitempty"`
}

func Probe

func Probe(ctx context.Context, filename string) (*ProbeInfo, error)

type StreamsInfo

type StreamsInfo struct {
	AvgFrameRate       string          `json:"avg_frame_rate"`
	BitRate            string          `json:"bit_rate,omitempty"`
	BitsPerSample      int             `json:"bits_per_sample,omitempty"`
	Channels           int             `json:"channels,omitempty"`
	CodecLongName      string          `json:"codec_long_name"`
	CodecName          string          `json:"codec_name"`
	CodecTag           string          `json:"codec_tag"`
	CodecTagString     string          `json:"codec_tag_string"`
	CodecTimeBase      string          `json:"codec_time_base"`
	CodecType          string          `json:"codec_type"`
	DisplayAspectRatio string          `json:"display_aspect_ratio,omitempty"`
	Duration           string          `json:"duration"`
	DurationTs         int             `json:"duration_ts"`
	HasBFrames         int             `json:"has_b_frames,omitempty"`
	Height             int             `json:"height,omitempty"`
	Index              int             `json:"index"`
	Level              int             `json:"level,omitempty"`
	PixFmt             string          `json:"pix_fmt,omitempty"`
	RFrameRate         string          `json:"r_frame_rate"`
	SampleAspectRatio  string          `json:"sample_aspect_ratio,omitempty"`
	SampleFmt          string          `json:"sample_fmt,omitempty"`
	SampleRate         string          `json:"sample_rate,omitempty"`
	StartPts           int             `json:"start_pts"`
	StartTime          string          `json:"start_time"`
	Tags               *FormatTagsInfo `json:"tags,omitempty"`
	TimeBase           string          `json:"time_base"`
	Width              int             `json:"width,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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