template.c: improve silent mode
src/template.c: 1. Improve silent mode (the program doesn't output anything to STDOUT in silent mode now) 2. Use conditional compilation for silent mode
This commit is contained in:
parent
3acc0be646
commit
976b7468cc
@ -68,10 +68,12 @@ int
|
||||
main(void)
|
||||
{
|
||||
// * log -> welcome
|
||||
#if !SILENT_MODE
|
||||
printf(":: C bytebeat generator runtime unit\n");
|
||||
fflush(stdout);
|
||||
#endif
|
||||
|
||||
if (!SILENT_MODE) {
|
||||
#if !SILENT_MODE
|
||||
printf(
|
||||
"\n"
|
||||
"Sample rate: %d Hz\n"
|
||||
@ -97,7 +99,7 @@ main(void)
|
||||
|
||||
printf("\n\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
#endif
|
||||
|
||||
// * allocate heap for sample data
|
||||
SAMPLE_TYPE* buffer = calloc(PRODUCT, sizeof(SAMPLE_TYPE));
|
||||
@ -130,10 +132,9 @@ main(void)
|
||||
buffer[w] = sample_res;
|
||||
|
||||
// 6. log
|
||||
if (
|
||||
!SILENT_MODE &&
|
||||
(w % FREQUENCY_OF_STATUS_REPORTING == 0 ||
|
||||
w >= PRODUCT - 1 /* writing last sample */)) {
|
||||
#if !SILENT_MODE
|
||||
if (w % FREQUENCY_OF_STATUS_REPORTING == 0 ||
|
||||
w >= PRODUCT - 1 /* writing last sample */) {
|
||||
printf(
|
||||
"%sremaining samples = %18" PRIuMAX " (%.2Lf%% done)",
|
||||
ANSI_CLEAR,
|
||||
@ -141,14 +142,17 @@ main(void)
|
||||
(long double)w * 100 / (long double)PRODUCT);
|
||||
fflush(stdout);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
printf("%s", ANSI_CLEAR);
|
||||
|
||||
// * wave file output
|
||||
// 0. log
|
||||
#if !SILENT_MODE
|
||||
printf("\nWriting out file output.wav...\n");
|
||||
fflush(stdout);
|
||||
#endif
|
||||
|
||||
// 1. open file
|
||||
FILE* output_file = fopen("output.wav", "wb");
|
||||
@ -197,7 +201,9 @@ main(void)
|
||||
fclose(output_file);
|
||||
|
||||
// * end of program
|
||||
#if !SILENT_MODE
|
||||
printf("Done!\n");
|
||||
#endif
|
||||
|
||||
// * free allocated heap
|
||||
free(buffer);
|
||||
|
Loading…
Reference in New Issue
Block a user