diff --git a/bytebeat_compiler.py b/bytebeat_compiler.py index b4e4e6d..43e4c74 100644 --- a/bytebeat_compiler.py +++ b/bytebeat_compiler.py @@ -87,6 +87,8 @@ if __name__ == "__main__": help="bit depth") parser.add_argument("-s", "--signed", default=False, action="store_true", help="is signed?") + parser.add_argument("-f", "--floating-point", default=False, + action="store_true", help="use floating point as the return type") parser.add_argument("-c", "--channels", default=1, type=int, help="amount of channels") parser.add_argument("-t", "--seconds", default=None, type=int, @@ -156,6 +158,7 @@ if __name__ == "__main__": "final_sample_rate_code": final_sample_rate_code, "bit_depth": args.bit_depth, "is_signed": "1" if args.signed else "0", + "fp_return_type": "1" if args.floating_point else "0", "channels": args.channels, "length": samples, "silent_mode": "true" if args.silent else "false", diff --git a/src/template.c b/src/template.c index 8787055..d486856 100644 --- a/src/template.c +++ b/src/template.c @@ -48,11 +48,19 @@ const char* ANSI_CLEAR = __ANSI_CLEAR_STRING; #define VERBOSE_MODE `verbose_mode` // function prototypes +#if FP_RETURN_TYPE +long double +#else SAMPLE_TYPE +#endif bytebeat(long double w); // function implementations +#if FP_RETURN_TYPE +long double +#else SAMPLE_TYPE +#endif bytebeat(long double w) { `final_sample_rate_code` @@ -122,7 +130,12 @@ main(void) } // * bytebeat generating loop - const uintmax_t product_minus_1 = PRODUCT - 1; + const uintmax_t product_minus_1 = PRODUCT - 1, + bit_depth_limiter = BIT_DEPTH_LIMITER +#if FP_RETURN_TYPE + + 1 +#endif + ; for (size_t w = 0; w < PRODUCT; w++) { // 1. generate audio data @@ -133,8 +146,12 @@ main(void) bytebeat_res = signed_to_unsigned(bytebeat_res); // 3. convert audio data to sample - SAMPLE_TYPE sample_res = (SAMPLE_TYPE) bytebeat_res & - BIT_DEPTH_LIMITER; + SAMPLE_TYPE sample_res = (SAMPLE_TYPE) +#if FP_RETURN_TYPE + fmodl(bytebeat_res, bit_depth_limiter); +#else + ((uintmax_t) bytebeat_res & bit_depth_limiter); +#endif // 4. if bit depth is less than 8, stretch it #if BIT_DEPTH < 8