From efcf811633c15c1ed6e42dec964483a72b247770 Mon Sep 17 00:00:00 2001 From: Karchnu Date: Mon, 5 Dec 2022 03:31:47 +0100 Subject: [PATCH] Distort: add distortion to a WAV music input. --- c/distort.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 c/distort.c diff --git a/c/distort.c b/c/distort.c new file mode 100644 index 0000000..d9a386a --- /dev/null +++ b/c/distort.c @@ -0,0 +1,50 @@ +#include +#include +#include +#include +#include + +#define BUFFER_LEN 1024 + +int main(int argc, char **argv) { + int distortionLevel; + SNDFILE *infile, *outfile; + SF_INFO sfinfo; + double buffer[BUFFER_LEN]; + + // Check for distortion level argument + if (argc < 2) { + printf("Usage: %s distortion_level\n", argv[0]); + return 1; + } + distortionLevel = atoi(argv[1]); + + // Open standard input as input file + if (!(infile = sf_open_fd(0, SFM_READ, &sfinfo, 0))) { + printf("Error: could not open standard input\n"); + return 1; + } + + // Open standard output as output file + if (!(outfile = sf_open_fd(1, SFM_WRITE, &sfinfo, 0))) { + printf("Error: could not open standard output\n"); + return 1; + } + + // Read and process data + while (sf_read_double(infile, buffer, BUFFER_LEN) > 0) { + for (int i=0; i