-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmmbop_exampleScript.m
More file actions
55 lines (43 loc) · 2.46 KB
/
mmbop_exampleScript.m
File metadata and controls
55 lines (43 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
% Set input variables
wavName = "exampleAudio.wav"; % our audio file
csvName = "exampleOnsets.csv"; % our csv of markers from reaper
normLevel = -3; % our normalisation level in dBFs
windowSize = 1; % size of onset search window in s, try to use 0.2 for MIR framesize safety
onsetDetectMethod = 'SpectralFlux'; % Pitched instrument with sustain, so Spectral Flux is preferrable.
beatDivisions = [1 1 1 1 1 1 1 1 1 1 2 1 1 2 0.5 0.5 0.5 0.5 1 1 0.5 0.5 0.5 0.5 1 1 1 1 2 1 1]; % Beat divisions for performance (1 being a full beat, 0.5 being a half beat etc)
% ----------------------------------------------------------------
% Load in our audio and markers using the function loadResource
[audio, Fs, res, markerTimes_s, markerNames, audio_fileName] = loadResource(wavName, csvName, normLevel);
% ----------------------------------------------------------------
% ----------------------------------------------------------------
% Get our onsets --------
onsets = getOnsets(windowSize, audio, Fs, markerTimes_s, onsetDetectMethod);
% ----------------------------------------------------------------
% ----------------------------------------------------------------
% Plot our audio and Onsets --------
plotOnsets(audio, Fs, audio_fileName, onsets)
% ----------------------------------------------------------------
% ----------------------------------------------------------------
% Get the tempo samples for each onset interval --------
[tempoSamples, tempoFit] = getTempo(onsets, beatDivisions);
% ----------------------------------------------------------------
% ----------------------------------------------------------------
% Get the tempo samples for each onset interval --------
plotTempo(tempoSamples, tempoFit, audio, Fs, audio_fileName, onsets);
% ----------------------------------------------------------------
% ----------------------------------------------------------------
% Save the data --------
% Generate filenames
tempoSamples_fileName = sprintf('%s_tempoSamples.csv', audio_fileName);
tempoData_fileName = sprintf('%s_tempoInfo.csv', audio_fileName);
onsets_fileName = sprintf('%s_onsets.csv', audio_fileName);
% Sort tempoInfo
tempoSlope = tempoFit(1)';
tempoStart = tempoFit(2)';
tempoMean = mean(tempoSamples)';
tempoData = table(tempoMean, tempoStart, tempoSlope);
% Write files
writematrix(onsets, onsets_fileName);
writematrix(tempoSamples, tempoSamples_fileName);
writetable(tempoData, tempoData_fileName);
% ----------------------------------------------------------------