Documentation ¶
Overview ¶
Go binding for OpenAL's "al" API.
See http://connect.creativelabs.com/openal/Documentation/OpenAL%201.1%20Specification.htm for details about OpenAL not described here.
OpenAL types are (in principle) mapped to Go types as follows:
ALboolean bool (al.h says char, but Go's bool should be compatible) ALchar uint8 (although al.h suggests int8, Go's uint8 (aka byte) seems better) ALbyte int8 (al.h says char, implying that char is signed) ALubyte uint8 (al.h says unsigned char) ALshort int16 ALushort uint16 ALint int32 ALuint uint32 ALsizei int32 (although that's strange, it's what OpenAL wants) ALenum int32 (although that's strange, it's what OpenAL wants) ALfloat float32 ALdouble float64 ALvoid not applicable (but see below)
We also stick to these (not mentioned explicitly in OpenAL):
ALvoid* unsafe.Pointer (but never exported) ALchar* string
Finally, in places where OpenAL expects pointers to C-style arrays, we use Go slices if appropriate:
ALboolean* []bool ALvoid* []byte (see Buffer.SetData() for example) ALint* []int32 ALuint* []uint32 []Source []Buffer ALfloat* []float32 ALdouble* []float64
Overall, the correspondence of types hopefully feels natural enough. Note that many of these types do not actually occur in the API.
The names of OpenAL constants follow the established Go conventions: instead of AL_FORMAT_MONO16 we use FormatMono16 for example.
Conversion to Go's camel case notation does however lead to name clashes between constants and functions. For example, AL_DISTANCE_MODEL becomes DistanceModel which collides with the OpenAL function of the same name used to set the current distance model. We have to rename either the constant or the function, and since the function name seems to be at fault (it's a setter but doesn't make that obvious), we rename the function.
In fact, we renamed plenty of functions, not just the ones where collisions with constants were the driving force. For example, instead of the Sourcef/GetSourcef abomination, we use Getf/Setf methods on a Source type. Everything should still be easily recognizable for OpenAL hackers, but this structure is a lot more sensible (and reveals that the OpenAL API is actually not such a bad design).
There are a few cases where constants would collide with the names of types we introduced here. Since the types serve a much more important function, we renamed the constants in those cases. For example AL_BUFFER would collide with the type Buffer so it's name is now Buffer_ instead. Not pretty, but in many cases you don't need the constants anyway as the functionality they represent is probably available through one of the convenience functions we introduced as well. For example consider the task of attaching a buffer to a source. In C, you'd say alSourcei(sid, AL_BUFFER, bid). In Go, you can say sid.Seti(Buffer_, bid) as well, but you probably want to say sid.SetBuffer(bid) instead.
TODO: Decide on the final API design; the current state has only specialized methods, none of the generic ones anymore; it exposes everything (except stuff we can't do) but I am not sure whether this is the right API for the level we operate on. Not yet anyway. Anyone?
Index ¶
- Constants
- func DeleteBuffer(buffer Buffer)
- func DeleteBuffers(buffers []Buffer)
- func DeleteSource(source Source)
- func DeleteSources(sources []Source)
- func GetDistanceModel() int32
- func GetDopplerFactor() float32
- func GetDopplerVelocity() float32
- func GetError() uint32
- func GetExtensions() string
- func GetRenderer() string
- func GetSpeedOfSound() float32
- func GetString(param int32) string
- func GetVendor() string
- func GetVersion() string
- func PauseSources(sources []Source)
- func PlaySources(sources []Source)
- func RewindSources(sources []Source)
- func SetDistanceModel(model int32)
- func SetDopplerFactor(value float32)
- func SetDopplerVelocity(value float32)
- func SetSpeedOfSound(value float32)
- func StopSources(sources []Source)
- type Buffer
- type Listener
- func (self Listener) GetGain() (gain float32)
- func (self Listener) GetOrientation() (at Vector, up Vector)
- func (self Listener) GetPosition() Vector
- func (self Listener) GetVelocity() Vector
- func (self Listener) SetGain(gain float32)
- func (self Listener) SetOrientation(at Vector, up Vector)
- func (self Listener) SetPosition(vector Vector)
- func (self Listener) SetVelocity(vector Vector)
- type Source
- func (self Source) BuffersProcessed() int32
- func (self Source) BuffersQueued() int32
- func (self Source) GetBuffer() (buffer Buffer)
- func (self Source) GetDirection() Vector
- func (self Source) GetGain() (gain float32)
- func (self Source) GetInnerAngle() float32
- func (self Source) GetLooping() bool
- func (self Source) GetMaxDistance() (distance float32)
- func (self Source) GetMaxGain() (gain float32)
- func (self Source) GetMinGain() (gain float32)
- func (self Source) GetOffsetBytes() int32
- func (self Source) GetOffsetSamples() int32
- func (self Source) GetOffsetSeconds() float32
- func (self Source) GetOuterAngle() float32
- func (self Source) GetOuterGain() float32
- func (self Source) GetPitch() (gain float32)
- func (self Source) GetPosition() Vector
- func (self Source) GetReferenceDistance() (distance float32)
- func (self Source) GetRolloffFactor() (gain float32)
- func (self Source) GetSourceRelative() bool
- func (self Source) GetVelocity() Vector
- func (self Source) Pause()
- func (self Source) Play()
- func (self Source) QueueBuffer(buffer Buffer)
- func (self Source) QueueBuffers(buffers []Buffer)
- func (self Source) Rewind()
- func (self Source) SetBuffer(buffer Buffer)
- func (self Source) SetDirection(vector Vector)
- func (self Source) SetGain(gain float32)
- func (self Source) SetInnerAngle(offset float32)
- func (self Source) SetLooping(yes bool)
- func (self Source) SetMaxDistance(distance float32)
- func (self Source) SetMaxGain(gain float32)
- func (self Source) SetMinGain(gain float32)
- func (self Source) SetOffsetBytes(offset int32)
- func (self Source) SetOffsetSamples(offset int32)
- func (self Source) SetOffsetSeconds(offset float32)
- func (self Source) SetOuterAngle(offset float32)
- func (self Source) SetOuterGain(offset float32)
- func (self Source) SetPitch(gain float32)
- func (self Source) SetPosition(vector Vector)
- func (self Source) SetReferenceDistance(distance float32)
- func (self Source) SetRolloffFactor(gain float32)
- func (self Source) SetSourceRelative(yes bool)
- func (self Source) SetVelocity(vector Vector)
- func (self Source) State() int32
- func (self Source) Stop()
- func (self Source) Type() int32
- func (self Source) UnqueueBuffer() Buffer
- func (self Source) UnqueueBuffers(buffers []Buffer)
- type Vector
Constants ¶
const ( FormatMono8 = 0x1100 FormatMono16 = 0x1101 FormatStereo8 = 0x1102 FormatStereo16 = 0x1103 )
Format of sound samples passed to Buffer.SetData().
const ( NoError = alFalse InvalidName = 0xA001 InvalidEnum = 0xA002 InvalidValue = 0xA003 InvalidOperation = 0xA004 )
Error codes from GetError()/for GetString().
const ( InverseDistance = 0xD001 InverseDistanceClamped = 0xD002 LinearDistance = 0xD003 LinearDistanceClamped = 0xD004 ExponentDistance = 0xD005 ExponentDistanceClamped = 0xD006 )
Distance models for SetDistanceModel() and GetDistanceModel().
const ( Initial = 0x1011 Playing = 0x1012 Paused = 0x1013 Stopped = 0x1014 )
Results from Source.State() query.
const ( Static = 0x1028 Streaming = 0x1029 Undetermined = 0x1030 )
Results from Source.Type() query.
const (
None = 0
)
General purpose constants. None can be used with SetDistanceModel() to disable distance attenuation. None can be used with Source.SetBuffer() to clear a Source of buffers.
Variables ¶
This section is empty.
Functions ¶
func DeleteBuffer ¶
func DeleteBuffer(buffer Buffer)
DeleteBuffer() deletes a single buffer. Convenience function, see DeleteBuffers().
func DeleteBuffers ¶
func DeleteBuffers(buffers []Buffer)
DeleteBuffers() deletes the given buffers.
func DeleteSource ¶
func DeleteSource(source Source)
DeleteSource() deletes a single source. Convenience function, see DeleteSources().
func DeleteSources ¶
func DeleteSources(sources []Source)
DeleteSources() deletes the given sources.
func GetError ¶
func GetError() uint32
GetError() returns the most recent error generated in the AL state machine.
func SetDistanceModel ¶
func SetDistanceModel(model int32)
SetDistanceModel() changes the current distance model. Pass "None" to disable distance attenuation. Renamed, was DistanceModel.
Types ¶
type Buffer ¶
type Buffer uint32
Buffers are storage space for sample data.
func NewBuffer ¶
func NewBuffer() Buffer
NewBuffer() creates a single buffer. Convenience function, see NewBuffers().
func NewBuffers ¶
NewBuffers() creates n fresh buffers. Renamed, was GenBuffers.
func (Buffer) GetBits ¶
GetBits() returns the resolution, either 8 or 16 bits, of the buffer's sample data. Convenience method.
func (Buffer) GetChannels ¶
GetChannels() returns the number of channels, either 1 or 2, of the buffer's sample data. Convenience method.
func (Buffer) GetFrequency ¶
GetFrequency() returns the frequency, in Hz, of the buffer's sample data. Convenience method.
func (Buffer) GetSize ¶
GetSize() returns the size, in bytes, of the buffer's sample data. Convenience method.
type Listener ¶
type Listener struct{}
Listener represents the singleton receiver of sound in 3d space.
We "fake" this type so we can provide OpenAL listener calls as methods. This is convenient and makes all those calls consistent with the way they work for Source and Buffer. You can't make new listeners, there's only one!
func (Listener) GetOrientation ¶
TODO: is there a better way to do this? Convenience method, see Listener.Getfv().
func (Listener) GetPosition ¶
Convenience method, see Listener.Getfv().
func (Listener) GetVelocity ¶
Convenience method, see Listener.Getfv().
func (Listener) SetOrientation ¶
TODO: is there a better way to do this? Convenience method, see Listener.Setfv().
func (Listener) SetPosition ¶
Convenience method, see Listener.Setfv().
func (Listener) SetVelocity ¶
Convenience method, see Listener.Setfv().
type Source ¶
type Source uint32
Sources represent sound emitters in 3d space.
func NewSource ¶
func NewSource() Source
NewSource() creates a single source. Convenience function, see NewSources().
func NewSources ¶
NewSources() creates n sources. Renamed, was GenSources.
func (Source) BuffersProcessed ¶
Convenience method, see Source.Geti().
func (Source) BuffersQueued ¶
Convenience method, see Source.Geti().
func (Source) GetDirection ¶
Convenience method, see Source.Getfv().
func (Source) GetInnerAngle ¶
Convenience method, see Source.Getf().
func (Source) GetLooping ¶
Convenience method, see Source.Geti().
func (Source) GetMaxDistance ¶
Convenience method, see Source.Getf().
func (Source) GetMaxGain ¶
Convenience method, see Source.Getf().
func (Source) GetMinGain ¶
Convenience method, see Source.Getf().
func (Source) GetOffsetBytes ¶
Convenience method, see Source.Geti().
func (Source) GetOffsetSamples ¶
Convenience method, see Source.Geti().
func (Source) GetOffsetSeconds ¶
Convenience method, see Source.Getf().
func (Source) GetOuterAngle ¶
Convenience method, see Source.Getf().
func (Source) GetOuterGain ¶
Convenience method, see Source.Getf().
func (Source) GetPosition ¶
Convenience method, see Source.Getfv().
func (Source) GetReferenceDistance ¶
Convenience method, see Source.Getf().
func (Source) GetRolloffFactor ¶
Convenience method, see Source.Getf().
func (Source) GetSourceRelative ¶
Convenience method, see Source.Geti().
func (Source) GetVelocity ¶
Convenience method, see Source.Getfv().
func (Source) QueueBuffer ¶
Convenience method, see Source.QueueBuffers().
func (Source) QueueBuffers ¶
Renamed, was SourceQueueBuffers.
func (Source) SetDirection ¶
Convenience method, see Source.Setfv().
func (Source) SetInnerAngle ¶
Convenience method, see Source.Setf().
func (Source) SetLooping ¶
Convenience method, see Source.Seti().
func (Source) SetMaxDistance ¶
Convenience method, see Source.Setf().
func (Source) SetMaxGain ¶
Convenience method, see Source.Setf().
func (Source) SetMinGain ¶
Convenience method, see Source.Setf().
func (Source) SetOffsetBytes ¶
Convenience method, see Source.Seti().
func (Source) SetOffsetSamples ¶
Convenience method, see Source.Seti().
func (Source) SetOffsetSeconds ¶
Convenience method, see Source.Setf().
func (Source) SetOuterAngle ¶
Convenience method, see Source.Setf().
func (Source) SetOuterGain ¶
Convenience method, see Source.Setf().
func (Source) SetPosition ¶
Convenience method, see Source.Setfv().
func (Source) SetReferenceDistance ¶
Convenience method, see Source.Setf().
func (Source) SetRolloffFactor ¶
Convenience method, see Source.Setf().
func (Source) SetSourceRelative ¶
Convenience method, see Source.Seti().
func (Source) SetVelocity ¶
Convenience method, see Source.Setfv().
func (Source) UnqueueBuffer ¶
Convenience method, see Source.QueueBuffers().
func (Source) UnqueueBuffers ¶
Renamed, was SourceUnqueueBuffers.