1
0

create branch float_type

This commit is contained in:
パチュリー・ノーレッジ 2024-06-02 14:06:07 +03:00
parent 68788a2db2
commit 71dbab6814
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B
2 changed files with 16 additions and 13 deletions

View File

@ -1,5 +1,8 @@
# C-JS-bytebeat-render
> **Warning**
> You're on the branch, where the program uses only type `float` for floating point values.
Dual-licensed under the [Unlicense](http://unlicense.org) (`LICENSE`) or Creative Commons Zero 1.0 Universal (`COPYING`).
**Description:** a bytebeat rendering engine in C (no support of JavaScript bytebeat yet)

View File

@ -78,27 +78,27 @@
// function prototypes
#if FP_RETURN_TYPE
long double
float
#else
SAMPLE_TYPE
#endif
bytebeat(long double time);
bytebeat(float time);
// function implementations
#if FP_RETURN_TYPE
long double
float
#else
SAMPLE_TYPE
#endif
bytebeat(long double time)
bytebeat(float time)
{
#if PRECALCULATED_RATIO
`final_sample_rate_code`
#elif ORIGINAL_SAMPLE_RATE != SAMPLE_RATE
# if SAMPLE_RATE > ORIGINAL_SAMPLE_RATE
time /= ((long double) SAMPLE_RATE) / ((long double) ORIGINAL_SAMPLE_RATE);
time /= ((float) SAMPLE_RATE) / ((float) ORIGINAL_SAMPLE_RATE);
# else
time *= ((long double) ORIGINAL_SAMPLE_RATE / ((long double) SAMPLE_RATE));
time *= ((float) ORIGINAL_SAMPLE_RATE / ((float) SAMPLE_RATE));
# endif
#endif
uintmax_t t = (uintmax_t) time;
@ -248,7 +248,7 @@ main(void)
#endif
#if BIT_DEPTH < 8
,
bit_depth_stretch = ((long double) BIT_DEPTH) / 8.L
bit_depth_stretch = ((float) BIT_DEPTH) / 8.L
#endif
;
@ -267,14 +267,14 @@ main(void)
#endif
// 1. generate audio data
#if FP_RETURN_TYPE
long double bytebeat_res =
floor(bytebeat(floor((long double) time)));
float bytebeat_res =
floorf(bytebeat(floorf((float) time)));
#elif IS_SIGNED
intmax_t bytebeat_res =
(intmax_t) bytebeat(floor((long double) time));
(intmax_t) bytebeat(floorf((float) time));
#else
uintmax_t bytebeat_res =
(uintmax_t) bytebeat(floor((long double) time));
(uintmax_t) bytebeat(floorf((float) time));
#endif
// 2. if signed, then wrap up to unsigned
@ -293,7 +293,7 @@ main(void)
// 4. if bit depth is less than 8, stretch it
#if BIT_DEPTH < 8
sample_res = (SAMPLE_TYPE)
((long double) sample_res * bit_depth_stretch);
((float) sample_res * bit_depth_stretch);
#endif
// 5. save sample into buffer
@ -315,7 +315,7 @@ main(void)
,
_ANSI_CLEAR_STRING,
gen_length_minus_1 - time,
((long double) time * 100) / (long double) GEN_LENGTH
((float) time * 100) / (float) GEN_LENGTH
#if SEQUENTIAL_MODE
, (uintmax_t) seq + 1, (uintmax_t) MAX
#endif