beat

Arrange audio samples into something bigger
git clone https://git.ce9e.org/beat.git

commit
e62a24ba6cf4352a3eb805195f57026a5a02d778
parent
ff8d39c401bc3ed046182c4760fba9e31181bdc5
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2019-12-18 10:40
make sure to not write more than frames

Diffstat

M beat.c 19 +++++++++++--------

1 files changed, 11 insertions, 8 deletions


diff --git a/beat.c b/beat.c

@@ -53,6 +53,14 @@ void add_file_at_beat(const char *path, int beat) {
   53    53     sf_close(infile);
   54    54 }
   55    55 
   -1    56 int _sf_writef_float(SNDFILE *sndfile, float *buf) {
   -1    57     int size = MIN(frames - buf_cur * buf_len, buf_len);
   -1    58     if (size <= 0) {
   -1    59         return 0;
   -1    60     }
   -1    61     return sf_writef_float(sndfile, buf, size);
   -1    62 }
   -1    63 
   56    64 int main(int argc, char **argv) {
   57    65     if (argc < 6 || argc % 2 != 0) {
   58    66         printf("Usage: beat OUTFILE SAMPLERATE BPM BEATS TRACKS BEAT INFILE [BEAT INFILE…]\n");
@@ -90,7 +98,7 @@ int main(int argc, char **argv) {
   90    98         char *path = argv[i + 1];
   91    99 
   92   100         while (beat * frames_per_beat >= (buf_cur + 1) * buf_len) {
   93    -1             sf_writef_float(outfile, ctx.buf, buf_len);
   -1   101             _sf_writef_float(outfile, ctx.buf);
   94   102             memset(ctx.buf, 0, buf_len * sizeof(float));
   95   103 
   96   104             float *tmp = ctx.buf;
@@ -102,13 +110,8 @@ int main(int argc, char **argv) {
  102   110         add_file_at_beat(path, beat);
  103   111     }
  104   112 
  105    -1     int rest = frames - buf_cur * buf_len;
  106    -1     if (rest > buf_len) {
  107    -1         sf_writef_float(outfile, ctx.buf, buf_len);
  108    -1         sf_writef_float(outfile, ctx.buf2, rest - buf_len);
  109    -1     } else {
  110    -1         sf_writef_float(outfile, ctx.buf, rest);
  111    -1     }
   -1   113     _sf_writef_float(outfile, ctx.buf);
   -1   114     _sf_writef_float(outfile, ctx.next->buf);
  112   115 
  113   116     sf_close(outfile);
  114   117 }