Initial commit.
This commit is contained in:
136
audio.odin
Normal file
136
audio.odin
Normal file
@@ -0,0 +1,136 @@
|
||||
package audio
|
||||
|
||||
import "core:log"
|
||||
|
||||
import "engine"
|
||||
|
||||
Sound :: engine.Sound
|
||||
Sound_Instance :: engine.Sound_Instance
|
||||
Bus :: engine.Bus
|
||||
Listener :: engine.Listener
|
||||
|
||||
Context :: struct {
|
||||
engine: engine.Engine,
|
||||
}
|
||||
|
||||
init :: proc(ctx: ^Context, max_sound_instances: u32) -> bool {
|
||||
assert(ctx != nil)
|
||||
ok := engine.init(&ctx.engine, max_sound_instances)
|
||||
|
||||
return ok
|
||||
}
|
||||
|
||||
tick :: proc(ctx: ^Context) {
|
||||
assert(ctx != nil)
|
||||
engine.tick(&ctx.engine)
|
||||
}
|
||||
|
||||
shutdown :: proc(ctx: ^Context) {
|
||||
assert(ctx != nil)
|
||||
engine.shutdown(&ctx.engine)
|
||||
}
|
||||
|
||||
|
||||
create_bus :: proc(ctx: ^Context) -> (Bus, bool) {
|
||||
assert(ctx != nil)
|
||||
|
||||
bus, ok := engine.create_bus(&ctx.engine)
|
||||
if !ok {
|
||||
return {}, false
|
||||
}
|
||||
|
||||
return bus, ok
|
||||
}
|
||||
|
||||
destroy_bus :: proc(ctx: ^Context, bus: ^Bus) {
|
||||
assert(ctx != nil)
|
||||
assert(bus != nil)
|
||||
|
||||
engine.destroy_bus(&ctx.engine, bus)
|
||||
}
|
||||
|
||||
create_listener :: proc(ctx: ^Context) -> (^Listener, bool) {
|
||||
assert(ctx != nil)
|
||||
return engine.create_listener(&ctx.engine)
|
||||
}
|
||||
|
||||
destroy_listener :: proc(ctx: ^Context, listener: ^Listener) {
|
||||
assert(ctx != nil)
|
||||
engine.destroy_listener(&ctx.engine, listener)
|
||||
}
|
||||
|
||||
load_sound :: proc {
|
||||
load_sound_from_path,
|
||||
}
|
||||
|
||||
load_sound_from_path :: proc(ctx: ^Context, path: string) -> (Sound, bool) {
|
||||
assert(ctx != nil)
|
||||
|
||||
sound, ok := engine.load_sound_from_path(&ctx.engine, path)
|
||||
if !ok {
|
||||
return {}, false
|
||||
}
|
||||
|
||||
return sound, true
|
||||
}
|
||||
|
||||
unload_sound :: proc(ctx: ^Context, sound: ^Sound) {
|
||||
assert(ctx != nil)
|
||||
assert(sound != nil)
|
||||
|
||||
engine.unload_sound(&ctx.engine, sound)
|
||||
}
|
||||
|
||||
play_sound :: proc {
|
||||
play_sound_at_position,
|
||||
}
|
||||
|
||||
play_sound_at_position :: proc(ctx: ^Context, sound: ^Sound, bus: ^Bus, position: [3]f32) -> (^Sound_Instance, bool) {
|
||||
assert(ctx != nil)
|
||||
|
||||
sound_instance, ok := engine.create_sound_instance(&ctx.engine, sound, bus)
|
||||
if !ok {
|
||||
log.warnf("Failed to play sound! Failed to create a sound instance.")
|
||||
return nil, false
|
||||
}
|
||||
|
||||
sound_instance.spatialized = true // TEMP: SS - Hardcoded. Expose!
|
||||
sound_instance.volume = 1.0 // TEMP: SS - Hardcoded. Expose!
|
||||
sound_instance.position = position
|
||||
sound_instance.min_distance = 1.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(
|
||||
&ctx.engine,
|
||||
sound_instance
|
||||
) {
|
||||
log.warnf("Failed to play sound instance.")
|
||||
return nil, false
|
||||
}
|
||||
|
||||
return sound_instance, true
|
||||
}
|
||||
|
||||
// sound_instance_playing :: proc(sound_instance: ^Sound_Instance) -> bool { // TODO: SS - Implement something like this.
|
||||
// assert(sound_instance != nil)
|
||||
|
||||
// return true // TEMP
|
||||
// }
|
||||
|
||||
update_listener :: proc(ctx: ^Context, listener: ^Listener, position, velocity, direction_forward, world_up: [3]f32) -> bool {
|
||||
assert(ctx != nil)
|
||||
assert(listener != nil)
|
||||
|
||||
if listener.id == engine.INVALID_LISTENER_ID {
|
||||
return false
|
||||
}
|
||||
|
||||
listener.position = position
|
||||
listener.velocity = velocity
|
||||
listener.direction_forward = direction_forward
|
||||
listener.world_up = world_up
|
||||
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user