diff --git a/.gitignore b/.gitignore index b9197c7..6ba3514 100644 --- a/.gitignore +++ b/.gitignore @@ -54,4 +54,4 @@ dkms.conf # ---> products build/ -output.wav +*.wav diff --git a/bytebeat_compiler.py b/bytebeat_compiler.py index 7124f5b..fa78b7b 100644 --- a/bytebeat_compiler.py +++ b/bytebeat_compiler.py @@ -76,6 +76,7 @@ def substitute_vars(replacements: Dict[str, Union[bool, str]], text: str, return text preprocessor_bool = lambda value: "1" if value else "0" +C_str_repr = lambda s: '"' + s.replace("\\", "\\\\").replace(r'"', r'\"') + '"' CC = fetch("CC") CFLAGS = fetch("CFLAGS") @@ -90,6 +91,8 @@ if __name__ == "__main__": "`OUTPUT_FILE`.") parser.add_argument("file", type=str, 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, help="sample rate (Hz)") parser.add_argument("-p", "--final-sample-rate", default=None, type=int, @@ -183,6 +186,7 @@ if __name__ == "__main__": rewrite_file(PATHS["substitute"], substitute_vars({ "bytebeat_contents": bytebeat_contents, + "output_file": C_str_repr(args.output), "sample_rate": args.sample_rate, "original_sample_rate": original_sample_rate, "final_sample_rate_code": final_sample_rate_code, diff --git a/src/template.c b/src/template.c index 72906fb..8da37c8 100644 --- a/src/template.c +++ b/src/template.c @@ -19,6 +19,8 @@ #endif const char* ANSI_CLEAR = __ANSI_CLEAR_STRING; +#define OUTPUT_FILE `output_file` + #define SAMPLE_RATE `sample_rate` #define ORIGINAL_SAMPLE_RATE `original_sample_rate` #define BIT_DEPTH `bit_depth` @@ -132,12 +134,12 @@ main(void) // * write WAVE headers // 0. log #if !SILENT_MODE - printf("\nWriting out file output.wav...\n"); + printf("\nWriting out file " OUTPUT_FILE "...\n"); fflush(stdout); #endif // 1. open file - FILE* output_file = fopen("output.wav", "wb"); + FILE* output_file = fopen(OUTPUT_FILE, "wb"); if (output_file == NULL || !output_file) { perror("fopen"); return 1;