Merge branch 'main' into DarellsAnnex

This commit is contained in:
darrll27 2021-12-09 13:34:15 -08:00 committed by GitHub
commit a889135a3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 472 additions and 2 deletions

9
implemented.csv Normal file
View File

@ -0,0 +1,9 @@
amplifyFreqRange.m, Filter, Connor Hsu
DarellAmplitudeEnvelope.m, AmpEnvelope, Darrell Chua
DarellAnnePitchEnvelope.m, PitchEnvelope, Darrel Chua / Anne Lin
DarellbandpassFilter.m, Filter, Darrel Chua
generate_sawtooth, Generator, Ben Zhang
generate_sine, Generator, Arthur Lu / Benjamin Liou
generate_square, Generator, Arthur Lu / Benjamin Liou
generate_triangle, Generator, Arthur Lu / Benjamin Liou
generate_white, Generator, Benjamin Liou
1 amplifyFreqRange.m Filter Connor Hsu
2 DarellAmplitudeEnvelope.m AmpEnvelope Darrell Chua
3 DarellAnnePitchEnvelope.m PitchEnvelope Darrel Chua / Anne Lin
4 DarellbandpassFilter.m Filter Darrel Chua
5 generate_sawtooth Generator Ben Zhang
6 generate_sine Generator Arthur Lu / Benjamin Liou
7 generate_square Generator Arthur Lu / Benjamin Liou
8 generate_triangle Generator Arthur Lu / Benjamin Liou
9 generate_white Generator Benjamin Liou

View File

@ -0,0 +1,17 @@
function x = Daniel_Doan_convolution(f,h)
%input: two 1d arrays representing two sound signals in the time domain
%output: the convolution of the two waves, which is the inverse FT of
%FT(f)*FT(h)
%author: Daniel Doan
%padding to ensure the entire convolution is calculated
pad = length(f) + length(h) - 1;
%take FT of f
F = fft(f, pad);
%take FT of h
H = fft(h, pad);
%multiply the two FTs
X = F .* H;
%take inverse FT of the product
x = ifft(X);
end

View File

