audio

package
v0.0.0-...-9174c1b Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2022 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Minimal Ogg decoder according to rfc3533 (https://www.xiph.org/ogg/doc/rfc3533.txt). Whenever 'the spec' is mentioned, it is referring to rfc3533.

Index

Constants

View Source
const (
	BufferLength    = 300 // 5min / 3.6MB
	Channels        = 1   // unfortunately, Discord doesn't seem to support stereo at the time
	BitRate         = 96000
	SampleRate      = 48000
	FrameSize       = 960                                      // 960 samples
	FrameDuration   = float64(FrameSize) / float64(SampleRate) // 20ms
	FramesPerSecond = SampleRate / FrameSize
)

Variables

View Source
var (
	ErrOggInvalidMagicNumber       = errors.New("ogg: invalid magic number")
	ErrOggInvalidChecksum          = errors.New("ogg: invalid checksum")
	ErrOggInvalidSegmentBufferSize = errors.New("ogg: WriteSegment(): invalid segment buffer size")
)
View Source
var (
	FHeaderTypeContinuation = uint8(0x1)
	FHeaderTypeBOS          = uint8(0x2) // Beginning of stream
	FHeaderTypeEOS          = uint8(0x4) // End of stream
)
View Source
var (
	ErrNotHttp = errors.New("the requested resource is not an http/https address")
)

Functions

func StreamToDiscordOpus

func StreamToDiscordOpus(ffmpegPath, input string, stdin io.Reader, seekSeconds float64, playbackSpeed float64, inetOnly bool) (audioFrameCh <-chan []byte, errCh <-chan error, killCh chan<- struct{})

Takes a file path/HTTP(S) stream URL and returns Discord audio frames through audioFrameCh. After audioFrameCh is closed, errCh can be read to get any potential error. Will cleanly kill ffmpeg if a struct{} is sent through killCh (IMPORTANT: only send the kill signal ONCE: there is a chance that this goroutine exits just before you send a kill signal; this will be absorbed by the channel buffer, but your program might get stuck if you try to send two kill signals to a dead stream).

Types

This section is empty.

Jump to

Keyboard shortcuts

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