miniaudio

package module
v0.0.0-...-a23bf68 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 2 Imported by: 0

README

miniaudio

A Go wrapper for miniaudio, providing native audio playback and capture capabilities through CGO bindings. This project enables Go applications to leverage the powerful miniaudio library for cross-platform audio processing with support for 3D spatialization, node-based effects graphs, and multiple audio backends.

Features

  • Cross-platform audio: Supports Windows (WASAPI, DirectSound, MME), Linux (ALSA, PulseAudio, JACK, OSS), and macOS/iOS (Core Audio)
  • High-level audio engine: Simple API for common audio operations
  • 3D spatial audio: Positional audio with listener positioning, Doppler effect, and attenuation models
  • Node-based effects graph: Build complex audio processing pipelines with customizable nodes
  • Sound playback: Play sounds from files, memory buffers, or custom data sources
  • Decoder support: Decode various audio formats (WAV, MP3, OGG, FLAC, etc.)
  • Low-level device access: Direct control of audio devices when needed

Design Principles

This library follows a minimal wrapper approach:

  • All Go functions call miniaudio's C API directly
  • CGO bindings are kept minimal and focused
  • Structs wrapping C pointers follow the pattern: NewXxx() for creation, Close() for cleanup
  • One-to-one mapping between C API functions and Go methods
  • No duplicate functionality beyond what miniaudio provides

Installation

go get github.com/nobonobo/miniaudio
Prerequisites
  • Go 1.23 or later
  • A C compiler (GCC, Clang, or MSVC)
  • miniaudio.h and miniaudio.c files in the project directory (included)

Quick Start

package main

import (
    "fmt"
    "github.com/nobonobo/miniaudio"
)

func main() {
    // Create and initialize the engine
    config := miniaudio.NewEngineConfig()
    defer config.Close()
    
    engine, err := miniaudio.NewEngine(config)
    if err != nil {
        fmt.Printf("Failed to create engine: %v\n", err)
        return
    }
    defer engine.Close()
    
    // Start the engine
    if err := engine.Start(); err != nil {
        fmt.Printf("Failed to start engine: %v\n", err)
        return
    }
    
    // Play a sound file
    if err := engine.PlaySound("path/to/sound.wav"); err != nil {
        fmt.Printf("Failed to play sound: %v\n", err)
    }
}

API Overview

Engine

The high-level audio engine for most audio needs:

// Create engine with custom configuration
config := miniaudio.NewEngineConfig()
config.SetSampleRate(48000)
config.SetChannels(2)
engine, err := miniaudio.NewEngine(config)

// Engine methods
engine.Start()
engine.Stop()
engine.PlaySound("sound.wav")
engine.SetVolume(0.5)
Sound Playback
// Play from file
sound, err := engine.PlaySoundFromFile("sound.wav", miniaudio.SoundFlagLooping, nil)

// Control sound
sound.SetVolume(0.8)
sound.SetPan(0.5)
sound.SetPitch(1.0)
sound.Play()
sound.Stop()
3D Audio
// Set listener position and orientation
engine.ListenerSetPosition(0, 0, 0, 0)
engine.ListenerSetDirection(0, 0, 0, -1)
engine.ListenerSetVelocity(0, 0, 0, 0)

// Spatial sounds automatically attenuate based on distance
Device Management
// Access underlying device for advanced control
device := engine.GetDevice()

Project Structure

.
├── miniaudio.go          # Main package and type definitions
├── miniaudio_types.go    # C struct wrappers and type constants
├── engine.go             # Engine and EngineConfig implementations
├── device.go             # Device and DeviceConfig implementations
├── decoder.go            # Decoder implementation
├── sound.go              # Sound implementation
├── nodegraph.go          # Node graph implementation
├── context.go            # Context implementation
├── miniaudio.h           # miniaudio header (included)
├── miniaudio.c           # miniaudio source (included)
├── miniaudio_callbacks.c # CGO callback bridge implementations
├── miniaudio_callbacks.h # Callback header definitions
└── docs/
    ├── api.md            # API reference
    └── memo.md           # Development notes

Examples

Generate and Play a Sine Wave
// See examples/wav_generator.go for WAV file generation
go run examples/wav_generator.go
Basic Sound Playback
// Run the test example
go run miniaudio_test.go

Supported Backends

Backend Platforms
WASAPI Windows 10+
DirectSound Windows
MME Windows
Core Audio macOS, iOS
ALSA Linux
PulseAudio Linux
JACK Linux
OSS BSD, Linux
AudioIO iOS, tvOS

Constants and Types

Sound Flags
const (
    SoundFlagStream        SoundFlags = 0x00000001  // Stream from source
    SoundFlagDecode        SoundFlags = 0x00000002  // Decode on the fly
    SoundFlagAsync         SoundFlags = 0x00000004  // Async loading
    SoundFlagWaitInit      SoundFlags = 0x00000008  // Wait for init
    SoundFlagUnknownLength SoundFlags = 0x00000010  // Unknown length
    SoundFlagLooping       SoundFlags = 0x00000020  // Loop playback
)
Audio Formats
const (
    FormatUnknown Format = 0
    FormatF32     Format = 1
    FormatF64     Format = 2
    FormatS16     Format = 3
    FormatS24     Format = 4
    FormatS32     Format = 5
    FormatU8      Format = 6
)
Device Types
const (
    DeviceTypePlayback DeviceType = 1 << 0
    DeviceTypeCapture  DeviceType = 1 << 1
    DeviceTypeDuplex   DeviceType = 1 << 2
    DeviceTypeLoopback DeviceType = 1 << 3
)

Error Handling

All functions return Go error types. Custom error types include:

  • ErrNilEngine: Returned when the engine is nil
  • ErrResult: Converted from miniaudio's ma_result codes
if err := engine.PlaySound("sound.wav"); err != nil {
    fmt.Printf("Error: %v\n", err)
}

Development

Building
# Build the package
go build ./...

# Run tests
go test -v ./...
Architecture

The wrapper follows a strict pattern:

  1. C structs are wrapped by Go structs containing only the C pointer
  2. NewXxx() functions allocate C memory, initialize, and return the wrapper
  3. Close() methods uninitialize and free C memory
  4. Methods on Go structs call corresponding C API functions
  5. Callbacks are bridged through dedicated .c/.h files

License

This project uses the miniaudio library which is licensed under the MIT License. See the included LICENSE file for details.

Documentation

Index

Constants

View Source
const (
	MA_SUCCESS               = 0
	MA_ERROR                 = -1
	MA_INVALID_ARGS          = -2
	MA_NO_MEMORY             = -3
	MA_OUT_OF_RANGE          = -4
	MA_ALREADY_INITIALIZED   = -5
	MA_NOT_FOUND             = -6
	MA_INVALID_OPERATION     = -7
	MA_INVALID_STATE         = -8
	MA_AUDIO_NOT_AVAILABLE   = -9
	MA_BACKEND_NOT_AVAILABLE = -10
	MA_NO_DATA               = -11
	MA_ALREADY_EOS           = -12
	MA_AT_END                = 0x1
	MA_NOT_IMPLEMENTED       = -13
)

Variables

View Source
var ErrNilEngine = &EngineError{msg: "engine is nil"}

ErrNilEngine is returned when the engine is nil.

Functions

func ErrResult

func ErrResult(result C.ma_result) error

ErrResult converts a ma_result to a Go error.

Types

type AllocationCallbacks

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

func NewAllocationCallbacks

func NewAllocationCallbacks() *AllocationCallbacks

func (*AllocationCallbacks) Close

func (c *AllocationCallbacks) Close()

type Backend

type Backend int32

Backend represents available audio backends.

const (
	BackendNone        Backend = 0
	BackendWASAPI      Backend = 1 << 0
	BackendDirectSound Backend = 1 << 1
	BackendMME         Backend = 1 << 2
	BackendAudioIO     Backend = 1 << 3
	BackendPortAudio   Backend = 1 << 4
	BackendALSA        Backend = 1 << 5
	BackendPulseAudio  Backend = 1 << 6
	BackendCoreAudio   Backend = 1 << 7
	BackendJACK        Backend = 1 << 8
	BackendOSS         Backend = 1 << 9
	BackendNaCl        Backend = 1 << 10
)

type Channel

type Channel int32

Channel represents ma_channel enum values.

const (
	ChannelMono               Channel = 1
	ChannelFrontLeft          Channel = 2
	ChannelFrontRight         Channel = 3
	ChannelFrontCenter        Channel = 4
	ChannelBackCenter         Channel = 5
	ChannelBackLeft           Channel = 6
	ChannelBackRight          Channel = 7
	ChannelFrontLeftOfCenter  Channel = 8
	ChannelFrontRightOfCenter Channel = 9
	ChannelBackLeftOfCenter   Channel = 10
	ChannelBackRightOfCenter  Channel = 11
	ChannelSideLeft           Channel = 12
	ChannelSideRight          Channel = 13
	ChannelLFE1               Channel = 14
	ChannelStereoLeft         Channel = 15
	ChannelStereoRight        Channel = 16
)

type ChannelMixMode

