diff options
author | bonmas14 <bonmas14@gmail.com> | 2025-09-21 23:12:28 +0300 |
---|---|---|
committer | bonmas14 <bonmas14@gmail.com> | 2025-09-21 23:12:28 +0300 |
commit | e9ecc6b4df41ced1b9dd39ad638435945d1a6374 (patch) | |
tree | 10b96db62df38aa269d1cc47d7f5be2d1d4513da /src | |
parent | b30d161ea14254173912fbb2afd296168f2561d8 (diff) | |
download | c_wizard-main.tar.gz c_wizard-main.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/entry.c | 26 | ||||
-rw-r--r-- | src/lpc10_enc_dec.h | 15 | ||||
-rw-r--r-- | src/program.c | 98 |
3 files changed, 104 insertions, 35 deletions
diff --git a/src/entry.c b/src/entry.c index f8b43d2..017ef56 100644 --- a/src/entry.c +++ b/src/entry.c @@ -1,3 +1,10 @@ +#include "raylib.h" + +#define RAYMATH_IMPLEMENTATION +#include "raymath.h" + +#define RAYGUI_IMPLEMENTATION +#include "raygui.h" #include <math.h> #include <stddef.h> @@ -5,6 +12,7 @@ #include <stdint.h> #include <stdbool.h> #include <float.h> +#include <string.h> /// ------------- @@ -59,16 +67,12 @@ typedef uint32_t b32; #endif #ifndef ERRLOG -#include <stdio.h> -#define ERRLOG(...) fprintf(stderr, __VA_ARGS__) +#define ERRLOG(...) TraceLog(LOG_ERROR, __VA_ARGS__) #endif #ifndef INFLOG -#include <stdio.h> -#define INFLOG(...) fprintf(stderr, __VA_ARGS__) +#define INFLOG(...) TraceLog(LOG_INFO, __VA_ARGS__) #endif -#include <string.h> - #if DEBUG # define assert(result) { \ if ((result) == 0) { \ @@ -84,16 +88,10 @@ typedef uint32_t b32; #define MEMCPY(dest, source, size) memcpy(dest, source, size) #define MEMCMP(a, b, size) memcmp(a, b, size) -#include "raylib.h" - #define TAU (2.0 * PI) -#define RAYMATH_IMPLEMENTATION -#include "raymath.h" - - -#define WINDOW_WIDTH 640 -#define WINDOW_HEIGHT 480 +#define WINDOW_WIDTH 900 +#define WINDOW_HEIGHT 700 f32 window_width = WINDOW_WIDTH; f32 window_height = WINDOW_HEIGHT; diff --git a/src/lpc10_enc_dec.h b/src/lpc10_enc_dec.h index 1d8f782..856d5f1 100644 --- a/src/lpc10_enc_dec.h +++ b/src/lpc10_enc_dec.h @@ -52,6 +52,7 @@ CHANGELOG: v1.0 Init version. v1.1 Adding LPC_UNUSED and LPC_INLINE macro as I forget to add it, preprocessor typos and coments style. + v1.2 Deleted setting frame_size_ms, as tms5220 is always 25 ms, introduced LPC_FRAME_SIZE_MS. */ #if !defined(LPC_ENC_DEC_H) @@ -91,10 +92,11 @@ extern "C" { #define LPC_PI 3.14159265358979323846f #define LPC_TAU (LPC_PI * 2) -#define LPC_SAMPLE_RATE 8000 -#define LPC_SAMPLES 200 -#define LPC_ENERGY_ZERO 0x0 -#define LPC_ENERGY_STOP 0xf +#define LPC_SAMPLE_RATE 8000 +#define LPC_SAMPLES 200 +#define LPC_ENERGY_ZERO 0x0 +#define LPC_ENERGY_STOP 0xf +#define LPC_FRAME_SIZE_MS 25 #if !defined(LPC_ALLOC) #include <stdlib.h> @@ -180,7 +182,6 @@ typedef struct { lpc_b32 do_pre_emphasis; lpc_f32 pre_emphasis_alpha; - lpc_u32 frame_size_ms; lpc_u32 window_size_in_segments; } Lpc_Encoder_Settings; @@ -189,7 +190,7 @@ typedef struct { 50.0f, 4000.0f, 1.0f, \ -0.1f, 2.0f, \ true, -0.9373, \ - 25, 2 \ + 2 \ } /* @@ -892,7 +893,7 @@ LPC_API Lpc_Codes lpc_encode(Lpc_Sample_Buffer buffer, Lpc_Encoder_Settings sett buffer = lpc_buffer_prepare_internal(buffer); pitch_buffer = lpc_buffer_copy_internal(buffer); - lpc_u32 segment_size = buffer.sample_rate / 1000 * settings.frame_size_ms; + lpc_u32 segment_size = buffer.sample_rate / 1000 * LPC_FRAME_SIZE_MS; lpc_u32 num_segments = ceilf((lpc_f32)buffer.frame_count / (lpc_f32)segment_size); segments = lpc_get_segments_internal(buffer, segment_size, num_segments); diff --git a/src/program.c b/src/program.c index 89901a9..3da1f14 100644 --- a/src/program.c +++ b/src/program.c @@ -1,10 +1,16 @@ #define LPC_STATIC_DECL #define LPC_ENC_DEC_IMPLEMENTATION #include "lpc10_enc_dec.h" +#include "blissful_orange.h" #define MAX_SAMPLES_UPDATE 512 #define SAMPLE_RATE 8000 +#define PADDING_PX 10 +#define FONT_SIZE 24 + +#define BACKGROUND_COLOR CLITERAL(Color) {0x1c, 0x1c, 0x1c, 0xff} + // AudioStream audio_stream; typedef enum { @@ -24,6 +30,10 @@ Program_State state; void program_init(void) { state.status = STATUS_IDLE; state.settings = LPC_DEFAULT_SETTINGS; + + SetWindowMinSize(WINDOW_WIDTH, WINDOW_HEIGHT); + GuiLoadStyleBlissfulOrange(); + GuiSetStyle(DEFAULT, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER); } void program_deinit(void) { @@ -103,30 +113,90 @@ void program_render(void) { Vector2 pos, size; const char *text; u64 i; + Rectangle rect; + s32 x, height, width; + + font = GetFontDefault(); BeginDrawing(); - ClearBackground(CLITERAL(Color) {0x1c, 0x1c, 0x1c, 0xff}); + ClearBackground(BACKGROUND_COLOR); - text = ">> drag and drop files here <<"; - font = GetFontDefault(); + switch (state.status) { + case STATUS_IDLE: + { + x = rect.x = window_width / 4; - size = MeasureTextEx(font, text, 24, 1); + width = rect.width = window_width / 2; + height = rect.height = window_height / 15; + rect.height -= PADDING_PX / 2; + rect.y = PADDING_PX / 2; - pos.x = window_width / 2 - size.x / 2; - pos.y = window_height / 2 - size.y / 2; + rect.width = window_width; + rect.x = 0; + GuiLabel(rect, "Pitch buffer settings"); + rect.x = x; + rect.width = width; - DrawTextEx(font, text, pos, 24, 1, WHITE); + rect.y += height; + GuiSlider(rect, "Low-cut", TextFormat("%.0f", state.settings.pitch_low_cut), &state.settings.pitch_low_cut, 1.0f, 500.0f); + rect.y += height; + GuiSlider(rect, "High-cut", TextFormat("%.0f", state.settings.pitch_high_cut), &state.settings.pitch_high_cut, 100.0f, 1000.0f); + rect.y += height; + GuiSlider(rect, "Q-Factor", TextFormat("%.2f", state.settings.pitch_q_factor), &state.settings.pitch_q_factor, 0.01f, 8.0f); - for (i = 0; i < state.path_list.count; i++) { - text = GetFileNameWithoutExt(state.path_list.paths[i]); + rect.y += height; + rect.width = window_width; + rect.x = 0; + GuiLabel(rect, "Ks processing buffer settings"); + rect.x = x; + rect.width = width; - text = TextFormat("[%s] %s", i < state.index ? "DONE" : "----", text); - size = MeasureTextEx(font, text, 24, 1); + rect.y += height; + GuiSlider(rect, "Low-cut", TextFormat("%.0f", state.settings.processing_low_cut), &state.settings.processing_low_cut, 1.0f, 500.0f); + rect.y += height; + GuiSlider(rect, "High-cut", TextFormat("%.0f", state.settings.processing_high_cut), &state.settings.processing_high_cut, 100.0f, 4000.0f); + rect.y += height; + GuiSlider(rect, "Q-Factor", TextFormat("%.2f", state.settings.processing_q_factor), &state.settings.processing_q_factor, 0.01f, 8.0f); + rect.y += height; - pos.x = size.y; - pos.y = size.y * (i + 1); + rect.y += height; + GuiSlider(rect, "Unvoiced thresh.", TextFormat("%.2f", state.settings.unvoiced_thresh), &state.settings.unvoiced_thresh, -1.0f, 1.0f); + rect.y += height; + GuiSlider(rect, "Unvoiced RMS mult.", TextFormat("%.2f", state.settings.unvoiced_rms_multiply), &state.settings.unvoiced_rms_multiply, 0.0f, 8.0f); - DrawTextEx(font, text, pos, 24, 1, WHITE); + rect.y += height; + GuiToggle(rect, "Pre Emphasis", (bool*)&state.settings.do_pre_emphasis); + rect.y += height; + GuiSlider(rect, "Alpha", TextFormat("%.6f", state.settings.pre_emphasis_alpha), &state.settings.pre_emphasis_alpha, -1.0f, 1.0f); + + rect.y += height * 2; + rect.width = window_width; + rect.x = 0; + GuiLabel(rect, "Drag and drop files you need to convert"); + } break; + case STATUS_CONVERTING: + { + text = "---- PROCESSING ----"; + size = MeasureTextEx(font, text, 24, 1); + pos.x = window_width / 2 - size.x / 2; + pos.y = window_height / 2 - size.y / 2; + + DrawTextEx(font, text, pos, 24, 1, WHITE); + + for (i = 0; i < state.path_list.count; i++) { + if (i < state.index) continue; + + text = GetFileNameWithoutExt(state.path_list.paths[i]); + + text = TextFormat("%s", text); + size = MeasureTextEx(font, text, 24, 1); + + pos.x = size.y; + pos.y = size.y * ((i - state.index) + 1); + + DrawTextEx(font, text, pos, 24, 1, WHITE); + } + } break; } EndDrawing(); |