create branch float_type
This commit is contained in:
parent
68788a2db2
commit
71dbab6814
@ -1,5 +1,8 @@
|
|||||||
# C-JS-bytebeat-render
|
# 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`).
|
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)
|
**Description:** a bytebeat rendering engine in C (no support of JavaScript bytebeat yet)
|
||||||
|
@ -78,27 +78,27 @@
|
|||||||
|
|
||||||
// function prototypes
|
// function prototypes
|
||||||
#if FP_RETURN_TYPE
|
#if FP_RETURN_TYPE
|
||||||
long double
|
float
|
||||||
#else
|
#else
|
||||||
SAMPLE_TYPE
|
SAMPLE_TYPE
|
||||||
#endif
|
#endif
|
||||||
bytebeat(long double time);
|
bytebeat(float time);
|
||||||
|
|
||||||
// function implementations
|
// function implementations
|
||||||
#if FP_RETURN_TYPE
|
#if FP_RETURN_TYPE
|
||||||
long double
|
float
|
||||||
#else
|
#else
|
||||||
SAMPLE_TYPE
|
SAMPLE_TYPE
|
||||||
#endif
|
#endif
|
||||||
bytebeat(long double time)
|
bytebeat(float time)
|
||||||
{
|
{
|
||||||
#if PRECALCULATED_RATIO
|
#if PRECALCULATED_RATIO
|
||||||
`final_sample_rate_code`
|
`final_sample_rate_code`
|
||||||
#elif ORIGINAL_SAMPLE_RATE != SAMPLE_RATE
|
#elif ORIGINAL_SAMPLE_RATE != SAMPLE_RATE
|
||||||
# if SAMPLE_RATE > ORIGINAL_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
|
# else
|
||||||
time *= ((long double) ORIGINAL_SAMPLE_RATE / ((long double) SAMPLE_RATE));
|
time *= ((float) ORIGINAL_SAMPLE_RATE / ((float) SAMPLE_RATE));
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
uintmax_t t = (uintmax_t) time;
|
uintmax_t t = (uintmax_t) time;
|
||||||
@ -248,7 +248,7 @@ main(void)
|
|||||||
#endif
|
#endif
|
||||||
#if BIT_DEPTH < 8
|
#if BIT_DEPTH < 8
|
||||||
,
|
,
|
||||||
bit_depth_stretch = ((long double) BIT_DEPTH) / 8.L
|
bit_depth_stretch = ((float) BIT_DEPTH) / 8.L
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -267,14 +267,14 @@ main(void)
|
|||||||
#endif
|
#endif
|
||||||
// 1. generate audio data
|
// 1. generate audio data
|
||||||
#if FP_RETURN_TYPE
|
#if FP_RETURN_TYPE
|
||||||
long double bytebeat_res =
|
float bytebeat_res =
|
||||||
floor(bytebeat(floor((long double) time)));
|
floorf(bytebeat(floorf((float) time)));
|
||||||
#elif IS_SIGNED
|
#elif IS_SIGNED
|
||||||
intmax_t bytebeat_res =
|
intmax_t bytebeat_res =
|
||||||
(intmax_t) bytebeat(floor((long double) time));
|
(intmax_t) bytebeat(floorf((float) time));
|
||||||
#else
|
#else
|
||||||
uintmax_t bytebeat_res =
|
uintmax_t bytebeat_res =
|
||||||
(uintmax_t) bytebeat(floor((long double) time));
|
(uintmax_t) bytebeat(floorf((float) time));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// 2. if signed, then wrap up to unsigned
|
// 2. if signed, then wrap up to unsigned
|
||||||
@ -293,7 +293,7 @@ main(void)
|
|||||||
// 4. if bit depth is less than 8, stretch it
|
// 4. if bit depth is less than 8, stretch it
|
||||||
#if BIT_DEPTH < 8
|
#if BIT_DEPTH < 8
|
||||||
sample_res = (SAMPLE_TYPE)
|
sample_res = (SAMPLE_TYPE)
|
||||||
((long double) sample_res * bit_depth_stretch);
|
((float) sample_res * bit_depth_stretch);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// 5. save sample into buffer
|
// 5. save sample into buffer
|
||||||
@ -315,7 +315,7 @@ main(void)
|
|||||||
,
|
,
|
||||||
_ANSI_CLEAR_STRING,
|
_ANSI_CLEAR_STRING,
|
||||||
gen_length_minus_1 - time,
|
gen_length_minus_1 - time,
|
||||||
((long double) time * 100) / (long double) GEN_LENGTH
|
((float) time * 100) / (float) GEN_LENGTH
|
||||||
#if SEQUENTIAL_MODE
|
#if SEQUENTIAL_MODE
|
||||||
, (uintmax_t) seq + 1, (uintmax_t) MAX
|
, (uintmax_t) seq + 1, (uintmax_t) MAX
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user