From 51dc33e7eb0e1d5b1b2497216fdc1465a7a67a4d Mon Sep 17 00:00:00 2001 From: parking_turkeys Date: Mon, 19 Oct 2026 13:17:31 -0400 Subject: [PATCH] i think it works? but there's a bug i think ill change the writewave stuff... --- change_length.c | 30 ++++++++++++++++++++++++++++++ colon3sampler.h | 2 ++ main.c | 12 +++++++++++- 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 change_length.c diff --git a/change_length.c b/change_length.c new file mode 100644 index 0000000..218c319 --- /dev/null +++ b/change_length.c @@ -0,0 +1,30 @@ +#include "colon3sampler.h" + +int change_wave_len(int16_t w[], int w_B, int16_t ow[], int co, int ow_B) +{ + int end_samples = (w_B/2) - co; + int i = 0; + if (w_B < ow_B) goto loop_co; + if (w_B > ow_B) goto cut_wave; + return 0; +loop_co: + int co_i = 0; + for (i = 0; i < (ow_B/2-end_samples); i++) { + ow[i] = w[co_i++]; + if (co_i == co) co_i = 0; + }; + goto append_end; +cut_wave: + if (end_samples >= (ow_B/2)) goto append_end; + for (i = 0; i < (ow_B/2-end_samples); i++) { + ow[i] = w[i]; + }; + goto append_end; +append_end: + + for (i = i; (i < end_samples) && (i < (ow_B/2)); i++) { + ow[i] = w[co++]; + }; + return 1; +}; + diff --git a/colon3sampler.h b/colon3sampler.h index b5f6dbc..29275a4 100644 --- a/colon3sampler.h +++ b/colon3sampler.h @@ -17,6 +17,8 @@ float midi_to_hz(char *note); int change_pitch(int16_t wave[], int w_B, float pitch_multiplier, int16_t out_wave[]); /* Give NULL for length */ int write_wave(char *out_filename, int16_t wave[], int w_B); +int change_wave_len(int16_t wave[], int w_B, int16_t out_wave[], int consonant, + int out_len_B); /* out length in bytes*/ /* From other things */ diff --git a/main.c b/main.c index bf92c28..4e1ef7e 100644 --- a/main.c +++ b/main.c @@ -149,15 +149,25 @@ int main(int argc, char *argv[]) printf("The pitch is %f Hz.\n", pitch_Hz); change_pitch: float pitch_mult = pitch_Hz/midi_to_hz(argv[3]); + pitch_mult = 2.0; /* testing */ printf("%f", pitch_mult); int resampled_len = change_pitch(phoneme, ph_B, pitch_mult, NULL); int16_t *resampled = malloc(resampled_len); change_pitch(phoneme, ph_B, pitch_mult, resampled); change_length: /* tba */ + int final_B = (int)ceil(ß(argv[7]) * 88.200); /* have to set + calculate + length on UI + frontend for + this to work + */ + int16_t *final = malloc(final_B); + change_wave_len(resampled, resampled_len, final, + (int) ceil(cons_i/pitch_mult), final_B); write_wave: /* change what u write later */ - write_wave(argv[2], resampled, resampled_len); + write_wave(argv[2], final, final_B); cleanup: free(wave); free(phoneme); -- 2.47.3