template.c: stringize integers where applicable
This commit is contained in:
parent
c76c809d2a
commit
110b065459
@ -44,6 +44,8 @@ const char* ANSI_CLEAR = __ANSI_CLEAR_STRING;
|
|||||||
|
|
||||||
#define SEQUENTIAL_MODE `sequential_mode`
|
#define SEQUENTIAL_MODE `sequential_mode`
|
||||||
#define BLOCK_SIZE_BYTES `block_size`
|
#define BLOCK_SIZE_BYTES `block_size`
|
||||||
|
#define MINIMUM_BLOCK_SIZE ((sizeof(SAMPLE_TYPE) + sizeof(uint8_t) - 1) / \
|
||||||
|
sizeof(uint8_t))
|
||||||
|
|
||||||
#define FP_RETURN_TYPE `fp_return_type`
|
#define FP_RETURN_TYPE `fp_return_type`
|
||||||
#define PRECALCULATED_RATIO `precalculated_ratio`
|
#define PRECALCULATED_RATIO `precalculated_ratio`
|
||||||
@ -53,6 +55,9 @@ const char* ANSI_CLEAR = __ANSI_CLEAR_STRING;
|
|||||||
#define unsigned_to_signed(x) (x - PCM_COEFFICIENT)
|
#define unsigned_to_signed(x) (x - PCM_COEFFICIENT)
|
||||||
#define signed_to_unsigned(x) (x + PCM_COEFFICIENT)
|
#define signed_to_unsigned(x) (x + PCM_COEFFICIENT)
|
||||||
|
|
||||||
|
#define STRINGIZE(x) #x
|
||||||
|
#define INT2STR(x) STRINGIZE(x)
|
||||||
|
|
||||||
// macros
|
// macros
|
||||||
#define ALLOCATE_MEMORY(nmemb) \
|
#define ALLOCATE_MEMORY(nmemb) \
|
||||||
SAMPLE_TYPE* buffer = malloc( \
|
SAMPLE_TYPE* buffer = malloc( \
|
||||||
@ -112,15 +117,24 @@ main(void)
|
|||||||
|
|
||||||
printf(
|
printf(
|
||||||
"\n"
|
"\n"
|
||||||
"Sample rate: %d Hz\n"
|
"Sample rate: " INT2STR(SAMPLE_RATE) " Hz\n"
|
||||||
"Channels: %d%s\n"
|
"Channels: " INT2STR(CHANNELS)
|
||||||
"Bit depth: %ssigned %d-bit\n"
|
#if CHANNELS <= 2
|
||||||
"Duration: ",
|
" ("
|
||||||
SAMPLE_RATE,
|
# if CHANNELS == 2
|
||||||
CHANNELS,
|
"stereo"
|
||||||
CHANNELS == 1 ? " (mono)" : (CHANNELS > 2 ? "" : " (stereo)"),
|
# else
|
||||||
IS_SIGNED ? "" : "un",
|
"mono"
|
||||||
BIT_DEPTH);
|
# endif
|
||||||
|
")"
|
||||||
|
#endif
|
||||||
|
"\n"
|
||||||
|
"Bit depth: "
|
||||||
|
#if !IS_SIGNED
|
||||||
|
"un"
|
||||||
|
#endif
|
||||||
|
"signed " INT2STR(BIT_DEPTH) "-bit\n"
|
||||||
|
"Duration: ");
|
||||||
|
|
||||||
if (seconds > 0)
|
if (seconds > 0)
|
||||||
if (seconds >= 3600)
|
if (seconds >= 3600)
|
||||||
@ -204,10 +218,8 @@ main(void)
|
|||||||
size_t BLOCK_SIZE = BLOCK_SIZE_BYTES / (sizeof(SAMPLE_TYPE) /
|
size_t BLOCK_SIZE = BLOCK_SIZE_BYTES / (sizeof(SAMPLE_TYPE) /
|
||||||
sizeof(uint8_t));
|
sizeof(uint8_t));
|
||||||
if (BLOCK_SIZE < 1) {
|
if (BLOCK_SIZE < 1) {
|
||||||
printf("The block size %" PRIuMAX " is too small, should be at least "
|
printf("The block size " INT2STR(BLOCK_SIZE_BYTES) " is too small, "
|
||||||
"%" PRIuMAX " bytes\n", (uintmax_t) BLOCK_SIZE_BYTES,
|
"should be at least %" PRIuMAX " bytes\n", MINIMUM_BLOCK_SIZE);
|
||||||
(uintmax_t) ((sizeof(SAMPLE_TYPE) + sizeof(uint8_t) - 1) /
|
|
||||||
sizeof(uint8_t)));
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user