nvm fuck libxm, fuck msvc, fuck bill gates and fuck (You)
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -17,6 +17,3 @@
|
||||
[submodule "external/SDL_mixer"]
|
||||
path = external/SDL_mixer
|
||||
url = https://github.com/libsdl-org/SDL_mixer
|
||||
[submodule "external/libxm"]
|
||||
path = external/libxm
|
||||
url = https://github.com/Artefact2/libxm
|
||||
|
||||
@@ -47,7 +47,7 @@ set(SDLMIXER_GME OFF CACHE BOOL "" FORCE)
|
||||
set(SDLMIXER_MOD_XMP OFF CACHE BOOL "" FORCE)
|
||||
set(SDLMIXER_MP3_MPG123 OFF CACHE BOOL "" FORCE)
|
||||
set(SDLMIXER_MIDI_FLUIDSYNTH OFF CACHE BOOL "" FORCE)
|
||||
set(SDLMIXER_OPUS OFF CACHE BOOL "" FORCE)
|
||||
set(SDLMIXER_OPUS ON CACHE BOOL "" FORCE)
|
||||
set(SDLMIXER_VORBIS_VORBISFILE OFF CACHE BOOL "" FORCE)
|
||||
set(SDLMIXER_VORBIS_TREMOR OFF CACHE BOOL "" FORCE)
|
||||
set(SDLMIXER_WAVPACK OFF CACHE BOOL "" FORCE)
|
||||
@@ -56,11 +56,7 @@ set(SDLMIXER_INSTALL OFF CACHE BOOL "" FORCE)
|
||||
add_subdirectory(external/SDL_mixer EXCLUDE_FROM_ALL)
|
||||
|
||||
add_subdirectory(external/lunasvg)
|
||||
if (WIN32)
|
||||
set(MATH_LIBRARY "" CACHE FILEPATH "Windows doesn't require libm for libxm" FORCE)
|
||||
endif ()
|
||||
add_subdirectory(external/libxm/src EXCLUDE_FROM_ALL)
|
||||
set(LIBXM_COMPAT_HEADER "${CMAKE_SOURCE_DIR}/include/libxm_compat.h")
|
||||
|
||||
|
||||
set(GLAD_SRC ${CMAKE_CURRENT_SOURCE_DIR}/include/glad/glad.cpp)
|
||||
|
||||
@@ -98,13 +94,6 @@ add_executable(${PROJECT_NAME}
|
||||
${TINYXML2_SRC}
|
||||
${PROJECT_SRC}
|
||||
)
|
||||
if (MSVC)
|
||||
file(TO_NATIVE_PATH "${LIBXM_COMPAT_HEADER}" LIBXM_COMPAT_HEADER_NATIVE)
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE "/FI${LIBXM_COMPAT_HEADER_NATIVE}")
|
||||
if (TARGET xm)
|
||||
target_compile_options(xm PRIVATE "/FI${LIBXM_COMPAT_HEADER_NATIVE}")
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
if (WIN32)
|
||||
enable_language(RC)
|
||||
@@ -160,7 +149,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE
|
||||
src/util
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE GL SDL3-static SDL3_mixer::SDL3_mixer lunasvg xm)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE GL SDL3-static SDL3_mixer::SDL3_mixer lunasvg)
|
||||
|
||||
message(STATUS "System: ${CMAKE_SYSTEM_NAME}")
|
||||
message(STATUS "Project: ${PROJECT_NAME}")
|
||||
|
||||
1
external/libxm
vendored
1
external/libxm
vendored
Submodule external/libxm deleted from 9f599c4dd4
@@ -1,10 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#ifndef __attribute__
|
||||
#define __attribute__(x)
|
||||
#endif
|
||||
#ifndef restrict
|
||||
#define restrict __restrict
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,90 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef __STDC_VERSION_STDCKDINT_H__
|
||||
#define __STDC_VERSION_STDCKDINT_H__ 202311L
|
||||
|
||||
#define __CKD_ADD_UNSIGNED(name, type) \
|
||||
static inline bool ckd_add_##name(type* result, type a, type b) \
|
||||
{ \
|
||||
type tmp = (type)(a + b); \
|
||||
*result = tmp; \
|
||||
return tmp < a; \
|
||||
}
|
||||
|
||||
#define __CKD_SUB_UNSIGNED(name, type) \
|
||||
static inline bool ckd_sub_##name(type* result, type a, type b) \
|
||||
{ \
|
||||
*result = (type)(a - b); \
|
||||
return a < b; \
|
||||
}
|
||||
|
||||
#define __CKD_ADD_SIGNED(name, type, min_v, max_v) \
|
||||
static inline bool ckd_add_##name(type* result, type a, type b) \
|
||||
{ \
|
||||
const type minValue = (type)(min_v); \
|
||||
const type maxValue = (type)(max_v); \
|
||||
const type tmp = (type)(a + b); \
|
||||
*result = tmp; \
|
||||
return (b > 0 && a > (type)(maxValue - b)) || (b < 0 && a < (type)(minValue - b)); \
|
||||
}
|
||||
|
||||
#define __CKD_SUB_SIGNED(name, type, min_v, max_v) \
|
||||
static inline bool ckd_sub_##name(type* result, type a, type b) \
|
||||
{ \
|
||||
const type minValue = (type)(min_v); \
|
||||
const type maxValue = (type)(max_v); \
|
||||
const type tmp = (type)(a - b); \
|
||||
*result = tmp; \
|
||||
return (b > 0 && a < (type)(minValue + b)) || (b < 0 && a > (type)(maxValue + b)); \
|
||||
}
|
||||
|
||||
__CKD_ADD_UNSIGNED(u8, uint8_t)
|
||||
__CKD_ADD_UNSIGNED(u16, uint16_t)
|
||||
__CKD_ADD_UNSIGNED(u32, uint32_t)
|
||||
__CKD_ADD_UNSIGNED(u64, uint64_t)
|
||||
__CKD_ADD_UNSIGNED(usz, size_t)
|
||||
|
||||
__CKD_SUB_UNSIGNED(u8, uint8_t)
|
||||
__CKD_SUB_UNSIGNED(u16, uint16_t)
|
||||
__CKD_SUB_UNSIGNED(u32, uint32_t)
|
||||
__CKD_SUB_UNSIGNED(u64, uint64_t)
|
||||
__CKD_SUB_UNSIGNED(usz, size_t)
|
||||
|
||||
__CKD_ADD_SIGNED(i8, int8_t, INT8_MIN, INT8_MAX)
|
||||
__CKD_ADD_SIGNED(i16, int16_t, INT16_MIN, INT16_MAX)
|
||||
__CKD_ADD_SIGNED(i32, int32_t, INT32_MIN, INT32_MAX)
|
||||
__CKD_ADD_SIGNED(i64, int64_t, INT64_MIN, INT64_MAX)
|
||||
|
||||
__CKD_SUB_SIGNED(i8, int8_t, INT8_MIN, INT8_MAX)
|
||||
__CKD_SUB_SIGNED(i16, int16_t, INT16_MIN, INT16_MAX)
|
||||
__CKD_SUB_SIGNED(i32, int32_t, INT32_MIN, INT32_MAX)
|
||||
__CKD_SUB_SIGNED(i64, int64_t, INT64_MIN, INT64_MAX)
|
||||
|
||||
#undef __CKD_ADD_UNSIGNED
|
||||
#undef __CKD_SUB_UNSIGNED
|
||||
#undef __CKD_ADD_SIGNED
|
||||
#undef __CKD_SUB_SIGNED
|
||||
|
||||
#define __CKD_DISPATCH(result, a, b, add_fn, sub_fn) \
|
||||
(_Generic((result), \
|
||||
uint8_t*: add_fn##_u8, \
|
||||
const uint8_t*: add_fn##_u8, \
|
||||
unsigned char*: add_fn##_u8, \
|
||||
uint16_t*: add_fn##_u16, \
|
||||
uint32_t*: add_fn##_u32, \
|
||||
uint64_t*: add_fn##_u64, \
|
||||
size_t*: add_fn##_usz, \
|
||||
int8_t*: add_fn##_i8, \
|
||||
int16_t*: add_fn##_i16, \
|
||||
int32_t*: add_fn##_i32, \
|
||||
int64_t*: add_fn##_i64)(result, a, b))
|
||||
|
||||
#define ckd_add(result, a, b) __CKD_DISPATCH(result, a, b, ckd_add, ckd_sub)
|
||||
#define ckd_sub(result, a, b) __CKD_DISPATCH(result, a, b, ckd_add, ckd_sub)
|
||||
|
||||
#endif /* __STDC_VERSION_STDCKDINT_H__ */
|
||||
@@ -781,10 +781,13 @@ namespace anm2ed::imgui
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
if (auto* music = resources.music_track_if_loaded())
|
||||
if (music->is_playing() && !aboutPopup.isOpen) music->stop();
|
||||
|
||||
overwritePopup.trigger();
|
||||
|
||||
if (ImGui::BeginPopupModal(overwritePopup.label, &overwritePopup.isOpen, ImGuiWindowFlags_NoResize))
|
||||
{
|
||||
|
||||
ImGui::Text("Are you sure? This will overwrite the existing file.");
|
||||
|
||||
auto widgetSize = widget_size_with_row_get(2);
|
||||
@@ -802,9 +805,6 @@ namespace anm2ed::imgui
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
if (auto* music = resources.music_track_if_loaded())
|
||||
if (music->is_playing() && !aboutPopup.isOpen) music->stop();
|
||||
|
||||
aboutPopup.end();
|
||||
|
||||
if (shortcut(manager.chords[SHORTCUT_NEW], shortcut::GLOBAL)) dialog.file_save(dialog::ANM2_NEW);
|
||||
@@ -818,3 +818,6 @@ namespace anm2ed::imgui
|
||||
if (shortcut(manager.chords[SHORTCUT_EXIT], shortcut::GLOBAL)) isQuitting = true;
|
||||
}
|
||||
}
|
||||
#ifndef ANM2ED_USE_LIBXM
|
||||
#define ANM2ED_USE_LIBXM 1
|
||||
#endif
|
||||
|
||||
@@ -1,24 +1,10 @@
|
||||
#include "audio.h"
|
||||
|
||||
#include <SDL3/SDL_properties.h>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <xm.h>
|
||||
|
||||
namespace anm2ed::resource
|
||||
{
|
||||
namespace
|
||||
{
|
||||
constexpr int XM_SAMPLE_RATE_ = 44100;
|
||||
constexpr uint16_t XM_CHUNK_FRAMES = 1024;
|
||||
constexpr int XM_MAX_SECONDS = 600;
|
||||
constexpr int XM_CHANNELS = 2;
|
||||
}
|
||||
|
||||
MIX_Mixer* Audio::mixer_get()
|
||||
{
|
||||
static auto mixer = MIX_CreateMixerDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, nullptr);
|
||||
@@ -32,67 +18,9 @@ namespace anm2ed::resource
|
||||
|
||||
Audio::Audio(const unsigned char* data, size_t size)
|
||||
{
|
||||
if (!data || size == 0) return;
|
||||
|
||||
auto is_chunk_silent = [](const float* samples, size_t count)
|
||||
{
|
||||
constexpr float epsilon = 1e-6f;
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
if (std::fabs(samples[i]) > epsilon) return false;
|
||||
return true;
|
||||
};
|
||||
|
||||
auto prescanStorage = std::make_unique<unsigned char[]>(XM_PRESCAN_DATA_SIZE);
|
||||
auto prescan = (xm_prescan_data_t*)prescanStorage.get();
|
||||
if (!xm_prescan_module((const char*)data, (uint32_t)size, prescan)) return;
|
||||
|
||||
const auto contextSize = static_cast<size_t>(xm_size_for_context(prescan));
|
||||
auto pool = std::make_unique<char[]>(contextSize);
|
||||
auto context = xm_create_context(pool.get(), prescan, (const char*)data, (uint32_t)size);
|
||||
if (!context) return;
|
||||
|
||||
xm_set_sample_rate(context, (uint16_t)XM_SAMPLE_RATE_);
|
||||
xm_set_max_loop_count(context, 1);
|
||||
|
||||
auto pcm = std::vector<float>{};
|
||||
pcm.reserve(static_cast<size_t>(XM_CHUNK_FRAMES) * XM_CHANNELS * 8);
|
||||
|
||||
size_t framesGenerated = 0;
|
||||
const auto maxFrames = static_cast<size_t>(XM_SAMPLE_RATE_) * XM_MAX_SECONDS;
|
||||
auto heardAudio = false;
|
||||
|
||||
while (framesGenerated < maxFrames)
|
||||
{
|
||||
auto framesThisPass = (uint16_t)std::min<size_t>(XM_CHUNK_FRAMES, maxFrames - framesGenerated);
|
||||
auto offset = pcm.size();
|
||||
pcm.resize(offset + framesThisPass * XM_CHANNELS);
|
||||
auto* chunkStart = pcm.data() + offset;
|
||||
xm_generate_samples(context, chunkStart, framesThisPass);
|
||||
framesGenerated += framesThisPass;
|
||||
|
||||
auto chunkSamples = (size_t)framesThisPass * XM_CHANNELS;
|
||||
auto chunkSilent = is_chunk_silent(chunkStart, chunkSamples);
|
||||
if (!chunkSilent)
|
||||
{
|
||||
heardAudio = true;
|
||||
}
|
||||
else if (heardAudio)
|
||||
{
|
||||
pcm.resize(offset);
|
||||
break;
|
||||
}
|
||||
|
||||
if (xm_get_loop_count(context) > 0) break;
|
||||
}
|
||||
|
||||
if (pcm.empty()) return;
|
||||
|
||||
auto spec = SDL_AudioSpec{};
|
||||
spec.freq = XM_SAMPLE_RATE_;
|
||||
spec.format = SDL_AUDIO_F32;
|
||||
spec.channels = XM_CHANNELS;
|
||||
|
||||
internal = MIX_LoadRawAudio(nullptr, pcm.data(), pcm.size() * sizeof(float), &spec);
|
||||
SDL_IOStream* io = SDL_IOFromConstMem(data, size);
|
||||
if (!io) return;
|
||||
internal = MIX_LoadAudio_IO(mixer_get(), io, true, true);
|
||||
}
|
||||
|
||||
void Audio::unload()
|
||||
|
||||
30340
src/resource/music.h
Normal file
30340
src/resource/music.h
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,9 @@
|
||||
#include "resources.h"
|
||||
|
||||
#include "xm_music.h"
|
||||
|
||||
#include <ranges>
|
||||
|
||||
#include "music.h"
|
||||
|
||||
using namespace anm2ed::resource;
|
||||
|
||||
namespace anm2ed
|
||||
@@ -24,14 +24,11 @@ namespace anm2ed
|
||||
{
|
||||
if (!isMusicLoaded)
|
||||
{
|
||||
music = Audio(xm::ABOUT, std::size(xm::ABOUT));
|
||||
music = Audio(music::ABOUT, std::size(music::ABOUT));
|
||||
isMusicLoaded = true;
|
||||
}
|
||||
return music;
|
||||
}
|
||||
|
||||
resource::Audio* Resources::music_track_if_loaded()
|
||||
{
|
||||
return isMusicLoaded ? &music : nullptr;
|
||||
}
|
||||
resource::Audio* Resources::music_track_if_loaded() { return isMusicLoaded ? &music : nullptr; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user