Skip to content

Commit 6896cf8

Browse files
change if chains to CLAMP
1 parent 5f9cd8e commit 6896cf8

File tree

2 files changed

+5
-24
lines changed

2 files changed

+5
-24
lines changed

src/audio/mixer.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,7 @@ static inline uint32_t min_u32(uint32_t a, uint32_t b) {
5757
}
5858

5959
static inline int16_t clamp_s16(int32_t x) {
60-
if (x > 32767) {
61-
return 32767;
62-
}
63-
if (x < -32768) {
64-
return -32768;
65-
}
60+
x = CLAMP(x, -326768, 32767);
6661
return (int16_t)x;
6762
}
6863

@@ -404,11 +399,7 @@ void mixer_idle(void)
404399
}
405400
for (; i < n32; i++) {
406401
int32_t x = mix_accum[i];
407-
if (x > 32767) {
408-
x = 32767;
409-
} else if (x < -32768) {
410-
x = -32768;
411-
}
402+
x = CLAMP(x, -32768, 32767);
412403
mix.mix_scratch[i] = (int16_t)x;
413404
}
414405

@@ -423,4 +414,4 @@ void mixer_idle(void)
423414
}
424415

425416
}
426-
}
417+
}

src/audio/wav.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -318,18 +318,8 @@ bool wav_from_memory(const void *wav, size_t wav_bytes, void **out_ptr, size_t *
318318
int32_t lo = l0 + (int32_t) ((((int64_t) dl) * (int64_t) frac) >> 32);
319319
int32_t ro = r0 + (int32_t) ((((int64_t) dr) * (int64_t) frac) >> 32);
320320

321-
if (lo > 32767) {
322-
lo = 32767;
323-
}
324-
if (lo < -32768) {
325-
lo = -32768;
326-
}
327-
if (ro > 32767) {
328-
ro = 32767;
329-
}
330-
if (ro < -32768) {
331-
ro = -32768;
332-
}
321+
lo = CLAMP(lo, -32768, 32767);
322+
ro = CLAMP(ro, -32768, 32767);
333323

334324
dst[i * 2u + 0u] = (int16_t) lo;
335325
dst[i * 2u + 1u] = (int16_t) ro;

0 commit comments

Comments
 (0)