diff --git a/src/template.c b/src/template.c index 1c544b4..bd922c8 100644 --- a/src/template.c +++ b/src/template.c @@ -68,36 +68,38 @@ 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" + "Channels: %d%s\n" + "Bit depth: %ssigned %d-bit\n" + "Duration: ", + SAMPLE_RATE, + CHANNELS, + CHANNELS == 1 ? " (mono)" : (CHANNELS > 2 ? "" : " (stereo)"), + IS_SIGNED ? "" : "un", + BIT_DEPTH); + + if (SECONDS >= 3600) printf( - "\n" - "Sample rate: %d Hz\n" - "Channels: %d%s\n" - "Bit depth: %ssigned %d-bit\n" - "Duration: ", - SAMPLE_RATE, - CHANNELS, - CHANNELS == 1 ? " (mono)" : (CHANNELS > 2 ? "" : " (stereo)"), - IS_SIGNED ? "" : "un", - BIT_DEPTH); + "%d:%02d:%02d", + SECONDS / 3600, + (SECONDS / 60) % 60, + SECONDS % 60); + else if (SECONDS >= 60) + printf("%d:%02d", SECONDS / 60, SECONDS % 60); + else + printf("%d seconds", SECONDS); - if (SECONDS >= 3600) - printf( - "%d:%02d:%02d", - SECONDS / 3600, - (SECONDS / 60) % 60, - SECONDS % 60); - else if (SECONDS >= 60) - printf("%d:%02d", SECONDS / 60, SECONDS % 60); - else - printf("%d seconds", SECONDS); - - printf("\n\n"); - fflush(stdout); - } + 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);