1
0
Fork 0

Adding upstream version 0.0~git20250520.a1d9079+dfsg.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-05-24 19:46:29 +02:00
parent 590ac7ff5f
commit 20149b7f3a
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
456 changed files with 70406 additions and 0 deletions

456
exp/audio/al/al.go Normal file
View file

@ -0,0 +1,456 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build darwin || linux || windows
// Package al provides OpenAL Soft bindings for Go.
//
// Calls are not safe for concurrent use.
//
// More information about OpenAL Soft is available at
// http://www.openal.org/documentation/openal-1.1-specification.pdf.
//
// In order to use this package on Linux desktop distros,
// you will need OpenAL library as an external dependency.
// On Ubuntu 14.04 'Trusty', you may have to install this library
// by running the command below.
//
// sudo apt-get install libopenal-dev
//
// When compiled for Android, this package uses OpenAL Soft. Please add its
// license file to the open source notices of your application.
// OpenAL Soft's license file could be found at
// http://repo.or.cz/w/openal-soft.git/blob/HEAD:/COPYING.
package al
// Capability represents OpenAL extension capabilities.
type Capability int32
// Enable enables a capability.
func Enable(c Capability) {
alEnable(int32(c))
}
// Disable disables a capability.
func Disable(c Capability) {
alDisable(int32(c))
}
// Enabled reports whether the specified capability is enabled.
func Enabled(c Capability) bool {
return alIsEnabled(int32(c))
}
// Vector represents an vector in a Cartesian coordinate system.
type Vector [3]float32
// Orientation represents the angular position of an object in a
// right-handed Cartesian coordinate system.
// A cross product between the forward and up vector returns a vector
// that points to the right.
type Orientation struct {
// Forward vector is the direction that the object is looking at.
Forward Vector
// Up vector represents the rotation of the object.
Up Vector
}
func orientationFromSlice(v []float32) Orientation {
return Orientation{
Forward: Vector{v[0], v[1], v[2]},
Up: Vector{v[3], v[4], v[5]},
}
}
func (v Orientation) slice() []float32 {
return []float32{v.Forward[0], v.Forward[1], v.Forward[2], v.Up[0], v.Up[1], v.Up[2]}
}
// Geti returns the int32 value of the given parameter.
func Geti(param int) int32 {
return alGetInteger(param)
}
// Getiv returns the int32 vector value of the given parameter.
func Getiv(param int, v []int32) {
alGetIntegerv(param, v)
}
// Getf returns the float32 value of the given parameter.
func Getf(param int) float32 {
return alGetFloat(param)
}
// Getfv returns the float32 vector value of the given parameter.
func Getfv(param int, v []float32) {
alGetFloatv(param, v[:])
}
// Getb returns the bool value of the given parameter.
func Getb(param int) bool {
return alGetBoolean(param)
}
// Getbv returns the bool vector value of the given parameter.
func Getbv(param int, v []bool) {
alGetBooleanv(param, v)
}
// GetString returns the string value of the given parameter.
func GetString(param int) string {
return alGetString(param)
}
// DistanceModel returns the distance model.
func DistanceModel() int32 {
return Geti(paramDistanceModel)
}
// SetDistanceModel sets the distance model.
func SetDistanceModel(v int32) {
alDistanceModel(v)
}
// DopplerFactor returns the doppler factor.
func DopplerFactor() float32 {
return Getf(paramDopplerFactor)
}
// SetDopplerFactor sets the doppler factor.
func SetDopplerFactor(v float32) {
alDopplerFactor(v)
}
// DopplerVelocity returns the doppler velocity.
func DopplerVelocity() float32 {
return Getf(paramDopplerVelocity)
}
// SetDopplerVelocity sets the doppler velocity.
func SetDopplerVelocity(v float32) {
alDopplerVelocity(v)
}
// SpeedOfSound is the speed of sound in meters per second (m/s).
func SpeedOfSound() float32 {
return Getf(paramSpeedOfSound)
}
// SetSpeedOfSound sets the speed of sound, its unit should be meters per second (m/s).
func SetSpeedOfSound(v float32) {
alSpeedOfSound(v)
}
// Vendor returns the vendor.
func Vendor() string {
return GetString(paramVendor)
}
// Version returns the version string.
func Version() string {
return GetString(paramVersion)
}
// Renderer returns the renderer information.
func Renderer() string {
return GetString(paramRenderer)
}
// Extensions returns the enabled extensions.
func Extensions() string {
return GetString(paramExtensions)
}
// Error returns the most recently generated error.
func Error() int32 {
return alGetError()
}
// Source represents an individual sound source in 3D-space.
// They take PCM data, apply modifications and then submit them to
// be mixed according to their spatial location.
type Source uint32
// GenSources generates n new sources. These sources should be deleted
// once they are not in use.
func GenSources(n int) []Source {
return alGenSources(n)
}
// PlaySources plays the sources.
func PlaySources(source ...Source) {
alSourcePlayv(source)
}
// PauseSources pauses the sources.
func PauseSources(source ...Source) {
alSourcePausev(source)
}
// StopSources stops the sources.
func StopSources(source ...Source) {
alSourceStopv(source)
}
// RewindSources rewinds the sources to their beginning positions.
func RewindSources(source ...Source) {
alSourceRewindv(source)
}
// DeleteSources deletes the sources.
func DeleteSources(source ...Source) {
alDeleteSources(source)
}
// Gain returns the source gain.
func (s Source) Gain() float32 {
return s.Getf(paramGain)
}
// SetGain sets the source gain.
func (s Source) SetGain(v float32) {
s.Setf(paramGain, v)
}
// MinGain returns the source's minimum gain setting.
func (s Source) MinGain() float32 {
return s.Getf(paramMinGain)
}
// SetMinGain sets the source's minimum gain setting.
func (s Source) SetMinGain(v float32) {
s.Setf(paramMinGain, v)
}
// MaxGain returns the source's maximum gain setting.
func (s Source) MaxGain() float32 {
return s.Getf(paramMaxGain)
}
// SetMaxGain sets the source's maximum gain setting.
func (s Source) SetMaxGain(v float32) {
s.Setf(paramMaxGain, v)
}
// Position returns the position of the source.
func (s Source) Position() Vector {
v := Vector{}
s.Getfv(paramPosition, v[:])
return v
}
// SetPosition sets the position of the source.
func (s Source) SetPosition(v Vector) {
s.Setfv(paramPosition, v[:])
}
// Velocity returns the source's velocity.
func (s Source) Velocity() Vector {
v := Vector{}
s.Getfv(paramVelocity, v[:])
return v
}
// SetVelocity sets the source's velocity.
func (s Source) SetVelocity(v Vector) {
s.Setfv(paramVelocity, v[:])
}
// Orientation returns the orientation of the source.
func (s Source) Orientation() Orientation {
v := make([]float32, 6)
s.Getfv(paramOrientation, v)
return orientationFromSlice(v)
}
// SetOrientation sets the orientation of the source.
func (s Source) SetOrientation(o Orientation) {
s.Setfv(paramOrientation, o.slice())
}
// State returns the playing state of the source.
func (s Source) State() int32 {
return s.Geti(paramSourceState)
}
// BuffersQueued returns the number of the queued buffers.
func (s Source) BuffersQueued() int32 {
return s.Geti(paramBuffersQueued)
}
// BuffersProcessed returns the number of the processed buffers.
func (s Source) BuffersProcessed() int32 {
return s.Geti(paramBuffersProcessed)
}
// OffsetSeconds returns the current playback position of the source in seconds.
func (s Source) OffsetSeconds() int32 {
return s.Geti(paramSecOffset)
}
// OffsetSample returns the sample offset of the current playback position.
func (s Source) OffsetSample() int32 {
return s.Geti(paramSampleOffset)
}
// OffsetByte returns the byte offset of the current playback position.
func (s Source) OffsetByte() int32 {
return s.Geti(paramByteOffset)
}
// Geti returns the int32 value of the given parameter.
func (s Source) Geti(param int) int32 {
return alGetSourcei(s, param)
}
// Getf returns the float32 value of the given parameter.
func (s Source) Getf(param int) float32 {
return alGetSourcef(s, param)
}
// Getfv returns the float32 vector value of the given parameter.
func (s Source) Getfv(param int, v []float32) {
alGetSourcefv(s, param, v)
}
// Seti sets an int32 value for the given parameter.
func (s Source) Seti(param int, v int32) {
alSourcei(s, param, v)
}
// Setf sets a float32 value for the given parameter.
func (s Source) Setf(param int, v float32) {
alSourcef(s, param, v)
}
// Setfv sets a float32 vector value for the given parameter.
func (s Source) Setfv(param int, v []float32) {
alSourcefv(s, param, v)
}
// QueueBuffers adds the buffers to the buffer queue.
func (s Source) QueueBuffers(buffer ...Buffer) {
alSourceQueueBuffers(s, buffer)
}
// UnqueueBuffers removes the specified buffers from the buffer queue.
func (s Source) UnqueueBuffers(buffer ...Buffer) {
alSourceUnqueueBuffers(s, buffer)
}
// ListenerGain returns the total gain applied to the final mix.
func ListenerGain() float32 {
return GetListenerf(paramGain)
}
// ListenerPosition returns the position of the listener.
func ListenerPosition() Vector {
v := Vector{}
GetListenerfv(paramPosition, v[:])
return v
}
// ListenerVelocity returns the velocity of the listener.
func ListenerVelocity() Vector {
v := Vector{}
GetListenerfv(paramVelocity, v[:])
return v
}
// ListenerOrientation returns the orientation of the listener.
func ListenerOrientation() Orientation {
v := make([]float32, 6)
GetListenerfv(paramOrientation, v)
return orientationFromSlice(v)
}
// SetListenerGain sets the total gain that will be applied to the final mix.
func SetListenerGain(v float32) {
SetListenerf(paramGain, v)
}
// SetListenerPosition sets the position of the listener.
func SetListenerPosition(v Vector) {
SetListenerfv(paramPosition, v[:])
}
// SetListenerVelocity sets the velocity of the listener.
func SetListenerVelocity(v Vector) {
SetListenerfv(paramVelocity, v[:])
}
// SetListenerOrientation sets the orientation of the listener.
func SetListenerOrientation(v Orientation) {
SetListenerfv(paramOrientation, v.slice())
}
// GetListenerf returns the float32 value of the listener parameter.
func GetListenerf(param int) float32 {
return alGetListenerf(param)
}
// GetListenerfv returns the float32 vector value of the listener parameter.
func GetListenerfv(param int, v []float32) {
alGetListenerfv(param, v)
}
// SetListenerf sets the float32 value for the listener parameter.
func SetListenerf(param int, v float32) {
alListenerf(param, v)
}
// SetListenerfv sets the float32 vector value of the listener parameter.
func SetListenerfv(param int, v []float32) {
alListenerfv(param, v)
}
// A buffer represents a chunk of PCM audio data that could be buffered to an audio
// source. A single buffer could be shared between multiple sources.
type Buffer uint32
// GenBuffers generates n new buffers. The generated buffers should be deleted
// once they are no longer in use.
func GenBuffers(n int) []Buffer {
return alGenBuffers(n)
}
// DeleteBuffers deletes the buffers.
func DeleteBuffers(buffer ...Buffer) {
alDeleteBuffers(buffer)
}
// Geti returns the int32 value of the given parameter.
func (b Buffer) Geti(param int) int32 {
return b.Geti(param)
}
// Frequency returns the frequency of the buffer data in Hertz (Hz).
func (b Buffer) Frequency() int32 {
return b.Geti(paramFreq)
}
// Bits return the number of bits used to represent a sample.
func (b Buffer) Bits() int32 {
return b.Geti(paramBits)
}
// Channels return the number of the audio channels.
func (b Buffer) Channels() int32 {
return b.Geti(paramChannels)
}
// Size returns the size of the data.
func (b Buffer) Size() int32 {
return b.Geti(paramSize)
}
// BufferData buffers PCM data to the current buffer.
func (b Buffer) BufferData(format uint32, data []byte, freq int32) {
alBufferData(b, format, data, freq)
}
// Valid reports whether the buffer exists and is valid.
func (b Buffer) Valid() bool {
return alIsBuffer(b)
}

