使用Matlab编曲
Matlab can be used as an arranger to create musical compositions. It's not as convenient as other arranging software though, it's fun to learn about sound principles in this way. So I have written some functions, see utils, starting from the most primitive way to eventually realise composing a piece of music. You need to follow these steps to do this:
Using FL Studio as an example, you can export midi files from Piano Roll. Then use the midi2track
function to generate a matrix containing the track information. (Of course, you can also write the matrix manually, but it may be too much trouble).
You can start by writing implicit functions to plot the waveform of the sound in one amplitude, and the envelope of the note respectively. The ADSR1
and ADSR2
functions are provided to quickly generate the envelopes. Individual notes are then obtained using the fnote
, fnote2
and fnote3
functions. For easy insertion, you can customise the loop to generate the notes of each scale consecutively. Or you can generate noise or fixed pitch notes as drum beats.
This may require a bit of thinking about the relationship between time and beat, but you can also use the tick2time
, beat2time
functions to convert the corresponding time directly. In order to insert notes later, you need to generate an array of ctime to keep track of the time accumulated for each tick. If the conversion scheme is 1 beat = 60/BPM second = 96 ticks, and if the whole song with 4*16 beats has a fixed tempo of 120 BPM, then the ctime should be written like this:
BPM=120*ones(96*4*16); %BPM per tick.
deltatime=60/96./BPM; %time for each tick
ctime=cumsum(deltatime); % cumulative time per tick
The soundTrack
function makes it easy and quick to insert notes into the timeline, provided you have done all the previous preparations. You can also use external audio sources (e.g. Piano 88), which should be stored in cells if pitch changes.
I've also written simple functions for Compressor
, Delay
, and Equlizer
. You can also use the more advanced functions of the Signal Processing Toolbox to make the sound fuller.