From 1183fdb69695847a4c6103c8edfe40aa80a6e126 Mon Sep 17 00:00:00 2001 From: Intel A80486DX2-66 Date: Sat, 18 Nov 2023 14:15:48 +0300 Subject: [PATCH] implement final simple rate conversion during generation (#3) --- bytebeat_compiler.py | 12 ++++++++++++ src/template.c | 1 + 2 files changed, 13 insertions(+) diff --git a/bytebeat_compiler.py b/bytebeat_compiler.py index a2098fc..dcfb106 100644 --- a/bytebeat_compiler.py +++ b/bytebeat_compiler.py @@ -64,6 +64,10 @@ if __name__ == "__main__": help="bytebeat formula file") parser.add_argument("-r", "--sample-rate", default=8000, type=int, help="sample rate (Hz)") + parser.add_argument("-p", "--final-sample-rate", default=None, type=int, + help="convert the output to a different sample rate (usually one that " + "is set in the system, to improve sound quality) during generation " + "(not just reinterpretation)") parser.add_argument("-b", "--bit-depth", default=8, type=int, help="bit depth") parser.add_argument("-s", "--signed", default=False, action="store_true", @@ -88,11 +92,19 @@ if __name__ == "__main__": if not args.no_return: # Insert return statement bytebeat_contents = f"\treturn\n\n{bytebeat_contents}" + final_sample_rate_code = "" + if not args.final_sample_rate is None: + sample_rate_ratio = args.sample_rate / args.final_sample_rate + final_sample_rate_code = f"w *= {sample_rate_ratio}L;" + args.sample_rate = args.final_sample_rate + substitute = read_file(PATHS["template"]) substitute = substitute_value("bytebeat_contents", bytebeat_contents, substitute) substitute = substitute_value("sample_rate", args.sample_rate, substitute) + substitute = substitute_value("final_sample_rate_code", + final_sample_rate_code, substitute) substitute = substitute_value("bit_depth", args.bit_depth, substitute) substitute = substitute_value("is_signed", diff --git a/src/template.c b/src/template.c index 6137f48..0d6eebf 100644 --- a/src/template.c +++ b/src/template.c @@ -95,6 +95,7 @@ random(void) SAMPLE_TYPE bytebeat(long double w) { + `final_sample_rate_code` uintmax_t t = (uintmax_t)w; `bytebeat_contents`