type ChannelMixMode int32

ChannelMixMode represents ma_channel_mix_mode enum values.

const (
	ChannelMixModeDefault     ChannelMixMode = 0
	ChannelMixModeStrict      ChannelMixMode = 1
	ChannelMixModeAllowLosses ChannelMixMode = 2
)

type Context

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

Context wraps ma_context.

func NewContext

func NewContext(backends []C.ma_backend, config *ContextConfig) (*Context, error)

NewContext creates a new Context instance, initializes it with ma_context_init, and returns it. The backends parameter specifies which backends to use. If nil, miniaudio's default priorities are used. The config parameter can be nil for defaults.

func (*Context) Backend

func (c *Context) Backend() C.ma_backend

Backend returns the backend of the context.

func (*Context) Close

func (c *Context) Close()

Close uninitializes and releases the context memory.

func (*Context) Devices

func (c *Context) Devices() (playbackInfo unsafe.Pointer, playbackCount uint32, captureInfo unsafe.Pointer, captureCount uint32, err error)

Devices retrieves the devices from the context. It returns playback infos pointer, playback count, capture infos pointer, and capture count. Do not free the returned buffers as their memory is managed internally by miniaudio.

type ContextConfig

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

ContextConfig wraps ma_context_config.

func NewContextConfig

func NewContextConfig() *ContextConfig

NewContextConfig creates a new ContextConfig and calls ma_context_config_init.

func (*ContextConfig) AlsaUseVerboseDeviceEnumeration

func (cc *ContextConfig) AlsaUseVerboseDeviceEnumeration() bool

AlsaUseVerboseDeviceEnumeration returns whether verbose device enumeration is enabled for ALSA.

func (*ContextConfig) Close

func (cc *ContextConfig) Close()

func (*ContextConfig) CoreAudioNoAudioSessionActivate

func (cc *ContextConfig) CoreAudioNoAudioSessionActivate() bool

CoreAudioNoAudioSessionActivate returns whether audio session activation is disabled for iOS.

func (*ContextConfig) CoreAudioNoAudioSessionDeactivate

func (cc *ContextConfig) CoreAudioNoAudioSessionDeactivate() bool

CoreAudioNoAudioSessionDeactivate returns whether audio session deactivation is disabled for iOS.

func (*ContextConfig) CoreAudioSessionCategory

func (cc *ContextConfig) CoreAudioSessionCategory() C.ma_ios_session_category

CoreAudioSessionCategory returns the CoreAudio session category.

func (*ContextConfig) CoreAudioSessionCategoryOptions

func (cc *ContextConfig) CoreAudioSessionCategoryOptions() uint32

CoreAudioSessionCategoryOptions returns the CoreAudio session category options.

func (*ContextConfig) DSoundHWND

func (cc *ContextConfig) DSoundHWND() uintptr

DSoundHWND returns the Windows window handle for DirectSound.

func (*ContextConfig) JackClientName

func (cc *ContextConfig) JackClientName() string

JackClientName returns the JACK client name.

func (*ContextConfig) JackTryStartServer

func (cc *ContextConfig) JackTryStartServer() bool

JackTryStartServer returns whether auto-starting the server is enabled for JACK.

func (*ContextConfig) PLog

func (cc *ContextConfig) PLog() *Log

PLog returns the log pointer.

func (*ContextConfig) PUserData

func (cc *ContextConfig) PUserData() unsafe.Pointer

PUserData returns the user data pointer.

func (*ContextConfig) PulseApplicationName

func (cc *ContextConfig) PulseApplicationName() string

PulseApplicationName returns the PulseAudio application name.

func (*ContextConfig) PulseServerName

func (cc *ContextConfig) PulseServerName() string

PulseServerName returns the PulseAudio server name.

func (*ContextConfig) PulseTryAutoSpawn

func (cc *ContextConfig) PulseTryAutoSpawn() bool

PulseTryAutoSpawn returns whether auto-spawning is enabled for PulseAudio.

func (*ContextConfig) SetAlsaUseVerboseDeviceEnumeration

func (cc *ContextConfig) SetAlsaUseVerboseDeviceEnumeration(enabled bool)

SetAlsaUseVerboseDeviceEnumeration sets whether verbose device enumeration is enabled for ALSA.

func (*ContextConfig) SetCoreAudioNoAudioSessionActivate

func (cc *ContextConfig) SetCoreAudioNoAudioSessionActivate(disabled bool)

SetCoreAudioNoAudioSessionActivate sets whether audio session activation is disabled for iOS.

func (*ContextConfig) SetCoreAudioNoAudioSessionDeactivate

func (cc *ContextConfig) SetCoreAudioNoAudioSessionDeactivate(disabled bool)

SetCoreAudioNoAudioSessionDeactivate sets whether audio session deactivation is disabled for iOS.

func (*ContextConfig) SetCoreAudioSessionCategory

func (cc *ContextConfig) SetCoreAudioSessionCategory(category C.ma_ios_session_category)

SetCoreAudioSessionCategory sets the CoreAudio session category.

func (*ContextConfig) SetCoreAudioSessionCategoryOptions

func (cc *ContextConfig) SetCoreAudioSessionCategoryOptions(options uint32)

SetCoreAudioSessionCategoryOptions sets the CoreAudio session category options.

func (*ContextConfig) SetDSoundHWND

func (cc *ContextConfig) SetDSoundHWND(hWnd uintptr)

SetDSoundHWND sets the Windows window handle for DirectSound.

func (*ContextConfig) SetJackClientName

func (cc *ContextConfig) SetJackClientName(name string)

SetJackClientName sets the JACK client name.

func (*ContextConfig) SetJackTryStartServer

func (cc *ContextConfig) SetJackTryStartServer(enabled bool)

SetJackTryStartServer sets whether auto-starting the server is enabled for JACK.

func (*ContextConfig) SetPLog

func (cc *ContextConfig) SetPLog(log *Log)

SetPLog sets the log pointer.

func (*ContextConfig) SetPUserData

func (cc *ContextConfig) SetPUserData(userData unsafe.Pointer)

SetPUserData sets the user data pointer.

func (*ContextConfig) SetPulseApplicationName

func (cc *ContextConfig) SetPulseApplicationName(name string)

SetPulseApplicationName sets the PulseAudio application name.

func (*ContextConfig) SetPulseServerName

func (cc *ContextConfig) SetPulseServerName(name string)

SetPulseServerName sets the PulseAudio server name.

func (*ContextConfig) SetPulseTryAutoSpawn

func (cc *ContextConfig) SetPulseTryAutoSpawn(enabled bool)

SetPulseTryAutoSpawn sets whether auto-spawning is enabled for PulseAudio.

func (*ContextConfig) SetThreadPriority

func (cc *ContextConfig) SetThreadPriority(priority C.ma_thread_priority)

SetThreadPriority sets the thread priority.

func (*ContextConfig) SetThreadStackSize

func (cc *ContextConfig) SetThreadStackSize(size uint64)

SetThreadStackSize sets the thread stack size.

func (*ContextConfig) ThreadPriority

func (cc *ContextConfig) ThreadPriority() C.ma_thread_priority

ThreadPriority returns the thread priority.

func (*ContextConfig) ThreadStackSize

func (cc *ContextConfig) ThreadStackSize() uint64

ThreadStackSize returns the thread stack size.

type DataSource

type DataSource interface {
	// contains filtered or unexported methods
}

type Decoder

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

Decoder wraps ma_decoder.

func NewDecoderFromFile

func NewDecoderFromFile(filePath string, config *DecoderConfig) (*Decoder, error)

NewDecoderFromFile creates a new Decoder from a file path and initializes it with ma_decoder_init_file.

func NewDecoderFromMemory

func NewDecoderFromMemory(data []byte, config *DecoderConfig) (*Decoder, error)

NewDecoderFromMemory creates a new Decoder from a byte slice and initializes it with ma_decoder_init_memory.

func (*Decoder) Close

func (d *Decoder) Close()

Close uninitializes and releases the decoder memory.

func (*Decoder) LengthInPCMFrames

func (d *Decoder) LengthInPCMFrames() (uint64, error)

LengthInPCMFrames returns the length in PCM frames of the decoded data.

func (*Decoder) PositionInPCMFrames

func (d *Decoder) PositionInPCMFrames() (uint64, error)

PositionInPCMFrames returns the current position in PCM frames.

func (*Decoder) ReadPCMFrames

func (d *Decoder) ReadPCMFrames(framesOut []float32) (uint64, error)

ReadPCMFrames reads PCM frames from the decoder.

func (*Decoder) SeekToPCMFrame

func (d *Decoder) SeekToPCMFrame(frameNumber uint64) error

SeekToPCMFrame seeks to a specific PCM frame position.

type DecoderConfig

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

DecoderConfig wraps ma_decoder_config.

func NewDecoderConfig

func NewDecoderConfig(format Format, channels uint32, sampleRate uint32) *DecoderConfig

NewDecoderConfig creates a new DecoderConfig and calls ma_decoder_config_init.

func (*DecoderConfig) ChannelMixMode

