]> _ Git - colon3sampler.git/commitdiff
weird bug, vlc wont recognize it TvT
authorparking_turkeys <roya1060wien@gmail.com>
Mon, 19 Oct 2026 16:55:31 +0000 (12:55 -0400)
committerparking_turkeys <roya1060wien@gmail.com>
Mon, 19 Oct 2026 16:55:31 +0000 (12:55 -0400)
Makefile
colon3sampler.h
main.c
test/a_out.wav [new file with mode: 0644]
test/test.wav [new file with mode: 0644]
writewave.c [new file with mode: 0644]

index c4b11aa..40404e8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,10 @@
 linux:
        $(CC) *.h *.c -Werror -Wall -Wno-unused-label -lm -o colon3sampler -std=c99
 linux-test: linux
+       @echo "testing the thing with an UTAU + oto stuff"
        ./colon3sampler test/a.wav test/a_out.wav F4 100 / 24.0 550 56 73 100 0 !120
+       @echo "testing the thing with teto singing A on C4 (switch to G4)"
+       @echo "./colon3sampler test/test.wav test/test_out.wav G4 100 / 0.0 550 2 2 100 0 !120"
+       @echo "it doesnt work btw but i frogor how to do comments"
        
 
index 2dda5b7..b5f6dbc 100644 (file)
@@ -16,6 +16,7 @@ float get_pitch(int16_t wave[], int w_B);
 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);
 
 
 /* From other things */
diff --git a/main.c b/main.c
index d6646cc..bf92c28 100644 (file)
--- a/main.c
+++ b/main.c
@@ -155,7 +155,9 @@ int main(int argc, char *argv[])
                change_pitch(phoneme, ph_B, pitch_mult, resampled);
        change_length:
                /* tba */
-       
+       write_wave:
+               /* change what u write later */
+               write_wave(argv[2], resampled, resampled_len);
        cleanup:
                free(wave);
                free(phoneme);
diff --git a/test/a_out.wav b/test/a_out.wav
new file mode 100644 (file)
index 0000000..c0aba63
Binary files /dev/null and b/test/a_out.wav differ
diff --git a/test/test.wav b/test/test.wav
new file mode 100644 (file)
index 0000000..71b7131
Binary files /dev/null and b/test/test.wav differ
diff --git a/writewave.c b/writewave.c
new file mode 100644 (file)
index 0000000..58532ea
--- /dev/null
@@ -0,0 +1,89 @@
+#include "colon3sampler.h"
+/* technically ive written this before but i want to redo it */
+
+#define HEADLEN 44
+#define FMTLEN  16
+
+static int write_blank_header(char *out_filename);
+static int append_wave(char *out_filename, int16_t wave[], int w_B);
+
+int write_wave(char *out_filename, int16_t wave[], int w_B)
+{
+       write_blank_header(out_filename);
+       append_wave(out_filename, wave, w_B);
+       return 1;
+};
+
+static int write_blank_header(char *fn)
+{
+       FILE *fp;
+       fp = fopen(fn, "wb");
+       struct __attribute__((packed)) header {
+               const char riff[4];
+               const uint32_t riff_len;
+               const char wave[4];
+               const char fmt_[4];
+               const uint32_t fmt__len;
+               const uint16_t format_tag;
+               const uint16_t channels;
+               const uint32_t sampling_rate;
+               const uint32_t bytes_per_second;
+               const uint16_t block_align;
+               const uint16_t bits_per_sample;
+               const uint16_t data[4];
+               const uint32_t data_size;
+       };
+       const struct header wavheader = {
+               {'R', 'I', 'F', 'F'},
+               HEADLEN-8,
+               {'W', 'A', 'V', 'E'},
+               {'f', 'm', 't', ' '},
+               FMTLEN,
+               1,
+               1,
+               44100,
+               88200,
+               2,
+               16,
+               {'d', 'a', 't', 'a'},
+               0
+       };
+       int b_w = fwrite(&wavheader, 1, HEADLEN, fp);
+       if (b_w < HEADLEN) goto error;
+       fclose(fp);
+       return 1;
+error:
+       printf("oh no error");
+       return 0;
+};
+
+static int append_wave(char *fn, int16_t w[], int w_B)
+{
+       if (fn == NULL) return 0;
+       FILE *fp;
+       fp = fopen(fn, "r+b"); /* not append since that writes to the end of
+                                 the file only, not write since that removes
+                                 the file. b does nothing on Linux/any POSIX
+                                 conforming system but on Windows is needed.
+                                 otherwise it won't work */
+       /* Not going to actually read how much the length is since i'm just
+        * overwriting it. It might be faster to combine this and the header
+        * part, actually... */
+
+       fseek(fp, 4, SEEK_SET); /* Filesize - 8 */
+       const uint32_t riffsize = HEADLEN + w_B - 8;
+       fwrite(&riffsize, 4, 1, fp);
+       
+       fseek(fp, 40, SEEK_SET); /* Wave size */
+       const uint32_t wavesize = (uint32_t)w_B;
+       fwrite(&wavesize, 4, 1, fp);
+
+       /* should be right at the start of the wave :) */
+       int w_i = fwrite(w, 2, w_B, fp); /* w_B 2byte items */
+       if (w_i < w_B) goto error;
+       fclose(fp);
+       return 1;
+error:
+       printf("error with appending wave");
+       return 0;
+};