1
0

bytebeat_render.c: add custom output

This commit is contained in:
Intel A80486DX2-66 2024-01-09 20:04:33 +03:00
parent 564a9c11d8
commit 0654aec5d1
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B
3 changed files with 9 additions and 3 deletions

2
.gitignore vendored
View File

@ -54,4 +54,4 @@ dkms.conf
# ---> products # ---> products
build/ build/
output.wav *.wav

View File

@ -76,6 +76,7 @@ def substitute_vars(replacements: Dict[str, Union[bool, str]], text: str,
return text return text
preprocessor_bool = lambda value: "1" if value else "0" preprocessor_bool = lambda value: "1" if value else "0"
C_str_repr = lambda s: '"' + s.replace("\\", "\\\\").replace(r'"', r'\"') + '"'
CC = fetch("CC") CC = fetch("CC")
CFLAGS = fetch("CFLAGS") CFLAGS = fetch("CFLAGS")
@ -90,6 +91,8 @@ if __name__ == "__main__":
"`OUTPUT_FILE`.") "`OUTPUT_FILE`.")
parser.add_argument("file", type=str, parser.add_argument("file", type=str,
help="bytebeat formula file (use `-` to read from stdin)") help="bytebeat formula file (use `-` to read from stdin)")
parser.add_argument("-o", "--output", default="output.wav", type=str,
help="specify output file path (default is `output.wav`")
parser.add_argument("-r", "--sample-rate", default=8000, type=int, parser.add_argument("-r", "--sample-rate", default=8000, type=int,
help="sample rate (Hz)") help="sample rate (Hz)")
parser.add_argument("-p", "--final-sample-rate", default=None, type=int, parser.add_argument("-p", "--final-sample-rate", default=None, type=int,
@ -183,6 +186,7 @@ if __name__ == "__main__":
rewrite_file(PATHS["substitute"], substitute_vars({ rewrite_file(PATHS["substitute"], substitute_vars({
"bytebeat_contents": bytebeat_contents, "bytebeat_contents": bytebeat_contents,
"output_file": C_str_repr(args.output),
"sample_rate": args.sample_rate, "sample_rate": args.sample_rate,
"original_sample_rate": original_sample_rate, "original_sample_rate": original_sample_rate,
"final_sample_rate_code": final_sample_rate_code, "final_sample_rate_code": final_sample_rate_code,

View File

@ -19,6 +19,8 @@
#endif #endif
const char* ANSI_CLEAR = __ANSI_CLEAR_STRING; const char* ANSI_CLEAR = __ANSI_CLEAR_STRING;
#define OUTPUT_FILE `output_file`
#define SAMPLE_RATE `sample_rate` #define SAMPLE_RATE `sample_rate`
#define ORIGINAL_SAMPLE_RATE `original_sample_rate` #define ORIGINAL_SAMPLE_RATE `original_sample_rate`
#define BIT_DEPTH `bit_depth` #define BIT_DEPTH `bit_depth`
@ -132,12 +134,12 @@ main(void)
// * write WAVE headers // * write WAVE headers
// 0. log // 0. log
#if !SILENT_MODE #if !SILENT_MODE
printf("\nWriting out file output.wav...\n"); printf("\nWriting out file " OUTPUT_FILE "...\n");
fflush(stdout); fflush(stdout);
#endif #endif
// 1. open file // 1. open file
FILE* output_file = fopen("output.wav", "wb"); FILE* output_file = fopen(OUTPUT_FILE, "wb");
if (output_file == NULL || !output_file) { if (output_file == NULL || !output_file) {
perror("fopen"); perror("fopen");
return 1; return 1;