func (dc *DecoderConfig) ChannelMixMode() ChannelMixMode

ChannelMixMode returns the channel mix mode.

func (*DecoderConfig) Channels

func (dc *DecoderConfig) Channels() uint32

Channels returns the output channel count.

func (*DecoderConfig) Close

func (dc *DecoderConfig) Close()

func (*DecoderConfig) CustomBackendCount

func (dc *DecoderConfig) CustomBackendCount() uint32

CustomBackendCount returns the custom backend count.

func (*DecoderConfig) DitherMode

func (dc *DecoderConfig) DitherMode() DitherMode

DitherMode returns the dither mode.

func (*DecoderConfig) EncodingFormat

func (dc *DecoderConfig) EncodingFormat() EncodingFormat

EncodingFormat returns the encoding format.

func (*DecoderConfig) Format

func (dc *DecoderConfig) Format() Format

Format returns the output format.

func (*DecoderConfig) PChannelMap

func (dc *DecoderConfig) PChannelMap() unsafe.Pointer

PChannelMap returns the channel map pointer.

func (*DecoderConfig) PCustomBackendUserData

func (dc *DecoderConfig) PCustomBackendUserData() unsafe.Pointer

PCustomBackendUserData returns the custom backend user data pointer.

func (*DecoderConfig) PPCustomBackendVTables

func (dc *DecoderConfig) PPCustomBackendVTables() unsafe.Pointer

PPCustomBackendVTables returns the custom backend vtable pointers.

func (*DecoderConfig) ResamplingChannels

func (dc *DecoderConfig) ResamplingChannels() uint32

ResamplingChannels returns the resampling channel count.

func (*DecoderConfig) ResamplingFormat

func (dc *DecoderConfig) ResamplingFormat() Format

ResamplingFormat returns the resampling format.

func (*DecoderConfig) ResamplingLPFOrder

func (dc *DecoderConfig) ResamplingLPFOrder() uint32

ResamplingLPFOrder returns the resampling LPF order.

func (*DecoderConfig) ResamplingSampleRateIn

func (dc *DecoderConfig) ResamplingSampleRateIn() uint32

ResamplingSampleRateIn returns the resampling input sample rate.

func (*DecoderConfig) ResamplingSampleRateOut

func (dc *DecoderConfig) ResamplingSampleRateOut() uint32

ResamplingSampleRateOut returns the resampling output sample rate.

func (*DecoderConfig) SampleRate

func (dc *DecoderConfig) SampleRate() uint32

SampleRate returns the output sample rate.

func (*DecoderConfig) SeekPointCount

func (dc *DecoderConfig) SeekPointCount() uint32

SeekPointCount returns the seek point count.

func (*DecoderConfig) SetChannelMixMode

func (dc *DecoderConfig) SetChannelMixMode(mode ChannelMixMode)

SetChannelMixMode sets the channel mix mode.

func (*DecoderConfig) SetChannels

func (dc *DecoderConfig) SetChannels(channels uint32)

SetChannels sets the output channel count.

func (*DecoderConfig) SetCustomBackendCount

func (dc *DecoderConfig) SetCustomBackendCount(count uint32)

SetCustomBackendCount sets the custom backend count.

func (*DecoderConfig) SetDitherMode

func (dc *DecoderConfig) SetDitherMode(mode DitherMode)

SetDitherMode sets the dither mode.

func (*DecoderConfig) SetEncodingFormat

func (dc *DecoderConfig) SetEncodingFormat(format EncodingFormat)

SetEncodingFormat sets the encoding format.

func (*DecoderConfig) SetFormat

func (dc *DecoderConfig) SetFormat(format Format)

SetFormat sets the output format.

func (*DecoderConfig) SetPChannelMap

func (dc *DecoderConfig) SetPChannelMap(channelMap unsafe.Pointer)

SetPChannelMap sets the channel map pointer.

func (*DecoderConfig) SetPCustomBackendUserData

func (dc *DecoderConfig) SetPCustomBackendUserData(userData unsafe.Pointer)

SetPCustomBackendUserData sets the custom backend user data pointer.

func (*DecoderConfig) SetPPCustomBackendVTables

func (dc *DecoderConfig) SetPPCustomBackendVTables(vtables unsafe.Pointer)

SetPPCustomBackendVTables sets the custom backend vtable pointers.

func (*DecoderConfig) SetResamplingChannels

func (dc *DecoderConfig) SetResamplingChannels(channels uint32)

SetResamplingChannels sets the resampling channel count.

func (*DecoderConfig) SetResamplingFormat

func (dc *DecoderConfig) SetResamplingFormat(format Format)

SetResamplingFormat sets the resampling format.

func (*DecoderConfig) SetResamplingLPFOrder

func (dc *DecoderConfig) SetResamplingLPFOrder(order uint32)

SetResamplingLPFOrder sets the resampling LPF order.

func (*DecoderConfig) SetResamplingSampleRateIn

func (dc *DecoderConfig) SetResamplingSampleRateIn(sampleRateIn uint32)

SetResamplingSampleRateIn sets the resampling input sample rate.

func (*DecoderConfig) SetResamplingSampleRateOut

func (dc *DecoderConfig) SetResamplingSampleRateOut(sampleRateOut uint32)

SetResamplingSampleRateOut sets the resampling output sample rate.

func (*DecoderConfig) SetSampleRate

func (dc *DecoderConfig) SetSampleRate(sampleRate uint32)

SetSampleRate sets the output sample rate.

func (*DecoderConfig) SetSeekPointCount

func (dc *DecoderConfig) SetSeekPointCount(count uint32)

SetSeekPointCount sets the seek point count.

type Device

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

Device wraps ma_device.

func NewDevice

func NewDevice(backends []C.ma_backend, config *DeviceConfig) (*Device, error)

NewDevice creates a new Device instance without a context, initializes it with ma_device_init_ex, and returns it.

func NewDeviceWithContext

func NewDeviceWithContext(ctx *Context, config *DeviceConfig) (*Device, error)

NewDeviceWithContext creates a new Device instance using the given context, initializes it with ma_device_init, and returns it.

func (*Device) CaptureChannels

func (d *Device) CaptureChannels() uint32

CaptureChannels returns the capture channel count of the device.

func (*Device) CaptureFormat

func (d *Device) CaptureFormat() Format

CaptureFormat returns the capture format of the device.

func (*Device) CaptureSampleRate

func (d *Device) CaptureSampleRate() uint32

CaptureSampleRate returns the capture sample rate of the device.

func (*Device) Channels

func (d *Device) Channels() uint32

Channels returns the playback channel count of the device.

func (*Device) Close

func (d *Device) Close()

Close uninitializes and releases the device memory.

func (*Device) Context

func (d *Device) Context() *Context

Context returns the context of the device.

func (*Device) Format

func (d *Device) Format() Format

Format returns the playback format of the device.

func (*Device) GetSampleRate

func (d *Device) GetSampleRate() uint32

GetSampleRate returns the sample rate of the device.

func (*Device) Start

func (d *Device) Start() error

Start starts the device.

func (*Device) Stop

func (d *Device) Stop() error

Stop stops the device.

type DeviceConfig

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

DeviceConfig wraps ma_device_config.

func NewDeviceConfig

func NewDeviceConfig(deviceType DeviceType) *DeviceConfig

NewDeviceConfig creates a new DeviceConfig and calls ma_device_config_init with the given device type.

func (*DeviceConfig) AaudioAllowSetBufferCapacity

func (dc *DeviceConfig) AaudioAllowSetBufferCapacity() bool

AaudioAllowSetBufferCapacity returns whether setting buffer capacity is allowed for AAudio.

func (*DeviceConfig) AaudioAllowedCapturePolicy

func (dc *DeviceConfig) AaudioAllowedCapturePolicy() C.ma_aaudio_allowed_capture_policy

AaudioAllowedCapturePolicy returns the AAudio allowed capture policy.

func (*DeviceConfig) AaudioContentType

func (dc *DeviceConfig) AaudioContentType() C.ma_aaudio_content_type

AaudioContentType returns the AAudio content type.

func (*DeviceConfig) AaudioEnableCompatibilityWorkarounds

func (dc *DeviceConfig) AaudioEnableCompatibilityWorkarounds() bool

AaudioEnableCompatibilityWorkarounds returns whether compatibility workarounds are enabled for AAudio.

func (*DeviceConfig) AaudioInputPreset

func (dc *DeviceConfig) AaudioInputPreset() C.ma_aaudio_input_preset

AaudioInputPreset returns the AAudio input preset.

func (*DeviceConfig) AaudioNoAutoStartAfterReroute

func (dc *DeviceConfig) AaudioNoAutoStartAfterReroute() bool

AaudioNoAutoStartAfterReroute returns whether auto start after reroute is disabled for AAudio.

func (*DeviceConfig) AaudioUsage

func (dc *DeviceConfig) AaudioUsage() C.ma_aaudio_usage

AaudioUsage returns the AAudio usage.

func (*DeviceConfig) AlsaNoAutoChannels

func (dc *DeviceConfig) AlsaNoAutoChannels() bool

