From 3c8c79d4a7379a55aad7e20d26d3bcb079937614 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 11 Dec 2021 09:01:58 -0800 Subject: [PATCH 1/2] Added a lullaby generator to src/Generators Signed-off-by: Gabriel Diaz --- src/.DS_Store | Bin 10244 -> 10244 bytes src/Generators/generate_lullaby.m | 66 ++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/Generators/generate_lullaby.m diff --git a/src/.DS_Store b/src/.DS_Store index a262e39857b141cde26b5ea2e1dc125a2574e533..385d2ba1eebac3cbb20daa0a8bb01b0640448dbc 100644 GIT binary patch delta 46 zcmV+}0MY-1P=rvBPXR8mP`eKSF0%{}3R delta 299 zcmZn(XbG6$&uFqSU^hRb$z~n_9%flS1`mcrh9ZVshJ1!RhD?TJ27iV$AS`A`Whj}v zUgWqm9u<=hN{H6uk!L8$&3AE0%E?b+U|`^ITFt3jy790hkWD~O3JH3gAWkjFFbq!4 s&n*BN4g+{CDGM&j%gN762P$UVEGjI;y_sF%7t7=e0!KE#6}D#r0E3N1+5i9m diff --git a/src/Generators/generate_lullaby.m b/src/Generators/generate_lullaby.m new file mode 100644 index 0000000..83df45d --- /dev/null +++ b/src/Generators/generate_lullaby.m @@ -0,0 +1,66 @@ +function x = generate_lullaby(amplitude, frequency, phase, fs, duration, duty) + % Generates sine waves that play 'twinkle twinkle little star' + % by using the frequency parameter as the root note for the melody. + % Currently the duty and duration parameters are not used within the + % function as there is no need for the former and it is currently + % difficult to constrain the melody duration based on user input. + % A function such as this one could be useful as a demo for what a + % melody sounds like on a synthesizer, and could even find use + % in toys designed to help small children sleep. + + % CONTRIBUTORS: + % generate_lullaby created by Gabriel Diaz + + % 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 + + %NOTE: whatever's passed as the duration parameter doesn't get used at + %the moment, since it's currently difficult to sync every note in the + %melody to play in shorter duartions such that the entire song lasts about + %as long as 'duration' + duration = 0; + duty = 0; %duty also isn't used in this function + + %current durations that the song will work with + note_duration = 0.4; + song_duration = note_duration * 48; + + %frequency multiples for all notes in melody, assuming that frequency is + %the root note of this chord: + maj_second_freq = frequency * 1.125; + maj_third_freq = frequency * 1.25; + fourth_freq = frequency * 1.33; + fifth_freq = frequency * 1.5; + maj_sixth_freq = frequency * 1.7; + + % initialize local variables from input arguments + n = fs * note_duration; % number of samples (length of matrix) + dt = 1 / fs; % sampling period: time between two sample points + t = [1:n].*dt - phase; %initialize time scale template + + %sine waves for every note in 'frequency's' respective major scale: + first = amplitude * sin(2 * pi * frequency * t - phase); + second = amplitude * sin(2 * pi * maj_second_freq * t - phase); + third = amplitude * sin(2 * pi * maj_third_freq * t - phase); + fourth = amplitude * sin(2 * pi * fourth_freq * t - phase); + fifth = amplitude * sin(2 * pi * fifth_freq * t - phase); + sixth = amplitude * sin(2 * pi * maj_sixth_freq * t - phase); + + %each one of the three melodies making up the song: + melody1 = [first,first,fifth,fifth,sixth,sixth,fifth,fifth]; %size 8 notes + melody2 = [fourth,fourth,third,third,second,second,first,first]; %size 8 notes + melody3 = [fifth,fifth,fourth,fourth,third,third,second,second]; %size 8 notes + + % populate the matrix(total size is 44 notes wide, which means the song's + % duration must fit within the specified duration parameter + x = [melody1,melody2,melody3,melody3,melody1,melody2]; + + %For testing + %t = 0:dt:song_duration; + %t(n) = []; + %plot(t, x); + %sound(x, fs); +end \ No newline at end of file From 5715e4bde96abff0b2af3aabbf122425bd4ef4ba Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 11 Dec 2021 09:22:13 -0800 Subject: [PATCH 2/2] added 'generate_lullaby' --- src/Generators/.DS_Store | Bin 0 -> 6148 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/Generators/.DS_Store diff --git a/src/Generators/.DS_Store b/src/Generators/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0