- commit
- c60e0226e653eba2995fa5fdff13820aa10f1b41
- parent
- e62a24ba6cf4352a3eb805195f57026a5a02d778
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2019-12-18 13:29
convert context to pointer
Diffstat
| M | beat.c | 29 | ++++++++++++++++------------- |
1 files changed, 16 insertions, 13 deletions
diff --git a/beat.c b/beat.c
@@ -7,7 +7,7 @@ 7 7 8 8 struct context { 9 9 float *buf;10 -1 float *buf2;-1 10 struct context *next; 11 11 }; 12 12 13 13 int samplerate; @@ -16,7 +16,7 @@ int frames; 16 16 int buf_cur; 17 17 size_t buf_len; 18 18 float factor;19 -1 struct context ctx;-1 19 struct context *ctx; 20 20 21 21 void add_file_at_beat(const char *path, int beat) { 22 22 int ibs = 1024; @@ -43,9 +43,9 @@ void add_file_at_beat(const char *path, int beat) { 43 43 sf_close(infile); 44 44 return; 45 45 } else if (rel_pos >= buf_len) {46 -1 ctx.buf2[rel_pos - buf_len] += fbuf[i] * factor;-1 46 ctx->next->buf[rel_pos - buf_len] += fbuf[i] * factor; 47 47 } else {48 -1 ctx.buf[rel_pos] += fbuf[i] * factor;-1 48 ctx->buf[rel_pos] += fbuf[i] * factor; 49 49 } 50 50 } 51 51 } @@ -75,13 +75,16 @@ int main(int argc, char **argv) { 75 75 buf_len = MIN(frames / 4, 1 << 18); 76 76 buf_cur = 0; 77 77 -1 78 ctx = (struct context *)malloc(sizeof(struct context)); 78 79 float buf[buf_len]; 79 80 memset(buf, 0, buf_len * sizeof(float));80 -1 ctx.buf = buf;-1 81 ctx->buf = buf; 81 82 -1 83 ctx->next = (struct context *)malloc(sizeof(struct context)); 82 84 float buf2[buf_len]; 83 85 memset(buf2, 0, buf_len * sizeof(float));84 -1 ctx.buf2 = buf2;-1 86 ctx->next->buf = buf2; -1 87 ctx->next->next = ctx; 85 88 86 89 SF_INFO sfinfo; 87 90 sfinfo.channels = 1; @@ -98,20 +101,20 @@ int main(int argc, char **argv) { 98 101 char *path = argv[i + 1]; 99 102 100 103 while (beat * frames_per_beat >= (buf_cur + 1) * buf_len) {101 -1 _sf_writef_float(outfile, ctx.buf);102 -1 memset(ctx.buf, 0, buf_len * sizeof(float));-1 104 _sf_writef_float(outfile, ctx->buf); -1 105 memset(ctx->buf, 0, buf_len * sizeof(float)); 103 106104 -1 float *tmp = ctx.buf;105 -1 ctx.buf = ctx.buf2;106 -1 ctx.buf2 = tmp;-1 107 ctx = ctx->next; 107 108 buf_cur += 1; 108 109 } 109 110 110 111 add_file_at_beat(path, beat); 111 112 } 112 113113 -1 _sf_writef_float(outfile, ctx.buf);114 -1 _sf_writef_float(outfile, ctx.next->buf);-1 114 _sf_writef_float(outfile, ctx->buf); -1 115 _sf_writef_float(outfile, ctx->next->buf); 115 116 -1 117 free(ctx->next); -1 118 free(ctx); 116 119 sf_close(outfile); 117 120 }