Renamed 'ljud' to 'miniaudio' to better represent what engine it is.

This commit is contained in:
2026-02-08 19:40:53 +01:00
parent 034b318059
commit cdbc7ba264
8 changed files with 69 additions and 73 deletions

View File

@@ -95,13 +95,12 @@ play_sound_at_position :: proc(ctx: ^Context, sound: ^Sound, bus: ^Bus, position
} }
sound_instance.spatialized = true // TEMP: SS - Hardcoded. Expose! sound_instance.spatialized = true // TEMP: SS - Hardcoded. Expose!
sound_instance.loop = false // TEMP: SS - Hardcoded. Expose!
sound_instance.volume = 1.0 // TEMP: SS - Hardcoded. Expose! sound_instance.volume = 1.0 // TEMP: SS - Hardcoded. Expose!
sound_instance.position = position sound_instance.position = position
sound_instance.min_distance = 1.0 // TEMP: SS - Hardcoded. Expose! sound_instance.min_distance = 1.0 // TEMP: SS - Hardcoded. Expose!
sound_instance.max_distance = 50.0 // TEMP: SS - Hardcoded. Expose! sound_instance.max_distance = 50.0 // TEMP: SS - Hardcoded. Expose!
log.infof("Got instance! Now we should 'start'/play it.")
if !engine.play_sound_instance( if !engine.play_sound_instance(
&ctx.engine, &ctx.engine,
sound_instance sound_instance
@@ -113,11 +112,9 @@ play_sound_at_position :: proc(ctx: ^Context, sound: ^Sound, bus: ^Bus, position
return sound_instance, true return sound_instance, true
} }
// sound_instance_playing :: proc(sound_instance: ^Sound_Instance) -> bool { // TODO: SS - Implement something like this. // TODO: SS - 'get_sound_instance_status(..)' that returns an enum for the state; not started, playing, stopped, done?
// assert(sound_instance != nil) // TODO: SS - 'stop_sound_instance(..)'
// TODO: SS - 'update_sound_instance(..)' that allows us to, for example, move the sound; projectile moving, bird flying, coin swaying, etc.
// return true // TEMP
// }
update_listener :: proc(ctx: ^Context, listener: ^Listener, position, velocity, direction_forward, world_up: [3]f32) -> bool { update_listener :: proc(ctx: ^Context, listener: ^Listener, position, velocity, direction_forward, world_up: [3]f32) -> bool {
assert(ctx != nil) assert(ctx != nil)

View File

@@ -2,7 +2,7 @@ package engine
import "core:log" import "core:log"
import "ljud" import "miniaudio"
Bus :: struct { Bus :: struct {
backend: ^Bus_Backend, backend: ^Bus_Backend,
@@ -13,8 +13,8 @@ create_bus :: proc(engine: ^Engine) -> (Bus, bool) {
bus: Bus bus: Bus
when AUDIO_ENGINE_LJUD { when AUDIO_ENGINE_MINIAUDIO {
backend, ok := ljud.create_bus(&engine.backend) backend, ok := miniaudio.create_bus(&engine.backend)
if !ok { if !ok {
return {}, false return {}, false
} }
@@ -37,8 +37,8 @@ destroy_bus :: proc(engine: ^Engine, bus: ^Bus) {
assert(bus != nil) assert(bus != nil)
assert(bus.backend != nil) assert(bus.backend != nil)
when AUDIO_ENGINE_LJUD { when AUDIO_ENGINE_MINIAUDIO {
ljud.destroy_bus(&engine.backend, bus.backend) miniaudio.destroy_bus(&engine.backend, bus.backend)
} }
else { else {
#assert("TODO: SS - Implement for Audio Engine backend") #assert("TODO: SS - Implement for Audio Engine backend")

View File

@@ -4,17 +4,17 @@ import "core:container/queue"
import "core:log" import "core:log"
import "core:math/linalg" import "core:math/linalg"
AUDIO_ENGINE_LJUD :: #config(AUDIO_ENGINE_LJUD, false) AUDIO_ENGINE_MINIAUDIO :: #config(AUDIO_ENGINE_MINIAUDIO, false)
AUDIO_ENGINE_FMOD :: #config(AUDIO_ENGINE_FMOD, false) AUDIO_ENGINE_FMOD :: #config(AUDIO_ENGINE_FMOD, false)
AUDIO_ENGINE_WWISE :: #config(AUDIO_ENGINE_WWISE, false) AUDIO_ENGINE_WWISE :: #config(AUDIO_ENGINE_WWISE, false)
import "ljud" import "miniaudio"
when AUDIO_ENGINE_LJUD { when AUDIO_ENGINE_MINIAUDIO {
Engine_Backend :: ljud.Engine Engine_Backend :: miniaudio.Engine
Sound_Backend :: ljud.Sound Sound_Backend :: miniaudio.Sound
Sound_Instance_Backend :: ljud.Sound_Instance Sound_Instance_Backend :: miniaudio.Sound_Instance
Bus_Backend :: ljud.Bus Bus_Backend :: miniaudio.Bus
} }
else when AUDIO_ENGINE_FMOD { else when AUDIO_ENGINE_FMOD {
@@ -34,29 +34,29 @@ init :: proc(engine: ^Engine, max_sound_instances: u32) -> bool {
assert(engine != nil) assert(engine != nil)
assert(max_sound_instances > 0) assert(max_sound_instances > 0)
when AUDIO_ENGINE_LJUD { when AUDIO_ENGINE_MINIAUDIO {
// engine.§ new(ljud.Engine) // engine.§ new(miniaudio.Engine)
// if engine.data != nil { // if engine.data != nil {
// v := transmute(^ljud.Engine)(engine.data) // v := transmute(^miniaudio.Engine)(engine.data)
// if !ljud.init(v) { // if !miniaudio.init(v) {
// free(engine.data) // free(engine.data)
// engine.data = nil // engine.data = nil
// log.errorf("Failed to initialize audio-engine LJUD.") // log.errorf("Failed to initialize audio-engine MINIAUDIO.")
// return false // return false
// } // }
// } // }
if !ljud.init(&engine.backend) { if !miniaudio.init(&engine.backend) {
// free(engine.data) // free(engine.data)
// engine.data = nil // engine.data = nil
log.errorf("Failed to initialize audio-engine LJUD.") log.errorf("Failed to initialize audio-engine MINIAUDIO.")
return false return false
} }
} }
else { else {
#assert("No audio-engine defined. '-define:AUDIO_ENGINE_X=true' where X is the audio-engine; 'LJUD', 'FMOD', 'WWISE'.") #assert("No audio-engine defined. '-define:AUDIO_ENGINE_X=true' where X is the audio-engine; 'MINIAUDIO', 'FMOD', 'WWISE'.")
} }
{ // Initialize sound-instances. { // Initialize sound-instances.
@@ -86,8 +86,8 @@ init :: proc(engine: ^Engine, max_sound_instances: u32) -> bool {
} }
tick :: proc(engine: ^Engine) { tick :: proc(engine: ^Engine) {
when AUDIO_ENGINE_LJUD { when AUDIO_ENGINE_MINIAUDIO {
ljud.tick(&engine.backend) miniaudio.tick(&engine.backend)
} }
else { else {
#assert("TODO: SS - Implement for Audio Engine backend") #assert("TODO: SS - Implement for Audio Engine backend")
@@ -100,8 +100,8 @@ tick :: proc(engine: ^Engine) {
} }
when AUDIO_ENGINE_LJUD { when AUDIO_ENGINE_MINIAUDIO {
ljud.tick_listener( miniaudio.tick_listener(
&engine.backend, &engine.backend,
u8(listener.id), u8(listener.id),
listener.enabled, listener.enabled,
@@ -117,8 +117,8 @@ tick :: proc(engine: ^Engine) {
shutdown :: proc(engine: ^Engine) { shutdown :: proc(engine: ^Engine) {
assert(engine != nil) assert(engine != nil)
when AUDIO_ENGINE_LJUD { when AUDIO_ENGINE_MINIAUDIO {
ljud.shutdown(&engine.backend) miniaudio.shutdown(&engine.backend)
} }
else { else {
#assert("TODO: SS - Implement for Audio Engine backend") #assert("TODO: SS - Implement for Audio Engine backend")

View File

@@ -3,8 +3,7 @@ package engine
import "core:log" import "core:log"
import "core:container/queue" import "core:container/queue"
import "ljud" import "miniaudio"
MAX_LISTENERS :: 4 MAX_LISTENERS :: 4

View File

@@ -1,4 +1,4 @@
package ljud package miniaudio_wrapper
import "core:log" import "core:log"
import "core:strings" import "core:strings"

View File

@@ -1,4 +1,4 @@
package ljud package miniaudio_wrapper
import "core:container/queue" import "core:container/queue"
import "core:log" import "core:log"
@@ -12,7 +12,7 @@ Engine :: struct {
init :: proc(engine: ^Engine) -> bool { init :: proc(engine: ^Engine) -> bool {
assert(engine != nil) assert(engine != nil)
log.infof("Initializing LJUD Engine") log.infof("Initializing Miniaudio Engine")
engine_config := ma.engine_config_init() engine_config := ma.engine_config_init()
engine_config.channels = 0 engine_config.channels = 0

View File

@@ -1,4 +1,4 @@
package ljud package miniaudio_wrapper
import "core:sys/orca" import "core:sys/orca"
import "base:runtime" import "base:runtime"
@@ -119,26 +119,27 @@ init_sound_instance :: proc(engine: ^Engine, bus: ^Bus, sound: ^Sound, sound_ins
return true return true
} }
Play_Sound_Instance_Spec :: struct { play_sound_instance :: proc(
engine: ^Engine,
sound_instance: ^Sound_Instance,
spatialized: bool, spatialized: bool,
loop: bool,
volume: f32, volume: f32,
position: [3]f32, position: [3]f32,
distance: struct { min, max: f32, } min_distance, max_distance: f32,
} ) -> bool {
play_sound_instance :: proc(engine: ^Engine, sound_instance: ^Sound_Instance, spec: Play_Sound_Instance_Spec) -> bool {
assert(engine != nil) assert(engine != nil)
assert(sound_instance != nil) assert(sound_instance != nil)
ma.sound_set_spatialization_enabled(sound_instance, b32(spec.spatialized)) ma.sound_set_spatialization_enabled(sound_instance, b32(spatialized))
ma.sound_set_volume(sound_instance, spec.volume) ma.sound_set_looping(sound_instance, b32(loop))
ma.sound_set_position(sound_instance, expand_values(spec.position)) ma.sound_set_volume(sound_instance, volume)
ma.sound_set_min_distance(sound_instance, spec.distance.min) ma.sound_set_position(sound_instance, expand_values(position))
ma.sound_set_max_distance(sound_instance, spec.distance.max) ma.sound_set_min_distance(sound_instance, min_distance)
ma.sound_set_max_distance(sound_instance, max_distance)
// TODO: SS - So many cool thingss available! Expose them. // TODO: SS - So many cool thingss available! Expose them.
// 'ma.sound_set_looping', 'ma.sound_set_pitch' etc. // 'ma.sound_set_pitch' etc.
seek_result := ma.sound_seek_to_pcm_frame(sound_instance, 0) seek_result := ma.sound_seek_to_pcm_frame(sound_instance, 0)
if seek_result != .SUCCESS { if seek_result != .SUCCESS {
@@ -152,6 +153,5 @@ play_sound_instance :: proc(engine: ^Engine, sound_instance: ^Sound_Instance, sp
return false return false
} }
return true return true
} }

View File

@@ -4,7 +4,7 @@ import os "core:os/os2"
import "core:container/queue" import "core:container/queue"
import "core:log" import "core:log"
import "ljud" import "miniaudio"
Sound :: struct { Sound :: struct {
path: string, // Where I was loaded from. path: string, // Where I was loaded from.
@@ -17,6 +17,7 @@ Sound_Instance :: struct {
backend: Sound_Instance_Backend, // Backend-representation. backend: Sound_Instance_Backend, // Backend-representation.
spatialized: bool, spatialized: bool,
loop: bool,
volume: f32, // 0..1 volume: f32, // 0..1
position: [3]f32, position: [3]f32,
min_distance, max_distance: f32, min_distance, max_distance: f32,
@@ -48,8 +49,8 @@ load_sound_from_path :: proc(engine: ^Engine, path: string) -> (Sound, bool) {
return {}, false return {}, false
} }
when AUDIO_ENGINE_LJUD { when AUDIO_ENGINE_MINIAUDIO {
backend, ok := ljud.load_sound_from_data(&engine.backend, data, ext) backend, ok := miniaudio.load_sound_from_data(&engine.backend, data, ext)
if !ok { if !ok {
return {}, false return {}, false
} }
@@ -80,8 +81,8 @@ unload_sound :: proc(engine: ^Engine, sound: ^Sound) {
assert(sound != nil) assert(sound != nil)
assert(sound.data != nil) assert(sound.data != nil)
when AUDIO_ENGINE_LJUD { when AUDIO_ENGINE_MINIAUDIO {
ljud.unload_sound(&engine.backend, sound.backend) miniaudio.unload_sound(&engine.backend, sound.backend)
} }
else when AUDIO_ENGINE_FMOD { else when AUDIO_ENGINE_FMOD {
@@ -116,8 +117,8 @@ create_sound_instance :: proc(engine: ^Engine, sound: ^Sound, bus: ^Bus) -> (^So
sound_instance.backend = {} sound_instance.backend = {}
instance_ok: bool instance_ok: bool
when AUDIO_ENGINE_LJUD { when AUDIO_ENGINE_MINIAUDIO {
instance_ok = ljud.init_sound_instance(&engine.backend, bus != nil ? bus.backend : nil, sound.backend, &sound_instance.backend) instance_ok = miniaudio.init_sound_instance(&engine.backend, bus != nil ? bus.backend : nil, sound.backend, &sound_instance.backend)
} }
else when AUDIO_ENGINE_FMOD { else when AUDIO_ENGINE_FMOD {
@@ -138,18 +139,17 @@ play_sound_instance :: proc(engine: ^Engine, sound_instance: ^Sound_Instance) ->
assert(engine != nil) assert(engine != nil)
assert(sound_instance != nil) assert(sound_instance != nil)
when AUDIO_ENGINE_LJUD { when AUDIO_ENGINE_MINIAUDIO {
spec := ljud.Play_Sound_Instance_Spec { return miniaudio.play_sound_instance(
spatialized = sound_instance.spatialized, &engine.backend,
volume = sound_instance.volume, &sound_instance.backend,
sound_instance.spatialized,
position = sound_instance.position, sound_instance.loop,
distance = { sound_instance.volume,
min = sound_instance.min_distance, sound_instance.position,
max = sound_instance.max_distance, sound_instance.min_distance,
}, sound_instance.max_distance,
} )
return ljud.play_sound_instance(&engine.backend, &sound_instance.backend, spec)
} }
else when AUDIO_ENGINE_FMOD { else when AUDIO_ENGINE_FMOD {
} }