move new functions to NotWorking

This commit is contained in:
Arthur Lu
2021-12-10 23:21:15 -08:00
parent 3b32df90de
commit 5c96e3e5a8
17 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
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.
n = size(input, 2);
non_stereophonic = input;
if (n == 1) || (n == 2)
non_stereophonic = input(:, 1); % Removes the sterophonic property of the input sound
% by just taking the first column of data.
non_stereophonic = transpose(non_stereophonic);
end
modified_input = non_stereophonic(1, :);
Len = length(modified_input);
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(modified_input)); % 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 .* lowAmplifyFilter; %Apply the "lowAmplifyFilter".
lowPassedInput = transpose(lowPassedInput);
% 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.
output = transpose(output);
end

View File

@@ -0,0 +1,41 @@
function x = generate_arcoStrings(amplitude, frequency, phase, fs, duration, duty)
% GENERATE_ARCOSTRINGS: returns a matrix of sampled waveform similar to
% strings played arco.
% CONTRIBUTORS:
% Brandon Roberts: Original author
% MuseScore: Reference source for overtone information
% 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 does not apply for instruments
% setup needed variables
n = fs * duration; % total data points
dt = 1 / fs; % space between samples
% initialize template time scale
t = [1:n].*dt - phase;
f = frequency .* (1 + 0.0002 .* sin(10.*pi.*t)./t); %frequency vibrato
% generate proper fundamental and overtones
x = (amplitude .* sin(2.*pi.*f.*t)) ... %fundamental (first partial)
+ (0.237992723.*amplitude .* sin(4.*pi.*f.*t)) ... %second partial
+ (0.0523347308.*amplitude .* sin(6.*pi.*f.*t)) ... %third partial
+ (0.124586119.*amplitude .* sin(8.*pi.*f.*t)) ... %fourth partial
+ (0.0854326396.*amplitude .* sin(10.*pi.*f.*t)) ... %fifth partial
+ (0.0578741297.*amplitude .* sin(12.*pi.*f.*t)) ... %sixth partial
+ (0.0291070237.*amplitude .* sin(14.*pi.*f.*t)) ... %seventh partial
+ (0.0270171595.*amplitude .* sin(16.*pi.*f.*t)) ... %eighth partial
+ (0.0290818446.*amplitude .* sin(18.*pi.*f.*t)) ... %ninth partial
+ (0.0356787652.*amplitude .* sin(20.*pi.*f.*t)) ... %tenth partial
+ (0.0112928202.*amplitude .* sin(22.*pi.*f.*t)) ... %eleventh partial
+ (0.00547645126.*amplitude .* sin(24.*pi.*f.*t)) ... %twelth partial
+ (0.00800694943.*amplitude .* sin(26.*pi.*f.*t)) ... %thirteenth partial
+ (0.00463295187.*amplitude .* sin(28.*pi.*f.*t)); %fourteenth partial
x = x .* (1 + 0.1 .* sin(10.*pi.*t)); %volume vibrato
end

View File

