diff --git a/base/project.js b/base/project.js index a76268ae..65dcecdd 100644 --- a/base/project.js +++ b/base/project.js @@ -41,6 +41,7 @@ if (platform == "windows") { project.add_lib("Dwmapi"); // DWMWA_USE_IMMERSIVE_DARK_MODE if (flags.with_audio) { project.add_lib("dsound"); + project.add_cfiles("sources/backends/windows_audio.*"); } if (flags.with_gamepad) { project.add_lib("dinput8"); @@ -67,6 +68,7 @@ else if (platform == "linux") { project.add_lib("vulkan"); if (flags.with_audio) { project.add_lib("asound"); + project.add_cfiles("sources/backends/linux_audio.*"); } if (flags.with_gamepad) { project.add_lib("udev"); @@ -204,10 +206,7 @@ if (flags.export_data_list) { } if (flags.with_audio) { - project.add_define("IRON_A1"); - project.add_define("IRON_A2"); - project.add_define("WITH_AUDIO"); - project.add_define("arm_audio"); + project.add_define("IRON_AUDIO"); project.add_cfiles("sources/libs/stb_vorbis.c"); } diff --git a/base/sources/backends/android_audio.c b/base/sources/backends/android_audio.c index daed1ce7..41de060d 100644 --- a/base/sources/backends/android_audio.c +++ b/base/sources/backends/android_audio.c @@ -1,5 +1,5 @@ -#ifdef IRON_A2 +#ifdef IRON_AUDIO #include "iron_audio.h" diff --git a/base/sources/backends/ios_audio.m b/base/sources/backends/ios_audio.m index b9483cec..a6da0775 100644 --- a/base/sources/backends/ios_audio.m +++ b/base/sources/backends/ios_audio.m @@ -1,5 +1,5 @@ -#ifdef IRON_A2 +#ifdef IRON_AUDIO #import #import diff --git a/base/sources/backends/ios_system.m b/base/sources/backends/ios_system.m index fc566db6..1e4a4fb8 100644 --- a/base/sources/backends/ios_system.m +++ b/base/sources/backends/ios_system.m @@ -552,7 +552,7 @@ void importFile(NSURL *url) { } - (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions { -#ifdef IRON_A2 +#ifdef IRON_AUDIO AVAudioSession *sessionInstance = [AVAudioSession sharedInstance]; NSError *error; NSString *category = AVAudioSessionCategoryAmbient; diff --git a/base/sources/backends/linux_audio.c b/base/sources/backends/linux_audio.c index e0ba0178..bcfa5be1 100644 --- a/base/sources/backends/linux_audio.c +++ b/base/sources/backends/linux_audio.c @@ -1,8 +1,9 @@ -#ifdef IRON_A2 +#ifdef IRON_AUDIO #include #include +#define IRON_IMPLEMENTATION #include #include #include diff --git a/base/sources/backends/macos_audio.c b/base/sources/backends/macos_audio.c index d98392de..77cb236c 100644 --- a/base/sources/backends/macos_audio.c +++ b/base/sources/backends/macos_audio.c @@ -1,5 +1,5 @@ -#ifdef IRON_A2 +#ifdef IRON_AUDIO #include #include diff --git a/base/sources/backends/wasm_audio.c b/base/sources/backends/wasm_audio.c index b5c38714..2266e63f 100644 --- a/base/sources/backends/wasm_audio.c +++ b/base/sources/backends/wasm_audio.c @@ -1,5 +1,5 @@ -#ifdef IRON_A2 +#ifdef IRON_AUDIO #include #include diff --git a/base/sources/backends/windows_audio.c b/base/sources/backends/windows_audio.c index b8b090b2..56ca6470 100644 --- a/base/sources/backends/windows_audio.c +++ b/base/sources/backends/windows_audio.c @@ -1,5 +1,5 @@ -#ifdef IRON_A2 +#ifdef IRON_AUDIO #include #include diff --git a/base/sources/engine.c b/base/sources/engine.c index 2569d64a..49945926 100644 --- a/base/sources/engine.c +++ b/base/sources/engine.c @@ -1849,7 +1849,7 @@ any_map_t *data_cached_blobs = NULL; any_map_t *data_cached_images = NULL; any_map_t *data_cached_videos = NULL; any_map_t *data_cached_fonts = NULL; -#ifdef arm_audio +#ifdef IRON_AUDIO any_map_t *data_cached_sounds = NULL; #endif i32 data_assets_loaded = 0; @@ -1857,9 +1857,9 @@ i32 data_assets_loaded = 0; buffer_t *iron_load_blob(char *file); gpu_texture_t *iron_load_texture(char *file); void gpu_delete_texture(gpu_texture_t *texture); -#ifdef arm_audio +#ifdef IRON_AUDIO void *iron_load_sound(char *file); -void iron_a1_sound_destroy(void *sound); +// void iron_a1_sound_destroy(void *sound); #endif char *data_path(void) { @@ -2049,7 +2049,7 @@ draw_font_t *data_get_font(char *file) { return b; } -#ifdef arm_audio +#ifdef IRON_AUDIO sound_t *data_get_sound(char *file) { if (data_cached_sounds == NULL) { data_cached_sounds = any_map_create(); @@ -2126,7 +2126,7 @@ void data_delete_font(char *handle) { map_delete(data_cached_fonts, handle); } -#ifdef arm_audio +#ifdef IRON_AUDIO void data_delete_sound(char *handle) { if (data_cached_sounds == NULL) { return; diff --git a/base/sources/engine.h b/base/sources/engine.h index 4d4cd293..1b96cb1e 100644 --- a/base/sources/engine.h +++ b/base/sources/engine.h @@ -550,7 +550,7 @@ extern any_map_t *data_cached_blobs; extern any_map_t *data_cached_images; extern any_map_t *data_cached_videos; extern any_map_t *data_cached_fonts; -#ifdef arm_audio +#ifdef IRON_AUDIO extern any_map_t *data_cached_sounds; #endif extern i32 data_assets_loaded; @@ -565,7 +565,7 @@ gpu_texture_t *data_get_image(char *file); buffer_t *data_get_blob(char *file); video_t *data_get_video(char *file); draw_font_t *data_get_font(char *file); -#ifdef arm_audio +#ifdef IRON_AUDIO sound_t *data_get_sound(char *file); #endif void data_delete_mesh(char *handle); @@ -573,7 +573,7 @@ void data_delete_blob(char *handle); void data_delete_image(char *handle); void data_delete_video(char *handle); void data_delete_font(char *handle); -#ifdef arm_audio +#ifdef IRON_AUDIO void data_delete_sound(char *handle); #endif bool data_is_abs(char *file); diff --git a/base/sources/iron.h b/base/sources/iron.h index e764d529..2f03310d 100644 --- a/base/sources/iron.h +++ b/base/sources/iron.h @@ -30,7 +30,7 @@ #else #include #endif -#ifdef WITH_AUDIO +#ifdef IRON_AUDIO #include "iron_audio.h" #endif #ifdef WITH_EMBED @@ -150,7 +150,7 @@ int kickstart(int argc, char **argv) { gc_start(&argc); _kickstart(); -#ifdef WITH_AUDIO +#ifdef IRON_AUDIO iron_a2_shutdown(); #endif gc_stop(); @@ -184,7 +184,7 @@ char *iron_get_arg(i32 index) { #include "kong/dir.h" #include #include -#ifdef WITH_AUDIO +#ifdef IRON_AUDIO #include "iron_audio.h" #endif #define STB_IMAGE_IMPLEMENTATION @@ -245,7 +245,7 @@ void _update() { } #endif -#ifdef WITH_AUDIO +#ifdef IRON_AUDIO iron_a2_update(); #endif @@ -586,7 +586,7 @@ void _iron_init(iron_window_options_t *ops) { iron_set_copy_callback(_copy, NULL); iron_set_paste_callback(_paste, NULL); iron_keyboard_set_key_press_callback(_key_press, NULL); -#ifdef WITH_AUDIO +#ifdef IRON_AUDIO iron_a1_init(); iron_a2_init(); #endif @@ -892,7 +892,7 @@ gpu_texture_t *iron_load_texture(char *file) { return gpu_create_texture_from_encoded_bytes(&buf, file); } -#ifdef WITH_AUDIO +#ifdef IRON_AUDIO void *iron_load_sound(char *file) { iron_a1_sound_t *sound = iron_a1_sound_create(file); return sound; diff --git a/base/sources/iron_audio.c b/base/sources/iron_audio.c index d3d3bfb1..7d4a7ad9 100644 --- a/base/sources/iron_audio.c +++ b/base/sources/iron_audio.c @@ -1,16 +1,19 @@ #include "iron_audio.h" -#ifdef IRON_A1 +#ifdef IRON_AUDIO #include "iron_audio.h" +#include "iron_file.h" #include "iron_math.h" #include "iron_thread.h" #include "iron_video.h" #include +#include #include #include #include +#include struct iron_a1_channel { iron_a1_sound_t *sound; @@ -88,18 +91,18 @@ void iron_a1_mix(iron_a2_buffer_t *buffer, uint32_t samples) { } } - for (int i = 0; i < CHANNEL_COUNT; ++i) { - if (videos[i].stream != NULL) { - float *samples = iron_internal_video_sound_stream_next_frame(videos[i].stream); - left_value += samples[0]; - left_value = fmaxf(fminf(left_value, 1.0f), -1.0f); - right_value += samples[1]; - right_value = fmaxf(fminf(right_value, 1.0f), -1.0f); - if (iron_internal_video_sound_stream_ended(videos[i].stream)) { - videos[i].stream = NULL; - } - } - } + // for (int i = 0; i < CHANNEL_COUNT; ++i) { + // if (videos[i].stream != NULL) { + // float *samples = iron_internal_video_sound_stream_next_frame(videos[i].stream); + // left_value += samples[0]; + // left_value = fmaxf(fminf(left_value, 1.0f), -1.0f); + // right_value += samples[1]; + // right_value = fmaxf(fminf(right_value, 1.0f), -1.0f); + // if (iron_internal_video_sound_stream_ended(videos[i].stream)) { + // videos[i].stream = NULL; + // } + // } + // } iron_mutex_unlock(&mutex); diff --git a/base/sources/iron_audio.h b/base/sources/iron_audio.h index 5dfe84f1..9e6c850b 100644 --- a/base/sources/iron_audio.h +++ b/base/sources/iron_audio.h @@ -1,6 +1,6 @@ #pragma once -#ifdef IRON_A1 +#ifdef IRON_AUDIO #include "iron_global.h" #include @@ -10,6 +10,40 @@ system audio-API or is implemented based on Audio2. */ +typedef struct iron_a1_sound { + uint8_t channel_count; + uint8_t bits_per_sample; + uint32_t samples_per_second; + int16_t *left; + int16_t *right; + int size; + float sample_rate_pos; + float volume; + bool in_use; +} iron_a1_sound_t; + +typedef struct iron_a1_sound_stream { + struct stb_vorbis *vorbis; + int chans; + int rate; + bool myLooping; + float myVolume; + bool rateDecodedHack; + bool end; + float samples[2]; + uint8_t *buffer; +} iron_a1_sound_stream_t; + +#define IRON_A2_MAX_CHANNELS 8 + +typedef struct iron_a2_buffer { + uint8_t channel_count; + float *channels[IRON_A2_MAX_CHANNELS]; + uint32_t data_size; + uint32_t read_location; + uint32_t write_location; +} iron_a2_buffer_t; + struct iron_internal_video_sound_stream; struct iron_a1_channel; @@ -34,18 +68,6 @@ void iron_a1_mix(iron_a2_buffer_t *buffer, uint32_t samples); void iron_internal_play_video_sound_stream(struct iron_internal_video_sound_stream *stream); void iron_internal_stop_video_sound_stream(struct iron_internal_video_sound_stream *stream); -typedef struct iron_a1_sound { - uint8_t channel_count; - uint8_t bits_per_sample; - uint32_t samples_per_second; - int16_t *left; - int16_t *right; - int size; - float sample_rate_pos; - float volume; - bool in_use; -} iron_a1_sound_t; - iron_a1_sound_t *iron_a1_sound_create(const char *filename); void iron_a1_sound_destroy(iron_a1_sound_t *sound); float iron_a1_sound_volume(iron_a1_sound_t *sound); @@ -53,18 +75,6 @@ void iron_a1_sound_set_volume(iron_a1_sound_t *sound, float value); struct stb_vorbis; -typedef struct iron_a1_sound_stream { - struct stb_vorbis *vorbis; - int chans; - int rate; - bool myLooping; - float myVolume; - bool rateDecodedHack; - bool end; - float samples[2]; - uint8_t *buffer; -} iron_a1_sound_stream_t; - iron_a1_sound_stream_t *iron_a1_sound_stream_create(const char *filename, bool looping); float *iron_a1_sound_stream_next_frame(iron_a1_sound_stream_t *stream); int iron_a1_sound_stream_channels(iron_a1_sound_stream_t *stream); @@ -80,7 +90,7 @@ void iron_a1_sound_stream_set_volume(iron_a1_sound_stream_t * #endif -#ifdef IRON_A2 +#ifdef IRON_AUDIO #include "iron_global.h" @@ -90,16 +100,6 @@ void iron_a1_sound_stream_set_volume(iron_a1_sound_stream_t * \brief Audio2 is a low-level audio-API that allows you to directly provide a stream of audio-samples. */ -#define IRON_A2_MAX_CHANNELS 8 - -typedef struct iron_a2_buffer { - uint8_t channel_count; - float *channels[IRON_A2_MAX_CHANNELS]; - uint32_t data_size; - uint32_t read_location; - uint32_t write_location; -} iron_a2_buffer_t; - void iron_a2_init(void); void iron_a2_set_callback(void (*iron_a2_audio_callback)(iron_a2_buffer_t *buffer, uint32_t samples, void *userdata), void *userdata); uint32_t iron_a2_samples_per_second(void); diff --git a/paint/project.js b/paint/project.js index 121a09c3..7c7c5a06 100644 --- a/paint/project.js +++ b/paint/project.js @@ -14,16 +14,17 @@ flags.with_plugins = true; flags.with_kong = true; flags.with_raytrace = true; flags.with_bc7 = true; +// flags.with_audio = true; flags.idle_sleep = true; flags.export_version_info = true; flags.export_data_list = platform == "android"; // .apk contents if (platform == "wasm") { - flags.with_nfd = false; - flags.with_compress = false; - flags.with_plugins = false; - flags.with_raytrace = false; - flags.export_data_list = true; + flags.with_nfd = false; + flags.with_compress = false; + flags.with_plugins = false; + flags.with_raytrace = false; + flags.export_data_list = true; } let project = new Project(flags.name);