#include <math.h>
#include <stdlib.h>
+#define ß(arg) arg_to_float(arg)
+
/* FUNCTIONS */
-int get_pitch(int16_t wave[], int w_B);
+/* Returns length required if new_wave is NULL, returns index of consonant
+ * otherwise. Length required is in BYTES. */
+int get_important_wave(int16_t orig_wave[], int w_B, int16_t new_wave[],
+ float offset, float cutoff, float consonant);
+float get_pitch(int16_t wave[], int w_B);
+/* From other things */
int readWave(char *filename, int16_t buffer[], int STP_ms); /* STP=0 */
+
+float length_arg_to_float(char *arg);
+float arg_to_float(char *arg);
+int report_error(char *msg, char *portion, char *program);
--- /dev/null
+#include "colon3sampler.h"
+
+int get_important_wave(int16_t ow[], int w_B, int16_t b[],
+ float off, float cut, float cons) {
+ /* idk */
+get_length:
+ int end_length_B = 0;
+ end_length_B = ((cut-off)*44.100) * 2;
+ if (end_length_B < 1) goto error;
+ if (b == NULL) goto tell_length;
+ if ((cut * 88.200) > w_B) goto error;
+write_wave:
+ int b_i = 0;
+ for (int i = (off*44.100); i < (cut*44.100); i++) {
+ b[b_i++] = ow[i];
+ };
+ goto tell_cons;
+error:
+ return -1;
+tell_length:
+ return end_length_B;
+tell_cons:
+ return (int) (cons*44.100)-(off*44.100);
+};
#include "colon3sampler.h"
-int get_pitch(int16_t w[], int w_B)
+float get_pitch(int16_t w[], int w_B)
{
/* count the things. */
int P = 0; int P_i = 0;
int *Ps = malloc(w_B);
- for (int i = 0; i < (w_B*2-5); i++) {
+ for (int i = 0; i < (w_B/2); i++) {
if (w[i] == 0) {
if (P > 1) {
Ps[P_i] = P;
P = 0;
};
};
+ //printf("%d\n", w[i]);
P++;
};
/* get average period */
int av = 0;
for (int i = 0; i < P_i; i++) {
av += Ps[i];
+ //printf("%d\n", Ps[i]);
};
free(Ps);
if (P_i == 0) goto error;
if (av == 0) goto error;
av = av/P_i;
+ printf("av: %d", av);
+ /* CONVERT THIS TO SECONDS >:( */
+ //float av_s = av/41000;
+ //printf("av_s: %f", av_s);
/* get frequency */
- float frq_f = 1/av;
+ float frq_f = 41000.0/av;
int frq = ceil(frq_f);
/* return frequency in Hz */
return frq;
* 3: Midi pitch ("F4")
* 4: Velocity (100)
* 5: Flags (nothing)
- * 6: 17.0 (oto[1])
+ * 6: 17.0 (oto[1]) (offset)
* 7: 550 (desired output length ig??)
- * 8: 238 (oto[2])
- * 9: 46 (oto[3])
+ * 8: 238 (oto[2]) (Part to loop)
+ * 9: 46 (oto[3]) (End)
* 10: 100 (volume ?)
* 11: 0 (modulation ?)
* 12: !120 (the tempo)
if (wave == NULL) goto error;
readWave(argv[1], wave, 0);
printf("Wave acquired.");
+ get_phoneme:
+ int ph_B = get_important_wave(wave, wave_length_bytes, NULL,
+ ß(argv[6]), ß(argv[9]), ß(argv[8]));
+ if (ph_B == -1) goto error;
+ int16_t *phoneme = malloc(ph_B);
+ int cons_i = get_important_wave(wave, wave_length_bytes,
+ phoneme, ß(argv[6]), ß(argv[9]), ß(argv[8]));
+ if (cons_i == -1) goto error;
+ printf("%d\n", cons_i);
get_pitch:
- int pitch_Hz = get_pitch(wave, wave_length_bytes);
- printf("The pitch is %d Hz.\n", pitch_Hz);
+ float pitch_Hz = get_pitch(phoneme, ph_B);
+ printf("The pitch is %f Hz.\n", pitch_Hz);
cleanup:
free(wave);
return 0;
error:
//putc('e');putc('r');putc('r');putc('o');putc('r');
+ printf("error :(");
return 1;
}
int STP_samples = ceil(STP_ms * 44100 * 0.001);
- printf("input file: %s \n", filename);
+ //printf("input file: %s \n", filename);
- fp = fopen(
- filename,
- "rb"
- );
+ fp = fopen(filename,"rb"); /* This seems to be causing a segmentation fault??*/
+
+ //printf("opened file.");
if (fp == NULL) {
/* UTAU has rests setup as simply notes with no file so you cant fail here
}; */
uint32_t data_length;
fread(&data_length, 4, 1, fp);
+ //printf("the wave is %d bytes long", data_length);
//NOW TO READ THE WAVE wwwwwwwwww
int sample_count = data_length/2;
--- /dev/null
+#include "colon3sampler.h"
+
+
+float length_arg_to_float(char *arg)
+{
+ //formatted in a weird af way
+ //from looking at other ppls code (gh/m13253/wavtool-yawu) + what i can tell:
+ //it is
+ //x@y[+-]z
+ //x == "ticks" (in yawu code) (idk what this means tbh) [INT] [POSSIBLY FLOAT?]
+ //y == tempo [INT] [UNLESS TEMPO IS FLOAT]
+ //z == divided by 1000 and then added to note_length in yawu.. (yes im just basing it off of there i cant figure ts out :((()
+ //so yawu finds note_length by ticks/tempo/8, and note_length seems to be in ... idk tbh LMAO
+ //uhh idk what a tick is tbh but for my (1/4) rest note ticks = 480 and tempo = 120 (z = 19.0)
+ //480/120/8 = 4/8 = 1/2
+ //ok for a full rest (4/4) it's 1920@120-71.0
+ //that's 1920/120/8 = 16/8 = 2
+ // so a 1/4 note is 1/2, a 4/4 note is 2, a 1/2 note is presumably 1
+ //in 120 tempo
+ //when in 120 tempo thats uhh 2 1/4 a second i think
+ //so that answer is in SECONDS. yay.
+ //and just adding the second part in i guess... shouldnt it be minused??
+ //actually no idea why the second part exists so im skipping it for now lmao
+ //tyty yawu code author. otherwise i would be COOKED
+
+ //OK NEW THING FIGURED OUT
+ //IF "calculate legnth on ui" is checked then uh
+ // the length thing is in MILLISECONDS. Yeah
+ int i = 0;
+ char c = 'x';
+ char buffer[50] = {'\0'}; //who is making smth with a longer number tbh
+ int b_i = 0;
+
+ float x = 0;
+ float y = 0;
+ float z = 0;
+
+ float sign = 1.0; //-1.0 for negative uwu
+
+ while ((c = arg[i++]) != '\0') {
+ switch (c) {
+ case '@':
+ //first break
+ x = arg_to_float(buffer);
+ b_i = 0;
+ break;
+ case '+':
+ //second break :p
+ y = arg_to_float(buffer);
+ b_i = 0;
+ break;
+ case '-':
+ //second break but NEGATIVE
+ y = arg_to_float(buffer);
+ b_i = 0;
+ sign = -1.0;
+ break;
+ case '\0':
+ //end
+ z = sign * arg_to_float(buffer);
+ b_i = 0;
+ break;
+ default:
+ buffer[b_i] = c;
+ b_i ++;
+ buffer[b_i] = '\0';
+ break;
+ };
+
+ };
+ z = sign * arg_to_float(buffer);
+ float result = x/y/8 + z/1000;
+ if (x == 0 || y == 0) {
+ //length calculated on UI
+ result = z/1000;
+ };
+ return result;
+};
+
+float arg_to_float(char *arg)
+{
+ //get digit from ascii by subtracting 48
+ char c;
+ float r = 0.0; //result
+ int d = 0; //i of decimal point if after decimal point
+ int i = 0;
+ while ((c = arg[i++]) != '\0') {
+ switch (c) {
+ case '.':
+ //decimal point
+ d = i;
+ break;
+ default:
+ //must be a digit
+ if (!d) {
+ r = r * 10.0;
+ r += (float)c - 48.0;
+ } else {
+ float t = (float)c - 48.0;
+ for (int n = 0; n <= (i - d); n++) {
+ t = t/10;
+ };
+ r += t;
+ };
+ break;
+ };
+ };
+ return r;
+};
+
+int report_error(char *msg, char *portion, char *program)
+{
+ fprintf(stderr, "%s: [%s] %s\n", program, portion, msg);
+ return 1;
+};