Documentation
¶
Index ¶
- type Context
- type Format
- type NewContextOptions
- type Player
- func (p *Player) BufferedSize() int
- func (p *Player) Close() error
- func (p *Player) Err() error
- func (p *Player) IsPlaying() bool
- func (p *Player) Pause()
- func (p *Player) Play()
- func (p *Player) Reset()deprecated
- func (p *Player) Seek(offset int64, whence int) (int64, error)
- func (p *Player) SetBufferSize(bufferSize int)
- func (p *Player) SetVolume(volume float64)
- func (p *Player) Volume() float64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context is the main object in Oto. It interacts with the audio drivers.
To play sound with Oto, first create a context. Then use the context to create an arbitrary number of players. Then use the players to play sound.
Creating multiple contexts is NOT supported.
func NewContext ¶
func NewContext(options *NewContextOptions) (*Context, chan struct{}, error)
NewContext creates a new context with given options. A context creates and holds ready-to-use Player objects. NewContext returns a context, a channel that is closed when the context is ready, and an error if it exists.
Creating multiple contexts is NOT supported.
func (*Context) NewPlayer ¶
NewPlayer creates a new, ready-to-use Player belonging to the Context. It is safe to create multiple players.
The format of r is as follows:
[data] = [sample 1] [sample 2] [sample 3] ... [sample *] = [channel 1] [channel 2] ... [channel *] = [byte 1] [byte 2] ...
Byte ordering is little endian.
A player has some amount of an underlying buffer. Read data from r is queued to the player's underlying buffer. The underlying buffer is consumed by its playing. Then, r's position and the current playing position don't necessarily match. If you want to clear the underlying buffer for some reasons e.g., you want to seek the position of r, call the player's Reset function.
You cannot share r by multiple players.
The returned player implements Player, BufferSizeSetter, and io.Seeker. You can modify the buffer size of a player by the SetBufferSize function. A small buffer size is useful if you want to play a real-time PCM for example. Note that the audio quality might be affected if you modify the buffer size.
If r does not implement io.Seeker, the returned player's Seek returns an error.
NewPlayer is concurrent-safe.
All the functions of a Player returned by NewPlayer are concurrent-safe.
type NewContextOptions ¶
type NewContextOptions struct { // SampleRate specifies the number of samples that should be played during one second. // Usual numbers are 44100 or 48000. One context has only one sample rate. You cannot play multiple audio // sources with different sample rates at the same time. SampleRate int // ChannelCount specifies the number of channels. One channel is mono playback. Two // channels are stereo playback. No other values are supported. ChannelCount int // Format specifies the format of sources. Format Format // BufferSize specifies a buffer size in the underlying device. // // If 0 is specified, the driver's default buffer size is used. // Set BufferSize to adjust the buffer size if you want to adjust latency or reduce noises. // Too big buffer size can increase the latency time. // On the other hand, too small buffer size can cause glitch noises due to buffer shortage. BufferSize time.Duration // Device specifies the device name. Device string }
NewContextOptions represents options for NewContext.
type Player ¶
type Player struct {
// contains filtered or unexported fields
}
Player is a PCM (pulse-code modulation) audio player.
func (*Player) BufferedSize ¶
BufferedSize returns the byte size of the buffer data that is not sent to the audio hardware yet.
func (*Player) Seek ¶
Seek implements io.Seeker.
Seek returns an error when the underlying source doesn't implement io.Seeker.
func (*Player) SetBufferSize ¶
SetBufferSize sets the buffer size. If 0 is specified, the default buffer size is used.