Renamed 'ljud' to 'miniaudio' to better represent what engine it is.
This commit is contained in:
94
engine/miniaudio/engine.odin
Normal file
94
engine/miniaudio/engine.odin
Normal file
@@ -0,0 +1,94 @@
|
||||
package miniaudio_wrapper
|
||||
|
||||
import "core:container/queue"
|
||||
import "core:log"
|
||||
import "core:strings"
|
||||
|
||||
import ma "vendor:miniaudio"
|
||||
|
||||
Engine :: struct {
|
||||
ma_engine: ma.engine,
|
||||
}
|
||||
|
||||
init :: proc(engine: ^Engine) -> bool {
|
||||
assert(engine != nil)
|
||||
log.infof("Initializing Miniaudio Engine")
|
||||
|
||||
engine_config := ma.engine_config_init()
|
||||
engine_config.channels = 0
|
||||
engine_config.sampleRate = 0
|
||||
engine_config.listenerCount = ma.ENGINE_MAX_LISTENERS // HMM: SS - Get this passed in?
|
||||
|
||||
res := ma.engine_init(&engine_config, &engine.ma_engine)
|
||||
if res != .SUCCESS {
|
||||
log.errorf("Failed to initialize miniaudio! Result: %v.", res)
|
||||
return false
|
||||
}
|
||||
|
||||
start_res := ma.engine_start(&engine.ma_engine) // TODO: SS - Move elsewhere?
|
||||
if start_res != .SUCCESS {
|
||||
log.errorf("Failed to start miniaudio! Result: %v.", start_res)
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
tick :: proc(engine: ^Engine) {
|
||||
assert(engine != nil)
|
||||
}
|
||||
|
||||
tick_listener :: proc(engine: ^Engine, id: u8, enabled: bool, position, velocity, direction_forward, world_up: [3]f32) {
|
||||
assert(engine != nil)
|
||||
|
||||
// Enabled.
|
||||
ma.engine_listener_set_enabled(
|
||||
&engine.ma_engine,
|
||||
u32(id),
|
||||
b32(enabled),
|
||||
)
|
||||
|
||||
// Position.
|
||||
ma.engine_listener_set_position(
|
||||
&engine.ma_engine,
|
||||
u32(id),
|
||||
expand_values(position)
|
||||
)
|
||||
|
||||
// Velocity.
|
||||
ma.engine_listener_set_velocity(
|
||||
&engine.ma_engine,
|
||||
u32(id),
|
||||
expand_values(velocity)
|
||||
)
|
||||
|
||||
// Direction (forward).
|
||||
ma.engine_listener_set_direction(
|
||||
&engine.ma_engine,
|
||||
u32(id),
|
||||
expand_values(direction_forward)
|
||||
)
|
||||
|
||||
// World (up).
|
||||
ma.engine_listener_set_world_up(
|
||||
&engine.ma_engine,
|
||||
u32(id),
|
||||
expand_values(world_up)
|
||||
)
|
||||
|
||||
// // Cone. // TODO: SS - Support! :)
|
||||
// ma.engine_listener_set_cone(
|
||||
// &engine.ma_engine,
|
||||
// u32(id),
|
||||
// ..
|
||||
// )
|
||||
|
||||
// log.infof("Ticked listener %v. Position: %v, velocity: %v, direction forward: %v, world up: %v", id, position, direction_forward, world_up)
|
||||
}
|
||||
|
||||
shutdown :: proc(engine: ^Engine) {
|
||||
assert(engine != nil)
|
||||
|
||||
log.infof("Shutting down Miniaudio Engine")
|
||||
ma.engine_uninit(&engine.ma_engine)
|
||||
}
|
||||
Reference in New Issue
Block a user