I need to make MUSIC on matlab

71 views (last 30 days)
Annie
Annie on 3 Nov 2013
Commented: Erdal Yegenaga on 1 Nov 2020
So I have to make a song on matlab and then set up sine waves that correspond to the notes on the scale. The notes are AGGABCFG. can someone help me with this?

Answers (3)

Azzi Abdelmalek
Azzi Abdelmalek on 3 Nov 2013
Edited: Azzi Abdelmalek on 3 Nov 2013
Look at these links
For your case
notes={'C' 'C#' 'D' 'Eb' 'E' 'F' 'F#' 'G' 'G#' 'A' 'Bb' 'B'}
freq=[261.6 277.2 293.7 311.1 329.6 349.2...
370.0 392.0 415.3 440.0 466.2 493.9]
song={'A' 'G' 'G' 'A' 'B' 'C' 'F' 'G'} % your song
a=[]
for k=1:numel(song)
note_value=0:0.000125:0.5 % You can change the note duration
a=[a sin(2*pi* freq(strcmp(notes,song{k}))*note_value)];
end
sound(a)
  2 Comments
Azzi Abdelmalek
Azzi Abdelmalek on 4 Nov 2013
[Annie commented]
thank you for you help!
Haripriya K
Haripriya K on 15 Jun 2020
hello can u say at what times these individual notes begin in the song?

Sign in to comment.


Dan Po
Dan Po on 17 Oct 2016
OMG I LOVE THIS POST
clear
tic
notes={'C' 'C#' 'D' 'Eb' 'E' 'F' 'F#' 'G' 'G#' 'A' 'Bb' 'B'};
freq=[261.6 277.2 293.7 311.1 329.6 349.2...
370.0 392.0 415.3 440.0 466.2 493.9];
song={'A' 'G' 'G' 'A' 'B' 'C' 'F' 'G'} ; % your song
a=[];
for i=2:70
for k=1:numel(song);
note_value=0:i*0.0001:0.5 ;% You can change the note duration
a=[a sin(2*pi* freq(strcmp(notes,song{k}))*note_value)];
end
end
sound(a);
toc

Erdal Yegenaga
Erdal Yegenaga on 1 Nov 2020
I am doing research for my graduation project, but I could not reach enough code information.I want to assign music notes to computer keys for digital synthesizer. Can you write this code with adsr enveloping please?
  2 Comments
John D'Errico
John D'Errico on 1 Nov 2020
Edited: John D'Errico on 1 Nov 2020
This is not an answer to anything, but a direct request for someone to provide code to you to do your task. If this is research, will you give direct credit to the person who did the work for you when you hand in your project? Will their name be listed on front of your project as a direct contributor? Or, would you happily hand in someone else's efforts as your own?
Erdal Yegenaga
Erdal Yegenaga on 1 Nov 2020
You r right. I asked my problem wrong way. Can you help me write to assign computer keys to play music notes?
clear ;
close all;
fs=8500;
t=0:0.000117:3;
note_do= sin(2*pi*261.6*t);
note_re= sin(2*pi*293.7*t);
note_mi= sin(2*pi*329.6*t);
note_fa= sin(2*pi*349.2*t);
note_sol= sin(2*pi*392*t);
note_la= sin(2*pi*440*t);
note_si= sin(2*pi*493.9*t);
note_do1= sin(2*pi*523.5*t);
y=note_do;
A = linspace(0, 0.9, (length(y)*0.10)); %rise 35% of signal
D = linspace(0.9, 0.7,(length(y)*0.05)); %drop of 5% of signal
S = linspace(0.7, 0.7,(length(y)*0.40)); %delay of 40% of signal
R = linspace(0.7, 0,(length(y)*0.20)); %drop of 25% of signal
ADSR = [A D S R] ;
x = zeros(size(y));
x(1:length(ADSR)) = ADSR;
tone=y.* x;
sound(tone,fs);

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!