mixer

package
v0.0.0-...-c6f5269 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2013 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package mixer provies access to the SDL2_mixer library.

Index

Constants

View Source
const (
	MAJOR_VERSION = C.SDL_MIXER_MAJOR_VERSION
	MINOR_VERSION = C.SDL_MIXER_MINOR_VERSION
	PATCHLEVEL    = C.SDL_MIXER_PATCHLEVEL
)

Variables

This section is empty.

Functions

func AllocateChannels

func AllocateChannels(numchans int) int

AllocateChannels sets the number of channels being mixed. This can be called multiple times, even with sounds playing. If numchans is less than the current number of channels, then the higher channels will be stopped, freed, and therefore not mixed any longer. It returns the number of channels allocated.

Note: If numchans is zero, AllocateChannels will free all mixing channels, however music will still play.

func CloseAudio

func CloseAudio()

CloseAudio shuts down and cleans up the mixer API. After calling this all audio is stopped, the device is closed, and the mixer functions should not be used. You may, of course use OpenAudio to start the functionality again.

Note: This function does not do anything until you have called it the same number of times that you called OpwnAudio. You may use QuerySpec to find out how many times CloseAudio needs to be called before the device is actually closed.

func ExpireChannel

func ExpireChannel(channel, ticks int) int

ExpireChannel halts playback on channel, or all channels if channel is -1, after ticks milliseconds.

ExpireChannel returns the number of channels set to expire. Whether or not they are active.

func FadeInChannel

func FadeInChannel(channel int, chunk Chunk, loops, ms int) (int, error)

Same as PlayChannel, but the chunk fades in over ms milliseconds.

func FadeInChannelTimed

func FadeInChannelTimed(channel int, chunk Chunk, loops, ms, ticks int) (int, error)

Same as PlayChannelTimed, but the chunk fades in over ms milliseconds.

func FadeOutChannel

func FadeOutChannel(which, ms int) int

FadeOutChannel gradually fades out playback on channel which, or all channels if which is -1, over ms milliseconds starting from now. The channel(s) will be halted after the fade out is completed. Only channels that are playing are set to fade out, including paused channels.

FadeOutChannel returns the number of channel set to fade out.

func FadeOutMusic

func FadeOutMusic(ms int) error

FadeOutMusic gradually fades out music over ms milliseconds starting from now. The music will be halted after the fade is completed.

func GetChunkDecoder

func GetChunkDecoder(index int) string

GetChunkDecoder gets the name of the chunk decoder at index. You must successfully call OpenAudio before calling the function.

func GetMusicDecoder

func GetMusicDecoder(index int) string

GetMusicDecoder gets the name of the music decoder at index. You must successfully call OpenAudio before calling the function.

func GetNumChunkDecoders

func GetNumChunkDecoders() int

GetNumChunkDecoders gets the number of chunk decoders mixer provides. You must successfully call OpenAudio before calling the function.

func GetNumMusicDecoders

func GetNumMusicDecoders() int

GetNumMusicDecoders gets the number of music decoders mixer provides. You must successfully call OpenAudio before calling the function.

func GetSoundFonts

func GetSoundFonts() string

func HaltChannel

func HaltChannel(channel int)

HaltChannel halts the playback on channel, or all channels if channel is -1.

func HaltMusic

func HaltMusic()

HaltMusic halts the playback of music. This interrupts music fader effects.

func Init

func Init(flags InitFlags) error

Init loads dynamic libraries and prepares them for use. Flags should be one or more flags from InitFlags OR'd together. It returns an error if a library fails to load.

func LinkedVersion

func LinkedVersion() *sdl.Version

LinkedVersion gets the version of the dynamically linked SDL2_mixer library. It should not be used to fill a version structure, instead you should use VERSION.

func OpenAudio

func OpenAudio(frequency int, format AudioFormat, channels, chunksize int) error

OpenAudio opens the mixer with a certain audio format. frequency is the output sampling frequency in samples per second (Hz). format is the output sample format. channels is the number of sound channels in output, it has nothing to do with mixing channels. chunksize is the size of each mixer sample. If it is too small the sound may skip on slow systems, if it is too large the sound effects will lag behind the action. OpenAudio also allocates 8 mixing channels.

SDL must be initialized with INIT_AUDIO before calling OpenAudio.

Common settings are:

frequency: 44100 or 22050
format: AUDIO_S16SYS
channels: 2 (stereo) or 1 (mono)
chunksize: 512, 1024, 2048, or 4096

func Pause

func Pause(channel int)

Pause pause playback on channel, or all channels if channel is -1. You may still halt a paused channel.

Note: Only channels which are actively playing will be paused.

func PauseMusic