486
exp/audio/al/al_android.go Normal file
View file

@ -0,0 +1,486 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package al
/*
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
#include <jni.h>
#include <limits.h>
#include <AL/al.h>
#include <AL/alc.h>
void al_init(uintptr_t java_vm, uintptr_t jni_env, jobject context, void** handle) {
JavaVM* vm = (JavaVM*)java_vm;
JNIEnv* env = (JNIEnv*)jni_env;
jclass android_content_Context = (*env)->FindClass(env, "android/content/Context");
jmethodID get_application_info = (*env)->GetMethodID(env, android_content_Context, "getApplicationInfo", "()Landroid/content/pm/ApplicationInfo;");
jclass android_content_pm_ApplicationInfo = (*env)->FindClass(env, "android/content/pm/ApplicationInfo");
jfieldID native_library_dir = (*env)->GetFieldID(env, android_content_pm_ApplicationInfo, "nativeLibraryDir", "Ljava/lang/String;");
jobject app_info = (*env)->CallObjectMethod(env, context, get_application_info);
jstring native_dir = (*env)->GetObjectField(env, app_info, native_library_dir);
const char *cnative_dir = (*env)->GetStringUTFChars(env, native_dir, 0);
char lib_path[PATH_MAX] = "";
strlcat(lib_path, cnative_dir, sizeof(lib_path));
strlcat(lib_path, "/libopenal.so", sizeof(lib_path));
*handle = dlopen(lib_path, RTLD_LAZY);
(*env)->ReleaseStringUTFChars(env, native_dir, cnative_dir);
}
void call_alEnable(LPALENABLE fn, ALenum capability) {
fn(capability);
}
void call_alDisable(LPALDISABLE fn, ALenum capability) {
fn(capability);
}
ALboolean call_alIsEnabled(LPALISENABLED fn, ALenum capability) {
return fn(capability);
}
ALint call_alGetInteger(LPALGETINTEGER fn, ALenum p) {
return fn(p);
}
void call_alGetIntegerv(LPALGETINTEGERV fn, ALenum p, ALint* v) {
fn(p, v);
}
ALfloat call_alGetFloat(LPALGETFLOAT fn, ALenum p) {
return fn(p);
}
void call_alGetFloatv(LPALGETFLOATV fn, ALenum p, ALfloat* v) {
fn(p, v);
}
ALboolean call_alGetBoolean(LPALGETBOOLEAN fn, ALenum p) {
return fn(p);
}
void call_alGetBooleanv(LPALGETBOOLEANV fn, ALenum p, ALboolean* v) {
fn(p, v);
}
const char* call_alGetString(LPALGETSTRING fn, ALenum p) {
return fn(p);
}
void call_alDistanceModel(LPALDISTANCEMODEL fn, ALenum v) {
fn(v);
}
void call_alDopplerFactor(LPALDOPPLERFACTOR fn, ALfloat v) {
fn(v);
}
void call_alDopplerVelocity(LPALDOPPLERVELOCITY fn, ALfloat v) {
fn(v);
}
void call_alSpeedOfSound(LPALSPEEDOFSOUND fn, ALfloat v) {
fn(v);
}
ALint call_alGetError(LPALGETERROR fn) {
return fn();
}
void call_alGenSources(LPALGENSOURCES fn, ALsizei n, ALuint* s) {
fn(n, s);
}
void call_alSourcePlayv(LPALSOURCEPLAYV fn, ALsizei n, const ALuint* s) {
fn(n, s);
}
void call_alSourcePausev(LPALSOURCEPAUSEV fn, ALsizei n, const ALuint* s) {
fn(n, s);
}
void call_alSourceStopv(LPALSOURCESTOPV fn, ALsizei n, const ALuint* s) {
fn(n, s);
}
void call_alSourceRewindv(LPALSOURCEREWINDV fn, ALsizei n, const ALuint* s) {
fn(n, s);
}
void call_alDeleteSources(LPALDELETESOURCES fn, ALsizei n, const ALuint* s) {
fn(n, s);
}
void call_alGetSourcei(LPALGETSOURCEI fn, ALuint s, ALenum k, ALint* v) {
fn(s, k, v);
}
void call_alGetSourcef(LPALGETSOURCEF fn, ALuint s, ALenum k, ALfloat* v) {
fn(s, k, v);
}
void call_alGetSourcefv(LPALGETSOURCEFV fn, ALuint s, ALenum k, ALfloat* v) {
fn(s, k, v);
}
void call_alSourcei(LPALSOURCEI fn, ALuint s, ALenum k, ALint v) {
fn(s, k, v);
}
void call_alSourcef(LPALSOURCEF fn, ALuint s, ALenum k, ALfloat v) {
fn(s, k, v);
}
void call_alSourcefv(LPALSOURCEFV fn, ALuint s, ALenum k, const ALfloat* v) {
fn(s, k, v);
}
void call_alSourceQueueBuffers(LPALSOURCEQUEUEBUFFERS fn, ALuint s, ALsizei n, const ALuint* b) {
fn(s, n, b);
}
void call_alSourceUnqueueBuffers(LPALSOURCEUNQUEUEBUFFERS fn, ALuint s, ALsizei n, ALuint* b) {
fn(s, n, b);
}
void call_alGetListenerf(LPALGETLISTENERF fn, ALenum k, ALfloat* v) {
fn(k, v);
}
void call_alGetListenerfv(LPALLISTENERFV fn, ALenum k, ALfloat* v) {
fn(k, v);
}
void call_alListenerf(LPALLISTENERF fn, ALenum k, ALfloat v) {
fn(k, v);
}
void call_alListenerfv(LPALLISTENERFV fn, ALenum k, const ALfloat* v) {
fn(k, v);
}
void call_alGenBuffers(LPALGENBUFFERS fn, ALsizei n, ALuint* v) {
fn(n, v);
}
void call_alDeleteBuffers(LPALDELETEBUFFERS fn, ALsizei n, ALuint* v) {
fn(n, v);
}
void call_alGetBufferi(LPALGETBUFFERI fn, ALuint b, ALenum k, ALint* v) {
fn(b, k, v);
}
void call_alBufferData(LPALBUFFERDATA fn, ALuint b, ALenum format, const ALvoid* data, ALsizei size, ALsizei freq) {
fn(b, format, data, size, freq);
}
ALboolean call_alIsBuffer(LPALISBUFFER fn, ALuint b) {
return fn(b);
}
*/
import "C"
import (
"errors"
"log"
"unsafe"
"golang.org/x/mobile/internal/mobileinit"
)
var (
alHandle unsafe.Pointer
alEnableFunc C.LPALENABLE
alDisableFunc C.LPALDISABLE
alIsEnabledFunc C.LPALISENABLED
alGetIntegerFunc C.LPALGETINTEGER
alGetIntegervFunc C.LPALGETINTEGERV
alGetFloatFunc C.LPALGETFLOAT
alGetFloatvFunc C.LPALGETFLOATV
alGetBooleanFunc C.LPALGETBOOLEAN
alGetBooleanvFunc C.LPALGETBOOLEANV
alGetStringFunc C.LPALGETSTRING
alDistanceModelFunc C.LPALDISTANCEMODEL
alDopplerFactorFunc C.LPALDOPPLERFACTOR
alDopplerVelocityFunc C.LPALDOPPLERVELOCITY
alSpeedOfSoundFunc C.LPALSPEEDOFSOUND
alGetErrorFunc C.LPALGETERROR
alGenSourcesFunc C.LPALGENSOURCES
alSourcePlayvFunc C.LPALSOURCEPLAYV
alSourcePausevFunc C.LPALSOURCEPAUSEV
alSourceStopvFunc C.LPALSOURCESTOPV
alSourceRewindvFunc C.LPALSOURCEREWINDV
alDeleteSourcesFunc C.LPALDELETESOURCES
alGetSourceiFunc C.LPALGETSOURCEI
alGetSourcefFunc C.LPALGETSOURCEF
alGetSourcefvFunc C.LPALGETSOURCEFV
alSourceiFunc C.LPALSOURCEI
alSourcefFunc C.LPALSOURCEF
alSourcefvFunc C.LPALSOURCEFV
alSourceQueueBuffersFunc C.LPALSOURCEQUEUEBUFFERS
alSourceUnqueueBuffersFunc C.LPALSOURCEUNQUEUEBUFFERS
alGetListenerfFunc C.LPALGETLISTENERF
alGetListenerfvFunc C.LPALGETLISTENERFV
alListenerfFunc C.LPALLISTENERF
alListenerfvFunc C.LPALLISTENERFV
alGenBuffersFunc C.LPALGENBUFFERS
alDeleteBuffersFunc C.LPALDELETEBUFFERS
alGetBufferiFunc C.LPALGETBUFFERI
alBufferDataFunc C.LPALBUFFERDATA
alIsBufferFunc C.LPALISBUFFER
alcGetErrorFunc C.LPALCGETERROR
alcOpenDeviceFunc C.LPALCOPENDEVICE
alcCloseDeviceFunc C.LPALCCLOSEDEVICE
alcCreateContextFunc C.LPALCCREATECONTEXT
alcMakeContextCurrentFunc C.LPALCMAKECONTEXTCURRENT
alcDestroyContextFunc C.LPALCDESTROYCONTEXT
)
func initAL() {
err := mobileinit.RunOnJVM(func(vm, env, ctx uintptr) error {
C.al_init(C.uintptr_t(vm), C.uintptr_t(env), C.jobject(ctx), &alHandle)
if alHandle == nil {
return errors.New("al: cannot load libopenal.so")
}
return nil
})
if err != nil {
log.Fatalf("al: %v", err)
}
alEnableFunc = C.LPALENABLE(fn("alEnable"))
alDisableFunc = C.LPALDISABLE(fn("alDisable"))
alIsEnabledFunc = C.LPALISENABLED(fn("alIsEnabled"))
alGetIntegerFunc = C.LPALGETINTEGER(fn("alGetInteger"))
alGetIntegervFunc = C.LPALGETINTEGERV(fn("alGetIntegerv"))
alGetFloatFunc = C.LPALGETFLOAT(fn("alGetFloat"))
alGetFloatvFunc = C.LPALGETFLOATV(fn("alGetFloatv"))
alGetBooleanFunc = C.LPALGETBOOLEAN(fn("alGetBoolean"))
alGetBooleanvFunc = C.LPALGETBOOLEANV(fn("alGetBooleanv"))
alGetStringFunc = C.LPALGETSTRING(fn("alGetString"))
alDistanceModelFunc = C.LPALDISTANCEMODEL(fn("alDistanceModel"))
alDopplerFactorFunc = C.LPALDOPPLERFACTOR(fn("alDopplerFactor"))
alDopplerVelocityFunc = C.LPALDOPPLERVELOCITY(fn("alDopplerVelocity"))
alSpeedOfSoundFunc = C.LPALSPEEDOFSOUND(fn("alSpeedOfSound"))
alGetErrorFunc = C.LPALGETERROR(fn("alGetError"))
alGenSourcesFunc = C.LPALGENSOURCES(fn("alGenSources"))
alSourcePlayvFunc = C.LPALSOURCEPLAYV(fn("alSourcePlayv"))
alSourcePausevFunc = C.LPALSOURCEPAUSEV(fn("alSourcePausev"))
alSourceStopvFunc = C.LPALSOURCESTOPV(fn("alSourceStopv"))
alSourceRewindvFunc = C.LPALSOURCEREWINDV(fn("alSourceRewindv"))
alDeleteSourcesFunc = C.LPALDELETESOURCES(fn("alDeleteSources"))
alGetSourceiFunc = C.LPALGETSOURCEI(fn("alGetSourcei"))
alGetSourcefFunc = C.LPALGETSOURCEF(fn("alGetSourcef"))
alGetSourcefvFunc = C.LPALGETSOURCEFV(fn("alGetSourcefv"))
alSourceiFunc = C.LPALSOURCEI(fn("alSourcei"))
alSourcefFunc = C.LPALSOURCEF(fn("alSourcef"))
alSourcefvFunc = C.LPALSOURCEFV(fn("alSourcefv"))
alSourceQueueBuffersFunc = C.LPALSOURCEQUEUEBUFFERS(fn("alSourceQueueBuffers"))
alSourceUnqueueBuffersFunc = C.LPALSOURCEUNQUEUEBUFFERS(fn("alSourceUnqueueBuffers"))
alGetListenerfFunc = C.LPALGETLISTENERF(fn("alGetListenerf"))
alGetListenerfvFunc = C.LPALGETLISTENERFV(fn("alGetListenerfv"))
alListenerfFunc = C.LPALLISTENERF(fn("alListenerf"))
alListenerfvFunc = C.LPALLISTENERFV(fn("alListenerfv"))
alGenBuffersFunc = C.LPALGENBUFFERS(fn("alGenBuffers"))
alDeleteBuffersFunc = C.LPALDELETEBUFFERS(fn("alDeleteBuffers"))
alGetBufferiFunc = C.LPALGETBUFFERI(fn("alGetBufferi"))
alBufferDataFunc = C.LPALBUFFERDATA(fn("alBufferData"))
alIsBufferFunc = C.LPALISBUFFER(fn("alIsBuffer"))
alcGetErrorFunc = C.LPALCGETERROR(fn("alcGetError"))
alcOpenDeviceFunc = C.LPALCOPENDEVICE(fn("alcOpenDevice"))
alcCloseDeviceFunc = C.LPALCCLOSEDEVICE(fn("alcCloseDevice"))
alcCreateContextFunc = C.LPALCCREATECONTEXT(fn("alcCreateContext"))
alcMakeContextCurrentFunc = C.LPALCMAKECONTEXTCURRENT(fn("alcMakeContextCurrent"))
alcDestroyContextFunc = C.LPALCDESTROYCONTEXT(fn("alcDestroyContext"))
}
func fn(fname string) unsafe.Pointer {
name := C.CString(fname)
defer C.free(unsafe.Pointer(name))
p := C.dlsym(alHandle, name)
if uintptr(p) == 0 {
log.Fatalf("al: couldn't dlsym %q", fname)
}
return p
}
func alEnable(capability int32) {
C.call_alEnable(alEnableFunc, C.ALenum(capability))
}
func alDisable(capability int32) {
C.call_alDisable(alDisableFunc, C.ALenum(capability))
}
func alIsEnabled(capability int32) bool {
return C.call_alIsEnabled(alIsEnabledFunc, C.ALenum(capability)) == C.AL_TRUE
}
func alGetInteger(k int) int32 {
return int32(C.call_alGetInteger(alGetIntegerFunc, C.ALenum(k)))
}
func alGetIntegerv(k int, v []int32) {
C.call_alGetIntegerv(alGetIntegervFunc, C.ALenum(k), (*C.ALint)(unsafe.Pointer(&v[0])))
}
func alGetFloat(k int) float32 {
return float32(C.call_alGetFloat(alGetFloatFunc, C.ALenum(k)))
}
func alGetFloatv(k int, v []float32) {
C.call_alGetFloatv(alGetFloatvFunc, C.ALenum(k), (*C.ALfloat)(unsafe.Pointer(&v[0])))
}
func alGetBoolean(k int) bool {
return C.call_alGetBoolean(alGetBooleanFunc, C.ALenum(k)) == C.AL_TRUE
}
func alGetBooleanv(k int, v []bool) {
val := make([]C.ALboolean, len(v))
for i, bv := range v {
if bv {
val[i] = C.AL_TRUE
} else {
val[i] = C.AL_FALSE
}
}
C.call_alGetBooleanv(alGetBooleanvFunc, C.ALenum(k), &val[0])
}
func alGetString(v int) string {
value := C.call_alGetString(alGetStringFunc, C.ALenum(v))
return C.GoString(value)
}
func alDistanceModel(v int32) {
C.call_alDistanceModel(alDistanceModelFunc, C.ALenum(v))
}
func alDopplerFactor(v float32) {
C.call_alDopplerFactor(alDopplerFactorFunc, C.ALfloat(v))
}
func alDopplerVelocity(v float32) {
C.call_alDopplerVelocity(alDopplerVelocityFunc, C.ALfloat(v))
}
func alSpeedOfSound(v float32) {
C.call_alSpeedOfSound(alSpeedOfSoundFunc, C.ALfloat(v))
}
func alGetError() int32 {
return int32(C.call_alGetError(alGetErrorFunc))
}
func alGenSources(n int) []Source {
s := make([]Source, n)
C.call_alGenSources(alGenSourcesFunc, C.ALsizei(n), (*C.ALuint)(unsafe.Pointer(&s[0])))
return s
}
func alSourcePlayv(s []Source) {
C.call_alSourcePlayv(alSourcePlayvFunc, C.ALsizei(len(s)), (*C.ALuint)(unsafe.Pointer(&s[0])))
}
func alSourcePausev(s []Source) {
C.call_alSourcePausev(alSourcePausevFunc, C.ALsizei(len(s)), (*C.ALuint)(unsafe.Pointer(&s[0])))
}
func alSourceStopv(s []Source) {
C.call_alSourceStopv(alSourceStopvFunc, C.ALsizei(len(s)), (*C.ALuint)(unsafe.Pointer(&s[0])))
}
func alSourceRewindv(s []Source) {
C.call_alSourceRewindv(alSourceRewindvFunc, C.ALsizei(len(s)), (*C.ALuint)(unsafe.Pointer(&s[0])))
}
func alDeleteSources(s []Source) {
C.call_alDeleteSources(alDeleteSourcesFunc, C.ALsizei(len(s)), (*C.ALuint)(unsafe.Pointer(&s[0])))
}
func alGetSourcei(s Source, k int) int32 {
var v C.ALint
C.call_alGetSourcei(alGetSourceiFunc, C.ALuint(s), C.ALenum(k), &v)
return int32(v)
}
func alGetSourcef(s Source, k int) float32 {
var v C.ALfloat
C.call_alGetSourcef(alGetSourcefFunc, C.ALuint(s), C.ALenum(k), &v)
return float32(v)
}
func alGetSourcefv(s Source, k int, v []float32) {
C.call_alGetSourcefv(alGetSourcefvFunc, C.ALuint(s), C.ALenum(k), (*C.ALfloat)(unsafe.Pointer(&v[0])))
}
func alSourcei(s Source, k int, v int32) {
C.call_alSourcei(alSourcefFunc, C.ALuint(s), C.ALenum(k), C.ALint(v))
}
func alSourcef(s Source, k int, v float32) {
C.call_alSourcef(alSourcefFunc, C.ALuint(s), C.ALenum(k), C.ALfloat(v))
}
func alSourcefv(s Source, k int, v []float32) {
C.call_alSourcefv(alSourcefvFunc, C.ALuint(s), C.ALenum(k), (*C.ALfloat)(unsafe.Pointer(&v[0])))
}
func alSourceQueueBuffers(s Source, b []Buffer) {
C.call_alSourceQueueBuffers(alSourceQueueBuffersFunc, C.ALuint(s), C.ALsizei(len(b)), (*C.ALuint)(unsafe.Pointer(&b[0])))
}
func alSourceUnqueueBuffers(s Source, b []Buffer) {
C.call_alSourceUnqueueBuffers(alSourceUnqueueBuffersFunc, C.ALuint(s), C.ALsizei(len(b)), (*C.ALuint)(unsafe.Pointer(&b[0])))
}
func alGetListenerf(k int) float32 {
var v C.ALfloat
C.call_alGetListenerf(alListenerfFunc, C.ALenum(k), &v)
return float32(v)
}
func alGetListenerfv(k int, v []float32) {
C.call_alGetListenerfv(alGetListenerfvFunc, C.ALenum(k), (*C.ALfloat)(unsafe.Pointer(&v[0])))
}
func alListenerf(k int, v float32) {
C.call_alListenerf(alListenerfFunc, C.ALenum(k), C.ALfloat(v))
}
func alListenerfv(k int, v []float32) {
C.call_alListenerfv(alListenerfvFunc, C.ALenum(k), (*C.ALfloat)(unsafe.Pointer(&v[0])))
}
func alGenBuffers(n int) []Buffer {
s := make([]Buffer, n)
C.call_alGenBuffers(alGenBuffersFunc, C.ALsizei(n), (*C.ALuint)(unsafe.Pointer(&s[0])))
return s
}
func alDeleteBuffers(b []Buffer) {
C.call_alDeleteBuffers(alDeleteBuffersFunc, C.ALsizei(len(b)), (*C.ALuint)(unsafe.Pointer(&b[0])))
}
func alGetBufferi(b Buffer, k int) int32 {
var v C.ALint
C.call_alGetBufferi(alGetBufferiFunc, C.ALuint(b), C.ALenum(k), &v)
return int32(v)
}
func alBufferData(b Buffer, format uint32, data []byte, freq int32) {
C.call_alBufferData(alBufferDataFunc, C.ALuint(b), C.ALenum(format), unsafe.Pointer(&data[0]), C.ALsizei(len(data)), C.ALsizei(freq))
}
func alIsBuffer(b Buffer) bool {
return C.call_alIsBuffer(alIsBufferFunc, C.ALuint(b)) == C.AL_TRUE
}

