template.c: extract BITS_PER_BYTE
Additionally, do not cast values to `long double` to calculate for `uintmax_t bit_depth_stretch`
This commit is contained in:
parent
c1ea01869f
commit
f1f5c2a859
@ -31,7 +31,9 @@
|
||||
#define CHANNELS `channels`
|
||||
#define LENGTH `length`
|
||||
|
||||
#if BIT_DEPTH <= 8
|
||||
#define BITS_PER_BYTE 8
|
||||
|
||||
#if BIT_DEPTH <= BITS_PER_BYTE
|
||||
# define SAMPLE_TYPE uint8_t
|
||||
#elif BIT_DEPTH >= 16
|
||||
# if IS_SIGNED
|
||||
@ -192,11 +194,11 @@ main(void)
|
||||
* in the file format structure
|
||||
*/,
|
||||
sample_rate = SAMPLE_RATE,
|
||||
byte_rate = (SAMPLE_RATE * BIT_DEPTH * CHANNELS) / 8;
|
||||
byte_rate = (SAMPLE_RATE * BIT_DEPTH * CHANNELS) / BITS_PER_BYTE;
|
||||
uint16_t fmt_type = 1, // format type is PCM
|
||||
channels = CHANNELS,
|
||||
block_align = (BIT_DEPTH * CHANNELS) / 8,
|
||||
bit_depth = BIT_DEPTH > 8 ? BIT_DEPTH : 8;
|
||||
block_align = (BIT_DEPTH * CHANNELS) / BITS_PER_BYTE,
|
||||
bit_depth = BIT_DEPTH > BITS_PER_BYTE ? BIT_DEPTH : BITS_PER_BYTE;
|
||||
|
||||
// 3. write headers
|
||||
// <L = Little-endian or B = Big-endian> : <name> : <bytes of field>
|
||||
@ -244,9 +246,9 @@ main(void)
|
||||
#if FP_RETURN_TYPE
|
||||
+ 1
|
||||
#endif
|
||||
#if BIT_DEPTH < 8
|
||||
#if BIT_DEPTH < BITS_PER_BYTE
|
||||
,
|
||||
bit_depth_stretch = ((long double) BIT_DEPTH) / 8.L
|
||||
bit_depth_stretch = BIT_DEPTH / BITS_PER_BYTE
|
||||
#endif
|
||||
;
|
||||
|
||||
@ -288,8 +290,8 @@ main(void)
|
||||
((uintmax_t) bytebeat_res & bit_depth_limiter);
|
||||
#endif
|
||||
|
||||
// 4. if bit depth is less than 8, stretch it
|
||||
#if BIT_DEPTH < 8
|
||||
// 4. if bit depth is less than BITS_PER_BYTE, stretch it
|
||||
#if BIT_DEPTH < BITS_PER_BYTE
|
||||
sample_res = (SAMPLE_TYPE)
|
||||
((long double) sample_res * bit_depth_stretch);
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user