func PauseMusic()

PauseMusic pauses the music playback. You may halt paused music.

Note: Music can only be paused if it is actively playing.

func Paused

func Paused(channel int) int

Paused tells you if channel is paused, or not. If channel is -1 it returns the number of paused channels, otherwise it returns 0 if channel is not paused or 1 if it is paused.

func PausedMusic

func PausedMusic() bool

PausedMusic tells you if music is paused, or not.

func PlayChannel

func PlayChannel(channel int, chunk Chunk, loops int) (int, error)

PlayChannel plays an audio chunk on a specific channel. If the specified channel is -1, play on the first free channel. If loops is greater then zero, loop the sound that many times. If loops is -1, loop inifinitely. Returns which channel was used to play the sound.

func PlayChannelTimed

func PlayChannelTimed(channel int, chunk Chunk, loops, ticks int) (int, error)

PlayChannelTimed is the same as PlayChannel, but the sound is played at most ticks milliseconds.

func Playing

func Playing(channel int) int

Playing tells you if channel is playing, or not. It does not check if the channel has been paused.

Playing returns zero if the channel is not playing, or 1 if it is playing. If channel is -1, it returns the number of channels that are playing.

func PlayingMusic

func PlayingMusic() bool

PlayingMusic tells you if music is actively playing, or not. It does not check if the channel has been paused.

func Quit

func Quit()

Quit unloads libraries loaded with Initialize.

func ReserveChannels

func ReserveChannels(num int) int

ReserveChannels reserves the first channels (0 -> n-1) for the application, i.e. don't allocate them dynamically to the next sample if requested with a -1 value below. Returns the number of reserved channels.

func Resume

func Resume(channel int)

Resume unpauses channel, or all playing and paused channels if channel is -1.

func ResumeMusic

func ResumeMusic()

ResumeMusics unpauses the music. This is safe to use on halted, paused, and already playing music.

func RewindMusic

func RewindMusic()

RewindMusic rewinds the music to the start. This is safe to use on halted, paused, and already playing music. It is not useful to rewind the music Immediately after starting playback, because it starts at the beginning by default.

RewindwMusic does not work for all music formats.

func SetMusicCMD

func SetMusicCMD(command string) int

SetMusicCMD sets the system command that is used to play music. The command should be a complete command, as if typed in to the command line, but it should expect the filename to be added as teh last argument. Set command to and empty string to turn off using an external command for music.

When SetMusicCMD is called any music playing is halted. The music file to play is set by calling LoadMUS(filename), and the filename is appended as the last argument on the commandline. The command will be sent signals SIGTERM to halt, SIGSTOP to pause, and SIGCONT to resume. The command program should react correctly to those signals for it to function properly with SDL2_Mixer. Volume should be set in the music player's command if the music player supports that.

Notes: Playing music through an external command may not work if the sound driver does not support multiple openings of the audio device. Also commands are not totally portable, so be careful.

func SetMusicPosition

func SetMusicPosition(position float64) int

SetMusicPosition sets the postion of the currently playing music. The position takes different meaning for different music sources. It only works on the music types listed below.

Position meanings:

MOD:
  position is cast to a uint16 and used for a pattern number in the
  module.  Passing zero is similar to rewinding the song.

OGG, FLAC, MP3_MAD, and MODPLUG:
  Jumps to the position seconds from the beginning of the song.

MP3:
  Jumps to the position seconds from the current position in the stream.
  So you may want to call RewindMusic before this.  Does not go in
  Reverse.

func SetSoundFonts

func SetSoundFonts(paths string) int

func VERSION

func VERSION(v *sdl.Version)

VERSION fills v with the compile-time version of the SDL2_mixer library.

func Volume

func Volume(channel, volume int) int

Volume sets the volume for any allocated channel. If channel is -1 then all channels are set at once. The volume is applied during the final mix, along with the sample volume. So setting this volume to 64 will halve the output of all samples played on the specified channel. All channels default to a volume of 128, which is the max. Newly allocated channels will have the max volume set, so setting all channels volumes does not affect subsequent channel allocations.

If volume is less then 0 then the volume will not be set.

Volume returns the current volume of the channel. If channel is -1, the average volume is returned.

func VolumeMusic

func VolumeMusic(volume int) int

VolumeMusic sets the volume for music. Setting the volume during a fade will not work, the faders use this function to perform their effect! Setting volume while using an external music player set by SetMusicCMD will have no effect.

If volume is less then 0 then the volume will not be set.

VolumeMusic returns the previous volume setting

Types

type AudioFormat