@@ -0,0 +1,45 @@
function x = generate_bassoon(amplitude, frequency, phase, fs, duration, duty)
% GENERATE_BASSOON: returns a matrix of sampled waveform similar to
% a bassoon.
% CONTRIBUTORS:
% Brandon Roberts: Original author
% MuseScore: Reference source for overtone information
% 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 does not apply for instruments
% setup needed variables
n = fs * duration; % total data points
dt = 1 / fs; % space between samples
% initialize template time scale
t = [1:n].*dt - phase;
f = frequency .* (1 + 0.0001 .* sin(4.*pi.*t)./t); %frequency vibrato
% generate proper fundamental and overtones
x = (0.0934091627.*amplitude .* sin(2.*pi.*f.*t)) ... %fundamental (first partial)
+ (0.0257187994.*amplitude .* sin(4.*pi.*f.*t)) ... %second partial
+ (0.120530806.*amplitude .* sin(6.*pi.*f.*t)) ... %third partial
+ (amplitude .* sin(8.*pi.*f.*t)) ... %fourth partial
+ (0.216745656.*amplitude .* sin(10.*pi.*f.*t)) ... %fifth partial
+ (0.0561137441.*amplitude .* sin(12.*pi.*f.*t)) ... %sixth partial
+ (0.0300031596.*amplitude .* sin(14.*pi.*f.*t)) ... %seventh partial
+ (0.0863949447.*amplitude .* sin(16.*pi.*f.*t)) ... %eighth partial
+ (0.0574533965.*amplitude .* sin(18.*pi.*f.*t)) ... %ninth partial
+ (0.0337819905.*amplitude .* sin(20.*pi.*f.*t)) ... %tenth partial
+ (0.0576176935.*amplitude .* sin(22.*pi.*f.*t)) ... %eleventh partial
+ (0.0107298578.*amplitude .* sin(24.*pi.*f.*t)) ... %twelth partial
+ (0.00582622433.*amplitude .* sin(26.*pi.*f.*t)) ... %thirteenth partial
+ (0.00540916272.*amplitude .* sin(28.*pi.*f.*t)) ... %fourteenth partial
+ (0.00615481833.*amplitude .* sin(30.*pi.*f.*t)) ... %fifteenth partial
+ (0.00480252765.*amplitude .* sin(32.*pi.*f.*t)) ... %sixteenth partial
+ (0.0100473934.*amplitude .* sin(34.*pi.*f.*t)) ... %seventeenth partial
+ (0.00528278041.*amplitude .* sin(36.*pi.*f.*t)); %eighteenth partial
x = x .* (1 + 0.1 .* sin(4.*pi.*t)); %volume vibrato
end

View File

@@ -0,0 +1,38 @@
function x = generate_clarinet(amplitude, frequency, phase, fs, duration, duty)
% GENERATE_CLARINET: returns a matrix of sampled waveform similar to
% a clarinet.
% CONTRIBUTORS:
% Brandon Roberts: Original author
% MuseScore: Reference source for overtone information
% 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 does not apply for instruments
% setup needed variables
n = fs * duration; % total data points
dt = 1 / fs; % space between samples
% initialize template time scale
t = [1:n].*dt - phase;
f = frequency; %clarinets play without vibrato
% generate proper fundamental and overtones. Note that the clarinet has
% heavily suppressed odd-numbered partials
x = (amplitude .* sin(2.*pi.*f.*t)) ... %fundamental (first partial)
+ (0.00290397158.*amplitude .* sin(4.*pi.*f.*t)) ... %second partial
+ (0.368654023.*amplitude .* sin(6.*pi.*f.*t)) ... %third partial
+ (0.0733323309.*amplitude .* sin(8.*pi.*f.*t)) ... %fourth partial
+ (0.299729339.*amplitude .* sin(10.*pi.*f.*t)) ... %fifth partial
+ (0.0483901284.*amplitude .* sin(12.*pi.*f.*t)) ... %sixth partial
+ (0.0941300303.*amplitude .* sin(14.*pi.*f.*t)) ... %seventh partial
+ (0.033165423.*amplitude .* sin(16.*pi.*f.*t)) ... %eighth partial
+ (0.00803526117.*amplitude .* sin(18.*pi.*f.*t)) ... %ninth partial
+ (0.0131383569.*amplitude .* sin(20.*pi.*f.*t)); %tenth partial
x = x .* (1 + 0.05 .* sin(10.*pi.*t)); %slight volume vibrato added for character
end

View File

@@ -0,0 +1,34 @@
function x = generate_flute(amplitude, frequency, phase, fs, duration, duty)
% GENERATE_FLUTE: returns a matrix of sampled waveform similar to
% a flute.
% CONTRIBUTORS:
% Brandon Roberts: Original author
% MuseScore: Reference source for overtone information
% 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 does not apply for instruments
% setup needed variables
n = fs * duration; % total data points
dt = 1 / fs; % space between samples
% initialize template time scale and frequency
t = [1:n].*dt - phase;
f = frequency .* (1 + 0.0002 .* sin(7.*pi.*t)./t); %frequency vibrato
% generate proper fundamental and overtones
x = (amplitude .* sin(4.*pi.*f.*t)) ... %fundamental (first partial)
+ (0.396821591.*amplitude .* sin(4.*pi.*f.*t)) ... %second partial
+ (0.157568887.*amplitude .* sin(6.*pi.*f.*t)) ... %third partial
+ (0.151279648.*amplitude .* sin(8.*pi.*f.*t)) ... %fourth partial
+ (0.106818975.*amplitude .* sin(10.*pi.*f.*t)) ... %fifth partial
+ (0.0138755668.*amplitude .* sin(12.*pi.*f.*t)) ... %sixth partial
+ (0.0100279037.*amplitude .* sin(14.*pi.*f.*t)); %seventh partial
x = x .* (1 + 0.25 .* sin(7.*pi.*t)); %volume vibrato
end