@ -1,5 +1,21 @@
%Written by Darell and Anne %Written by Darell and Anne
%This envelope uses linear calculations %If there is a frequency of 200Hz:
%1. it needs to ramp up a frequency from 0Hz to the 200Hz over the attack time
%2. It needs to ramp down to a set sustained frequency over the decay time e.g. 160Hz < 200Hz
%3. It maintains this 160Hz until the release time
%4. Release time: It decays from 160Hz further all the way back to 0Hz.
%This envelope uses logarithmic calculations
% CONTRIBUTORS:
% Person1: Darell
% Person2: Anne
% DOCUMENTATION:
% phase shift is in number of periods
% fs is the sampling frequency: how many sample points per second
% duration is time in seconds
% duty is a number between 0 and 1
function output = DarellAnnePitchEnvelope(input, Fs, attack,decay,sustain,release) %percentages for attack, decay, sustain, release function output = DarellAnnePitchEnvelope(input, Fs, attack,decay,sustain,release) %percentages for attack, decay, sustain, release
len = length(input); len = length(input);
@ -55,4 +71,4 @@ function output = DarellAnnePitchEnvelope(input, Fs, attack,decay,sustain,releas
tcounter = tcounter+1; tcounter = tcounter+1;
end end
end end

37
src/Meghaj_Echo.m Normal file
View File

@ -0,0 +1,37 @@
% Meghaj_Echo: input a wave (in time domain) and a frequency to induce an
% echo/lag effect to. The outputted wave amplifies frequencies above the
% cutoff and creates an echo in the frequencies below the cutoff creating
% a beat lag effect. Inspired by "muffled_effect_schluep" and lecture notes
% Works best on songs that have a clear snare line with a frequency of
% HIGH = 1000. Use on song files like "Strong-Bassline.mp3"
% CONTRIBUTORS:
% Meghaj Vadlaputi: Function Author
function y = Meghaj_Echo(x, HIGH)
len = length(x);
X = fft(x);
X = fftshift(X); %Fourier transform the input wave
Y = zeros(1, len);
for ind = 1:len
%Multiplying the Fourier transform in frequency domain by e^jw(0.05)
%to induce a time shift of 0.05 seconds creating the "lag" effect on
%frequencies below HIGH (HIGH = 1000 works best)
%Multiplying the remaining signal by 1.25 amplifies other
%frequencies to balance
if abs(X(ind)) < HIGH
Y(ind) = X(ind) + 0.5*(X(ind)*exp(1i*ind*0.05));
else
Y(ind) = 1.25*X(ind);
end
end
Y = fftshift(Y);
y = ifft(Y);
y = real(y);
end

BIN
src/Strong_Bassline.mp3 Normal file

Binary file not shown.

62
src/bandreject_filter.m Normal file
View File

@ -0,0 +1,62 @@
function output_y = bandreject_filter(Input, Fs, Low, High)
% A filter that lets through most frequencies unaltered
% but attentuates the frequencies in the specified range to
% very low levels
% (basically exliminates them)
% By Yalu Ouyang
% Input: the input signal in the time domain
% Fs: the sampling frequency
% Low: the lower limit of the specified range
% High: the upper limit of the specified range
% Returns Output: the filtered signal in the time domain
len = length(Input);
F = Fs * (-len/2 : (len/2 - 1)) / len ;
% modified signal in the frequency domain
% using Fourier Transform
mod_freq = fftshift(fft(Input));
len_f = length(mod_freq);
% use this array to record the frequencies
% that should pass through
% 0 indicates reject
% 1 indicates pass
multiplier = zeros([1,len_f]);
for index = 1 : len_f
% within range of band reject
% so elminate these frequencies
if ((Low < abs(F(index))) && (abs(F(index)) < High))
multiplier(index) = 0;
% outside of specified range
% so shoudln't be altered
else
multiplier(index) = 1;
end
end
% filtered signal in the frequency domain
filtered_mod_freq = fftshift(mod_freq .* multiplier);
% convert signal back to the time domain
Output = real(ifft(filtered_mod_freq));
end
% This function is useful for eliminating
% unwanted signals that have frequencies close to the
% median frequency of the original signal
% (consider overall frequencies as one part,
% this elminates the middle portion)
% Fourier transform is applied in this function
% to make it easier to eliminate specified
% frequencies of the signal
% (easier to do so in the frequency domain)

55
src/epic_effect_schluep.m Normal file
View File

@ -0,0 +1,55 @@
function output = epic_effect_schluep(input, Fs, LOW, MED, HIGH)
% epic_effect_schluep: Outputs a more "epic" version of the input sound.
% This is done by amplifying low frequencies and by implementing a chorus
% effect. A chorus effect is created when multiple copies of sound delayed
% by a small, random amount are added to the original signal. Works best on
% songs with a stronger bassline.
% Try this function out with "Strong_Bassline.mp3".
% CONTRIBUTORS:
% Nicolas Schluep: Function Author
% DOCUMENTATION:
% input: The input sound in the time-domain.
% Fs: The sampling rate of the input signal. A typical value is 44100 Hz.
% HIGH: The maximum frequency the filter will amplify. A typical value for
% this variable is 1000 Hz.
non_stereophonic = input(:, 1); % Removes the sterophonic property of the input sound
% by just taking the first column of data.
Len = length(non_stereophonic);
F = Fs * ((-Len/2) : ((Len/2) - 1)) / Len; % Creating the array of frequencies
% which the FFT Shifted version of the signal can be plotted against.
inputFreq = fftshift(fft(non_stereophonic)); % Creates the Fourier Transform of the
% input signal. fftshift() makes it such that the zero frequency is at the
% center of the array.
lowAmplifyFilter = zeros(1, length(inputFreq));
% Creating a filter which amplifies lower frequencies.
for i = 1:length(lowAmplifyFilter)
if abs(F(i)) < HIGH
lowAmplifyFilter(i) = 1.25;
else
lowAmplifyFilter(i) = 1.00;
end
end
lowPassedInput = inputFreq .* transpose(lowAmplifyFilter); %Apply the "lowAmplifyFilter".
% Adding the chorus effect.
realOutput = real(ifft(fftshift(lowPassedInput)));
output = realOutput;
% Adding 100 randomly delayed signals to the original signal which creates the chorus effect.
for i = 1:100
currentDelay = 0.003 * rand(); % The current delay of the sound in seconds.
currentIndex = round(currentDelay * Fs); % Find the first index where the sound should start playing.
delayedOutput = [zeros(currentIndex, 1); realOutput]; % Adds "currentIndex" zeros to the front of the
% "realOutput" vector to create a slightly delayed version of the signal.
delayedOutput = delayedOutput(1:length(realOutput)); % Truncates the "delayedOutput"
% vector so that it can be added to the "realOutput" vector.
output = output + delayedOutput;
end
output = output ./ 100; % Divide by 100 to decrease the amplitude of the sound to a normal level.

29
src/fade_in.m Normal file
View File

@ -0,0 +1,29 @@
function output = fade_in(input, time)
% Creates a fade-in sound effect that lasts a given
% time parameter of the input sound signal
% By Yalu Ouyang
% input: a 1D array that represents the sound signal in the time domain
% time: how long the fade in effect should last
% Shouldn't be longer than the input signal (in which case the function
% treats it as the duration of the signal)
% Returns modified signal in the time domain (output).
len = length(input);
% if time parameter longer than signal, treat time as
% the duration of original signal
if time > len
time = len
end
% set multiplier as 1D array
% fade in effect: from no volume to full volume of signal
multiplier = (1 : time) / time;
% the resulting fade-in output
output = input .* multiplier;
end
% This is useful for making videos, specifically the intro part

