base: fix audio compile
This commit is contained in:
+3
-4
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
#ifdef IRON_A2
|
||||
#ifdef IRON_AUDIO
|
||||
|
||||
#include "iron_audio.h"
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
#ifdef IRON_A2
|
||||
#ifdef IRON_AUDIO
|
||||
|
||||
#import <AudioToolbox/AudioToolbox.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
|
||||
#ifdef IRON_A2
|
||||
#ifdef IRON_AUDIO
|
||||
|
||||
#include <alsa/asoundlib.h>
|
||||
#include <errno.h>
|
||||
#define IRON_IMPLEMENTATION
|
||||
#include <iron_audio.h>
|
||||
#include <poll.h>
|
||||
#include <pthread.h>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
#ifdef IRON_A2
|
||||
#ifdef IRON_AUDIO
|
||||
|
||||
#include <CoreAudio/AudioHardware.h>
|
||||
#include <CoreServices/CoreServices.h>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
#ifdef IRON_A2
|
||||
#ifdef IRON_AUDIO
|
||||
|
||||
#include <iron_audio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
#ifdef IRON_A2
|
||||
#ifdef IRON_AUDIO
|
||||
|
||||
#include <backends/windows_system.h>
|
||||
#include <iron_audio.h>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
+6
-6
@@ -30,7 +30,7 @@
|
||||
#else
|
||||
#include <sys/stat.h>
|
||||
#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 <lz4x.h>
|
||||
#include <stdio.h>
|
||||
#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;
|
||||
|
||||
+16
-13
@@ -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 <assert.h>
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
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);
|
||||
|
||||
|
||||
+36
-36
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef IRON_A1
|
||||
#ifdef IRON_AUDIO
|
||||
|
||||
#include "iron_global.h"
|
||||
#include <stdbool.h>
|
||||
@@ -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);
|
||||
|
||||
+6
-5
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user