implement sokol_audio integration and start working on mixer
This commit is contained in:
parent
ac5c52ea9f
commit
440b388b03
@ -127,7 +127,7 @@ Iprof :: #import "Iprof"(IMPORT_MODE = .METAPROGRAM);
|
||||
{
|
||||
args := string.[
|
||||
"emcc",
|
||||
"src/platform_specific/main.c", "dist/main.o", "modules/sokol-jai/sokol/gfx/sokol_gfx_wasm_gl_debug.a", "modules/sokol-jai/sokol/log/sokol_log_wasm_gl_debug.a", "modules/sokol-jai/sokol/time/sokol_time_wasm_gl_debug.a", "modules/sokol-jai/sokol/app/sokol_app_wasm_gl_debug.a", "modules/sokol-jai/sokol/glue/sokol_glue_wasm_gl_debug.a", "modules/sokol-jai/sokol/fetch/sokol_fetch_wasm_gl_debug.a", "modules/sokol-jai/sokol/gl/sokol_gl_wasm_gl_debug.a", "modules/sokol-jai/sokol/fontstash/sokol_fontstash_wasm_gl_debug.a",
|
||||
"src/platform_specific/main.c", "dist/main.o", "modules/sokol-jai/sokol/gfx/sokol_gfx_wasm_gl_release.a", "modules/sokol-jai/sokol/log/sokol_log_wasm_gl_release.a", "modules/sokol-jai/sokol/audio/sokol_audio_wasm_gl_release.a", "modules/sokol-jai/sokol/time/sokol_time_wasm_gl_release.a", "modules/sokol-jai/sokol/app/sokol_app_wasm_gl_release.a", "modules/sokol-jai/sokol/glue/sokol_glue_wasm_gl_release.a", "modules/sokol-jai/sokol/fetch/sokol_fetch_wasm_gl_release.a", "modules/sokol-jai/sokol/gl/sokol_gl_wasm_gl_release.a", "modules/sokol-jai/sokol/fontstash/sokol_fontstash_wasm_gl_release.a",
|
||||
"modules/sokol-jai/sokol/stbi/stb_image.a",
|
||||
"-o", "dist/index.html",
|
||||
"-sSTACK_SIZE=10MB",
|
||||
|
||||
@ -29,6 +29,7 @@ build_lib_wasm_release sokol_debugtext debugtext/sokol_debugtext_wasm_gl_relea
|
||||
build_lib_wasm_release sokol_shape shape/sokol_shape_wasm_gl_release SOKOL_GLES3
|
||||
build_lib_wasm_release sokol_fontstash fontstash/sokol_fontstash_wasm_gl_release SOKOL_GLES3
|
||||
build_lib_wasm_release sokol_fetch fetch/sokol_fetch_wasm_gl_release SOKOL_GLES3
|
||||
build_lib_wasm_release sokol_audio audio/sokol_audio_wasm_gl_release SOKOL_GLES3
|
||||
build_lib_wasm_release sokol_gl gl/sokol_gl_wasm_gl_release SOKOL_GLES3
|
||||
build_lib_wasm_release stb_image stbi/stb_image SOKOL_GLES3
|
||||
|
||||
@ -43,6 +44,7 @@ build_lib_wasm_debug sokol_debugtext debugtext/sokol_debugtext_wasm_gl_debug
|
||||
build_lib_wasm_debug sokol_shape shape/sokol_shape_wasm_gl_debug SOKOL_GLES3
|
||||
build_lib_wasm_debug sokol_fontstash fontstash/sokol_fontstash_wasm_gl_debug SOKOL_GLES3
|
||||
build_lib_wasm_debug sokol_fetch fetch/sokol_fetch_wasm_gl_debug SOKOL_GLES3
|
||||
build_lib_wasm_debug sokol_audio audio/sokol_audio_wasm_gl_debug SOKOL_GLES3
|
||||
build_lib_wasm_debug sokol_gl gl/sokol_gl_wasm_gl_debug SOKOL_GLES3
|
||||
build_lib_wasm_debug stb_image stbi/stb_image SOKOL_GLES3
|
||||
|
||||
|
||||
30
src/audio/audio.jai
Normal file
30
src/audio/audio.jai
Normal file
@ -0,0 +1,30 @@
|
||||
#load "backend.jai";
|
||||
#load "load.jai";
|
||||
|
||||
Mixer_Bus :: enum {
|
||||
MUSIC;
|
||||
SOUND_EFFECT;
|
||||
DIALOGUE;
|
||||
}
|
||||
|
||||
Mixer :: struct {
|
||||
|
||||
}
|
||||
|
||||
mixer_get_samples :: (buffer: *float, mixer: *Mixer, sampleCount: s32, channelCount: s32) {
|
||||
|
||||
}
|
||||
|
||||
audio_init :: () {
|
||||
load_wav_file();
|
||||
}
|
||||
|
||||
audio_cleanup :: () {
|
||||
saudio_shutdown();
|
||||
}
|
||||
|
||||
mono_track : [..]float;
|
||||
|
||||
cur_sample : int = 0;
|
||||
|
||||
audio_samples : []s16;
|
||||
10
src/audio/backend.jai
Normal file
10
src/audio/backend.jai
Normal file
@ -0,0 +1,10 @@
|
||||
sokol_audio_callback :: (buffer: *float, num_frames: s32, num_channels: s32) #c_call {
|
||||
push_context,defer_pop default_context;
|
||||
|
||||
if mono_track.count < 1 then return;
|
||||
|
||||
for i : 0..num_frames-1 {
|
||||
buffer[i] = mono_track[cur_sample] * 0.1;
|
||||
cur_sample += 1;
|
||||
}
|
||||
}
|
||||
19
src/audio/load.jai
Normal file
19
src/audio/load.jai
Normal file
@ -0,0 +1,19 @@
|
||||
Wav :: #import "Wav_File";
|
||||
|
||||
audio_info : Wav.Waveformatex;
|
||||
|
||||
load_wav_file :: () {
|
||||
audio := load_string_from_pack("./game/resources/sound/music/monoco.wav");
|
||||
format, samples, success := Wav.get_wav_header(audio);
|
||||
if !success print("Failed to load wav file!!!!!\n");
|
||||
audio_info = format;
|
||||
audio_samples.data = cast(*s16)samples.data;
|
||||
audio_samples.count = samples.count / 2;
|
||||
print("Format: %\n", format.wBitsPerSample);
|
||||
for sample, i: audio_samples {
|
||||
if i % 2 == 0 {
|
||||
array_add(*mono_track, cast(float)sample / 32768.0);
|
||||
}
|
||||
}
|
||||
print("Converted % samples", mono_track.count);
|
||||
}
|
||||
@ -27,6 +27,7 @@ stbi :: #import "stb_image";
|
||||
#load "ray.jai";
|
||||
#load "world.jai";
|
||||
#load "utils.jai";
|
||||
#load "audio/audio.jai";
|
||||
|
||||
#if USE_SAMPLE_GAME {
|
||||
#load "../sample_game/game.jai";
|
||||
@ -87,6 +88,10 @@ init :: () {
|
||||
sfetch_setup(*(sfetch_desc_t.{
|
||||
logger = .{ func = slog_func },
|
||||
}));
|
||||
saudio_setup(*(saudio_desc.{
|
||||
logger = .{ func = slog_func },
|
||||
stream_cb = sokol_audio_callback,
|
||||
}));
|
||||
stm_setup();
|
||||
state.dpi_scale = sapp_dpi_scale();
|
||||
atlas_dim := round_pow2(512.0 * state.dpi_scale);
|
||||
@ -131,6 +136,8 @@ init_after_asset_pack :: () {
|
||||
load_color_lut_images();
|
||||
load_post_process_from_pack();
|
||||
|
||||
audio_init();
|
||||
|
||||
// We want to do this last.
|
||||
game_init();
|
||||
|
||||
@ -200,6 +207,7 @@ frame :: () {
|
||||
}
|
||||
|
||||
cleanup :: () {
|
||||
audio_cleanup();
|
||||
sg_shutdown();
|
||||
}
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#import,dir "../../modules/sokol-jai/sokol/log"(DEBUG = RELEASE_BUILD);
|
||||
#import,dir "../../modules/sokol-jai/sokol/time"(DEBUG = RELEASE_BUILD);
|
||||
#import,dir "../../modules/sokol-jai/sokol/fetch"(DEBUG = RELEASE_BUILD);
|
||||
#import,dir "../../modules/sokol-jai/sokol/audio"(DEBUG = RELEASE_BUILD);
|
||||
|
||||
#load "../main.jai";
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user