32
src/fade_out.m Normal file
View File

@ -0,0 +1,32 @@
function output = fade_out(input, time)
% Creates a fade-out sound effect that lasts a given
% time parameter of the input sound signal
% By Yalu Ouyang
% input: a 1D array that represents the sound signal in the time domain
% time: how long the fade out effect should last
% Shouldn't be longer than the input signal
% (in which case the function treats it as the duration of the signal)
% Returns modified signal in the time domain (output).
len = length(input);
% if time parameter longer than signal, treat time as
% the duration of original signal
if time > len
time = len
end
% set multiplier as 1D array
multiplier = (1 : time) / time;
% fade out effect: from full volume of signal to no volume
multiplier = flip(multiplier)
% the resulting fade-in output
output = input .* multiplier;
end
% This is useful for creating videos, specifically the outro part

View File

@ -0,0 +1,44 @@
function x = generate_halfCircles(amplitude, frequency, phase, fs, duration, duty)
% Generates half circles.
% By Conner Hsu
% DOCUMENTATION:
% amplitude scales how tall the half circle is.
% phase shift is in number of periods
% fs is the sampling frequency: how many sample points per second
% duration is time in seconds
% duty cycle should be a number between 0 and 1.
% duty of 0 or less would return 0 for all sample points
% duty of 0.25 would return a half circle for first quarter of each cycle
% then return 0 for the remaining 3/4ths
% duty of 1 would return all +amplitude
% initialize local variables from input arguments
n = fs * duration; % number of samples (length of matrix)
dt = 1 / fs; % sampling period: time between two sample points
% initialize a one dimensional zero matrix to be populated
x = zeros(1, n);
% populate the matrix
for i = 1:n
t = i * dt; % time at the i'th sample
% periodic ramp from 0 to 1
% progression through a cycle
st = mod(frequency * t - phase, 1);
if(st < duty)
x(i) = sqrt((duty/2)^2-(st-duty/2)^2)/2*amplitude;
else
x(i) = 0;
end
end
%Testing code.
%t = 0:dt:duration;
%t(n) = [];
%plot(t, x);
sound(x, fs);
end

37
src/lfo_sawtooth.m Normal file
View File

@ -0,0 +1,37 @@
function x = lfo_sawtooth(amplitude, frequency, phase, fs, duration, input)
% LFO_SAWTOOTH: modulates an input matrix to a sawtooth parameter
% CONTRIBUTORS:
% Ben Zhang: Function Author
% DOCUMENTATION:
% frequency is below 20Hz for people to hear the sound
% fs and duration should be same as input
% initialize local variables from input arguments
n = fs * duration; % number of samples (length of matrix)
dt = 1 / fs; % sampling period: time between two sample points
% initialize lfo, which will be used to modulate the input
lfo = zeros(1, n);
period = 1 / frequency; % period of the wave
slope = 2 * amplitude / period; % the incline slope from start to amplitude
% populate lfo matrix
for i = 1:n
t = i * dt; % time at the i'th sample
st = mod(frequency * t - phase, 1); % Progression through cycle
%part before the straght vertical line
if(st < period /2)
lfo(i) = amplitude * slope;
%part after the straght vertical line
else
lfo(i) = amplitude * (slope - 1);
end
% modulate input
x = lfo .* input;
end

View File