View File

@@ -0,0 +1,41 @@
function x = generate_horn(amplitude, frequency, phase, fs, duration, duty)
% GENERATE_HORN: returns a matrix of sampled waveform similar to
% a horn.
% CONTRIBUTORS:
% Brandon Roberts: Original author
% MuseScore: Reference source for overtone information
% 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 does not apply for instruments
% setup needed variables
n = fs * duration; % total data points
dt = 1 / fs; % space between samples
% initialize template time scale
t = [1:n].*dt - phase;
f = frequency .* (1 + 0.0002 .* sin(4.*pi.*t)./t); %frequency vibrato
% generate proper fundamental and overtones
x = (0.21707879.*amplitude .* sin(2.*pi.*f.*t)) ... %fundamental (first partial)
+ (amplitude .* sin(4.*pi.*f.*t)) ... %second partial
+ (0.234667056.*amplitude .* sin(6.*pi.*f.*t)) ... %third partial
+ (0.088606568.*amplitude .* sin(8.*pi.*f.*t)) ... %fourth partial
+ (0.0864485981.*amplitude .* sin(10.*pi.*f.*t)) ... %fifth partial
+ (0.0275181724.*amplitude .* sin(12.*pi.*f.*t)) ... %sixth partial
+ (0.0472968588.*amplitude .* sin(14.*pi.*f.*t)) ... %seventh partial
+ (0.0246462876.*amplitude .* sin(16.*pi.*f.*t)) ... %eighth partial
+ (0.00816134476.*amplitude .* sin(18.*pi.*f.*t)) ... %ninth partial
+ (0.00691199377.*amplitude .* sin(20.*pi.*f.*t)) ... %tenth partial
+ (0.00494872793.*amplitude .* sin(22.*pi.*f.*t)) ... %eleventh partial
+ (0.0048026999.*amplitude .* sin(24.*pi.*f.*t)) ... %twelth partial
+ (0.00335864486.*amplitude .* sin(26.*pi.*f.*t)) ... %thirteenth partial
+ (0.00262850467.*amplitude .* sin(28.*pi.*f.*t)); %fourteenth partial
x = x .* (1 + 0.05 .* sin(2.*pi.*t)); %volume vibrato
end

View File

@@ -0,0 +1,37 @@
function x = generate_oboe(amplitude, frequency, phase, fs, duration, duty)
% GENERATE_OBOE: returns a matrix of sampled waveform similar to
% an oboe.
% CONTRIBUTORS:
% Brandon Roberts: Original author
% MuseScore: Reference source for overtone information
% 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 does not apply for instruments
% setup needed variables
n = fs * duration; % total data points
dt = 1 / fs; % space between samples
% initialize template time scale
t = [1:n].*dt - phase;
f = frequency .* (1 + 0.0001 .* sin(10.*pi.*t)./t); %frequency vibrato
% generate proper fundamental and overtones
x = (0.274577037.*amplitude .* sin(2.*pi.*f.*t)) ... %fundamental (first partial)
+ (0.612336031.*amplitude .* sin(4.*pi.*f.*t)) ... %second partial
+ (amplitude .* sin(6.*pi.*f.*t)) ... %third partial
+ (0.105870314.*amplitude .* sin(8.*pi.*f.*t)) ... %fourth partial
+ (0.00825325944.*amplitude .* sin(10.*pi.*f.*t)) ... %fifth partial
+ (0.0767380354.*amplitude .* sin(12.*pi.*f.*t)) ... %sixth partial
+ (0.0381430831.*amplitude .* sin(14.*pi.*f.*t)) ... %seventh partial
+ (0.010765121.*amplitude .* sin(16.*pi.*f.*t)) ... %eighth partial
+ (0.0024454102.*amplitude .* sin(18.*pi.*f.*t)) ... %ninth partial
+ (0.00963544782.*amplitude .* sin(20.*pi.*f.*t)); %tenth partial
x = x .* (1 + 0.1 .* sin(10.*pi.*t)); %volume vibrato
end

View File

@@ -0,0 +1,44 @@
function x = generate_organ(amplitude, frequency, phase, fs, duration, duty)
% GENERATE_ORGAN: returns a matrix of sampled waveform similar to
% an organ.
% CONTRIBUTORS:
% Brandon Roberts: Original author
% MuseScore: Reference source for overtone information
% 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 does not apply for instruments
% setup needed variables
n = fs * duration; % total data points
dt = 1 / fs; % space between samples
% initialize template time scale
t = [1:n].*dt - phase;
f = frequency; %no frequency vibrato
% generate proper fundamental and overtones
x = (0.605975181.*amplitude .* sin(2.*pi.*f.*t)) ... %fundamental (first partial)
+ (0.96669476.*amplitude .* sin(4.*pi.*f.*t)) ... %second partial
+ (0.509982853.*amplitude .* sin(6.*pi.*f.*t)) ... %third partial
+ (amplitude .* sin(8.*pi.*f.*t)) ... %fourth partial
+ (0.138074341.*amplitude .* sin(10.*pi.*f.*t)) ... %fifth partial
+ (0.397744776.*amplitude .* sin(12.*pi.*f.*t)) ... %sixth partial
+ (0.00348745968.*amplitude .* sin(14.*pi.*f.*t)) ... %seventh partial
+ (0.350983754.*amplitude .* sin(16.*pi.*f.*t)) ... %eighth partial
+ (0.0326368101.*amplitude .* sin(18.*pi.*f.*t)) ... %ninth partial
+ (0.0121770467.*amplitude .* sin(20.*pi.*f.*t)) ... %tenth partial
+ (0.000406870296.*amplitude .* sin(22.*pi.*f.*t)) ... %eleventh partial
+ (0.0440001162.*amplitude .* sin(24.*pi.*f.*t)) ... %twelth partial
+ (0.00299340289.*amplitude .* sin(26.*pi.*f.*t)) ... %thirteenth partial
+ (0.00767241129.*amplitude .* sin(28.*pi.*f.*t)) ... %fourteenth partial
+ (0.00337121102.*amplitude .* sin(30.*pi.*f.*t)) ... %fifteenth partial
+ (0.0389432997.*amplitude .* sin(32.*pi.*f.*t)) ... %sixteenth partial
+ (0.00496963004.*amplitude .* sin(64.*pi.*f.*t)); %thirty-second partial
%no volume vibrato
end

View File

@@ -0,0 +1,46 @@
function x = generate_saxophone(amplitude, frequency, phase, fs, duration, duty)
% GENERATE_SAXOPHONE: returns a matrix of sampled waveform similar to
% a saxophone.
% CONTRIBUTORS:
% Brandon Roberts: Original author
% MuseScore: Reference source for overtone information
% 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 does not apply for instruments
% setup needed variables
n = fs * duration; % total data points
dt = 1 / fs; % space between samples
% initialize template time scale
t = [1:n].*dt - phase;
f = frequency .* (1 + 0.0001 .* sin(9.*pi.*t)./t); %frequency vibrato
% generate proper fundamental and overtones
x = (0.64011635.*amplitude .* sin(2.*pi.*f.*t)) ... %fundamental (first partial)
+ (0.558462369.*amplitude .* sin(4.*pi.*f.*t)) ... %second partial
+ (amplitude .* sin(6.*pi.*f.*t)) ... %third partial
+ (0.156636999.*amplitude .* sin(8.*pi.*f.*t)) ... %fourth partial
+ (0.102886106.*amplitude .* sin(10.*pi.*f.*t)) ... %fifth partial
+ (0.289185376.*amplitude .* sin(12.*pi.*f.*t)) ... %sixth partial
+ (0.21277411.*amplitude .* sin(14.*pi.*f.*t)) ... %seventh partial
+ (0.108250745.*amplitude .* sin(16.*pi.*f.*t)) ... %eighth partial
+ (0.077212478.*amplitude .* sin(18.*pi.*f.*t)) ... %ninth partial
+ (0.285980527.*amplitude .* sin(20.*pi.*f.*t)) ... %tenth partial
+ (0.167644958.*amplitude .* sin(22.*pi.*f.*t)) ... %eleventh partial
+ (0.115479073.*amplitude .* sin(24.*pi.*f.*t)) ... %twelth partial
+ (0.0345740512.*amplitude .* sin(26.*pi.*f.*t)) ... %thirteenth partial
+ (0.0192987651.*amplitude .* sin(28.*pi.*f.*t)) ... %fourteenth partial
+ (0.0140386324.*amplitude .* sin(30.*pi.*f.*t)) ... %fifteenth partial
+ (0.0102938359.*amplitude .* sin(32.*pi.*f.*t)) ... %sixteenth partial
+ (0.0166338634.*amplitude .* sin(34.*pi.*f.*t)) ... %seventeenth partial
+ (0.0128019786.*amplitude .* sin(36.*pi.*f.*t)) ... %eighteenth partial
+ (0.00442408514.*amplitude .* sin(38.*pi.*f.*t)); %nineteenth partial
x = x .* (1 + 0.1 .* sin(9.*pi.*t)); %volume vibrato
end

