disgoplayer

package module
v0.0.0-...-33aa5e2 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2022 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Go Reference Go Report Go Version License DisGoPlayer Version Support Discord

discord gopher

DisGoPlayer

The disgoplayer module provides opus/pcm/mp3 audio encoding/decoding/resampling as C bindings based on the libopus, libsamplerate and mpg123 libraries. 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/disgoplayer
Usage

// TODO

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OpusProviderClosed = errors.New("opus provider closed")

OpusProviderClosed indicates that the voice.OpusFrameProvider was closed.

Functions

func NewErrorHandlerOpusFrameProvider

func NewErrorHandlerOpusFrameProvider(opusFrameProvider voice.OpusFrameProvider, errorHandleFunc ErrorHandleFunc) voice.OpusFrameProvider

NewErrorHandlerOpusFrameProvider creates a new voice.OpusFrameProvider which intercepts errors returned by the given voice.OpusFrameProvider and calls the given ErrorHandleFunc. This can be used to intercept io.EOF or other errors and stop the playback or start a new track.

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.

func NewPauseableOpusFrameProvider

func NewPauseableOpusFrameProvider(provider voice.OpusFrameProvider, pausedFunc func() bool) voice.OpusFrameProvider

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 ErrorHandleFunc

type ErrorHandleFunc func(err error)

ErrorHandleFunc is a function which is called when an error is returned by the given voice.OpusFrameProvider.

type Listener

type Listener interface {
	OnPause(player Player)
	OnResume(player Player)
	OnStart(player Player)
	OnEnd(player Player)
	OnError(player Player, err error)
	OnClose(player Player)
}

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 NewPCMFrameChannelConverterCombinedReceiver

func NewPCMFrameChannelConverterCombinedReceiver(receiver PCMCombinedFrameReceiver, rate int, inputChannels int, outputChannels int) 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)

NewCustomMP3PCMFrameProvider returns a PCMFrameProvider that reads mp3 and converts it into pcm frames. You can specify the rate and channels of the output PCM frames.

func NewCustomPCMStreamProvider

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

NewCustomPCMStreamProvider creates a new PCMFrameProvider which reads PCM frames from the given io.Reader. You can specify the sample rate and number of channels.

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 NewPCMFrameChannelConverterProvider

func NewPCMFrameChannelConverterProvider(Provider PCMFrameProvider, rate int, inputChannels int, outputChannels int) PCMFrameProvider

func NewPCMFrameResamplerProvider

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

NewPCMFrameResamplerProvider creates a PCMFrameProvider that resamples the PCM frames to the specified sample rate. If the resampler is nil, it will be created with samplerate.ConverterTypeSincBestQuality. The input sample rate is the sample rate of the PCM frames provided by the provider. The output sample rate is the sample rate of the PCM frames returned by the provider. The channels are the number of channels of the PCM frames provided by the provider.

func NewPCMStreamProvider

func NewPCMStreamProvider(r io.Reader) PCMFrameProvider

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

func NewPCMVolumeFrameProvider

func NewPCMVolumeFrameProvider(pcmFrameProvider PCMFrameProvider, volumeProvider func() float32) PCMFrameProvider

func NewPauseablePCMFrameProvider

func NewPauseablePCMFrameProvider(provider PCMFrameProvider, pauseProvider func() bool) PCMFrameProvider

func NewVariablePCMFrameProvider

func NewVariablePCMFrameProvider(providerFunc func() 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 NewPCMFrameChannelConverterReceiver

func NewPCMFrameChannelConverterReceiver(receiver PCMFrameReceiver, rate int, inputChannels int, outputChannels int) PCMFrameReceiver

func NewPCMFrameResamplerReceiver

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

NewPCMFrameResamplerReceiver creates a PCMFrameReceiver that resamples the PCM frames to the specified sample rate. If the resampler is nil, it will be created with samplerate.ConverterTypeSincBestQuality. The input sample rate is the sample rate of the PCM frames provided by the receiver. The output sample rate is the sample rate of the PCM frames returned by the receiver. The channels are the number of channels of the PCM frames provided by the receiver.

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.

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.

type Player

type Player interface {
	voice.OpusFrameProvider

	Volume() float32
	SetVolume(volume float32)
	Paused() bool
	SetPaused(paused bool)
}

func NewPlayer

func NewPlayer(providerFunc func() PCMFrameProvider, listeners ...Listener) (Player, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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