View file

@ -0,0 +1,208 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build darwin || (linux && !android) || windows
package al
/*
#cgo darwin CFLAGS: -DGOOS_darwin
#cgo linux CFLAGS: -DGOOS_linux
#cgo windows CFLAGS: -DGOOS_windows
#cgo darwin LDFLAGS: -framework OpenAL
#cgo linux LDFLAGS: -lopenal
#cgo windows LDFLAGS: -lOpenAL32
#ifdef GOOS_darwin
#include <stdlib.h>
#include <OpenAL/al.h>
#endif
#ifdef GOOS_linux
#include <stdlib.h>
#include <AL/al.h> // install on Ubuntu with: sudo apt-get install libopenal-dev
#endif
#ifdef GOOS_windows
#include <windows.h>
#include <stdlib.h>
#include <AL/al.h>
#endif
*/
import "C"
import "unsafe"
func alEnable(capability int32) {
C.alEnable(C.ALenum(capability))
}
func alDisable(capability int32) {
C.alDisable(C.ALenum(capability))
}
func alIsEnabled(capability int32) bool {
return C.alIsEnabled(C.ALenum(capability)) == C.AL_TRUE
}
func alGetInteger(k int) int32 {
return int32(C.alGetInteger(C.ALenum(k)))
}
func alGetIntegerv(k int, v []int32) {
C.alGetIntegerv(C.ALenum(k), (*C.ALint)(unsafe.Pointer(&v[0])))
}
func alGetFloat(k int) float32 {
return float32(C.alGetFloat(C.ALenum(k)))
}
func alGetFloatv(k int, v []float32) {
C.alGetFloatv(C.ALenum(k), (*C.ALfloat)(unsafe.Pointer(&v[0])))
}
func alGetBoolean(k int) bool {
return C.alGetBoolean(C.ALenum(k)) == C.AL_TRUE
}
func alGetBooleanv(k int, v []bool) {
val := make([]C.ALboolean, len(v))
for i, bv := range v {
if bv {
val[i] = C.AL_TRUE
} else {
val[i] = C.AL_FALSE
}
}
C.alGetBooleanv(C.ALenum(k), &val[0])
}
func alGetString(v int) string {
value := C.alGetString(C.ALenum(v))
return C.GoString((*C.char)(value))
}
func alDistanceModel(v int32) {
C.alDistanceModel(C.ALenum(v))
}
func alDopplerFactor(v float32) {
C.alDopplerFactor(C.ALfloat(v))
}
func alDopplerVelocity(v float32) {
C.alDopplerVelocity(C.ALfloat(v))
}
func alSpeedOfSound(v float32) {
C.alSpeedOfSound(C.ALfloat(v))
}
func alGetError() int32 {
return int32(C.alGetError())
}
func alGenSources(n int) []Source {
s := make([]Source, n)
C.alGenSources(C.ALsizei(n), (*C.ALuint)(unsafe.Pointer(&s[0])))
return s
}
func alSourcePlayv(s []Source) {
C.alSourcePlayv(C.ALsizei(len(s)), (*C.ALuint)(unsafe.Pointer(&s[0])))
}
func alSourcePausev(s []Source) {
C.alSourcePausev(C.ALsizei(len(s)), (*C.ALuint)(unsafe.Pointer(&s[0])))
}
func alSourceStopv(s []Source) {
C.alSourceStopv(C.ALsizei(len(s)), (*C.ALuint)(unsafe.Pointer(&s[0])))
}
func alSourceRewindv(s []Source) {
C.alSourceRewindv(C.ALsizei(len(s)), (*C.ALuint)(unsafe.Pointer(&s[0])))
}
func alDeleteSources(s []Source) {
C.alDeleteSources(C.ALsizei(len(s)), (*C.ALuint)(unsafe.Pointer(&s[0])))
}
func alGetSourcei(s Source, k int) int32 {
var v C.ALint
C.alGetSourcei(C.ALuint(s), C.ALenum(k), &v)
return int32(v)
}
func alGetSourcef(s Source, k int) float32 {
var v C.ALfloat
C.alGetSourcef(C.ALuint(s), C.ALenum(k), &v)
return float32(v)
}
func alGetSourcefv(s Source, k int, v []float32) {
C.alGetSourcefv(C.ALuint(s), C.ALenum(k), (*C.ALfloat)(unsafe.Pointer(&v[0])))
}
func alSourcei(s Source, k int, v int32) {
C.alSourcei(C.ALuint(s), C.ALenum(k), C.ALint(v))
}
func alSourcef(s Source, k int, v float32) {
C.alSourcef(C.ALuint(s), C.ALenum(k), C.ALfloat(v))
}
func alSourcefv(s Source, k int, v []float32) {
C.alSourcefv(C.ALuint(s), C.ALenum(k), (*C.ALfloat)(unsafe.Pointer(&v[0])))
}
func alSourceQueueBuffers(s Source, b []Buffer) {
C.alSourceQueueBuffers(C.ALuint(s), C.ALsizei(len(b)), (*C.ALuint)(unsafe.Pointer(&b[0])))
}
func alSourceUnqueueBuffers(s Source, b []Buffer) {
C.alSourceUnqueueBuffers(C.ALuint(s), C.ALsizei(len(b)), (*C.ALuint)(unsafe.Pointer(&b[0])))
}
func alGetListenerf(k int) float32 {
var v C.ALfloat
C.alGetListenerf(C.ALenum(k), &v)
return float32(v)
}
func alGetListenerfv(k int, v []float32) {
C.alGetListenerfv(C.ALenum(k), (*C.ALfloat)(unsafe.Pointer(&v[0])))
}
func alListenerf(k int, v float32) {
C.alListenerf(C.ALenum(k), C.ALfloat(v))
}
func alListenerfv(k int, v []float32) {
C.alListenerfv(C.ALenum(k), (*C.ALfloat)(unsafe.Pointer(&v[0])))
}
func alGenBuffers(n int) []Buffer {
s := make([]Buffer, n)
C.alGenBuffers(C.ALsizei(n), (*C.ALuint)(unsafe.Pointer(&s[0])))
return s
}
func alDeleteBuffers(b []Buffer) {
C.alDeleteBuffers(C.ALsizei(len(b)), (*C.ALuint)(unsafe.Pointer(&b[0])))
}
func alGetBufferi(b Buffer, k int) int32 {
var v C.ALint
C.alGetBufferi(C.ALuint(b), C.ALenum(k), &v)
return int32(v)
}
func alBufferData(b Buffer, format uint32, data []byte, freq int32) {
C.alBufferData(C.ALuint(b), C.ALenum(format), unsafe.Pointer(&data[0]), C.ALsizei(len(data)), C.ALsizei(freq))
}
func alIsBuffer(b Buffer) bool {
return C.alIsBuffer(C.ALuint(b)) == C.AL_TRUE
}