View File

@@ -0,0 +1,27 @@
function x = generate_shepardsCarillon(amplitude, frequency, phase, fs, duration, duty)
% GENERATE_SHEPARDSCARILLON: returns a matrix of sampled waveform similar to
% tubular bells, doubled at octaves.
% Calls generate_tubularBells
% CONTRIBUTORS:
% Brandon Roberts: Original author
% MuseScore: Reference source for overtone information
% 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 does not apply for instruments
% generate proper tone
x = generate_tubularBells(amplitude/5, frequency/16, phase, fs, duration, duty) ... %4 octaves below
+ generate_tubularBells(amplitude/4, frequency/8, phase, fs, duration, duty) ... %3 octaves below
+ generate_tubularBells(amplitude/3, frequency/4, phase, fs, duration, duty) ... %2 octaves below
+ generate_tubularBells(amplitude/2, frequency/2, phase, fs, duration, duty) ... %1 octave below
+ generate_tubularBells(amplitude, frequency, phase, fs, duration, duty) ... %unison
+ generate_tubularBells(amplitude/2, frequency*2, phase, fs, duration, duty) ... %1 octave above
+ generate_tubularBells(amplitude/3, frequency*4, phase, fs, duration, duty) ... %2 octaves above
+ generate_tubularBells(amplitude/4, frequency*8, phase, fs, duration, duty) ... %3 octaves above
+ generate_tubularBells(amplitude/5, frequency*16, phase, fs, duration, duty); %4 octaves above
end

View File

@@ -0,0 +1,33 @@
function x = generate_shepardsOrgan(amplitude, frequency, phase, fs, duration, duty)
% GENERATE_SHEPARDSORGAN: returns a matrix of sampled waveform similar to
% an organ, doubled at octaves.
% Calls generate_organ
% CONTRIBUTORS:
% Brandon Roberts: Original author
% MuseScore: Reference source for overtone information
% 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 does not apply for instruments
% generate proper tone
x = generate_organ(amplitude/8, frequency/128, phase, fs, duration, duty) ... %7 octaves below
+ generate_organ(amplitude/7, frequency/64, phase, fs, duration, duty) ... %6 octaves below
+ generate_organ(amplitude/6, frequency/32, phase, fs, duration, duty) ... %5 octaves below
+ generate_organ(amplitude/5, frequency/16, phase, fs, duration, duty) ... %4 octaves below
+ generate_organ(amplitude/4, frequency/8, phase, fs, duration, duty) ... %3 octaves below
+ generate_organ(amplitude/3, frequency/4, phase, fs, duration, duty) ... %2 octaves below
+ generate_organ(amplitude/2, frequency/2, phase, fs, duration, duty) ... %1 octave below
+ generate_organ(amplitude, frequency, phase, fs, duration, duty) ... %unison
+ generate_organ(amplitude/2, frequency*2, phase, fs, duration, duty) ... %1 octave above
+ generate_organ(amplitude/3, frequency*4, phase, fs, duration, duty) ... %2 octaves above
+ generate_organ(amplitude/4, frequency*8, phase, fs, duration, duty) ... %3 octaves above
+ generate_organ(amplitude/5, frequency*16, phase, fs, duration, duty) ... %4 octaves above
+ generate_organ(amplitude/6, frequency*32, phase, fs, duration, duty) ... %5 octaves above
+ generate_organ(amplitude/7, frequency*64, phase, fs, duration, duty) ... %6 octaves above
+ generate_organ(amplitude/8, frequency*128, phase, fs, duration, duty); %7 octaves above
end

