]> _ Git - colon3sampler.git/commitdiff
It works omg; im going to make it less choppy now :) [still need to fix pitch detecti...
authorparking_turkeys <roya1060wien@gmail.com>
Mon, 19 Oct 2026 17:39:34 +0000 (13:39 -0400)
committerparking_turkeys <roya1060wien@gmail.com>
Mon, 19 Oct 2026 17:39:34 +0000 (13:39 -0400)
main.c
writewave.c

diff --git a/main.c b/main.c
index 4e1ef7e..bf05a03 100644 (file)
--- a/main.c
+++ b/main.c
@@ -149,13 +149,12 @@ 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 */
+               pitch_mult = 1.2; /* 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
index 58532ea..acb6139 100644 (file)
@@ -18,6 +18,7 @@ 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;
@@ -50,6 +51,46 @@ static int write_blank_header(char *fn)
        };
        int b_w = fwrite(&wavheader, 1, HEADLEN, fp);
        if (b_w < HEADLEN) goto error;
+       */
+       const char riff_id[4] = {'R', 'I', 'F', 'F' };
+       fwrite(riff_id, 4, 1, fp);
+
+       const uint32_t riff_length = HEADLEN - 8;
+       fwrite(&riff_length, 4, 1, fp);
+
+       const char wave_id[4] = {'W', 'A', 'V', 'E'};
+       fwrite(wave_id, 4, 1, fp);
+
+       const char fmt_id[4] = {'f', 'm', 't', ' '};
+       fwrite(fmt_id, 4, 1, fp);
+
+       const uint32_t fmt_length = FMTLEN;
+       fwrite(&fmt_length, 4, 1, fp);
+
+       const uint16_t format_tag = 1; //microsoft PCM i think??
+       fwrite(&format_tag, 2, 1, fp);
+
+       const uint16_t channel_count = 1; //mono
+       fwrite(&channel_count, 2, 1, fp);
+
+       const uint32_t sampling_rate = 44100;
+       fwrite(&sampling_rate, 4, 1, fp);
+
+       const uint32_t bytes_per_second = 88200;
+       fwrite(&bytes_per_second, 4, 1, fp);
+
+       const uint16_t block_align = 2; //no idea what this means
+       fwrite(&block_align, 2, 1, fp);
+
+       const uint16_t bits_per_sample = 16;
+       fwrite(&bits_per_sample, 2, 1, fp);
+
+       const char data_id[4] = {'d', 'a', 't', 'a'};
+       fwrite(data_id, 4, 1, fp);
+
+       const uint32_t data_size = 0;
+       fwrite(&data_size, 4, 1, fp);
+
        fclose(fp);
        return 1;
 error:
@@ -79,8 +120,11 @@ static int append_wave(char *fn, int16_t w[], int 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;
+       /* oop actually */
+       fclose(fp);
+       fp = fopen(fn, "ab");
+       int w_i = fwrite(w, 1, w_B, fp); /* w_B 1byte items */
+       if (w_i < w_B - 1) goto error;
        fclose(fp);
        return 1;
 error: