annotate core/magnatagatune/AudioFeatureRAW.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 % --
wolffd@0 2 % This class loads and hanles the aufdio features included with the MTT
wolffd@0 3 % Library
wolffd@0 4 % ---
wolffd@0 5
wolffd@0 6
wolffd@0 7 classdef AudioFeatureRAW < MTTAudioFeature & handle
wolffd@0 8
wolffd@0 9
wolffd@0 10 properties(Constant = true)
wolffd@0 11
wolffd@0 12 end
wolffd@0 13
wolffd@0 14 properties
wolffd@0 15 % ---
wolffd@0 16 % Set default parameters
wolffd@0 17 % ---
wolffd@0 18 my_params = struct([]);
wolffd@0 19
wolffd@0 20 end
wolffd@0 21 % ---
wolffd@0 22 % member functions
wolffd@0 23 % ---
wolffd@0 24 methods
wolffd@0 25
wolffd@0 26 % ---
wolffd@0 27 % constructor: pointer to feature in database
wolffd@0 28 % ---
wolffd@0 29 function feature = AudioFeatureRAW(varargin)
wolffd@0 30
wolffd@0 31 feature = feature@MTTAudioFeature(varargin{:});
wolffd@0 32
wolffd@0 33 end
wolffd@0 34
wolffd@0 35 function [a1, a2, a3] = visualise(feature)
wolffd@0 36 % ---
wolffd@0 37 % plots the different data types collected in this feature
wolffd@0 38 % ---
wolffd@0 39 for i = 1:numel(feature)
wolffd@0 40 clip = feature(i).data.info.owner;
wolffd@0 41
wolffd@0 42 % ---
wolffd@0 43 % labels for chroma data
wolffd@0 44 % ---
wolffd@0 45 chroma_labels = {'c', 'c#', 'd','d#', 'e', 'f','f#', 'g','g#', 'a','a#', 'b'};
wolffd@0 46 mode_labels = {'minor', 'major'};
wolffd@0 47
wolffd@0 48 % hange labels to reflect detected mode
wolffd@0 49 chroma_labels{feature(i).data.key + 1} = ...
wolffd@0 50 sprintf('(%s) %s',mode_labels{feature(i).data.mode + 1}, chroma_labels{feature(i).data.key + 1});
wolffd@0 51
wolffd@0 52
wolffd@0 53 secs = [feature(i).data.sections_start; feature(i).data.sections_duration];
wolffd@0 54
wolffd@0 55 h = figure;
wolffd@0 56
wolffd@0 57 % number of subplots
wolffd@0 58 n = 3;
wolffd@0 59
wolffd@0 60 % ---
wolffd@0 61 % chroma feature display
wolffd@0 62 % ---
wolffd@0 63 subplot(n,1,1);
wolffd@0 64
wolffd@0 65 % get segment times and fix for same lengths for all plots
wolffd@0 66 % ---
wolffd@0 67 % NOTE: Last segment will appear longer
wolffd@0 68 % ---
wolffd@0 69 segments = [feature(i).data.segments_start];
wolffd@0 70 segments(end) = feature(i).data.duration;
wolffd@0 71
wolffd@0 72 % display chroma vectors
wolffd@0 73 uimagesc(segments, 0:11, [feature(i).data.segments_pitches]);
wolffd@0 74
wolffd@0 75 set(gca,'YTick',[0:11], 'YTickLabel', chroma_labels);
wolffd@0 76
wolffd@0 77 axis xy
wolffd@0 78 colormap(hot)
wolffd@0 79 %colorbar;
wolffd@0 80 ylabel('chroma class');
wolffd@0 81 title(sprintf('clip %d: %s by %s, chromagram', ...
wolffd@0 82 clip.id, clip.title(),clip.artist()));
wolffd@0 83
wolffd@0 84 % added sections
wolffd@0 85 axis([0 feature(i).data.duration -1 11.5]);
wolffd@0 86 hl = line([secs(1,:); sum(secs,1)],ones(2, size(secs,2)) * -0.8);
wolffd@0 87 set(hl,'LineWidth',6);
wolffd@0 88
wolffd@0 89 a1 = gca;
wolffd@0 90
wolffd@0 91 % ---
wolffd@0 92 % mfcc feature display
wolffd@0 93 %
wolffd@0 94 % NOTE: the first position of timbre is reduced in energy,
wolffd@0 95 % as this seems to introduce some corruption in lots of data
wolffd@0 96 % ---
wolffd@0 97 timbre = feature(i).data.segments_timbre(:,1);
wolffd@0 98 timbre = timbre/ max(max(abs(timbre))) * ...
wolffd@0 99 mean( mean( abs( feature(i).data.segments_timbre(:,2:min(end,5)))));
wolffd@0 100
wolffd@0 101 subplot(n,1,2);
wolffd@0 102 uimagesc(segments, 0:11, [timbre feature(i).data.segments_timbre(:,2:end)]);
wolffd@0 103
wolffd@0 104 axis xy
wolffd@0 105 %colorbar;
wolffd@0 106 xlabel('time[s]');
wolffd@0 107 ylabel('mfcc coeff');
wolffd@0 108 title(sprintf('mfcc timbre features'));
wolffd@0 109
wolffd@0 110 a2 = gca;
wolffd@0 111
wolffd@0 112 % ---
wolffd@0 113 % beats and sections
wolffd@0 114 % ---
wolffd@0 115
wolffd@0 116 subplot(n,1,3);
wolffd@0 117 axis([0 feature(i).data.duration -0.6 1.2]);
wolffd@0 118
wolffd@0 119 hl = line([0 feature(i).data.duration],[0 0]);
wolffd@0 120 set(hl, 'Color','g');
wolffd@0 121
wolffd@0 122 a3 = gca;
wolffd@0 123
wolffd@0 124 if ~isfield(feature.data,'bars');
wolffd@0 125 return;
wolffd@0 126 end
wolffd@0 127
wolffd@0 128 beats = feature.data.beats;
wolffd@0 129 bars = feature.data.bars;
wolffd@0 130 tatums = feature.data.tatums;
wolffd@0 131 % tatums
wolffd@0 132 hl = line([tatums(1,:); tatums(1,:)],[ones(1, size(tatums,2)) * -0.2; max(-0.1,tatums(2,:))]);
wolffd@0 133 set(hl,'LineWidth',1);
wolffd@0 134 set(hl, 'Color','k');
wolffd@0 135
wolffd@0 136 % beats
wolffd@0 137 hl = line([beats(1,:); beats(1,:)],[ones(1, size(beats,2)) * -0.4; max(-0.1,beats(2,:))]);
wolffd@0 138 set(hl,'LineWidth',2);
wolffd@0 139 set(hl, 'Color','b');
wolffd@0 140
wolffd@0 141 % bars
wolffd@0 142 hl = line([bars(1,:); bars(1,:)],[ones(1, size(bars,2)) * -0.5; max(-0.1,bars(2,:))]);
wolffd@0 143 set(hl,'LineWidth',4);
wolffd@0 144 set(hl, 'Color','r');
wolffd@0 145
wolffd@0 146 % sections
wolffd@0 147 hl = line([secs(1,:); sum(secs,1)],ones(2, size(secs,2)) * -0.5);
wolffd@0 148 set(hl,'LineWidth',6);
wolffd@0 149
wolffd@0 150 ylabel('confidence');
wolffd@0 151 title(sprintf('rhythmic features @%3.1f BPM, %d/4 meter',...
wolffd@0 152 feature(i).data.tempo, feature(i).data.timeSignature));
wolffd@0 153
wolffd@0 154 end
wolffd@0 155 end
wolffd@0 156 end
wolffd@0 157
wolffd@0 158 end