View File

@@ -0,0 +1,33 @@
function x = generate_shepardsStrings(amplitude, frequency, phase, fs, duration, duty)
% GENERATE_SHEPARDSSTRINGS: returns a matrix of sampled waveform similar to
% arco strings, doubled at octaves.
% Calls generate_arcoStrings
% CONTRIBUTORS:
% Brandon Roberts: Original author
% MuseScore: Reference source for overtone information
% 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 does not apply for instruments
% generate proper tone
x = generate_arcoStrings(amplitude/8, frequency/128, phase, fs, duration, duty) ... %7 octaves below
+ generate_arcoStrings(amplitude/7, frequency/64, phase, fs, duration, duty) ... %6 octaves below
+ generate_arcoStrings(amplitude/6, frequency/32, phase, fs, duration, duty) ... %5 octaves below
+ generate_arcoStrings(amplitude/5, frequency/16, phase, fs, duration, duty) ... %4 octaves below
+ generate_arcoStrings(amplitude/4, frequency/8, phase, fs, duration, duty) ... %3 octaves below
+ generate_arcoStrings(amplitude/3, frequency/4, phase, fs, duration, duty) ... %2 octaves below
+ generate_arcoStrings(amplitude/2, frequency/2, phase, fs, duration, duty) ... %1 octave below
+ generate_arcoStrings(amplitude, frequency, phase, fs, duration, duty) ... %unison
+ generate_arcoStrings(amplitude/2, frequency*2, phase, fs, duration, duty) ... %1 octave above
+ generate_arcoStrings(amplitude/3, frequency*4, phase, fs, duration, duty) ... %2 octaves above
+ generate_arcoStrings(amplitude/4, frequency*8, phase, fs, duration, duty) ... %3 octaves above
+ generate_arcoStrings(amplitude/5, frequency*16, phase, fs, duration, duty) ... %4 octaves above
+ generate_arcoStrings(amplitude/6, frequency*32, phase, fs, duration, duty) ... %5 octaves above
+ generate_arcoStrings(amplitude/7, frequency*64, phase, fs, duration, duty) ... %6 octaves above
+ generate_arcoStrings(amplitude/8, frequency*128, phase, fs, duration, duty); %7 octaves above
end

View File

@@ -0,0 +1,49 @@
function x = generate_trumpet(amplitude, frequency, phase, fs, duration, duty)
% GENERATE_TRUMPET: returns a matrix of sampled waveform similar to
% a trumpet.
% CONTRIBUTORS:
% Brandon Roberts: Original author
% MuseScore: Reference source for overtone information
% 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 does not apply for instruments
% setup needed variables
n = fs * duration; % total data points
dt = 1 / fs; % space between samples
% initialize template time scale
t = [1:n].*dt - phase;
f = frequency .* (1 + 0.00005 .* sin(10.*pi.*t)./t); %frequency vibrato
% generate proper fundamental and overtones
x = (0.802698298.*amplitude .* sin(2.*pi.*f.*t)) ... %fundamental (first partial)
+ (amplitude .* sin(4.*pi.*f.*t)) ... %second partial
+ (0.700319932.*amplitude .* sin(6.*pi.*f.*t)) ... %third partial
+ (0.748098515.*amplitude .* sin(8.*pi.*f.*t)) ... %fourth partial
+ (0.909272003.*amplitude .* sin(10.*pi.*f.*t)) ... %fifth partial
+ (0.471477725.*amplitude .* sin(12.*pi.*f.*t)) ... %sixth partial
+ (0.200863214.*amplitude .* sin(14.*pi.*f.*t)) ... %seventh partial
+ (0.264578051.*amplitude .* sin(16.*pi.*f.*t)) ... %eighth partial
+ (0.282234698.*amplitude .* sin(18.*pi.*f.*t)) ... %ninth partial
+ (0.128787879.*amplitude .* sin(20.*pi.*f.*t)) ... %tenth partial
+ (0.100688156.*amplitude .* sin(22.*pi.*f.*t)) ... %eleventh partial
+ (0.0874984909.*amplitude .* sin(24.*pi.*f.*t)) ... %twelth partial
+ (0.0488047809.*amplitude .* sin(26.*pi.*f.*t)) ... %thirteenth partial
+ (0.0261680551.*amplitude .* sin(28.*pi.*f.*t)) ... %fourteenth partial
+ (0.0186224798.*amplitude .* sin(30.*pi.*f.*t)) ... %fifteenth partial
+ (0.0255342267.*amplitude .* sin(32.*pi.*f.*t)) ... %sixteenth partial
+ (0.0111674514.*amplitude .* sin(34.*pi.*f.*t)) ... %seventeenth partial
+ (0.010020524.*amplitude .* sin(36.*pi.*f.*t)) ... %eighteenth partial
+ (0.00694192925.*amplitude .* sin(38.*pi.*f.*t)) ... %nineteenth partial
+ (0.00307859471.*amplitude .* sin(40.*pi.*f.*t)) ... %twentieth partial
+ (0.00338041772.*amplitude .* sin(42.*pi.*f.*t)) ... %twentyfirst partial
+ (0.0026862248.*amplitude .* sin(44.*pi.*f.*t)); %twentysecond partial
x = x .* (1 + 0.02 .* sin(10.*pi.*t)); %volume vibrato
end

