--- /dev/null
+#include "colon3sampler.h"
+
+static int change_speed_pitch(int16_t wave[], int w_B, float pitch_mult,
+ int16_t out_wave[], int out_w_B); /* Put NULL to get length */
+static int16_t get_fractional_index(int16_t wave[], float index);
+
+int change_pitch(int16_t w[], int w_B, float p_m, int16_t ow[])
+{
+ /* Oh i dont know how to do this */
+ /* It'll probably be bad to change it too much */
+get_length:
+ int length = floor((w_B/2)/p_m) * 2;
+ printf("original length: %d; mult: %f; new length: %d\n", w_B, p_m, length);
+ if (ow == NULL) goto return_length;
+change_pitch:
+ change_speed_pitch(w, w_B, p_m, ow, length);
+
+return_success:
+ return 1;
+return_error:
+ fprintf(stderr, "error :(\n");
+ return 0;
+return_length:
+ return length;
+};
+
+static int change_speed_pitch(int16_t w[], int w_B, float p_m,
+ int16_t ow[], int ow_B)
+{
+ int ow_i = 0;
+ for (double i = 0.0; (i+p_m) < (w_B/2); i+=p_m) {
+ if (ow_i >= (ow_B/2)) {
+ printf( "ow_i: %d; i: %f; ow_B: %d\n"
+ "Too short out wave for change_speed_pitch\n",
+ ow_i, i, ow_B);
+ return 0;
+ };
+ /* if it's round it's easy... */
+ if (i == (float)floor(i)) {
+ ow[ow_i] = w[(int)floor(i)];
+ } else {
+ ow[ow_i] = get_fractional_index(w, i);
+ };
+ ow_i++;
+ };
+ return 1;
+};
+
+static int16_t get_fractional_index(int16_t w[], float i)
+{
+ /* idk */
+ int lower = w[(int)floor(i)];
+ int higher = w[(int)ceil(i)];
+ float fraction = i - floor(i);
+ int16_t result = higher*fraction + lower*(1-fraction);
+ return result;
+
+};
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>
-#include <math.h>
+#include <math.h>
#include <stdlib.h>
#define ß(arg) arg_to_float(arg)
float offset, float cutoff, float consonant);
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 */
+
/* From other things */
int readWave(char *filename, int16_t buffer[], int STP_ms); /* STP=0 */
change_pitch:
float pitch_mult = pitch_Hz/midi_to_hz(argv[3]);
printf("%f", pitch_mult);
- //change_pitch(phoneme, ph_B, 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 */
+
cleanup:
free(wave);
+ free(phoneme);
+ free(resampled);
return 0;
error:
//putc('e');putc('r');putc('r');putc('o');putc('r');