AlsaNoAutoChannels returns whether auto channels is disabled for ALSA.

func (*DeviceConfig) AlsaNoAutoFormat

func (dc *DeviceConfig) AlsaNoAutoFormat() bool

AlsaNoAutoFormat returns whether auto format is disabled for ALSA.

func (*DeviceConfig) AlsaNoAutoResample

func (dc *DeviceConfig) AlsaNoAutoResample() bool

AlsaNoAutoResample returns whether auto resample is disabled for ALSA.

func (*DeviceConfig) AlsaNoMMap

func (dc *DeviceConfig) AlsaNoMMap() bool

AlsaNoMMap returns whether MMap is disabled for ALSA.

func (*DeviceConfig) CaptureCalculateLFEFromSpatialChannels

func (dc *DeviceConfig) CaptureCalculateLFEFromSpatialChannels() bool

CaptureCalculateLFEFromSpatialChannels returns whether LFE calculation from spatial channels is enabled.

func (*DeviceConfig) CaptureChannelMixMode

func (dc *DeviceConfig) CaptureChannelMixMode() ChannelMixMode

CaptureChannelMixMode returns the capture channel mix mode.

func (*DeviceConfig) CaptureChannels

func (dc *DeviceConfig) CaptureChannels() uint32

CaptureChannels returns the capture channel count.

func (*DeviceConfig) CaptureDeviceID

func (dc *DeviceConfig) CaptureDeviceID() *DeviceID

CaptureDeviceID returns the capture device ID.

func (*DeviceConfig) CaptureFormat

func (dc *DeviceConfig) CaptureFormat() Format

CaptureFormat returns the capture format.

func (*DeviceConfig) CapturePChannelMap

func (dc *DeviceConfig) CapturePChannelMap() unsafe.Pointer

CapturePChannelMap returns the capture channel map pointer.

func (*DeviceConfig) CaptureShareMode

func (dc *DeviceConfig) CaptureShareMode() C.ma_share_mode

CaptureShareMode returns the capture share mode.

func (*DeviceConfig) Close

func (dc *DeviceConfig) Close()

func (*DeviceConfig) CoreaudioAllowNominalSampleRateChange

func (dc *DeviceConfig) CoreaudioAllowNominalSampleRateChange() bool

CoreaudioAllowNominalSampleRateChange returns whether nominal sample rate change is allowed for CoreAudio.

func (*DeviceConfig) DataCallback

func (dc *DeviceConfig) DataCallback() C.ma_device_data_proc

DataCallback returns the data callback.

func (*DeviceConfig) NoClip

func (dc *DeviceConfig) NoClip() bool

NoClip returns whether clipping is disabled.

func (*DeviceConfig) NoDisableDenormals

func (dc *DeviceConfig) NoDisableDenormals() bool

NoDisableDenormals returns whether denormal disabling is disabled.

func (*DeviceConfig) NoFixedSizedCallback

func (dc *DeviceConfig) NoFixedSizedCallback() bool

NoFixedSizedCallback returns whether fixed-sized callback disabling is enabled.

func (*DeviceConfig) NoPreSilencedOutputBuffer

func (dc *DeviceConfig) NoPreSilencedOutputBuffer() bool

NoPreSilencedOutputBuffer returns whether pre-silencing of output buffer is disabled.

func (*DeviceConfig) NotificationCallback

func (dc *DeviceConfig) NotificationCallback() C.ma_device_notification_proc

NotificationCallback returns the notification callback.

func (*DeviceConfig) OpenslEnableCompatibilityWorkarounds

func (dc *DeviceConfig) OpenslEnableCompatibilityWorkarounds() bool

OpenslEnableCompatibilityWorkarounds returns whether compatibility workarounds are enabled for OpenSL.

func (*DeviceConfig) OpenslRecordingPreset

func (dc *DeviceConfig) OpenslRecordingPreset() C.ma_opensl_recording_preset

OpenslRecordingPreset returns the OpenSL recording preset.

func (*DeviceConfig) OpenslStreamType

func (dc *DeviceConfig) OpenslStreamType() C.ma_opensl_stream_type

OpenslStreamType returns the OpenSL stream type.

func (*DeviceConfig) PUserData

func (dc *DeviceConfig) PUserData() unsafe.Pointer

PUserData returns the user data pointer.

func (*DeviceConfig) PerformanceProfile

func (dc *DeviceConfig) PerformanceProfile() C.ma_performance_profile

PerformanceProfile returns the performance profile.

func (*DeviceConfig) PeriodSizeInFrames

func (dc *DeviceConfig) PeriodSizeInFrames() uint32

PeriodSizeInFrames returns the period size in frames.

func (*DeviceConfig) PeriodSizeInMilliseconds

func (dc *DeviceConfig) PeriodSizeInMilliseconds() uint32

PeriodSizeInMilliseconds returns the period size in milliseconds.

func (*DeviceConfig) Periods

func (dc *DeviceConfig) Periods() uint32

Periods returns the periods count.

func (*DeviceConfig) PlaybackCalculateLFEFromSpatialChannels

func (dc *DeviceConfig) PlaybackCalculateLFEFromSpatialChannels() bool

PlaybackCalculateLFEFromSpatialChannels returns whether LFE calculation from spatial channels is enabled.

func (*DeviceConfig) PlaybackChannelMixMode

func (dc *DeviceConfig) PlaybackChannelMixMode() ChannelMixMode

PlaybackChannelMixMode returns the playback channel mix mode.

func (*DeviceConfig) PlaybackChannels

func (dc *DeviceConfig) PlaybackChannels() uint32

PlaybackChannels returns the playback channel count.

func (*DeviceConfig) PlaybackDeviceID

func (dc *DeviceConfig) PlaybackDeviceID() *DeviceID

PlaybackDeviceID returns the playback device ID.

func (*DeviceConfig) PlaybackFormat

func (dc *DeviceConfig) PlaybackFormat() Format

PlaybackFormat returns the playback format.

func (*DeviceConfig) PlaybackPChannelMap

func (dc *DeviceConfig) PlaybackPChannelMap() unsafe.Pointer

PlaybackPChannelMap returns the playback channel map pointer.

func (*DeviceConfig) PlaybackShareMode

func (dc *DeviceConfig) PlaybackShareMode() C.ma_share_mode

PlaybackShareMode returns the playback share mode.

func (*DeviceConfig) PulseChannelMap

func (dc *DeviceConfig) PulseChannelMap() int32

PulseChannelMap returns the PulseAudio channel map setting.

func (*DeviceConfig) PulseStreamNameCapture

func (dc *DeviceConfig) PulseStreamNameCapture() string

PulseStreamNameCapture returns the PulseAudio capture stream name.

func (*DeviceConfig) PulseStreamNamePlayback

func (dc *DeviceConfig) PulseStreamNamePlayback() string

PulseStreamNamePlayback returns the PulseAudio playback stream name.

func (*DeviceConfig) SampleRate

func (dc *DeviceConfig) SampleRate() uint32

SampleRate returns the sample rate.

func (*DeviceConfig) SetAaudioAllowSetBufferCapacity

func (dc *DeviceConfig) SetAaudioAllowSetBufferCapacity(allowed bool)

SetAaudioAllowSetBufferCapacity sets whether setting buffer capacity is allowed for AAudio.

func (*DeviceConfig) SetAaudioAllowedCapturePolicy

func (dc *DeviceConfig) SetAaudioAllowedCapturePolicy(policy C.ma_aaudio_allowed_capture_policy)

SetAaudioAllowedCapturePolicy sets the AAudio allowed capture policy.

func (*DeviceConfig) SetAaudioContentType

func (dc *DeviceConfig) SetAaudioContentType(contentType C.ma_aaudio_content_type)

SetAaudioContentType sets the AAudio content type.

func (*DeviceConfig) SetAaudioEnableCompatibilityWorkarounds

func (dc *DeviceConfig) SetAaudioEnableCompatibilityWorkarounds(enabled bool)

SetAaudioEnableCompatibilityWorkarounds sets whether compatibility workarounds are enabled for AAudio.

func (*DeviceConfig) SetAaudioInputPreset

func (dc *DeviceConfig) SetAaudioInputPreset(preset C.ma_aaudio_input_preset)

SetAaudioInputPreset sets the AAudio input preset.

func (*DeviceConfig) SetAaudioNoAutoStartAfterReroute

func (dc *DeviceConfig) SetAaudioNoAutoStartAfterReroute(disabled bool)

SetAaudioNoAutoStartAfterReroute sets whether auto start after reroute is disabled for AAudio.

func (*DeviceConfig) SetAaudioUsage

func (dc *DeviceConfig) SetAaudioUsage(usage C.ma_aaudio_usage)

SetAaudioUsage sets the AAudio usage.

func (*DeviceConfig) SetAlsaNoAutoChannels

func (dc *DeviceConfig) SetAlsaNoAutoChannels(disabled bool)

SetAlsaNoAutoChannels sets whether auto channels is disabled for ALSA.

func (*DeviceConfig) SetAlsaNoAutoFormat

func (dc *DeviceConfig) SetAlsaNoAutoFormat(disabled bool)

