-
Notifications
You must be signed in to change notification settings - Fork 2
/
runAlignment.m
73 lines (62 loc) · 2.95 KB
/
runAlignment.m
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
function [allstate,selectstate,spec,yinres]=runAlignment(filename, midiname, numNotes, stateOrd2, noteNum, means, covars, learnparams)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [allstate selectstate spec yinres]=seeAlignment(audiofile,midifile,...
% numNotes, stateOrd, noteNum, means, covars,learnparams)
%
% Description:
% Calls the DTW alignment function and refines the results with the HMM
% alignment algorithm, with both a basic and modified state spaces (based
% on the lyrics). This function returns the results of both the state
% spaces as well as the YIN analysis of the specified audio file.
%
% Inputs:
% filename - name of audio file
% midiname - name of MIDI file
% numNotes - number of notes in the MIDI file to be aligned
% stateOrd2 - vector of state sequence
% noteNum - vector of note numbers corresponding to state sequence
% means - mean values for each state
% covars - covariance values for each state
% learnparams - flag as to whether to learn means and covars in the HMM
%
% Outputs:
% allstate - ending times for each state
% selectstate - ending times for each state
% spec - spectogram of the audio file
% yinres - structure of results of funning the YIN algorithm on the
% audio signal indicated by the input variable filename
%
% Automatic Music Performance Analysis and Analysis Toolkit (AMPACT)
% http://www.ampact.org
% (c) copyright 2011 Johanna Devaney (j@devaney.ca), all rights reserved.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if ~exist('learnparams', 'var'), learnparams = 0; end
% refine stateOrd2 to correspond to the number of states specified
% in numStates
numStates = max(find(noteNum <= numNotes));
stateOrd2=stateOrd2(1:numStates);
noteNum=noteNum(1:numStates);
% read audio file and perform DTW alignment and YIN analysis
hop = 32;
[audiofile, sr] = wavread(filename);
% normalize audio file
audiofile=audiofile/sqrt(mean(audiofile.^2))*.6;
%get vals
[align, yinres, spec] = getVals(filename, midiname, audiofile, sr, hop);
clear audiofile
% run HMM alignment with the full state sequence
[vpath,startingState,prior,trans,meansFull,covarsFull,mixmat,obs,stateOrd] = runHMMAlignment(numNotes, means, covars, align, yinres, sr, learnparams);
% tally of the number of frames in each state
histvals = hist(vpath, 1:max(vpath));
% ending time of each state in seconds
cumsumvals = cumsum(histvals*hop/sr);
% run HMM alignment with the state sequence refined, based on the lyrics
cumsumvals2=selectStates(startingState,prior,trans,meansFull,covarsFull,mixmat,obs,stateOrd2,noteNum,sr);
% create 3*N matrices of the alignments, where the first row is the
% current states, the second row is the time which the state ends, and
% the third row is the state index and N is the total number of states
allstate=stateOrd;
allstate(2,1:length(cumsumvals))=cumsumvals;
selectstate=stateOrd2;
selectstate(2,1:length(cumsumvals2))=cumsumvals2;
selectstate(3,:) = noteNum;