@@ -398,11 +398,13 @@ static inline int32_t i2sin_normalize_signed(uint32_t raw, uint8_t in_depth,
398398}
399399
400400// Write `raw` (input-depth bits, just-read FIFO sample) to `buffer` at sample
401- // index `idx`, converting from `in_depth` to `out_depth` (shift-only
402- // semantics, sign-preserving for signed) and (if needed) flipping the sign bit
403- // for the unsigned-WAV convention. When upscaling, the input occupies the high
404- // `in_depth` bits and the new low bits are left as zero. Output element size
405- // follows `out_depth`: 1 byte at 8, 2 bytes at 16, 4 bytes at 24 or 32.
401+ // index `idx`, converting from `in_depth` to `out_depth` (sign-preserving for
402+ // signed) and (if needed) flipping the sign bit for the unsigned-WAV
403+ // convention. When upscaling, the value is right-justified: the meaningful data
404+ // stays in the low `in_depth` bits with the upper bits carrying the sign, so a
405+ // wider output simply uses a larger container without scaling the magnitude up.
406+ // (Note this means 24-bit-in-32-bit output is right-justified.) Output element size follows `out_depth`: 1 byte
407+ // at 8, 2 bytes at 16, 4 bytes at 24 or 32.
406408//
407409// For signed 24-bit output, the int32 slot holds the sign-extended value
408410// (range -2^23 .. 2^23-1) — unlike the default `output_bit_depth=bit_depth=24`
@@ -414,10 +416,10 @@ static inline void i2sin_write_converted(void *buffer, uint32_t idx,
414416 int32_t s = i2sin_normalize_signed (raw , in_depth , left_justified );
415417 int32_t shifted ;
416418 if (out_depth >= in_depth ) {
417- // Left -justify: place the input's bits in the high bits of the wider
418- // output and leave the new low bits as zero . The API contract is that
419- // for upscaled output the meaningful data is the high `in_depth` bits .
420- shifted = s << ( out_depth - in_depth ) ;
419+ // Right -justify: keep the value as-is so the meaningful bits stay in the
420+ // low `in_depth` bits (upper bits already sign-extended) . The wider
421+ // output just provides a larger container .
422+ shifted = s ;
421423 } else {
422424 shifted = s >> (in_depth - out_depth );
423425 }
0 commit comments