Mercurial > hg > camir-aes2014
comparison toolboxes/MIRtoolbox1.3.2/MIRToolbox/@mirmidi/mirmidi.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 function varargout = mirmidi(orig,varargin) | |
2 % m = mirmidi(x) converts into a MIDI sequence. | |
3 % Option associated to mirpitch function can be specified: | |
4 % 'Contrast' with default value c = .3 | |
5 | |
6 thr.key = 'Contrast'; | |
7 thr.type = 'Integer'; | |
8 thr.default = .3; | |
9 option.thr = thr; | |
10 | |
11 mono.key = 'Mono'; | |
12 mono.type = 'Boolean'; | |
13 mono.default = 1; | |
14 option.mono = mono; | |
15 | |
16 release.key = {'Release','Releases'}; | |
17 release.type = 'String'; | |
18 release.choice = {'Olivier','Valeri',0,'no','off'}; | |
19 release.default = 'Valeri'; | |
20 option.release = release; | |
21 | |
22 specif.option = option; | |
23 | |
24 varargout = mirfunction(@mirmidi,orig,varargin,nargout,specif,@init,@main); | |
25 | |
26 | |
27 function [x type] = init(x,option) | |
28 try | |
29 hz2midi(440); | |
30 catch | |
31 mirerror('MIRMIDI','MIDItoolbox does not seem to be installed.'); | |
32 end | |
33 if not(isamir(x,'mirmidi')) && not(isamir(x,'mirpitch')) | |
34 if isa(x,'mirdesign') && not(option.mono) | |
35 x = set(x,'SeparateChannels',1); | |
36 end | |
37 o = mironsets(x,'Attacks','Releases',option.release); | |
38 x = {o x}; | |
39 end | |
40 type = 'mirmidi'; | |
41 | |
42 | |
43 function m = main(x,option,postoption) | |
44 if iscell(x) %not(isamir(x,'mirmidi')) | |
45 o = x{1}; | |
46 a = x{2}; | |
47 s = mirsegment(a,o); | |
48 x = mirpitch(s,'Contrast',option.thr,'Sum',0); | |
49 do = get(o,'PeakVal'); | |
50 da = get(o,'AttackPos'); | |
51 dr = get(o,'ReleasePos'); | |
52 df = get(o,'FramePos'); | |
53 else | |
54 do = NaN; | |
55 end | |
56 dp = get(x,'Data'); | |
57 %fp = get(x,'FramePos'); | |
58 nmat = cell(1,length(dp)); | |
59 for i = 1:length(dp) | |
60 nmat{i} = []; | |
61 for j = 2:length(dp{i}) | |
62 tij = mean(df{i}{1}(:,da{i}{1}{1}(j-1))); | |
63 dij = mean(df{i}{1}(:,dr{i}{1}{1}(j-1))) - tij; | |
64 if not(iscell(do)) | |
65 vij = 120; | |
66 else | |
67 vij = round(do{i}{1}{1}(j-1)/max(do{i}{1}{1})*120); | |
68 end | |
69 for k = 1:size(dp{i}{j},3) | |
70 for l = 1:size(dp{i}{j},2) | |
71 for n = 1:length(dp{i}{j}{1,l,k}) | |
72 f = dp{i}{j}{1,l,k}(n); | |
73 p = round(hz2midi(f)); | |
74 nmat{i} = [nmat{i}; tij dij 1 p vij tij dij]; | |
75 end | |
76 end | |
77 end | |
78 end | |
79 end | |
80 m = class(struct,'mirmidi',mirdata(x)); | |
81 m = set(m,'Data',nmat); |