Compare commits

...

2 Commits

Author SHA1 Message Date
Karchnu 0b5db1314f Makefile 2023-06-26 12:50:35 +02:00
Karchnu efcf811633 Distort: add distortion to a WAV music input. 2022-12-05 03:31:47 +01:00
2 changed files with 70 additions and 0 deletions

20
Makefile Normal file
View File

@ -0,0 +1,20 @@
all:
DOMAIN ?= karchnu.fr
get-certificate-info:
openssl s_client -connect $(DOMAIN):443
show-connected-ipv4:
@# Don't forget the double $$ since we are in a Makefile.
@netstat -n -p tcp | drop-until tcp | awk '{print $$5}' | cut -d. -f 1-4 | sort | uniq
detect-volume:
ffmpeg -i $(SRC) -af "volumedetect" -vn -sn -dn -f null /dev/null
PORT ?=
which-bin-uses-this-port:
fstat | grep ':$(PORT)'
MAIL_DOMAIN ?= mail.karchnu.fr
verify-mail-certificate:
echo | openssl s_client -starttls smtp -showcerts -connect $(MAIL_DOMAIN):587 -servername $(MAIL_DOMAIN) | openssl x509 -noout -dates

50
c/distort.c Normal file
View File

@ -0,0 +1,50 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <sndfile.h>
#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<BUFFER_LEN; i++) {
// Add distortion to the sample
buffer[i] = buffer[i] * (1.0 + (distortionLevel/100.0) * sin(2.0 * M_PI * buffer[i]));
}
// Write the processed sample to the output file
sf_write_double(outfile, buffer, BUFFER_LEN);
}
// Close files
sf_close(infile);
sf_close(outfile);
return 0;
}