To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / _song / song_syncchroma.m
History | View | Annotate | Download (2.98 KB)
| 1 |
function song = song_syncchroma(song, param) |
|---|---|
| 2 |
|
| 3 |
[song.syncchroma.treble, treblenrm] = syncchroma(song.chroma.treble, song.beattimes, song.t); |
| 4 |
[song.syncchroma.bass, bassnrm] = syncchroma(song.chroma.bass, song.beattimes, song.t(:)); |
| 5 |
|
| 6 |
song.syncchroma.bass(isnan(sum(song.syncchroma.bass,2)),:) = 1; |
| 7 |
song.syncchroma.treble(isnan(sum(song.syncchroma.treble,2)),:) = 1; |
| 8 |
|
| 9 |
song.syncchroma.bass(sum(song.syncchroma.bass,2)<.01,:) = 1; |
| 10 |
song.syncchroma.treble(sum(song.syncchroma.treble,2)<.01,:) = 1; |
| 11 |
|
| 12 |
bcnrm = qnorm(song.syncchroma.bass,1,2); |
| 13 |
if param.dsp.bassbin13 % if the model requires a thirteenth bass bin |
| 14 |
bc = qnormalise(song.syncchroma.bass,1,2); |
| 15 |
bc13 = (12 * max(bc,[],2)).^(-2) .* bcnrm; |
| 16 |
bc13(isnan(bc13)) = 1; |
| 17 |
song.syncchroma.bass = [song.syncchroma.bass, bc13]; |
| 18 |
end |
| 19 |
|
| 20 |
switch param.dsp.norm |
| 21 |
case 'max' |
| 22 |
song.syncchroma.bass = qnormalise(song.syncchroma.bass,inf,2); |
| 23 |
song.syncchroma.treble = qnormalise(song.syncchroma.treble,inf,2); |
| 24 |
case 'L1' |
| 25 |
song.syncchroma.bass = qnormalise(song.syncchroma.bass,1,2); |
| 26 |
song.syncchroma.treble = qnormalise(song.syncchroma.treble,1,2); |
| 27 |
case 'L2' |
| 28 |
disp('L2 norm')
|
| 29 |
song.syncchroma.bass = qnormalise(song.syncchroma.bass,2,2); |
| 30 |
song.syncchroma.treble = qnormalise(song.syncchroma.treble,2,2); |
| 31 |
case 'standardize' |
| 32 |
song.syncchroma.bass = standardize(song.syncchroma.bass); |
| 33 |
song.syncchroma.treble = standardize(song.syncchroma.treble); |
| 34 |
case 'meta' |
| 35 |
song.syncchroma.bass = qnormalise(song.syncchroma.bass,inf,2); |
| 36 |
disp('no standardization for treble chroma; max normalisation for bass')
|
| 37 |
otherwise |
| 38 |
'blub' |
| 39 |
end |
| 40 |
|
| 41 |
% make all NaNs to 1 |
| 42 |
song.syncchroma.bass(isnan(sum(song.syncchroma.bass,2)),:) = 1; |
| 43 |
song.syncchroma.treble(isnan(sum(song.syncchroma.treble,2)),:) = 1; |
| 44 |
% aah, what does this do??? |
| 45 |
% song.syncchroma.bass(sum(song.syncchroma.bass,2) < 1,:) = 1; |
| 46 |
% song.syncchroma.treble(sum(song.syncchroma.treble,2) < 1,:) = 1; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
% below "wide" chroma processing, that's neglected ... |
| 52 |
% try |
| 53 |
% [song.syncchroma.wide, widenrm] = syncchroma(song.chroma.wide, song.beattimes, song.t); |
| 54 |
% for iBeat = 1:song.nBeat |
| 55 |
% song.syncchroma.wide(iBeat,:) = song.syncchroma.wide(iBeat,:) / widenrm(iBeat); |
| 56 |
% end |
| 57 |
% catch |
| 58 |
% warning('could not find wide chroma');
|
| 59 |
% end |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
function [bc, nrm] = syncchroma(chromag,beats,frame_t) |
| 64 |
% assigning beats to frames |
| 65 |
nBeat = size(beats,1); |
| 66 |
nFrame = length(frame_t); |
| 67 |
|
| 68 |
bc = ones(nBeat,size(chromag,1)); |
| 69 |
chromag(:,isnan(sum(chromag))) = 1; |
| 70 |
|
| 71 |
if size(beats,2) < 2 |
| 72 |
for iBeat = 1:nBeat-1 |
| 73 |
currind = find(frame_t >= beats(iBeat) & frame_t < beats(iBeat+1)); |
| 74 |
bc(iBeat,:) = median(chromag(:,currind),2); |
| 75 |
% if ~any(isnan(bc(iBeat,:))) |
| 76 |
% bc(iBeat,:) = bc(iBeat,:)/max(bc(iBeat,:)); |
| 77 |
% end |
| 78 |
end |
| 79 |
else |
| 80 |
for iBeat = 1:nBeat |
| 81 |
currind = find(frame_t >= beats(iBeat,1) & frame_t < beats(iBeat,2)); |
| 82 |
bc(iBeat,:) = median(chromag(:,currind),2)'; |
| 83 |
end |
| 84 |
end |
| 85 |
nrm = qnorm(bc,inf,2); |
| 86 |
% bc = qnormalise(bc,inf,2); |