74
exp/audio/al/alc.go Normal file
View file

@ -0,0 +1,74 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build darwin || linux || windows
package al
import (
"errors"
"sync"
"unsafe"
)
var (
mu sync.Mutex
device unsafe.Pointer
context unsafe.Pointer
)
// DeviceError returns the last known error from the current device.
func DeviceError() int32 {
return alcGetError(device)
}
// TODO(jbd): Investigate the cases where multiple audio output
// devices might be needed.
// OpenDevice opens the default audio device.
// Calls to OpenDevice are safe for concurrent use.
func OpenDevice() error {
mu.Lock()
defer mu.Unlock()
// already opened
if device != nil {
return nil
}
dev := alcOpenDevice("")
if dev == nil {
return errors.New("al: cannot open the default audio device")
}
ctx := alcCreateContext(dev, nil)
if ctx == nil {
alcCloseDevice(dev)
return errors.New("al: cannot create a new context")
}
if !alcMakeContextCurrent(ctx) {
alcCloseDevice(dev)
return errors.New("al: cannot make context current")
}
device = dev
context = ctx
return nil
}
// CloseDevice closes the device and frees related resources.
// Calls to CloseDevice are safe for concurrent use.
func CloseDevice() {
mu.Lock()
defer mu.Unlock()
if device == nil {
return
}
alcCloseDevice(device)
if context != nil {
alcDestroyContext(context)
}
device = nil
context = nil
}

