dca package - github.com/cheezecakee/dca - Go Packages

dca

package module
v0.0.0-...-f89cad9 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2024 License: BSD-3-Clause Imports: 13 Imported by: 0

README

dca Go report Build Status

dca is a audio file format that uses opus packets and json metadata.

This package is a forked version of jogrammings's dca, it implements an encoder and a helper streamer for dca v0.

It works with the newest FFMPEG version.

Docs on GoDoc

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBadFrame = errors.New("Bad Frame")

ErrBadFrame

View Source
var ErrNegativeFrameSize = errors.New("Frame size is negative, possibly corrupted.")
View Source
var ErrVoiceConnClosed = errors.New("Voice connection closed")
View Source
var Logger *log.Logger
View Source
var StdEncodeOptions = &EncodeOptions{
	FrameRate:        48000,
	FrameDuration:    20,
	Bitrate:          64,
	CompressionLevel: 10,
	PacketLoss:       1,
	BufferedFrames:   100,
	VariableBitrate:  true,
	StartTime:        0,
}

Functions

func DecodeFrame

func DecodeFrame(r io.Reader) (frame []byte, err error)

DecodeFrame decodes a dca frame from an io.Reader and returns the raw opus audio ready to be sent to discord

Types

type AudioApplication

type AudioApplication string

AudioApplication is an application profile for opus encoding

type EncodeOptions

type EncodeOptions struct {
	FrameRate        int  // audio sampling rate (ex 48000)
	FrameDuration    int  // audio frame duration can be 20, 40, or 60 (ms)
	Bitrate          int  // audio encoding bitrate in kb/s can be 8 - 128
	PacketLoss       int  // expected packet loss percentage
	CompressionLevel int  // Compression level, higher is better qualiy but slower encoding (0 - 10)
	BufferedFrames   int  // How big the frame buffer should be
	Threads          int  // Number of threads to use, 0 for auto
	VariableBitrate  bool // Whether vbr is used or not (variable bitrate)
	StartTime        int  // Start Time of the input stream in seconds
}

EncodeOptions is a set of options for encoding dca

type EncodeSession

type EncodeSession struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func EncodeFile

func EncodeFile(path string, options *EncodeOptions) (session *EncodeSession, err error)

EncodeFile encodes the file/url/other in path

func (*EncodeSession) Cleanup

func (e *EncodeSession) Cleanup()

Cleanup cleans up the encoding session, throwring away all unread frames and stopping ffmpeg ensuring that no ffmpeg processes starts piling up on your system You should always call this after it's done

func (*EncodeSession) Error

func (e *EncodeSession) Error() error

Error returns any error that occured during the encoding process

func (*EncodeSession) FrameDuration

func (e *EncodeSession) FrameDuration() time.Duration

FrameDuration implements OpusReader, retruning the duration of each frame

func (*EncodeSession) Options

func (e *EncodeSession) Options() *EncodeOptions

Options returns the options used

func (*EncodeSession) OpusFrame

func (e *EncodeSession) OpusFrame() (frame []byte, err error)

OpusFrame implements OpusReader, returning the next opus frame

func (*EncodeSession) Read

func (e *EncodeSession) Read(p []byte) (n int, err error)

Read implements io.Reader, n == len(p) if err == nil, otherwise n contains the number bytes read before an error occured

func (*EncodeSession) ReadFrame

func (e *EncodeSession) ReadFrame() (frame []byte, err error)

ReadFrame blocks until a frame is read or there are no more frames Note: If rawoutput is not set, the first frame will be a metadata frame

func (*EncodeSession) Running

func (e *EncodeSession) Running() (running bool)

Running returns true if running

func (*EncodeSession) Stop

func (e *EncodeSession) Stop() error

Stop stops the encoding session

func (*EncodeSession) Truncate

func (e *EncodeSession) Truncate()

Truncate is deprecated, use Cleanup instead this will be removed in a future version

type Frame

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

type OpusReader

type OpusReader interface {
	OpusFrame() (frame []byte, err error)
	FrameDuration() time.Duration
}

type StreamingSession

type StreamingSession struct {
	sync.Mutex
	// contains filtered or unexported fields
}

StreamingSession provides an easy way to directly transmit opus audio to discord from an encode session.

func NewStream

func NewStream(source OpusReader, vc *discordgo.VoiceConnection, done chan error) *StreamingSession

Creates a new stream from an Opusreader.

func (*StreamingSession) Finished

func (s *StreamingSession) Finished() (bool, error)

Finished returns wether the stream finished or not, and any error that caused it to stop

func (*StreamingSession) Paused

func (s *StreamingSession) Paused() bool

Paused returns wether the stream is paused or not

func (*StreamingSession) PlaybackPosition

func (s *StreamingSession) PlaybackPosition() time.Duration

PlaybackPosition returns the the duration of content we have transmitted so far

func (*StreamingSession) SetPaused

func (s *StreamingSession) SetPaused(paused bool)

SetPaused provides pause/unpause functionality

Jump to

Keyboard shortcuts

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