@ -0,0 +1,56 @@
function output = muffled_effect_schluep(input, Fs, LOW, MED, HIGH)
% muffled_effect_schluep: Outputs a muffled version of the the original input
% sound in the time domain. This makes it sound as if the audio is being
% played in another room.
% Try this function out with "Strong_Bassline.mp3".
% CONTRIBUTORS:
% Nicolas Schluep: Function Author
% DOCUMENTATION:
% input: The input sound in the time-domain.
% Fs: The sampling rate of the input signal. A typical value is 44100 Hz.
% HIGH: The maximum frequency that the low-pass filter will let pass. A
% typical value for this variable is 1000 Hz.
non_stereophonic = input(:, 1); % Removes the sterophonic property of the input sound
% by just taking the first column of data.
Len = length(non_stereophonic);
F = Fs * ((-Len/2) : ((Len/2) - 1)) / Len; % Creating the array of frequencies
% which the FFT Shifted version of the signal can be plotted against.
inputFreq = fftshift(fft(non_stereophonic)); % Creates the Fourier Transform of the
% input signal. fftshift() makes it such that the zero frequency is at the
% center of the array.
lowPassFilter = zeros(1, length(inputFreq));
% Creating Low Pass Filter
for i = 1:length(lowPassFilter)
if abs(F(i)) < HIGH
lowPassFilter(i) = 1;
else
lowPassFilter(i) = 0;
end
end
lowPassedInput = inputFreq .* transpose(lowPassFilter); %Apply the low-pass filter.
% Adding a slight reverb effect.
realOutput = real(ifft(fftshift(lowPassedInput)));
delay = 0.001; % The delay of the sound in seconds.
index = round(delay*Fs); % Find the first index where sound should start playing
% by multiplying the delay by the sampling frequency.
delayedOutput = [zeros(index, 1); realOutput]; % Adds "index" zeros to the front of the
% "realOutput" vector to create a slightly delayed version of the signal.
delayedOutput = delayedOutput(1:length(realOutput)); % Truncates the "delayedOutput"
% vector so that it can be added to the "realOutput" vector.
output = (realOutput + delayedOutput) ./ 2.0; % Adds the "realOutput" and "delayedOutput"
% vectors to create a reverb effect. Divides by 2 to avoid clipping
% effects.

View File

@ -0,0 +1,62 @@
function output = seperate_prevalent_schluep(input, Fs, LOW, MED, HIGH)
% seperate_prevalent_schluep: Attempts to seperate the most prevalent frequencies
% from the input sound by finding the most prevalent frequencies and applying
% a band-pass filter to a small region around those frequencies.
% Try this function out with "Strong_Bassline.mp3".
% CONTRIBUTORS:
% Nicolas Schluep: Function Author
% DOCUMENTATION:
% input: The input sound in the time-domain.
% Fs: The sampling rate of the input signal. A typical value is 44100 Hz.
% HIGH: The maximum distance around the maximum frequency value that will
% not be attenuated. A good range of values is usually 250-500 Hz, but it
% depends on the input sound.
non_stereophonic = input(:, 1); % Removes the sterophonic property of the input sound
% by just taking the first column of data.
Len = length(non_stereophonic);
F = Fs * ((-Len/2) : ((Len/2) - 1)) / Len; % Creating the array of frequencies
% which the FFT Shifted version of the signal can be plotted against.
inputFreq = fftshift(fft(non_stereophonic)); % Creates the Fourier Transform of the
% input signal. fftshift() makes it such that the zero frequency is at the
% center of the array.
bandPassFilter = zeros(1, length(inputFreq));
maxAmplitude = 0;
mostPrevalentFrequency = 0;
% Finding the most prevalent frequency.
for i = round(length(inputFreq)/2):length(inputFreq)
if inputFreq(i) > maxAmplitude
maxAmplitude = inputFreq(i);
mostPrevalentFrequency = F(i);
end
end
% Determining maximum and minimum frequency values for the Band Pass filter.
maxFrequency = mostPrevalentFrequency + HIGH;
minFrequency = mostPrevalentFrequency - HIGH;
if minFrequency < 0.0
minFrequency = 0.0;
end
% Creating the Band-Pass filter.
for i = 1:length(bandPassFilter)
if (abs(F(i)) < maxFrequency) && (abs(F(i)) > minFrequency)
bandPassFilter(i) = 1;
else
bandPassFilter(i) = 0;
end
end
bandPassedInput = inputFreq .* transpose(bandPassFilter); %Apply the Band-Pass Filter.
output = real(ifft(fftshift(bandPassedInput)));

14
unimplemented.csv Normal file
View File

@ -0,0 +1,14 @@
add_sine.m
amplify.m
bandreject_filter.m
Daniel_Doan_convolution.m
epic_effect_schluep.m
fade_in.m
fade_out.m
generate_halfCircles.m
lfo_sawtooth.m
lfo_sine.m
muffled_effect_schluep.m
Petha_Hsu_PitchOffset.m
reverse.m
seperate_prevalent_schluep.m
1 add_sine.m
2 amplify.m
3 bandreject_filter.m
4 Daniel_Doan_convolution.m
5 epic_effect_schluep.m
6 fade_in.m
7 fade_out.m
8 generate_halfCircles.m
9 lfo_sawtooth.m
10 lfo_sine.m
11 muffled_effect_schluep.m
12 Petha_Hsu_PitchOffset.m
13 reverse.m
14 seperate_prevalent_schluep.m