type AudioFormat uint16
const (
	AUDIO_U8     AudioFormat = C.AUDIO_U8     // Unsigned 8-bit samples
	AUDIO_S8     AudioFormat = C.AUDIO_S8     // Signed 8-bit samples
	AUDIO_U16LSB AudioFormat = C.AUDIO_U16LSB // Unsigned 16-bit samples
	AUDIO_S16LSB AudioFormat = C.AUDIO_S16LSB // Signed 16-bit samples
	AUDIO_U16MSB AudioFormat = C.AUDIO_U16MSB // As above, but big-endian byte order
	AUDIO_S16MSB AudioFormat = C.AUDIO_S16MSB // As above, but big-endian byte order
	AUDIO_U16    AudioFormat = C.AUDIO_U16
	AUDIO_S16    AudioFormat = C.AUDIO_S16

	// Native audio byte ordering
	AUDIO_U16SYS AudioFormat = C.AUDIO_U16SYS
	AUDIO_S16SYS AudioFormat = C.AUDIO_S16SYS // Same as MIX_DEFAULT_FORMAT
)

func QuerySpec

func QuerySpec() (format AudioFormat, frequency, channels, opened int)

QuerySpec returns what the actual audio device parameters are. opened is the number of times the device was opened or 0 on error.

type Chunk

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

The internal format for an audio chunk.

func LoadWAV

func LoadWAV(file string) (Chunk, error)

LoadWAV loads a file into a Chunk.

func LoadWAVFromReader

func LoadWAVFromReader(reader io.Reader) (Chunk, error)

LoadWAVFromReader loads an io.Reader into a Chunk.

func (Chunk) Free

func (c Chunk) Free()

Free frees c.

func (Chunk) Volume

func (c Chunk) Volume(volume int) int

Volume sets the volume for c. The volume setting will take effect when the chunk is used on a channel, be mixed into the output.

If volume is less then 0 then the volume will not be set.

Volume returns the previous volume of c.

type Fading

type Fading int
const (
	NO_FADING  Fading = C.MIX_NO_FADING
	FADING_OUT Fading = C.MIX_FADING_OUT
	FADING_IN  Fading = C.MIX_FADING_IN
)

func FadingChannel

func FadingChannel(which int) Fading

FadingChannel tells you if which channel is fading in, out, or not at all. It does not tell you if the channel is playing anything, or paused.

Note which can not be -1.

func FadingMusic

func FadingMusic() Fading

FadingMusic tells you if the music is fading in, out, or not at all. It does not tell you if the channel is playing anything, or paused.

type InitFlags

type InitFlags int32
const (
	INIT_FLAC       InitFlags = C.MIX_INIT_FLAC
	INIT_MOD        InitFlags = C.MIX_INIT_MOD
	INIT_MP3        InitFlags = C.MIX_INIT_MP3
	INIT_OGG        InitFlags = C.MIX_INIT_OGG
	INIT_FLUIDSYNTH InitFlags = C.MIX_INIT_FLUIDSYNTH
)

type Music

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

The internal format for a music chunk.

func LoadMUS

func LoadMUS(file string) (Music, error)

LoadMUS loads a file into a Music.

func LoadMUSFromReader

func LoadMUSFromReader(reader io.Reader) (Music, error)

LoadMUSFromReader loads an io.Reader into a Music.

func (Music) FadeIn

func (m Music) FadeIn(loops, ms int) error

FadeIn is the same as Play, but m fades in over ms milliseconds.

func (Music) FadeInPos

func (m Music) FadeInPos(loops, ms int, position float64) error

FadeInPos is the same as FadeIn, but the music will be started at position. position has different meanings for different types of music files, see SetMusicPosition for more information.

func (Music) Free

func (m Music) Free()

Free frees m.

func (Music) GetType

func (m Music) GetType() MusicType

GetType gets the music format of m, or the currently playing music, if m is a zero value Music.

func (Music) Play

func (m Music) Play(loops int) error

Play plays m loops number of times. If loops is -1 m will loop forever. The previous is music is halted, or if fading out it waits (blocking) for that to finish.

type MusicType

type MusicType int32
const (
	MUS_NONE    MusicType = C.MUS_NONE
	MUS_CMD     MusicType = C.MUS_CMD
	MUS_WAV     MusicType = C.MUS_WAV
	MUS_MOD     MusicType = C.MUS_MOD
	MUS_MID     MusicType = C.MUS_MID
	MUS_OGG     MusicType = C.MUS_OGG
	MUS_MP3     MusicType = C.MUS_MP3
	MUS_MP3_MAD MusicType = C.MUS_MP3_MAD
	MUS_FLAC    MusicType = C.MUS_FLAC
	MUS_MODPLUG MusicType = C.MUS_MODPLUG
)

Jump to

Keyboard shortcuts

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