beat

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

commit
85bf9190b51a8861c591d6ca1b39f9cbc8ab8770
parent
a563820799caa2e6f8ca9d2fe40ea38c44f54ee7
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2019-12-18 10:19
rename different sndfiles

Diffstat

M beat.c 20 ++++++++++----------

1 files changed, 10 insertions, 10 deletions


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

@@ -24,13 +24,13 @@ void add_file_at_beat(const char *path, int beat) {
   24    24     int rel_pos = pos - buf_cur * buf_len;
   25    25     float fbuf[ibs];
   26    26     SF_INFO sfinfo;
   27    -1     SNDFILE *sndfile = sf_open(path, SFM_READ, &sfinfo);
   -1    27     SNDFILE *infile = sf_open(path, SFM_READ, &sfinfo);
   28    28 
   29    29     // assert sfinfo.samplerate == samplerate
   30    30     // assert sfinfo.channels == 1
   31    31 
   32    32     while (1) {
   33    -1         int count = sf_readf_float(sndfile, fbuf, ibs);
   -1    33         int count = sf_readf_float(infile, fbuf, ibs);
   34    34         count = MIN(count, frames - pos - 1);
   35    35 
   36    36         if (count <= 0) break;
@@ -40,7 +40,7 @@ void add_file_at_beat(const char *path, int beat) {
   40    40             rel_pos += 1;
   41    41             if (rel_pos >= 2 * buf_len) {
   42    42                 printf("dropping %s at %i\n", path, pos);
   43    -1                 sf_close(sndfile);
   -1    43                 sf_close(infile);
   44    44                 return;
   45    45             } else if (rel_pos >= buf_len) {
   46    46                 ctx.buf2[rel_pos - buf_len] += fbuf[i] * factor;
@@ -50,7 +50,7 @@ void add_file_at_beat(const char *path, int beat) {
   50    50         }
   51    51     }
   52    52 
   53    -1     sf_close(sndfile);
   -1    53     sf_close(infile);
   54    54 }
   55    55 
   56    56 int main(int argc, char **argv) {
@@ -83,14 +83,14 @@ int main(int argc, char **argv) {
   83    83     sfinfo.sections = 1;
   84    84     sfinfo.seekable = 1;
   85    85 
   86    -1     SNDFILE *sndfile = sf_open(argv[1], SFM_WRITE, &sfinfo);
   -1    86     SNDFILE *outfile = sf_open(argv[1], SFM_WRITE, &sfinfo);
   87    87 
   88    88     for (int i = 6; i + 1 < argc; i += 2) {
   89    89         int beat = atoi(argv[i]);
   90    90         char *path = argv[i + 1];
   91    91 
   92    92         if (beat * frames_per_beat >= (buf_cur + 1) * buf_len) {
   93    -1             sf_writef_float(sndfile, ctx.buf, buf_len);
   -1    93             sf_writef_float(outfile, ctx.buf, buf_len);
   94    94             memset(ctx.buf, 0, buf_len * sizeof(float));
   95    95 
   96    96             float *tmp = ctx.buf;
@@ -104,11 +104,11 @@ int main(int argc, char **argv) {
  104   104 
  105   105     int rest = frames - buf_cur * buf_len;
  106   106     if (rest > buf_len) {
  107    -1         sf_writef_float(sndfile, ctx.buf, buf_len);
  108    -1         sf_writef_float(sndfile, ctx.buf2, rest - buf_len);
   -1   107         sf_writef_float(outfile, ctx.buf, buf_len);
   -1   108         sf_writef_float(outfile, ctx.buf2, rest - buf_len);
  109   109     } else {
  110    -1         sf_writef_float(sndfile, ctx.buf, rest);
   -1   110         sf_writef_float(outfile, ctx.buf, rest);
  111   111     }
  112   112 
  113    -1     sf_close(sndfile);
   -1   113     sf_close(outfile);
  114   114 }