#include "colon3sampler.h"
+#define END 2900
+#define LOOPBEFORE 1
+
+static int loop_after_co(int16_t w[], int w_B, int16_t ow[], int co, int ow_B);
+static int loop_b4_co(int16_t w[], int w_B, int16_t ow[], int co, int ow_B);
+
int change_wave_len(int16_t w[], int w_B, int16_t ow[], int co, int ow_B)
{
+ if (LOOPBEFORE) {
+ loop_b4_co(w, w_B, ow, co, ow_B);
+ } else {
+ loop_after_co(w, w_B, ow, co, ow_B);
+ };
+ return 1;
+
+};
+
+static int loop_after_co(int16_t w[], int w_B, int16_t ow[], int co, int ow_B)
+{
+
+ if (w_B == ow_B) return 0;
+ int w_i = 0;
+ for (int i = 0; i < ow_B/2; i++) {
+ ow[i] = 0;
+ };
+ int i = 0;
+ for (i = 0; (i < (ow_B/2 - END)); i++) {
+ if (ow[i] == 0) {
+ ow[i] = w[w_i++];
+ } else {
+ ow[i] = ow[i]/2;
+ ow[i] += w[w_i++]/2;
+ };
+ if (w_i == w_B/2-END) {
+ w_i = co;
+ };
+ };
+ for (i = i; i < ow_B/2; i++) {
+ ow[i] = w[w_i++];
+ };
+
+ return 1;
+};
+
+static int loop_b4_co(int16_t w[], int w_B, int16_t ow[], int co, int ow_B)
+{
if (w_B == ow_B) return 0;
int end_samples = (w_B/2) - co;
int half_samples = co/2;
int i = 0;
anfang:
- for (i = 0; (i < half_samples) && (i < ow_B/2-end_samples); i++) {
+ for (i = 0; (i < half_samples) && (i < ow_B/2); i++) {
ow[i] = w[i];
};
if (w_B < ow_B) goto loop_co;
goto append_end;
cut_wave:
if (end_samples >= (ow_B/2)) goto append_end;
- for (i = i; i < (ow_B/2-end_samples); i++) {
+ for (i = i; 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++) {
+ for (i = i; (co < w_B/2) && (i < (ow_B/2)); i++) {
ow[i] = w[co++];
};
+ if (i < ow_B/2) printf("Ugh, didn't wave long enough\n");
return 1;
};
-
/* idk */
get_length:
int end_length_B = 0;
- end_length_B = ((cut-off)*44.100) * 2;
+ end_length_B = w_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++) {
+ for (int i = (off*44.100); i < ((w_B/2) - (cut*44.100)); i++) {
b[b_i++] = ow[i];
};
goto tell_cons;