playback

package
v0.0.0-...-8876515 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2018 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package playback contains functions and types to stream and play audio

Index

Constants

This section is empty.

Variables

View Source
var AudioDir string

AudioDir is the directory containing the audio file

Functions

func CombineSamples

func CombineSamples(low []float64, high []float64) [][2]float64

CombineSamples combines to []float64 to one [][2]float64, such that low[i] == returned[i][0] and high[i] == returned[i][1]

func Init

func Init(sampleRate int) error

Init prepares a player for playback with the given sample rate

func QueueChunk

func QueueChunk(startTime int64, chunkID int64, samples [][2]float64)

QueueChunk queue a chunk for playback

func SetVolume

func SetVolume(v float64)

SetVolume sets the playback volume of the player

Types

type Playlist

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

Playlist is a array of songs, which can then be streamed. After reaching the end of the playlist, playback will resume at the start.

func NewPlaylist

func NewPlaylist(bufferSize int, songs []string, nanBreakSize int) *Playlist

NewPlaylist create a new playlist with the given buffer size and songs in it, which inserts nanBreakSize nan-samples between songs, which players use to realign playback.

func (*Playlist) AddSong

func (pl *Playlist) AddSong(song string)

AddSong adds a song at the end of the playlist.

func (*Playlist) CurrentSong

func (pl *Playlist) CurrentSong() string

CurrentSong returns the song currently being played

func (*Playlist) Fill

func (pl *Playlist) Fill(low []float64, high []float64) uint64

Fill reads the samples from the internal buffer and fills low and high with them. low and high must have the same length. returns the sampleIndex of the first read

func (*Playlist) InsertSong

func (pl *Playlist) InsertSong(song string, index int)

InsertSong inserts a song into the playlist. The index is clipped to the bounds of the playlist.

func (*Playlist) Playing

func (pl *Playlist) Playing() bool

Playing returns true if the playlist is currently playing audio.

func (*Playlist) Pos

func (pl *Playlist) Pos() int

Pos returns the position of the song currently being played.

func (*Playlist) RemoveSong

func (pl *Playlist) RemoveSong(index int) string

RemoveSong remove the song at index from the playlist and returns the removed song. The index is clipped to the bounds of the playlist. If the playlist is empty, noting happens and "" is returned.

func (*Playlist) SetNewSongHandler

func (pl *Playlist) SetNewSongHandler(nsh func(startSampleIndex uint64, filename string, songLength int64))

SetNewSongHandler sets the new song handler, which is called every time the playlist begins playing a new song

func (*Playlist) SetPauseToggleHandler

func (pl *Playlist) SetPauseToggleHandler(psh func(playing bool, sample uint64))

SetPauseToggleHandler sets the pause toggle handler, which is called every time the playlist is paused/resumed

func (*Playlist) SetPlaying

func (pl *Playlist) SetPlaying(p bool)

SetPlaying can set whether or not the playlist should be playing audio.

func (*Playlist) SetPos

func (pl *Playlist) SetPos(pos int)

SetPos jumps to the song at pos.

func (*Playlist) Songs

func (pl *Playlist) Songs() []string

Songs returns all songs in the playlist.

func (*Playlist) StreamLoop

func (pl *Playlist) StreamLoop(ctx context.Context)

StreamLoop reads the samples of the song into the internal buffer. This method blocks until the passed context is canceled. It must be called once before streaming from the playlist and must not be called again before the returning after the context was canceled.

Jump to

Keyboard shortcuts

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