View file

@ -0,0 +1,76 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package al
/*
#include <stdlib.h>
#include <dlfcn.h>
#include <AL/al.h>
#include <AL/alc.h>
ALCint call_alcGetError(LPALCGETERROR fn, ALCdevice* d) {
return fn(d);
}
ALCdevice* call_alcOpenDevice(LPALCOPENDEVICE fn, const ALCchar* name) {
return fn(name);
}
ALCboolean call_alcCloseDevice(LPALCCLOSEDEVICE fn, ALCdevice* d) {
return fn(d);
}
ALCcontext* call_alcCreateContext(LPALCCREATECONTEXT fn, ALCdevice* d, const ALCint* attrs) {
return fn(d, attrs);
}
ALCboolean call_alcMakeContextCurrent(LPALCMAKECONTEXTCURRENT fn, ALCcontext* c) {
return fn(c);
}
void call_alcDestroyContext(LPALCDESTROYCONTEXT fn, ALCcontext* c) {
return fn(c);
}
*/
import "C"
import (
"sync"
"unsafe"
)
var once sync.Once
func alcGetError(d unsafe.Pointer) int32 {
dev := (*C.ALCdevice)(d)
return int32(C.call_alcGetError(alcGetErrorFunc, dev))
}
func alcOpenDevice(name string) unsafe.Pointer {
once.Do(initAL)
n := C.CString(name)
defer C.free(unsafe.Pointer(n))
return (unsafe.Pointer)(C.call_alcOpenDevice(alcOpenDeviceFunc, (*C.ALCchar)(unsafe.Pointer(n))))
}
func alcCloseDevice(d unsafe.Pointer) bool {
dev := (*C.ALCdevice)(d)
return C.call_alcCloseDevice(alcCloseDeviceFunc, dev) == C.AL_TRUE
}
func alcCreateContext(d unsafe.Pointer, attrs []int32) unsafe.Pointer {
dev := (*C.ALCdevice)(d)
// TODO(jbd): Handle attrs.
return (unsafe.Pointer)(C.call_alcCreateContext(alcCreateContextFunc, dev, nil))
}
func alcMakeContextCurrent(c unsafe.Pointer) bool {
ctx := (*C.ALCcontext)(c)
return C.call_alcMakeContextCurrent(alcMakeContextCurrentFunc, ctx) == C.AL_TRUE
}
func alcDestroyContext(c unsafe.Pointer) {
C.call_alcDestroyContext(alcDestroyContextFunc, (*C.ALCcontext)(c))
}

