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)
|
main(void)
|
||||||
{
|
{
|
||||||
// * log -> welcome
|
// * log -> welcome
|
||||||
|
#if !SILENT_MODE
|
||||||
printf(":: C bytebeat generator runtime unit\n");
|
printf(":: C bytebeat generator runtime unit\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!SILENT_MODE) {
|
#if !SILENT_MODE
|
||||||
printf(
|
printf(
|
||||||
"\n"
|
"\n"
|
||||||
"Sample rate: %d Hz\n"
|
"Sample rate: %d Hz\n"
|
||||||
@ -97,7 +99,7 @@ main(void)
|
|||||||
|
|
||||||
printf("\n\n");
|
printf("\n\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
#endif
|
||||||
|
|
||||||
// * allocate heap for sample data
|
// * allocate heap for sample data
|
||||||
SAMPLE_TYPE* buffer = calloc(PRODUCT, sizeof(SAMPLE_TYPE));
|
SAMPLE_TYPE* buffer = calloc(PRODUCT, sizeof(SAMPLE_TYPE));
|
||||||
@ -130,10 +132,9 @@ main(void)
|
|||||||
buffer[w] = sample_res;
|
buffer[w] = sample_res;
|
||||||
|
|
||||||
// 6. log
|
// 6. log
|
||||||
if (
|
#if !SILENT_MODE
|
||||||
!SILENT_MODE &&
|
if (w % FREQUENCY_OF_STATUS_REPORTING == 0 ||
|
||||||
(w % FREQUENCY_OF_STATUS_REPORTING == 0 ||
|
w >= PRODUCT - 1 /* writing last sample */) {
|
||||||
w >= PRODUCT - 1 /* writing last sample */)) {
|
|
||||||
printf(
|
printf(
|
||||||
"%sremaining samples = %18" PRIuMAX " (%.2Lf%% done)",
|
"%sremaining samples = %18" PRIuMAX " (%.2Lf%% done)",
|
||||||
ANSI_CLEAR,
|
ANSI_CLEAR,
|
||||||
@ -141,14 +142,17 @@ main(void)
|
|||||||
(long double)w * 100 / (long double)PRODUCT);
|
(long double)w * 100 / (long double)PRODUCT);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%s", ANSI_CLEAR);
|
printf("%s", ANSI_CLEAR);
|
||||||
|
|
||||||
// * wave file output
|
// * wave file output
|
||||||
// 0. log
|
// 0. log
|
||||||
|
#if !SILENT_MODE
|
||||||
printf("\nWriting out file output.wav...\n");
|
printf("\nWriting out file output.wav...\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
#endif
|
||||||
|
|
||||||
// 1. open file
|
// 1. open file
|
||||||
FILE* output_file = fopen("output.wav", "wb");
|
FILE* output_file = fopen("output.wav", "wb");
|
||||||
@ -197,7 +201,9 @@ main(void)
|
|||||||
fclose(output_file);
|
fclose(output_file);
|
||||||
|
|
||||||
// * end of program
|
// * end of program
|
||||||
|
#if !SILENT_MODE
|
||||||
printf("Done!\n");
|
printf("Done!\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
// * free allocated heap
|
// * free allocated heap
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
Loading…
Reference in New Issue
Block a user