SetAlsaNoAutoFormat sets whether auto format is disabled for ALSA.

func (*DeviceConfig) SetAlsaNoAutoResample

func (dc *DeviceConfig) SetAlsaNoAutoResample(disabled bool)

SetAlsaNoAutoResample sets whether auto resample is disabled for ALSA.

func (*DeviceConfig) SetAlsaNoMMap

func (dc *DeviceConfig) SetAlsaNoMMap(disabled bool)

SetAlsaNoMMap sets whether MMap is disabled for ALSA.

func (*DeviceConfig) SetCaptureCalculateLFEFromSpatialChannels

func (dc *DeviceConfig) SetCaptureCalculateLFEFromSpatialChannels(enabled bool)

SetCaptureCalculateLFEFromSpatialChannels sets whether LFE calculation from spatial channels is enabled.

func (*DeviceConfig) SetCaptureChannelMixMode

func (dc *DeviceConfig) SetCaptureChannelMixMode(mode ChannelMixMode)

SetCaptureChannelMixMode sets the capture channel mix mode.

func (*DeviceConfig) SetCaptureChannels

func (dc *DeviceConfig) SetCaptureChannels(channels uint32)

SetCaptureChannels sets the capture channel count.

func (*DeviceConfig) SetCaptureDeviceID

func (dc *DeviceConfig) SetCaptureDeviceID(id *DeviceID)

SetCaptureDeviceID sets the capture device ID.

func (*DeviceConfig) SetCaptureFormat

func (dc *DeviceConfig) SetCaptureFormat(format Format)

SetCaptureFormat sets the capture format.

func (*DeviceConfig) SetCapturePChannelMap

func (dc *DeviceConfig) SetCapturePChannelMap(channelMap unsafe.Pointer)

SetCapturePChannelMap sets the capture channel map pointer.

func (*DeviceConfig) SetCaptureShareMode

func (dc *DeviceConfig) SetCaptureShareMode(mode C.ma_share_mode)

SetCaptureShareMode sets the capture share mode.

func (*DeviceConfig) SetCoreaudioAllowNominalSampleRateChange

func (dc *DeviceConfig) SetCoreaudioAllowNominalSampleRateChange(allowed bool)

SetCoreaudioAllowNominalSampleRateChange sets whether nominal sample rate change is allowed for CoreAudio.

func (*DeviceConfig) SetDataCallback

func (dc *DeviceConfig) SetDataCallback(callback C.ma_device_data_proc)

SetDataCallback sets the data callback.

func (*DeviceConfig) SetNoClip

func (dc *DeviceConfig) SetNoClip(disabled bool)

SetNoClip sets whether clipping is disabled.

func (*DeviceConfig) SetNoDisableDenormals

func (dc *DeviceConfig) SetNoDisableDenormals(disabled bool)

SetNoDisableDenormals sets whether denormal disabling is disabled.

func (*DeviceConfig) SetNoFixedSizedCallback

func (dc *DeviceConfig) SetNoFixedSizedCallback(enabled bool)

SetNoFixedSizedCallback sets whether fixed-sized callback disabling is enabled.

func (*DeviceConfig) SetNoPreSilencedOutputBuffer

func (dc *DeviceConfig) SetNoPreSilencedOutputBuffer(disabled bool)

SetNoPreSilencedOutputBuffer sets whether pre-silencing of output buffer is disabled.

func (*DeviceConfig) SetNotificationCallback

func (dc *DeviceConfig) SetNotificationCallback(callback C.ma_device_notification_proc)

SetNotificationCallback sets the notification callback.

func (*DeviceConfig) SetOpenslEnableCompatibilityWorkarounds

func (dc *DeviceConfig) SetOpenslEnableCompatibilityWorkarounds(enabled bool)

SetOpenslEnableCompatibilityWorkarounds sets whether compatibility workarounds are enabled for OpenSL.

func (*DeviceConfig) SetOpenslRecordingPreset

func (dc *DeviceConfig) SetOpenslRecordingPreset(preset C.ma_opensl_recording_preset)

SetOpenslRecordingPreset sets the OpenSL recording preset.

func (*DeviceConfig) SetOpenslStreamType

func (dc *DeviceConfig) SetOpenslStreamType(streamType C.ma_opensl_stream_type)

SetOpenslStreamType sets the OpenSL stream type.

func (*DeviceConfig) SetPUserData

func (dc *DeviceConfig) SetPUserData(userData unsafe.Pointer)

SetPUserData sets the user data pointer.

func (*DeviceConfig) SetPerformanceProfile

func (dc *DeviceConfig) SetPerformanceProfile(profile C.ma_performance_profile)

SetPerformanceProfile sets the performance profile.

func (*DeviceConfig) SetPeriodSizeInFrames

func (dc *DeviceConfig) SetPeriodSizeInFrames(periodSize uint32)

SetPeriodSizeInFrames sets the period size in frames.

func (*DeviceConfig) SetPeriodSizeInMilliseconds

func (dc *DeviceConfig) SetPeriodSizeInMilliseconds(periodSize uint32)

SetPeriodSizeInMilliseconds sets the period size in milliseconds.

func (*DeviceConfig) SetPeriods

func (dc *DeviceConfig) SetPeriods(periods uint32)

SetPeriods sets the periods count.

func (*DeviceConfig) SetPlaybackCalculateLFEFromSpatialChannels

func (dc *DeviceConfig) SetPlaybackCalculateLFEFromSpatialChannels(enabled bool)

SetPlaybackCalculateLFEFromSpatialChannels sets whether LFE calculation from spatial channels is enabled.

func (*DeviceConfig) SetPlaybackChannelMixMode

func (dc *DeviceConfig) SetPlaybackChannelMixMode(mode ChannelMixMode)

SetPlaybackChannelMixMode sets the playback channel mix mode.

func (*DeviceConfig) SetPlaybackChannels

func (dc *DeviceConfig) SetPlaybackChannels(channels uint32)

SetPlaybackChannels sets the playback channel count.

func (*DeviceConfig) SetPlaybackDeviceID

func (dc *DeviceConfig) SetPlaybackDeviceID(id *DeviceID)

SetPlaybackDeviceID sets the playback device ID.

func (*DeviceConfig) SetPlaybackFormat

func (dc *DeviceConfig) SetPlaybackFormat(format Format)

SetPlaybackFormat sets the playback format.

func (*DeviceConfig) SetPlaybackPChannelMap

func (dc *DeviceConfig) SetPlaybackPChannelMap(channelMap unsafe.Pointer)

SetPlaybackPChannelMap sets the playback channel map pointer.

func (*DeviceConfig) SetPlaybackShareMode

func (dc *DeviceConfig) SetPlaybackShareMode(mode C.ma_share_mode)

SetPlaybackShareMode sets the playback share mode.

func (*DeviceConfig) SetPulseChannelMap

func (dc *DeviceConfig) SetPulseChannelMap(channelMap int32)

SetPulseChannelMap sets the PulseAudio channel map setting.

func (*DeviceConfig) SetPulseStreamNameCapture

func (dc *DeviceConfig) SetPulseStreamNameCapture(name string)

SetPulseStreamNameCapture sets the PulseAudio capture stream name.

func (*DeviceConfig) SetPulseStreamNamePlayback

func (dc *DeviceConfig) SetPulseStreamNamePlayback(name string)

SetPulseStreamNamePlayback sets the PulseAudio playback stream name.

func (*DeviceConfig) SetSampleRate

func (dc *DeviceConfig) SetSampleRate(sampleRate uint32)

SetSampleRate sets the sample rate.

func (*DeviceConfig) SetStopCallback

func (dc *DeviceConfig) SetStopCallback(callback C.ma_stop_proc)

SetStopCallback sets the stop callback.

func (*DeviceConfig) SetWasapiLoopbackProcessID

func (dc *DeviceConfig) SetWasapiLoopbackProcessID(id uint32)

SetWasapiLoopbackProcessID sets the WASAPI loopback process ID.

func (*DeviceConfig) SetWasapiNoAutoConvertSRC

func (dc *DeviceConfig) SetWasapiNoAutoConvertSRC(disabled bool)

SetWasapiNoAutoConvertSRC sets whether auto-convert SRC is disabled for WASAPI.

func (*DeviceConfig) SetWasapiNoDefaultQualitySRC

func (dc *DeviceConfig) SetWasapiNoDefaultQualitySRC(disabled bool)

SetWasapiNoDefaultQualitySRC sets whether default quality SRC is disabled for WASAPI.

func (*DeviceConfig) SetWasapiNoHardwareOffloading

func (dc *DeviceConfig) SetWasapiNoHardwareOffloading(disabled bool)

SetWasapiNoHardwareOffloading sets whether hardware offloading is disabled for WASAPI.

func (*DeviceConfig) StopCallback

func (dc *DeviceConfig) StopCallback() C.ma_stop_proc

StopCallback returns the stop callback.

func (*DeviceConfig) WasapiLoopbackProcessID

func (dc *DeviceConfig) WasapiLoopbackProcessID() uint32

WasapiLoopbackProcessID returns the WASAPI loopback process ID.

