-
Notifications
You must be signed in to change notification settings - Fork 0
/
distortion.m
25 lines (18 loc) · 1.02 KB
/
distortion.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function distortionSignal = customDistortion(inputSignal, gain, clipLevel, wetDryMix)
inputSignal = inputSignal / max(abs(inputSignal));
distorted = gain * inputSignal;
distorted(distorted > clipLevel) = clipLevel;
distorted(distorted < -clipLevel) = -clipLevel;
distorted = distorted / max(abs(distorted));
distortionSignal = wetDryMix * distorted + (1 - wetDryMix) * inputSignal;
distortionSignal = distortionSignal / max(abs(distortionSignal));
end
gain = 3;
clipLevel = 0.4;
wetDryMix = 0.78;
[audioIn, Fs] = audioread('samples/fake-tales-of-san-francisco.mp3');
distortionSignal = customDistortion(audioIn, gain, clipLevel, wetDryMix);
audiowrite('outputs/fake-tales-of-san-francisco-overdrive.wav', distortionSignal, Fs);
[audioIn, Fs] = audioread('samples/phonk-808-bass-sustained_90bpm_G#_major.wav');
distortionSignal = customDistortion(audioIn, gain, clipLevel, wetDryMix);
audiowrite('outputs/phonk-808-bass-sustained_90bpm_G#_major-drive.wav', distortionSignal, Fs);