View file

@ -0,0 +1,70 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build darwin || (linux && !android) || windows
package al
/*
#cgo darwin CFLAGS: -DGOOS_darwin
#cgo linux CFLAGS: -DGOOS_linux
#cgo windows CFLAGS: -DGOOS_windows
#cgo darwin LDFLAGS: -framework OpenAL
#cgo linux LDFLAGS: -lopenal
#cgo windows LDFLAGS: -lOpenAL32
#ifdef GOOS_darwin
#include <stdlib.h>
#include <OpenAL/alc.h>
#endif
#ifdef GOOS_linux
#include <stdlib.h>
#include <AL/alc.h>
#endif
#ifdef GOOS_windows
#include <windows.h>
#include <stdlib.h>
#include <AL/alc.h>
#endif
*/
import "C"
import "unsafe"
/*
On Ubuntu 14.04 'Trusty', you may have to install these libraries:
sudo apt-get install libopenal-dev
*/
func alcGetError(d unsafe.Pointer) int32 {
dev := (*C.ALCdevice)(d)
return int32(C.alcGetError(dev))
}
func alcOpenDevice(name string) unsafe.Pointer {
n := C.CString(name)
defer C.free(unsafe.Pointer(n))
return (unsafe.Pointer)(C.alcOpenDevice((*C.ALCchar)(unsafe.Pointer(n))))
}
func alcCloseDevice(d unsafe.Pointer) bool {
dev := (*C.ALCdevice)(d)
return C.alcCloseDevice(dev) == C.ALC_TRUE
}
func alcCreateContext(d unsafe.Pointer, attrs []int32) unsafe.Pointer {
dev := (*C.ALCdevice)(d)
return (unsafe.Pointer)(C.alcCreateContext(dev, nil))
}
func alcMakeContextCurrent(c unsafe.Pointer) bool {
ctx := (*C.ALCcontext)(c)
return C.alcMakeContextCurrent(ctx) == C.ALC_TRUE
}
func alcDestroyContext(c unsafe.Pointer) {
C.alcDestroyContext((*C.ALCcontext)(c))
}

