1
0

implement final simple rate conversion during generation (#3)

This commit is contained in:
Intel A80486DX2-66 2023-11-18 14:15:48 +03:00
parent 8d33c88e35
commit 1183fdb696
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B
2 changed files with 13 additions and 0 deletions

View File

@ -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",

View File

@ -95,6 +95,7 @@ random(void)
SAMPLE_TYPE
bytebeat(long double w)
{
`final_sample_rate_code`
uintmax_t t = (uintmax_t)w;
`bytebeat_contents`