Download Reading Music The Treble Clef A treble clef symbol tells you that the

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Figured bass wikipedia , lookup

Notes inégales wikipedia , lookup

Mensural notation wikipedia , lookup

Polyrhythm wikipedia , lookup

Time signature wikipedia , lookup

Transcript
Reading Music
The Treble Clef
A treble clef symbol tells you that the second line from the bottom (the line that the symbol curls around) is
"G". On any staff, the notes are always arranged so that the next letter is always on the next higher line or
space. The last note letter, G, is always followed by another A.
The Base Clef
A bass clef symbol tells you that the second line from the top (the one bracketed by the symbol's dots) is F. The
notes are still arranged in ascending order, but they are all in different places than they were in treble clef.
1
Below are the names of the notes for both clefs. The reason for the two clefs is that most instruments using the
base clef have a lower pitch meaning that the notes would appear so far below the staff, they would be hard to
read.
The treble clef:
The bass clef:
Length of notes
There are various types of notes, each of which is held for a different length of time. The way a note appears
indicates how many beats it should last.
In most music:
Whole notes last four beats.
Half notes last two beats.
Quarter notes last one beat.
Any note shorter than a quarter note has one or more "hooks" to indicate its length. Each hook cuts the note's
length in half.
Eighth notes (one hook) last one-half beat.
Sixteenth notes (two hooks) last one-quarter beat.
These continue on to thirty-second and sixty-fourth notes (with three and four hooks, respectively). If two or
more notes requiring hooks appear in a row, they're often connected with "beams." The number of horizontal
lines in a beam indicates note length.
Two eighth notes connected by a beam
2
Music also has rests, which indicate silent beats. They're counted in the same way as notes, and correspond to
the notes they represent.
Whole note rest
Half note rest
Quarter note rest
Eighth note rest
Sixteenth note rest
Understand time signatures
Music usually has two numbers at the beginning, one on top of the other. This is called a time signature. The
time signature indicates how many beats there are in a measure (the space between bar lines), as well as what
the general pace (rhythm) of a song will be.
Bar lines are vertical lines that intersect the entire stave at regular intervals. The end of a piece of music is
indicated by a double bar line.
The top number of a time signature indicates how many beats are in a measure. The bottom number indicates
the type of note that makes up each beat.
The most common time signature in popular music is 4/4 (four beats in each measure, and each beat is made up
of a quarter note). Sometimes 4/4 time is indicated with a large "C" centered vertically on the stave at its
beginning (which stands for "common time").
The sound output of musical instruments does not immediately build up to its full intensity nor does the sound
fall to zero intensity instantaneously. It takes a certain amount of time for the sound to build up in intensity and
a certain amount of time for the sound to die away. The period of time during which a musical tone is building
up to some amplitude (volume) is called the “attack time” and the time required for the tone’s intensity to
partially die away is called its “decay time.” The time for final attenuation is called the “release time.” Many
instruments allow the user to hold the tone for a period of time which is known as the “sustain time” so that
3
various note durations can be achieved. The amplitude of the tone can “fit” inside a curve often called the
Attack-Decay-Sustain-Release (ADSR) envelope as depicted in Figure 1.
Figure 1
MATLAB Implementation
The implementation of a music synthesizer involves three codes:
1. tone synthesizer or sinusoid generator,
2. ADSR envelope generator,
3. composer/player code.
It is assumed that the digital synthesis is at a rate of fs = 16,000 samples per second. At this rate we are able to
reproduce all piano frequencies according to Nyquist theory
Octave
C
#
C /Db
D
# b
D /E
E
F
#
F /Gb
G
#
G /Ab
A
# b
A /B
B
0
16.35
17.32
18.35
19.45
20.6
21.83
23.12
24.5
25.96
27.5
29.14
30.87
1
32.7
34.65
36.71
38.89
41.2
43.65
46.25
49
51.91
55
58.27
61.74
2
65.41
69.3
73.42
77.78
82.41
87.31
92.5
98
103.83
110
116.54
123.47
3
130.81
138.59
146.83
155.56
164.81
174.61
185
196
207.65
220
233.08
246.94
4
261.63
277.18
293.66
311.13
329.63
349.23
369.99
392
415.3
440
466.16
493.88
5
523.25
554.37
587.33
622.25
659.26
698.46
739.99
783.99
830.61
880
932.33
987.77
6
1046.5
1108.73
1174.66
1244.51
1318.51
1396.91
1479.98
1567.98
1661.22
1760
1864.66
1975.53
7
2093
2217.46
2349.32
2489.02
2637.02
2793.83
2959.96
3135.96
3322.44
3520
3729.31
3951.07
4
M Files
 Script Files
There are two different kinds of m-files. The simplest, a script file, which is merely a collection of
MATLAB commands. When the script file is executed by typing its name at the interactive prompt,
MATLAB reads and executes the commands within the m-file just as if one were entering them
manually. It is as if one were cutting and pasting the m-file contents into the MATLAB command
window.
If the command "whos" is typed, it can be seen that the variables that are in the memory at the end
of the program also remain in memory after the m-file has finished running. This is because we have
written the m-file has been written as a script file where it has simply collected together several
commands into a file, and then the code executes them one-by-one when the script is run, as if they
were merely being typed into the interactive session window.

Functions
The second kind of m-file, contains a single function that has the same name as that of the m-file.
This m-file contains an independent section of code with a clearly defined input/output interface;
that is, it can be invoked by passing to it a list of arguments arg1, arg2, ... and it returns as output the
values out1, out2, ….
The first non-commented line of a function m-file contains the function header, which is of the form
function [out1,out2,...] = filename(arg1,arg2,...);
The m-file ends with the command return, which returns the program execution to the place where
the function was called.
Music Generation
Figure 2 below is the MATLAB code to generate a sine wave, where f is the frequency, fs the sampling
frequency and duration the length of the note. The function should be save as singen.m and the only
parameter returned by this function is x. If no parameters were returned then the equals sign may be omitted
i.e. function singen(f,fs,duration)
function x = singen(f,fs,duration)
% Input
% f - frequency of sinusoid
% fs - sampling frequency
% duration - duration of signal in seconds
% Output
% x - vector of sinusoid samples
n = [0:fs*duration]';
x = sin(2*pi*f/fs*n);
Figure 2
A continuous-time sinusoid can be expressed as:
xtsin2ft
where f is the frequency of the sinusoid. Samples of (2) which are taken T seconds apart (called the sample
period) can be expressed as:
xn   2fnT
 sin( 2nf / fs )
where n is the sample index and fs = 1 / T is the sample rate. The MATLAB function above (Figure 2) generates
a sinusoid which returns a vector of synthesized sinusoid samples.
5
Envelope Generator
The envelope will give the sinusoid characteristic to mimic real instruments in the way the notes build up and
decay. The envelope is constructed one segment (A, D, S, and R) at a time. Each segment is approximated with
an exponential which rises or decays to the target value as in Figure 3.
Figure 3 ADSR for a (a) a piano and (b) a guitar
This approximation then leads to a digital filter implementation (difference equation), whose response yields
samples of an exponential curve. In addition, a gain parameter is allowed for to control the speed at which the
exponential reaches the target value. The difference equation is given by a single-pole filter
anaˆg1gan 1
where a(n) are the envelope values, ˆ a is the target value, and g is the gain parameter. Figure 6 illustrates a
MATLAB function which returns a vector of ADSR envelope values. For simplicity, there is no decay segment
and it is assumed an envelope duration of 1 second or 16,000 samples or a whole note. In reality, music is
composed of many durations of notes not just whole notes. In this case:
sustain_duration = note_duration – attack_duration – release_duration.
An example envelope (similar in nature to a piano) can be generated with the MATLAB calls in Figure 4. This
function should be saved as adsr_gen.m i.e. it should have the same name as the function. Note that the
function returns one parameter, namely a.
function a = adsr_gen(target,gain,duration)
% Input
% target - vector of attack, sustain, release target values
% gain - vector of attack, sustain, release gain values
% duration - vector of attack, sustain, release durations in ms
% Output
% a - vector of adsr envelope values
fs = 16000;
a = zeros(fs,1); % assume 1 second duration ADSR envelope
duration = round(duration./1000.*fs); % envelope duration in samp
% Attack phase
start = 2;
stop = duration(1);
for n = [start:stop]
a(n) = target(1)*gain(1) + (1.0 - gain(1))*a(n-1);
end
% Sustain phase
start = stop + 1;
stop = start + duration(2);
for n = [start:stop]
a(n) = target(2)*gain(2) + (1.0 - gain(2))*a(n-1);
end
% Release phase
start = stop + 1;
stop = fs;
6
for n = [start:stop]
a(n) = target(3)*gain(3) + (1.0 - gain(3))*a(n-1);
end;
Figure 4
An envelope may be plotted using the following MATLAB code:
»target = [0.99999;0.25;0];
»gain = [0.005;0.0004;0.00075];
»duration = [125;625;250];
»a = adsr_gen(target,gain,duration);
»plot(a);
Hopefully generating the following plot.
To play a sound, type:
»f0 = 440;fs = 16000;
»x = singen(f0,fs,1-1/fs);
»y = a .* x; % Modulate
»sound(y,fs);
And to normalise for an accurate reproduction:
»y = y ./ max(abs(y)); % Normalise samples
7