func (*DeviceConfig) WasapiNoAutoConvertSRC

func (dc *DeviceConfig) WasapiNoAutoConvertSRC() bool

WasapiNoAutoConvertSRC returns whether auto-convert SRC is disabled for WASAPI.

func (*DeviceConfig) WasapiNoDefaultQualitySRC

func (dc *DeviceConfig) WasapiNoDefaultQualitySRC() bool

WasapiNoDefaultQualitySRC returns whether default quality SRC is disabled for WASAPI.

func (*DeviceConfig) WasapiNoHardwareOffloading

func (dc *DeviceConfig) WasapiNoHardwareOffloading() bool

WasapiNoHardwareOffloading returns whether hardware offloading is disabled for WASAPI.

type DeviceDirection

type DeviceDirection int32

DeviceDirection represents ma_device_direction enum values.

const (
	DeviceDirectionPlayback DeviceDirection = 1 << 0
	DeviceDirectionCapture  DeviceDirection = 1 << 1
)

type DeviceID

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

type DeviceType

type DeviceType int32

DeviceType represents ma_device_type enum values.

const (
	DeviceTypePlayback DeviceType = 1 << 0
	DeviceTypeCapture  DeviceType = 1 << 1
	DeviceTypeDuplex   DeviceType = 1 << 2
	DeviceTypeLoopback DeviceType = 1 << 3
)

type DitherMode

type DitherMode int32

DitherMode represents ma_dither_mode enum values.

const (
	DitherModeNone        DitherMode = 0
	DitherModeRectangular DitherMode = 1
)

type EncodingFormat

type EncodingFormat int32

EncodingFormat represents ma_encoding_format enum values.

const (
	EncodingFormatUnknown EncodingFormat = 0
	EncodingFormatWav     EncodingFormat = 1
	EncodingFormatAiff    EncodingFormat = 2
)

type Engine

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

Engine is a high-level audio engine that wraps around the resource manager and node graph.

func NewEngine

func NewEngine(config *EngineConfig) (*Engine, error)

NewEngine creates a new Engine instance, initializes it with ma_engine_init, and returns it.

func (*Engine) Channels

func (e *Engine) Channels() uint32

Channels returns the number of channels of the engine.

func (*Engine) Close

func (e *Engine) Close()

Close uninitializes and releases the engine memory.

func (*Engine) CopySound

func (e *Engine) CopySound(existing *Sound, flags SoundFlags, group *Sound) (*Sound, error)

CopySound creates a copy of an existing sound.

func (*Engine) Endpoint

func (e *Engine) Endpoint() *Node

Endpoint returns the endpoint node.

func (*Engine) FindClosestListener

func (e *Engine) FindClosestListener(x, y, z float32) uint32

FindClosestListener finds the closest listener to the given position.

func (*Engine) GainDB

func (e *Engine) GainDB() float32

GainDB returns the engine gain in dB.

func (*Engine) GetDevice

func (e *Engine) GetDevice() *C.ma_device

GetDevice returns the underlying device.

func (*Engine) ListenerCone

func (e *Engine) ListenerCone(listenerIndex uint32) (innerAngle, outerAngle, outerGain float32)

ListenerCone returns the cone of the listener.

func (*Engine) ListenerCount

func (e *Engine) ListenerCount() uint32

ListenerCount returns the number of listeners.

func (*Engine) ListenerDirection

func (e *Engine) ListenerDirection(listenerIndex uint32) (x, y, z float32)

ListenerDirection returns the direction of the listener.

func (*Engine) ListenerIsEnabled

func (e *Engine) ListenerIsEnabled(listenerIndex uint32) bool

ListenerIsEnabled returns whether the listener is enabled.

func (*Engine) ListenerPosition

func (e *Engine) ListenerPosition(listenerIndex uint32) (x, y, z float32)

ListenerPosition returns the position of the listener.

func (*Engine) ListenerSetCone

func (e *Engine) ListenerSetCone(listenerIndex uint32, innerAngle, outerAngle, outerGain float32) error

ListenerSetCone sets the cone of the listener.

func (*Engine) ListenerSetDirection

func (e *Engine) ListenerSetDirection(listenerIndex uint32, x, y, z float32) error

ListenerSetDirection sets the direction of the listener.

func (*Engine) ListenerSetEnabled

func (e *Engine) ListenerSetEnabled(listenerIndex uint32, enabled bool) error

ListenerSetEnabled enables or disables the listener.

func (*Engine) ListenerSetPosition

func (e *Engine) ListenerSetPosition(listenerIndex uint32, x, y, z float32) error

ListenerSetPosition sets the position of the listener.

func (*Engine) ListenerSetVelocity

func (e *Engine) ListenerSetVelocity(listenerIndex uint32, x, y, z float32) error

ListenerSetVelocity sets the velocity of the listener (for Doppler effect).

func (*Engine) ListenerSetWorldUp

func (e *Engine) ListenerSetWorldUp(listenerIndex uint32, x, y, z float32) error

ListenerSetWorldUp sets the world up vector of the listener.

func (*Engine) ListenerVelocity

func (e *Engine) ListenerVelocity(listenerIndex uint32) (x, y, z float32)

ListenerVelocity returns the velocity of the listener.

func (*Engine) Log

func (e *Engine) Log() *C.ma_log

Log returns the underlying log.

func (*Engine) NodeGraph

func (e *Engine) NodeGraph() *C.ma_node_graph

NodeGraph returns the underlying node graph.

func (*Engine) PlaySound

func (e *Engine) PlaySound(filePath string) error

PlaySound plays a sound with the given file path.

func (*Engine) PlaySoundEx

func (e *Engine) PlaySoundEx(filePath string, pNode *Node, nodeInputBusIndex uint32) error

PlaySoundEx plays a sound with the given file path, parent node, and input bus index.

func (*Engine) PlaySoundFromDataSource

func (e *Engine) PlaySoundFromDataSource(dataSource DataSource, flags SoundFlags, group *Sound) (*Sound, error)

PlaySoundFromDataSource creates and starts a sound from a data source.

func (*Engine) PlaySoundFromFile

func (e *Engine) PlaySoundFromFile(filePath string, flags SoundFlags, group *Sound, doneFence unsafe.Pointer) (*Sound, error)

PlaySoundFromFile creates and starts a sound from a file path.

func (*Engine) ReadPCMFrames

func (e *Engine) ReadPCMFrames(frameCount uint64, pFramesOut []float32) (framesRead uint64, err error)

ReadPCMFrames reads PCM frames from the engine.

func (*Engine) ResourceManager

func (e *Engine) ResourceManager() *C.ma_resource_manager

ResourceManager returns the underlying resource manager.

func (*Engine) SampleRate

func (e *Engine) SampleRate() uint32

SampleRate returns the sample rate of the engine.

func (*Engine) SetGainDB

func (e *Engine) SetGainDB(gainDB float32) error

SetGainDB sets the engine gain in dB.

func (*Engine) SetTime

func (e *Engine) SetTime(time uint64) error

SetTime sets the global time in PCM frames (deprecated).

func (*Engine) SetTimeInMilliseconds

func (e *Engine) SetTimeInMilliseconds(time uint64) error

SetTimeInMilliseconds sets the current global time in milliseconds.

func (*Engine) SetTimeInPCMFrames

func (e *Engine) SetTimeInPCMFrames(time uint64) error

SetTimeInPCMFrames sets the current global time in PCM frames.

func (*Engine) SetVolume

func (e *Engine) SetVolume(volume float32) error

SetVolume sets the engine volume.

func (*Engine) Start

func (e *Engine) Start() error

Start starts the engine.

func (*Engine) Stop

func (e *Engine) Stop() error

Stop stops the engine.

func (*Engine) Time

func (e *Engine) Time() uint64

Time returns the current global time in PCM frames (deprecated).

func (*Engine) TimeInMilliseconds

func (e *Engine) TimeInMilliseconds() uint64

TimeInMilliseconds returns the current global time in milliseconds.

func (*Engine) TimeInPCMFrames

func (e *Engine) TimeInPCMFrames() uint64

TimeInPCMFrames returns the current global time in PCM frames.

func (*Engine) Volume

func (e *Engine) Volume() float32

Volume returns the engine volume.

type EngineConfig

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

EngineConfig wraps ma_engine_config.

func NewEngineConfig

func NewEngineConfig() *EngineConfig

NewEngineConfig creates a new EngineConfig and calls ma_engine_config_init.

func (*EngineConfig) Channels

func (ec *EngineConfig) Channels() uint32

Channels returns the channel count.

func (*EngineConfig) Close

func (ec *EngineConfig) Close()

func (*EngineConfig) DataCallback

func (ec *EngineConfig) DataCallback() C.ma_device_data_proc

DataCallback returns the data callback.

func (*EngineConfig) DefaultVolumeSmoothTimeInPCMFrames

func (ec *EngineConfig) DefaultVolumeSmoothTimeInPCMFrames() uint32

DefaultVolumeSmoothTimeInPCMFrames returns the default volume smooth time in PCM frames.

