From 3336c2923ed155b4e66ba43764cf44333099cecf Mon Sep 17 00:00:00 2001 From: Neelay Joglekar Date: Fri, 10 Dec 2021 16:07:51 -0800 Subject: [PATCH 1/6] Seems to work --- src/lfo_freq_sine.m | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/lfo_freq_sine.m diff --git a/src/lfo_freq_sine.m b/src/lfo_freq_sine.m new file mode 100644 index 0000000..3fc4273 --- /dev/null +++ b/src/lfo_freq_sine.m @@ -0,0 +1,32 @@ +function output = lfo_freq_sine(amplitude, frequency, phase, fs, duration, input) +%LFO_FREQ_SINE Modulates the frequency of an input with a sine LFO + +% CONTRIBUTORS: +% Neelay Joglekar: Original author + +% SOURCES: +% Code based off of Benjamin Liou's functions (lfo_sine) +% https://dsp.stackexchange.com/questions/2349/help-with-algorithm-for-modulating-oscillator-pitch-using-lfo + +% DOCUMENTATION: +% Frequency is modulated by 20 semitones (20 above, 20 below) + + % 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 + + % create output array + output = zeros([1, n]); + + x = 0.0; % theoretical input index, assuming input not discrete + % populate output + for i = 1:n + t = i * dt; % time at the i'th sample + omega_ratio = 2 ^ (20/12 * sin(2 * pi * frequency * t - phase)); + x = mod(x + omega_ratio, n); + x_0 = floor(x) + 1; + x_1 = mod(x_0 + 1, n) + 1; + output(i) = (input(x_1) - input(x_0)) * (x - x_0) + input(x_0); + end +end + From 079800ac25610069c10e430fe30b29e23380da2a Mon Sep 17 00:00:00 2001 From: Neelay Joglekar Date: Fri, 10 Dec 2021 16:36:28 -0800 Subject: [PATCH 2/6] Work in src LFO/ for now --- src/{ => LFO}/lfo_freq_sine.m | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{ => LFO}/lfo_freq_sine.m (100%) diff --git a/src/lfo_freq_sine.m b/src/LFO/lfo_freq_sine.m similarity index 100% rename from src/lfo_freq_sine.m rename to src/LFO/lfo_freq_sine.m From b27aef78a995fd130f90c69827b5661a0d2168d3 Mon Sep 17 00:00:00 2001 From: Neelay Joglekar Date: Fri, 10 Dec 2021 16:57:21 -0800 Subject: [PATCH 3/6] Added documentation --- src/LFO/lfo_freq_sine.m | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/LFO/lfo_freq_sine.m b/src/LFO/lfo_freq_sine.m index 3fc4273..bef74a5 100644 --- a/src/LFO/lfo_freq_sine.m +++ b/src/LFO/lfo_freq_sine.m @@ -5,11 +5,13 @@ function output = lfo_freq_sine(amplitude, frequency, phase, fs, duration, input % Neelay Joglekar: Original author % SOURCES: -% Code based off of Benjamin Liou's functions (lfo_sine) -% https://dsp.stackexchange.com/questions/2349/help-with-algorithm-for-modulating-oscillator-pitch-using-lfo +% Code inspired by Benjamin Liou's lfo functions +% Code also inspired by Darren and Anne's pitch envelopes +% Source for frequency modulation equation: +% https://dsp.stackexchange.com/questions/2349/help-with-algorithm-for-modulating-oscillator-pitch-using-lfo % DOCUMENTATION: -% Frequency is modulated by 20 semitones (20 above, 20 below) +% Frequency is modulated by sine wave with given amplitude (in octaves, not Hz) % initialize local variables from input arguments n = fs * duration; % number of samples (length of matrix) @@ -18,12 +20,17 @@ function output = lfo_freq_sine(amplitude, frequency, phase, fs, duration, input % create output array output = zeros([1, n]); - x = 0.0; % theoretical input index, assuming input not discrete + x = 0.0; % the theoretical input index if the input were not discrete % populate output for i = 1:n t = i * dt; % time at the i'th sample - omega_ratio = 2 ^ (20/12 * sin(2 * pi * frequency * t - phase)); + + % Increment x based off of sine wave output + omega_ratio = 2 ^ (amplitude * sin(2 * pi * frequency * t - phase)); x = mod(x + omega_ratio, n); + + % Linearly interpolate the actual indicies adjacent to x + % to get an output value x_0 = floor(x) + 1; x_1 = mod(x_0 + 1, n) + 1; output(i) = (input(x_1) - input(x_0)) * (x - x_0) + input(x_0); From cb791584ae9df29e6b06121cbbf6048b5e6063cc Mon Sep 17 00:00:00 2001 From: Neelay Joglekar Date: Fri, 10 Dec 2021 17:14:22 -0800 Subject: [PATCH 4/6] Works, with documentation --- src/LFO/lfo_freq_saw.m | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/LFO/lfo_freq_saw.m diff --git a/src/LFO/lfo_freq_saw.m b/src/LFO/lfo_freq_saw.m new file mode 100644 index 0000000..361a741 --- /dev/null +++ b/src/LFO/lfo_freq_saw.m @@ -0,0 +1,38 @@ +function output = lfo_freq_saw(amplitude, frequency, phase, fs, duration, input) +%LFO_FREQ_SAW Modulates the frequency of an input with a saw LFO + +% CONTRIBUTORS: +% Neelay Joglekar: Original author + +% SOURCES: +% Code inspired by Benjamin Liou's lfo functions +% Code also inspired by Darren and Anne's pitch envelopes +% Source for frequency modulation equation: +% https://dsp.stackexchange.com/questions/2349/help-with-algorithm-for-modulating-oscillator-pitch-using-lfo + +% DOCUMENTATION: +% Frequency is modulated by saw wave with given amplitude (in octaves, not Hz) + + % 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 + + % create output array + output = zeros([1, n]); + + x = 0.0; % the theoretical input index if the input were not discrete + % populate output + for i = 1:n + t = i * dt; % time at the i'th sample + + % Increment x based off of saw wave output + omega_ratio = 2 ^ (amplitude * (2 * mod((t - phase / (2*pi)) * frequency, 1) - 1)); + x = mod(x + omega_ratio, n); + + % Linearly interpolate the actual indicies adjacent to x + % to get an output value + x_0 = floor(x) + 1; + x_1 = mod(x_0 + 1, n) + 1; + output(i) = (input(x_1) - input(x_0)) * (x - x_0) + input(x_0); + end +end From 194a7a206e999b52a499ea8d511642465903468f Mon Sep 17 00:00:00 2001 From: Neelay Joglekar Date: Fri, 10 Dec 2021 17:27:50 -0800 Subject: [PATCH 5/6] Works and Documented --- src/LFO/lfo_freq_square.m | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/LFO/lfo_freq_square.m diff --git a/src/LFO/lfo_freq_square.m b/src/LFO/lfo_freq_square.m new file mode 100644 index 0000000..f413e6c --- /dev/null +++ b/src/LFO/lfo_freq_square.m @@ -0,0 +1,38 @@ +function output = lfo_freq_square(amplitude, frequency, phase, fs, duration, input) +%LFO_FREQ_SQUARE Modulates the frequency of an input with a square LFO + +% CONTRIBUTORS: +% Neelay Joglekar: Original author + +% SOURCES: +% Code inspired by Benjamin Liou's lfo functions +% Code also inspired by Darren and Anne's pitch envelopes +% Source for frequency modulation equation: +% https://dsp.stackexchange.com/questions/2349/help-with-algorithm-for-modulating-oscillator-pitch-using-lfo + +% DOCUMENTATION: +% Frequency is modulated by square wave with given amplitude (in octaves, not Hz) + + % 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 + + % create output array + output = zeros([1, n]); + + x = 0.0; % the theoretical input index if the input were not discrete + % populate output + for i = 1:n + t = i * dt; % time at the i'th sample + + % Increment x based off of square wave output + omega_ratio = 2 ^ (amplitude * (2 * round(mod((t - phase / (2*pi)) * frequency, 1)) - 1)); + x = mod(x + omega_ratio, n); + + % Linearly interpolate the actual indicies adjacent to x + % to get an output value + x_0 = floor(x) + 1; + x_1 = mod(x_0 + 1, n) + 1; + output(i) = (input(x_1) - input(x_0)) * (x - x_0) + input(x_0); + end +end \ No newline at end of file From 44f49de45a96e9582212862aaaa0231225dd763d Mon Sep 17 00:00:00 2001 From: Neelay Joglekar Date: Fri, 10 Dec 2021 17:30:57 -0800 Subject: [PATCH 6/6] Moved all functions to src --- src/{LFO => }/lfo_freq_saw.m | 0 src/{LFO => }/lfo_freq_sine.m | 0 src/{LFO => }/lfo_freq_square.m | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename src/{LFO => }/lfo_freq_saw.m (100%) rename src/{LFO => }/lfo_freq_sine.m (100%) rename src/{LFO => }/lfo_freq_square.m (100%) diff --git a/src/LFO/lfo_freq_saw.m b/src/lfo_freq_saw.m similarity index 100% rename from src/LFO/lfo_freq_saw.m rename to src/lfo_freq_saw.m diff --git a/src/LFO/lfo_freq_sine.m b/src/lfo_freq_sine.m similarity index 100% rename from src/LFO/lfo_freq_sine.m rename to src/lfo_freq_sine.m diff --git a/src/LFO/lfo_freq_square.m b/src/lfo_freq_square.m similarity index 100% rename from src/LFO/lfo_freq_square.m rename to src/lfo_freq_square.m