View File

@@ -0,0 +1,38 @@
function x = generate_tubularBells(amplitude, frequency, phase, fs, duration, duty)
% GENERATE_TUBULARBELLS: returns a matrix of sampled waveform similar to
% a tubular bell.
% CONTRIBUTORS:
% Brandon Roberts: Original author
% MuseScore: Reference source for overtone information
% 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 does not apply for instruments
% amplitude decays exponentially at varying rates for different paritals
% setup needed variables
n = fs * duration; % total data points
dt = 1 / fs; % space between samples
% initialize template time scale
t = [1:n].*dt - phase;
f = frequency; %no frequency vibrato
% generate proper fundamental and overtones
x = (0.105668016.*amplitude .* sin(pi.*f.*t))./(2.^(t./10)) ... %hum tone
+ (0.143724696.*amplitude .* sin(2.*pi.*f.*t))./(2.^(t./5)) ... %strike tone
+ (0.12.*amplitude .* sin(12./5.*pi.*f.*t))./(2.^(t./3)) ... %minor third overtone
+ (0.10.*amplitude .* sin(3.*pi.*f.*t))./(2.^(t./2.5)) ... %perfect fifth overtone
+ (0.8.*amplitude .* sin(4.*pi.*f.*t))./(2.^(t./2)) ... %perfect octave overtone
+ (0.6.*amplitude .* sin(5.*pi.*f.*t))./(2.^(t./1.5)) ... %major third overtone
+ (0.4.*amplitude .* sin(8.*pi.*f.*t))./(2.^(t)) ... %second perfect fifth overtone
+ (0.4.*amplitude .* sin(2.2.*pi.*f.*t))./(2.^(4.*t)) ... %transient 1
+ (0.4.*amplitude .* sin(1.8.*pi.*f.*t))./(2.^(8.*t)) ... %transient 2
+ (0.4.*amplitude .* sin(2.7.*pi.*f.*t))./(2.^(10.*t));%transient 3
x = x .* (1 + 0.02 .* sin(10.*pi.*t)); %volume vibrato
end

View File

@@ -0,0 +1,70 @@
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.
n = size(input, 2);
non_stereophonic = input;
if (n == 1) || (n == 2)
non_stereophonic = input(:, 1); % Removes the sterophonic property of the input sound
% by just taking the first column of data.
non_stereophonic = transpose(non_stereophonic);
end
modified_input = non_stereophonic(1, :);
Len = length(modified_input);
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(modified_input)); % 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 .* lowPassFilter; %Apply the low-pass filter.
lowPassedInput = transpose(lowPassedInput);
% 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.
output = transpose(output);
end

View File

@@ -0,0 +1,73 @@
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.
n = size(input, 2);
non_stereophonic = input;
if (n == 1) || (n == 2)
non_stereophonic = input(:, 1); % Removes the sterophonic property of the input sound
% by just taking the first column of data.
non_stereophonic = transpose(non_stereophonic);
end
modified_input = non_stereophonic(1, :);
Len = length(modified_input);
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(modified_input)); % 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 .* bandPassFilter; %Apply the Band-Pass Filter.
output = real(ifft(fftshift(bandPassedInput)));
end