func (*EngineConfig) GainSmoothTimeInFrames

func (ec *EngineConfig) GainSmoothTimeInFrames() uint32

GainSmoothTimeInFrames returns the gain smooth time in frames.

func (*EngineConfig) GainSmoothTimeInMilliseconds

func (ec *EngineConfig) GainSmoothTimeInMilliseconds() uint32

GainSmoothTimeInMilliseconds returns the gain smooth time in milliseconds.

func (*EngineConfig) ListenerCount

func (ec *EngineConfig) ListenerCount() uint32

ListenerCount returns the listener count.

func (*EngineConfig) MonoExpansionMode

func (ec *EngineConfig) MonoExpansionMode() uint32

MonoExpansionMode returns the mono expansion mode.

func (*EngineConfig) NoAutoStart

func (ec *EngineConfig) NoAutoStart() bool

NoAutoStart returns whether auto start is disabled.

func (*EngineConfig) NoDevice

func (ec *EngineConfig) NoDevice() bool

NoDevice returns whether device creation is disabled.

func (*EngineConfig) NotificationCallback

func (ec *EngineConfig) NotificationCallback() C.ma_device_notification_proc

NotificationCallback returns the notification callback.

func (*EngineConfig) OnProcess

func (ec *EngineConfig) OnProcess() C.ma_engine_process_proc

OnProcess returns the on process callback.

func (*EngineConfig) PContext

func (ec *EngineConfig) PContext() *Context

PContext returns the context pointer.

func (*EngineConfig) PDevice

func (ec *EngineConfig) PDevice() *Device

PDevice returns the device pointer.

func (*EngineConfig) PLog

func (ec *EngineConfig) PLog() *Log

PLog returns the log pointer.

func (*EngineConfig) PProcessUserData

func (ec *EngineConfig) PProcessUserData() unsafe.Pointer

PProcessUserData returns the user data for onProcess.

func (*EngineConfig) PaymentDeviceID

func (ec *EngineConfig) PaymentDeviceID() *DeviceID

PaymentDeviceID returns the playback device ID pointer.

func (*EngineConfig) PeriodSizeInFrames

func (ec *EngineConfig) PeriodSizeInFrames() uint32

PeriodSizeInFrames returns the period size in frames.

func (*EngineConfig) PeriodSizeInMilliseconds

func (ec *EngineConfig) PeriodSizeInMilliseconds() uint32

PeriodSizeInMilliseconds returns the period size in milliseconds.

func (*EngineConfig) PreMixStackSizeInBytes

func (ec *EngineConfig) PreMixStackSizeInBytes() uint32

PreMixStackSizeInBytes returns the pre-mix stack size in bytes.

func (*EngineConfig) SampleRate

func (ec *EngineConfig) SampleRate() uint32

SampleRate returns the sample rate.

func (*EngineConfig) SetChannels

func (ec *EngineConfig) SetChannels(channels uint32)

SetChannels sets the channel count.

func (*EngineConfig) SetDataCallback

func (ec *EngineConfig) SetDataCallback(callback C.ma_device_data_proc)

SetDataCallback sets the data callback.

func (*EngineConfig) SetDefaultVolumeSmoothTimeInPCMFrames

func (ec *EngineConfig) SetDefaultVolumeSmoothTimeInPCMFrames(frames uint32)

SetDefaultVolumeSmoothTimeInPCMFrames sets the default volume smooth time in PCM frames.

func (*EngineConfig) SetGainSmoothTimeInFrames

func (ec *EngineConfig) SetGainSmoothTimeInFrames(frames uint32)

SetGainSmoothTimeInFrames sets the gain smooth time in frames.

func (*EngineConfig) SetGainSmoothTimeInMilliseconds

func (ec *EngineConfig) SetGainSmoothTimeInMilliseconds(milliseconds uint32)

SetGainSmoothTimeInMilliseconds sets the gain smooth time in milliseconds.

func (*EngineConfig) SetListenerCount

func (ec *EngineConfig) SetListenerCount(count uint32)

SetListenerCount sets the listener count.

func (*EngineConfig) SetMonoExpansionMode

func (ec *EngineConfig) SetMonoExpansionMode(mode uint32)

SetMonoExpansionMode sets the mono expansion mode.

func (*EngineConfig) SetNoAutoStart

func (ec *EngineConfig) SetNoAutoStart(noAutoStart bool)

SetNoAutoStart sets whether auto start is disabled.

func (*EngineConfig) SetNoDevice

func (ec *EngineConfig) SetNoDevice(noDevice bool)

SetNoDevice sets whether device creation is disabled.

func (*EngineConfig) SetNotificationCallback

func (ec *EngineConfig) SetNotificationCallback(callback C.ma_device_notification_proc)

SetNotificationCallback sets the notification callback.

func (*EngineConfig) SetOnProcess

func (ec *EngineConfig) SetOnProcess(callback C.ma_engine_process_proc)

SetOnProcess sets the on process callback.

func (*EngineConfig) SetPContext

func (ec *EngineConfig) SetPContext(ctx *Context)

SetPContext sets the context pointer.

func (*EngineConfig) SetPDevice

func (ec *EngineConfig) SetPDevice(device *Device)

SetPDevice sets the device pointer.

func (*EngineConfig) SetPLog

func (ec *EngineConfig) SetPLog(log *Log)

SetPLog sets the log pointer.

func (*EngineConfig) SetPPaymentDeviceID

func (ec *EngineConfig) SetPPaymentDeviceID(deviceID *DeviceID)

SetPPaymentDeviceID sets the playback device ID pointer.

func (*EngineConfig) SetPProcessUserData

func (ec *EngineConfig) SetPProcessUserData(userData unsafe.Pointer)

SetPProcessUserData sets the user data for onProcess.

func (*EngineConfig) SetPeriodSizeInFrames

func (ec *EngineConfig) SetPeriodSizeInFrames(periodSize uint32)

SetPeriodSizeInFrames sets the period size in frames.

func (*EngineConfig) SetPeriodSizeInMilliseconds

func (ec *EngineConfig) SetPeriodSizeInMilliseconds(periodSize uint32)

SetPeriodSizeInMilliseconds sets the period size in milliseconds.

func (*EngineConfig) SetPreMixStackSizeInBytes

func (ec *EngineConfig) SetPreMixStackSizeInBytes(size uint32)

SetPreMixStackSizeInBytes sets the pre-mix stack size in bytes.

func (*EngineConfig) SetSampleRate

func (ec *EngineConfig) SetSampleRate(sampleRate uint32)

SetSampleRate sets the sample rate.

type EngineError

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

EngineError is an error type for engine operations.

func (*EngineError) Error

func (e *EngineError) Error() string

type Format

type Format int32

Format represents ma_format enum values.

const (
	FormatUnknown Format = 0
	FormatF32     Format = 1
	FormatF64     Format = 2
	FormatS16     Format = 3
	FormatS24     Format = 4
	FormatS32     Format = 5
	FormatU8      Format = 6
)

type Log

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

type Node

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

type NodeGraph

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

NodeGraph wraps ma_node_graph.

func NewNodeGraph

func NewNodeGraph(config *NodeGraphConfig) (*NodeGraph, error)

NewNodeGraph creates a new NodeGraph instance, initializes it with ma_node_graph_init, and returns it.

func (*NodeGraph) Channels

func (ng *NodeGraph) Channels() uint32

Channels returns the number of channels of the node graph.

func (*NodeGraph) Close

func (ng *NodeGraph) Close()

Close uninitializes and releases the node graph memory.

func (*NodeGraph) Endpoint

func (ng *NodeGraph) Endpoint() *Node

Endpoint returns the endpoint node of the node graph.

func (*NodeGraph) ProcessingSizeInFrames

func (ng *NodeGraph) ProcessingSizeInFrames() uint32

ProcessingSizeInFrames returns the processing size in frames of the node graph.

func (*NodeGraph) ReadPCMFrames

func (ng *NodeGraph) ReadPCMFrames(framesOut []float32, frameCount uint64) (uint64, error)

ReadPCMFrames reads PCM frames from the node graph.

func (*NodeGraph) SetTime

func (ng *NodeGraph) SetTime(globalTime uint64) error

SetTime sets the time of the node graph.

func (*NodeGraph) Time

func (ng *NodeGraph) Time() uint64

Time returns the current time of the node graph.

type NodeGraphConfig

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

NodeGraphConfig wraps ma_node_graph_config.

func NewNodeGraphConfig

func NewNodeGraphConfig(channels uint32) *NodeGraphConfig

NewNodeGraphConfig creates a new NodeGraphConfig and calls ma_node_graph_config_init.

func (*NodeGraphConfig) Close

func (ngc *NodeGraphConfig) Close()

type NodeState

type NodeState int32

NodeState represents ma_node_state enum values.

const (
	NodeStateInitializing   NodeState = 0
	NodeStateReady          NodeState = 1
	NodeStateProcessing     NodeState = 2
	NodeStateStopping       NodeState = 3
	NodeStateStopped        NodeState = 4
	NodeStateUninitializing NodeState = 5
)

type ResamplerQuality

type ResamplerQuality int32