82
exp/audio/al/const.go Normal file
View file

@ -0,0 +1,82 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build darwin || linux || windows
package al
// Error returns one of these error codes.
const (
InvalidName = 0xA001
InvalidEnum = 0xA002
InvalidValue = 0xA003
InvalidOperation = 0xA004
OutOfMemory = 0xA005
)
// Distance models.
const (
InverseDistance = 0xD001
InverseDistanceClamped = 0xD002
LinearDistance = 0xD003
LinearDistanceClamped = 0xD004
ExponentDistance = 0xD005
ExponentDistanceClamped = 0xD006
)
// Global parameters.
const (
paramDistanceModel = 0xD000
paramDopplerFactor = 0xC000
paramDopplerVelocity = 0xC001
paramSpeedOfSound = 0xC003
paramVendor = 0xB001
paramVersion = 0xB002
paramRenderer = 0xB003
paramExtensions = 0xB004
)
// Source and listener parameters.
const (
paramGain = 0x100A
paramPosition = 0x1004
paramVelocity = 0x1006
paramOrientation = 0x100F
paramMinGain = 0x100D
paramMaxGain = 0x100E
paramSourceState = 0x1010
paramBuffersQueued = 0x1015
paramBuffersProcessed = 0x1016
paramSecOffset = 0x1024
paramSampleOffset = 0x1025
paramByteOffset = 0x1026
)
// A source could be in the state of initial, playing, paused or stopped.
const (
Initial = 0x1011
Playing = 0x1012
Paused = 0x1013
Stopped = 0x1014
)
// Buffer parameters.
const (
paramFreq = 0x2001
paramBits = 0x2002
paramChannels = 0x2003
paramSize = 0x2004
)
// Audio formats. Buffer.BufferData accepts one of these formats as the data format.
const (
FormatMono8 = 0x1100
FormatMono16 = 0x1101
FormatStereo8 = 0x1102
FormatStereo16 = 0x1103
)
// CapabilityDistanceModel represents the capability of specifying a different distance
// model for each source.
const CapabilityDistanceModel = Capability(0x200)