- commit
- b333e94a91cf57149a14eac992f8b7a53956627d
- parent
- a873c755a4b8e9d977129d76dbd591360455fce4
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2023-12-24 15:00
fix: clip instead of silently failing
Diffstat
| M | beat.c | 11 | +++++++++++ |
1 files changed, 11 insertions, 0 deletions
diff --git a/beat.c b/beat.c
@@ -79,11 +79,22 @@ void add_file_at_beat(const char *path, int beat) {
79 79 sf_close(infile);
80 80 }
81 81
-1 82 void clip(float *buf) {
-1 83 for (int i = 0; i < BUFSIZE * 2; i++) {
-1 84 if (buf[i] < -1.0) {
-1 85 buf[i] = -1.0;
-1 86 } else if (buf[i] > 1.0) {
-1 87 buf[i] = 1.0;
-1 88 }
-1 89 }
-1 90 }
-1 91
82 92 int _sf_writef_float(SNDFILE *sndfile, float *buf) {
83 93 int size = MIN(frames - buf_cur * BUFSIZE, BUFSIZE);
84 94 if (size <= 0) {
85 95 return 0;
86 96 }
-1 97 clip(buf);
87 98 return sf_writef_float(sndfile, buf, size);
88 99 }
89 100