audio

package module
v0.0.0-...-69fa46c Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

README

audio

The audio module provides opus/pcm audio encoding/decoding as C bindings based on the libopus library. It also lets you combine multiple pcm streams into a single pcm stream. This module requires CGO to be enabled.

Getting Started

Installing
$ go get github.com/disgoorg/disgo/audio

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPCMOpusProvider

func NewPCMOpusProvider(encoder *opus.Encoder, pcmProvider PCMFrameProvider) (voice.OpusFrameProvider, error)

NewPCMOpusProvider creates a new voice.OpusFrameProvider which gets PCM frames from the given PCMFrameProvider and encodes the PCM frames into Opus frames. You can pass your own *opus.Encoder or nil to use the default Opus encoder(48000hz sample rate, 2 channels, opus.ApplicationAudio & 64kbps bitrate).

func NewPCMOpusReceiver

func NewPCMOpusReceiver(decoderCreateFunc func() (*opus.Decoder, error), pcmFrameReceiver PCMFrameReceiver, receiveUserFunc voice.ShouldReceiveUserFunc) voice.OpusFrameReceiver

NewPCMOpusReceiver creates a new voice.OpusFrameReceiver which receives Opus frames and decodes them into PCM frames. A new decoder is created for each user. You can pass your own *opus.Decoder by passing a decoderCreateFunc or nil to use the default Opus decoder(48000hz sample rate, 2 channels). You can filter users by passing a voice.ShouldReceiveUserFunc or nil to receive all users.

Types

type CombinedPCMPacket

type CombinedPCMPacket struct {
	Sequences  []uint16
	Timestamps []uint32
	SSRCs      []uint32
	PCM        []int16
}

CombinedPCMPacket is a PCMPacket which got created by combining multiple PCMPacket(s).

type PCMCombinedFrameReceiver

type PCMCombinedFrameReceiver interface {
	// ReceiveCombinedPCMFrame is called when a new CombinedPCMPacket is received.
	ReceiveCombinedPCMFrame(userIDs []snowflake.ID, packet *CombinedPCMPacket) error

	// Close is called when the PCMCombinedFrameReceiver is no longer needed. It should close any open resources.
	Close()
}

PCMCombinedFrameReceiver is an interface for receiving PCMPacket(s) from multiple users as one CombinedPCMPacket.

func NewPCMCombinedStreamReceiver

func NewPCMCombinedStreamReceiver(w io.Writer) PCMCombinedFrameReceiver

NewPCMCombinedStreamReceiver creates a new PCMCombinedFrameReceiver which writes the CombinedPCMPacket to the given io.Writer.

func NewSampleRateCombinedReceiver

func NewSampleRateCombinedReceiver(resampler *samplerate.Resampler, inputSampleRate int, outputSampleRate int, pcmFrameReceiver PCMCombinedFrameReceiver) PCMCombinedFrameReceiver

type PCMFrameProvider

type PCMFrameProvider interface {
	// ProvidePCMFrame is called to get a PCM frame.
	ProvidePCMFrame() ([]int16, error)

	// Close is called when the provider is no longer needed. It should close any open resources.
	Close()
}

PCMFrameProvider is an interface for providing PCM frames.

func NewCustomMP3PCMFrameProvider

func NewCustomMP3PCMFrameProvider(decoder *mp3.Decoder, rate int, channels int) (PCMFrameProvider, io.Writer, error)

func NewCustomPCMStreamProvider

func NewCustomPCMStreamProvider(r io.Reader, rate int, channels int) PCMFrameProvider

func NewMP3PCMFrameProvider

func NewMP3PCMFrameProvider(decoder *mp3.Decoder) (PCMFrameProvider, io.Writer, error)

NewMP3PCMFrameProvider returns a PCMFrameProvider that reads mp3 and converts it into pcm frames. Write the Mp3 data to the returned mp3Writer.

func NewPCMStreamProvider

func NewPCMStreamProvider(r io.Reader) PCMFrameProvider

NewPCMStreamProvider creates a new PCMFrameProvider which reads PCM frames from the given io.Reader.

func NewSampleRateProvider

func NewSampleRateProvider(resampler *samplerate.Resampler, inputSampleRate int, outputSampleRate int, pcmFrameProvider PCMFrameProvider) PCMFrameProvider

type PCMFrameReceiver

type PCMFrameReceiver interface {
	// ReceivePCMFrame is called when a PCM frame is received.
	ReceivePCMFrame(userID snowflake.ID, packet *PCMPacket) error

	// CleanupUser is called when a user is disconnected. This should close any resources associated with the user.
	CleanupUser(userID snowflake.ID)

	// Close is called when the receiver is no longer needed. It should close any open resources.
	Close()
}

PCMFrameReceiver is an interface for receiving PCM frames.

func NewPCMCombinerReceiver

func NewPCMCombinerReceiver(logger log.Logger, pcmCombinedFrameReceiver PCMCombinedFrameReceiver) PCMFrameReceiver

NewPCMCombinerReceiver creates a new PCMFrameReceiver which combines multiple PCMPacket(s) into a single CombinedPCMPacket. You can process the CombinedPCMPacket by passing a PCMCombinedFrameReceiver.

func NewPCMStreamReceiver

func NewPCMStreamReceiver(w io.Writer, receiveUserFunc voice.ShouldReceiveUserFunc) PCMFrameReceiver

NewPCMStreamReceiver creates a new PCMFrameReceiver which writes PCM frames to the given io.Writer. You can filter which users should be written by passing a voice.ShouldReceiveUserFunc.

func NewSampleRateReceiver

func NewSampleRateReceiver(resampler *samplerate.Resampler, inputSampleRate int, outputSampleRate int, pcmFrameReceiver PCMFrameReceiver) PCMFrameReceiver

type PCMPacket

type PCMPacket struct {
	SSRC      uint32
	Sequence  uint16
	Timestamp uint32
	PCM       []int16
}

PCMPacket is a 20ms PCM frame with a ssrc, sequence and timestamp.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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