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