ResamplerQuality represents ma_resampler_quality enum values.

const (
	ResamplerQualityLow    ResamplerQuality = 0
	ResamplerQualityMedium ResamplerQuality = 1
	ResamplerQualityHigh   ResamplerQuality = 2
	ResamplerQualityHighFC ResamplerQuality = 3
)

type ReverveNode

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

func NewReverveNode

func NewReverveNode(nodeGraph *NodeGraph, config *ReverveNodeConfig, callbacks *AllocationCallbacks) *ReverveNode

func (*ReverveNode) Close

func (n *ReverveNode) Close()

func (*ReverveNode) Damping

func (n *ReverveNode) Damping() float32

Damping はダンピング量を返します。範囲: 0.0 〜 1.0

func (*ReverveNode) DryVolume

func (n *ReverveNode) DryVolume() float32

DryVolume はドライ信号の音量を返します。範囲: 0.0 〜 1.0

func (*ReverveNode) Mode

func (n *ReverveNode) Mode() float32

Mode はリバーブのモードを返します。0.5 未満は通常、それ以上はフリーズ(凍結)モード

func (*ReverveNode) RoomSize

func (n *ReverveNode) RoomSize() float32

RoomSize は部屋のサイズを返します。範囲: 0.0 〜 1.0

func (*ReverveNode) SetDamping

func (n *ReverveNode) SetDamping(damping float32)

SetDamping はダンピング量を設定します。範囲: 0.0 〜 1.0

func (*ReverveNode) SetDryVolume

func (n *ReverveNode) SetDryVolume(dryVolume float32)

SetDryVolume はドライ信号の音量を設定します。範囲: 0.0 〜 1.0

func (*ReverveNode) SetMode

func (n *ReverveNode) SetMode(mode float32)

SetMode はリバーブのモードを設定します。0.5 未満は通常、それ以上はフリーズ(凍結)モード

func (*ReverveNode) SetRoomSize

func (n *ReverveNode) SetRoomSize(roomSize float32)

SetRoomSize は部屋のサイズを設定します。範囲: 0.0 〜 1.0

func (*ReverveNode) SetWetVolume

func (n *ReverveNode) SetWetVolume(wetVolume float32)

SetWetVolume はウェット信号の音量を設定します。範囲: 0.0 〜 1.0

func (*ReverveNode) SetWidth

func (n *ReverveNode) SetWidth(width float32)

SetWidth はステレオ幅を設定します。範囲: 0.0 〜 1.0

func (*ReverveNode) WetVolume

func (n *ReverveNode) WetVolume() float32

WetVolume はウェット信号の音量を返します。範囲: 0.0 〜 1.0

func (*ReverveNode) Width

func (n *ReverveNode) Width() float32

Width はステレオ幅を返します。範囲: 0.0 〜 1.0

type ReverveNodeConfig

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

func NewReverveNodeConfig

func NewReverveNodeConfig(channels, sampleRate uint32) *ReverveNodeConfig

func (*ReverveNodeConfig) Damping

func (c *ReverveNodeConfig) Damping() float32

Damping はダンピング量を返します。範囲: 0.0 〜 1.0

func (*ReverveNodeConfig) DryVolume

func (c *ReverveNodeConfig) DryVolume() float32

DryVolume はドライ信号の音量を返します。範囲: 0.0 〜 1.0

func (*ReverveNodeConfig) Free

func (c *ReverveNodeConfig) Free()

func (*ReverveNodeConfig) Mode

func (c *ReverveNodeConfig) Mode() float32

Mode はリバーブのモードを返します。0.5 未満は通常、それ以上はフリーズ(凍結)モード

func (*ReverveNodeConfig) RoomSize

func (c *ReverveNodeConfig) RoomSize() float32

RoomSize は部屋のサイズを返します。範囲: 0.0 〜 1.0

func (*ReverveNodeConfig) SetDamping

func (c *ReverveNodeConfig) SetDamping(damping float32)

SetDamping はダンピング量を設定します。範囲: 0.0 〜 1.0

func (*ReverveNodeConfig) SetDryVolume

func (c *ReverveNodeConfig) SetDryVolume(dryVolume float32)

SetDryVolume はドライ信号の音量を設定します。範囲: 0.0 〜 1.0

func (*ReverveNodeConfig) SetMode

func (c *ReverveNodeConfig) SetMode(mode float32)

SetMode はリバーブのモードを設定します。0.5 未満は通常、それ以上はフリーズ(凍結)モード

func (*ReverveNodeConfig) SetRoomSize

func (c *ReverveNodeConfig) SetRoomSize(roomSize float32)

SetRoomSize は部屋のサイズを設定します。範囲: 0.0 〜 1.0

func (*ReverveNodeConfig) SetWetVolume

func (c *ReverveNodeConfig) SetWetVolume(wetVolume float32)

SetWetVolume はウェット信号の音量を設定します。範囲: 0.0 〜 1.0

func (*ReverveNodeConfig) SetWidth

func (c *ReverveNodeConfig) SetWidth(width float32)

SetWidth はステレオ幅を設定します。範囲: 0.0 〜 1.0

func (*ReverveNodeConfig) WetVolume

func (c *ReverveNodeConfig) WetVolume() float32

WetVolume はウェット信号の音量を返します。範囲: 0.0 〜 1.0

func (*ReverveNodeConfig) Width

func (c *ReverveNodeConfig) Width() float32

Width はステレオ幅を返します。範囲: 0.0 〜 1.0

type SeekOrigin

type SeekOrigin int32

SeekOrigin represents ma_seek_origin enum values.

const (
	SeekOriginBegin   SeekOrigin = 0
	SeekOriginCurrent SeekOrigin = 1
	SeekOriginEnd     SeekOrigin = 2
)

type Sound

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

Sound wraps ma_sound.

func NewSound

func NewSound(engine *Engine, config *SoundConfig) (*Sound, error)

NewSound creates a new Sound instance and initializes it with ma_sound_init_ex.

func (*Sound) Close

func (s *Sound) Close()

Close uninitializes and releases the sound memory.

func (*Sound) DataSource

func (s *Sound) DataSource() unsafe.Pointer

DataSource returns the data source of this sound.

func (*Sound) Engine

func (s *Sound) Engine() *Engine

Engine returns the engine this sound belongs to.

func (*Sound) IsPlaying

func (s *Sound) IsPlaying() bool

IsPlaying returns whether the sound is playing.

func (*Sound) IsSpatializationEnabled

func (s *Sound) IsSpatializationEnabled() bool

IsSpatializationEnabled returns whether the sound spatialization is enabled.

func (*Sound) Pan

func (s *Sound) Pan() float32

Pan gets the sound pan.

func (*Sound) Pitch

func (s *Sound) Pitch() float32

Pitch gets the sound pitch.

func (*Sound) Position

func (s *Sound) Position() (x, y, z float32)

Position gets the sound position.

func (*Sound) ResetStartTime

func (s *Sound) ResetStartTime()

ResetStartTime resets the sound start time.

func (*Sound) ResetStopTime

func (s *Sound) ResetStopTime()

ResetStopTime resets the sound stop time.

func (*Sound) SetPan

func (s *Sound) SetPan(pan float32)

SetPan sets the sound pan.

func (*Sound) SetPitch

func (s *Sound) SetPitch(pitch float32)

SetPitch sets the sound pitch.

func (*Sound) SetPosition

func (s *Sound) SetPosition(x, y, z float32)

SetPosition sets the sound position.

func (*Sound) SetSpatializationEnabled

func (s *Sound) SetSpatializationEnabled(enabled bool)

SetSpatializationEnabled sets the sound spatialization enabled.

func (*Sound) SetVolume

func (s *Sound) SetVolume(volume float32)

SetVolume sets the sound volume.

func (*Sound) Start

func (s *Sound) Start() error

Start starts the sound.

func (*Sound) Stop

func (s *Sound) Stop() error

Stop stops the sound.

func (*Sound) Volume

func (s *Sound) Volume() float32

Volume gets the sound volume.

type SoundConfig

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

SoundConfig wraps ma_sound_config.

func NewSoundConfig

func NewSoundConfig(engine *Engine) *SoundConfig

NewSoundConfig creates a new SoundConfig and calls ma_sound_config_init_2.

func (*SoundConfig) Close

func (sc *SoundConfig) Close()

type SoundFlags

type SoundFlags uint32
const (
	SoundFlagStream        SoundFlags = 0x00000001
	SoundFlagDecode        SoundFlags = 0x00000002
	SoundFlagAsync         SoundFlags = 0x00000004
	SoundFlagWaitInit      SoundFlags = 0x00000008
	SoundFlagUnknownLength SoundFlags = 0x00000010
	SoundFlagLooping       SoundFlags = 0x00000020

	SoundFlagNoDefaultAttachment SoundFlags = 0x00001000
	SoundFlagNoPitch             SoundFlags = 0x00002000
	SoundFlagNoSpatialization    SoundFlags = 0x00004000
)

Directories

Path Synopsis
examples
orbiting-sound command
play-from-file command

Jump to

Keyboard shortcuts

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