MATLAB Creating Music with MATLAB: Code, Synthesis, and Possibilities Explained

  • Thread starter Thread starter needOfHelpCMath
  • Start date Start date
  • Tags Tags
    Matlab Music
AI Thread Summary
The discussion revolves around a project involving MATLAB code to synthesize and play a 30-second excerpt of Johann Sebastian Bach's Fugue #2 from a provided file, fugue.mat. The file contains a structure array named "voice" with three elements, each representing a musical voice containing vectors for pitch, start time, and duration of notes. The user is tasked with writing code to load this data, synthesize the notes according to their timing, and play them back. The user has shared initial code snippets that attempt to define the pitch, start, and duration for the first three notes of the first voice but expresses uncertainty about whether the code is correct or if it meets the project requirements. The discussion also touches on the user's motivation for the project, questioning whether the goal is to create music or to analyze the data using MATLAB.
needOfHelpCMath
Messages
70
Reaction score
0
I have project code using MatLab and so far I am having difficulties of understanding what it is asking for. May anyone explain for me please.

The file fugue.mat It contains numerical data that encode about
30-seconds worth of Johann Sebastian Bach's Fugue #2 for the Well-Tempered Clavier. You are
to write MATLAB code that loads this file, synthesizes the notes with correct timing, and then
plays the notes.
You will also prepare a document discussing possibilities for the computer-generated synthesis
of music.This is the code that i must read in to in order to play my code sound:

function soundproject3(fileToRead1)
%IMPORTFILE(FILETOREAD1)
% Imports data from the specified file
% FILETOREAD1: file to read

% Auto-generated by MATLAB on 27-Nov-2016 16:45:27

% Import the file
newData1 = load('-mat', fileToRead1);

% Create new variables in the base workspace from those fields.
vars = fieldnames(newData1);
for i = 1:length(vars)
assignin('base', vars{i}, newData1.(vars{i}));
end

Description of Project

The file fugue.mat contains a structure array called voice with three elements. (In musical
terms, this fugue contains three voices.) These elements are:
voice(m), where m = 1, 2, or 3
Each of these elements is a structure. Each of the elements represents a sequence of notes that is
to be played. Each structure contains three fields:
voice(m).pitch
voice(m).start
voice(m).duration

Each of these fields is a vector. For a given structure − for example, voice(2)− the three
vectors − pitch, start, duration − are of equal length. These three vectors together
define a sequence of notes. The vector start defines the start time of each note. The vector
duration defines the duration of each note. The vector pitch defines the pitch of each
note.
2
For example, the first number in the vector voice(2).start
voice(2).start(1)
is the start time in seconds of the first note in the sequence of notes defined by voice(2). The
first number in the vector voice(2).duration
voice(2).duration(1)
is the duration in seconds of this first note. The first number in the vector voice(2).pitch
voice(2).pitch(1)
is the pitch number of this first note.
Using the symbol p to represent the pitch number voice(m).pitch(n), the pitch number
for the n-th note of the m-th voice, the frequency of this note is given by
440 × 2(𝑝−49)⁄12 Hz

So here what i have so far:
Code:
voice(1).pitch(1)
    pitch(1) = {1};
voice(1).start(1)
    start(1) = {1};
voice(1).duration(1)
       duration(1) = {1};

voice(1).pitch(2)
    pitch(2) = {1};
voice(1).start(2)
    start(2) = {1};
voice(1).duration(2)
    duration(2) = {1};

voice(1).pitch(3)
    pitch(3) = {1};
voice(1).start(3)
    start(3)= {1};
voice(1).duration(3)
    duration(3) = {3};
I am not sure if my code is right or i complete do not know what they are asking for.
 
Physics news on Phys.org
Are you interested in actually creating music? Or you want to develop something semi-trivial so you can analyse it using MATLAB?
 

Similar threads

Replies
4
Views
2K
Replies
4
Views
1K
Replies
32
Views
4K
Replies
2
Views
2K
Replies
1
Views
2K
Replies
5
Views
2K
Back
Top