c@120
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
c@120
|
2
|
c@120
|
3 /*
|
c@120
|
4 QM Vamp Plugin Set
|
c@120
|
5
|
c@120
|
6 Centre for Digital Music, Queen Mary, University of London.
|
c@120
|
7 All rights reserved.
|
c@120
|
8 */
|
c@120
|
9
|
c@120
|
10 /*transcription vamp plugin: Ruohua Zhou, Josh Reiss, josh.reiss@elec.qmul.ac.uk */
|
c@120
|
11
|
c@120
|
12 #include "Transcription.h"
|
c@120
|
13 #include <vamp-sdk/PluginAdapter.h>
|
c@120
|
14 #include <math.h>
|
c@120
|
15 #include <stdlib.h>
|
c@120
|
16
|
c@120
|
17 using std::string;
|
c@120
|
18 using std::vector;
|
c@120
|
19 using std::cerr;
|
c@120
|
20 using std::endl;
|
c@120
|
21
|
c@120
|
22 const double CNum[8] = {
|
c@120
|
23 3.025328153863e-005,0.0002117729707704,0.0006353189123113, 0.001058864853852,
|
c@120
|
24 0.001058864853852,0.0006353189123113,0.0002117729707704,3.025328153863e-005
|
c@120
|
25 };
|
c@120
|
26
|
c@120
|
27 const double CDen[8] = {
|
c@120
|
28 1, -4.647847898799, 9.540784706769, -11.14354542746,
|
c@120
|
29 7.967285533211, -3.477244449085, 0.8559660579522, -0.09152610255505
|
c@120
|
30 };
|
c@120
|
31
|
c@120
|
32 const int A[10] = {0, 120, 190, 240, 279, 310, 337, 360, 380, 399};
|
c@120
|
33
|
c@120
|
34
|
c@120
|
35
|
c@120
|
36 const double EualCurve960[960] = {
|
c@120
|
37 83.750025,83.532690,83.315770,83.099260,82.883159,82.667463,82.452170,82.237276,82.022779,81.808675,
|
c@120
|
38 81.594963,81.381639,81.168699,80.956142,80.743964,80.532163,80.320735,80.109677,79.898987,79.688663,79.478700,79.269096,79.059848,78.850953,
|
c@120
|
39 78.642408,78.434211,78.226359,78.018848,77.811676,77.604839,77.398336,77.192162,76.986316,76.780794,76.575593,76.370710,76.166143,75.961889,
|
c@120
|
40 75.757945,75.554307,75.350973,75.147940,74.945205,74.742766,74.540618,74.338761,74.137189,73.935902,73.734895,73.534166,73.333712,73.133529,
|
c@120
|
41 72.933616,72.733970,72.534586,72.335463,72.136598,71.937987,71.739628,71.541517,71.343653,71.146032,70.948650,70.751506,70.554597,70.357919,
|
c@120
|
42 70.161469,69.965245,69.769244,69.573462,69.377898,69.182548,68.987408,68.792477,68.597752,68.403228,68.208905,68.014781,67.820873,67.627197,
|
c@120
|
43 67.433772,67.240617,67.047749,66.855187,66.662949,66.471053,66.279516,66.088358,65.897597,65.707250,65.517336,65.327873,65.138879,64.950373,
|
c@120
|
44 64.762372,64.574894,64.387959,64.201583,64.015785,63.830584,63.645997,63.462043,63.278739,63.096105,62.914158,62.732915,62.552397,62.372620,
|
c@120
|
45 62.193602,62.015363,61.837920,61.661291,61.485494,61.310549,61.136471,60.963274,60.790941,60.619447,60.448770,60.278885,60.109770,59.941401,
|
c@120
|
46 59.773755,59.606807,59.440536,59.274916,59.109924,58.945538,58.781733,58.618486,58.455773,58.293572,58.131858,57.970608,57.809799,57.649407,
|
c@120
|
47 57.489408,57.329780,57.170498,57.011539,56.852880,56.694496,56.536366,56.378464,56.220768,56.063255,55.905900,55.748680,55.591571,55.434551,
|
c@120
|
48 55.277595,55.120681,54.963784,54.806886,54.649983,54.493077,54.336169,54.179261,54.022353,53.865448,53.708546,53.551650,53.394759,53.237877,
|
c@120
|
49 53.081003,52.924139,52.767287,52.610448,52.453624,52.296815,52.140023,51.983250,51.826496,51.669763,51.513053,51.356366,51.199705,51.043070,
|
c@120
|
50 50.886463,50.729885,50.573337,50.416821,50.260338,50.103890,49.947478,49.791103,49.634766,49.478469,49.322214,49.166001,49.009832,48.853710,
|
c@120
|
51 48.697648,48.541659,48.385757,48.229958,48.074273,47.918719,47.763308,47.608055,47.452974,47.298080,47.143385,46.988904,46.834652,46.680642,
|
c@120
|
52 46.526889,46.373405,46.220207,46.067307,45.914720,45.762460,45.610540,45.458976,45.307780,45.156968,45.006553,44.856549,44.706971,44.557832,
|
c@120
|
53 44.409146,44.260928,44.113192,43.965951,43.819220,43.673013,43.527344,43.382227,43.237676,43.093703,42.950305,42.807478,42.665218,42.523520,
|
c@120
|
54 42.382381,42.241794,42.101757,41.962264,41.823311,41.684894,41.547008,41.409648,41.272811,41.136491,41.000685,40.865387,40.730594,40.596301,
|
c@120
|
55 40.462503,40.329195,40.196375,40.064036,39.932175,39.800787,39.669867,39.539412,39.409417,39.279876,39.150787,39.022143,38.893942,38.766178,
|
c@120
|
56 38.638846,38.511944,38.385465,38.259405,38.133761,38.008525,37.883679,37.759203,37.635076,37.511278,37.387789,37.264588,37.141656,37.018971,
|
c@120
|
57 36.896513,36.774262,36.652197,36.530298,36.408545,36.286918,36.165395,36.043957,35.922583,35.801253,35.679947,35.558643,35.437322,35.315964,
|
c@120
|
58 35.194547,35.073052,34.951458,34.829745,34.707892,34.585879,34.463686,34.341293,34.218678,34.095822,33.972704,33.849303,33.725600,33.601574,
|
c@120
|
59 33.477205,33.352481,33.227425,33.102069,32.976445,32.850585,32.724520,32.598284,32.471906,32.345420,32.218858,32.092250,31.965629,31.839028,
|
c@120
|
60 31.712477,31.586009,31.459655,31.333448,31.207419,31.081601,30.956024,30.830722,30.705725,30.581067,30.456777,30.332890,30.209436,30.086447,
|
c@120
|
61 29.963955,29.841993,29.720591,29.599783,29.479599,29.360071,29.241233,29.123114,29.005748,28.889166,28.773400,28.658474,28.544378,28.431095,
|
c@120
|
62 28.318607,28.206897,28.095947,27.985740,27.876257,27.767481,27.659396,27.551982,27.445224,27.339102,27.233599,27.128699,27.024383,26.920633,
|
c@120
|
63 26.817433,26.714764,26.612609,26.510951,26.409772,26.309053,26.208779,26.108930,26.009491,25.910442,25.811766,25.713446,25.615465,25.517804,
|
c@120
|
64 25.420446,25.323374,25.226570,25.130016,25.033695,24.937589,24.841681,24.745955,24.650409,24.555043,24.459856,24.364847,24.270016,24.175363,
|
c@120
|
65 24.080887,23.986588,23.892466,23.798520,23.704751,23.611156,23.517737,23.424492,23.331422,23.238526,23.145803,23.053253,22.960877,22.868672,
|
c@120
|
66 22.776640,22.684779,22.593090,22.501572,22.410224,22.319046,22.228038,22.137200,22.046530,21.956029,21.865697,21.775532,21.685535,21.595704,
|
c@120
|
67 21.506041,21.416544,21.327213,21.238047,21.149047,21.060211,20.971540,20.883034,20.794691,20.706512,20.618496,20.530642,20.442952,20.355423,
|
c@120
|
68 20.268057,20.180852,20.093808,20.006925,19.920202,19.833640,19.747237,19.660994,19.574910,19.488985,19.403218,19.317610,19.232159,19.146866,
|
c@120
|
69 19.061729,18.976750,18.891927,18.807260,18.722749,18.638393,18.554193,18.470147,18.386255,18.302518,18.218934,18.135504,18.052227,17.969105,
|
c@120
|
70 17.886151,17.803379,17.720805,17.638444,17.556310,17.474419,17.392786,17.311425,17.230351,17.149581,17.069127,16.989007,16.909233,16.829822,
|
c@120
|
71 16.750789,16.672148,16.593914,16.516103,16.438729,16.361808,16.285354,16.209382,16.133907,16.058945,15.984510,15.910617,15.837282,15.764518,
|
c@120
|
72 15.692342,15.620768,15.549811,15.479486,15.409809,15.340793,15.272455,15.204808,15.137869,15.071646,15.006129,14.941300,14.877144,14.813643,
|
c@120
|
73 14.750781,14.688540,14.626906,14.565860,14.505386,14.445467,14.386088,14.327231,14.268879,14.211016,14.153626,14.096691,14.040195,13.984121,
|
c@120
|
74 13.928453,13.873174,13.818267,13.763716,13.709504,13.655615,13.602031,13.548736,13.495714,13.442948,13.390420,13.338115,13.286016,13.234107,
|
c@120
|
75 13.182369,13.130788,13.079346,13.028026,12.976813,12.925693,12.874671,12.823756,12.772958,12.722285,12.671746,12.621351,12.571107,12.521025,
|
c@120
|
76 12.471113,12.421380,12.371835,12.322488,12.273346,12.224419,12.175717,12.127248,12.079020,12.031044,11.983328,11.935880,11.888711,11.841828,
|
c@120
|
77 11.795242,11.748960,11.702993,11.657348,11.612035,11.567063,11.522441,11.478178,11.434282,11.390764,11.347631,11.304893,11.262558,11.220637,
|
c@120
|
78 11.179137,11.138068,11.097437,11.057252,11.017521,10.978252,10.939452,10.901129,10.863290,10.825944,10.789098,10.752760,10.716937,10.681638,
|
c@120
|
79 10.646869,10.612640,10.578956,10.545827,10.513259,10.481261,10.449840,10.419004,10.388760,10.359117,10.330082,10.301663,10.273867,10.246702,
|
c@120
|
80 10.220176,10.194296,10.169071,10.144508,10.120615,10.097399,10.074868,10.053030,10.031892,10.011463,9.991749,9.972762,9.954523,9.937056,9.920385,
|
c@120
|
81 9.904534,9.889527,9.875389,9.862144,9.849815,9.838428,9.828005,9.818572,9.810152,9.802770,9.796449,9.791214,9.787089,9.784099,9.782266,9.781616,
|
c@120
|
82 9.782172,9.783959,9.787001,9.791322,9.796946,9.803897,9.812200,9.821878,9.832956,9.845457,9.859407,9.874829,9.891747,9.910185,9.930168,9.951720,
|
c@120
|
83 9.974864,9.999625,10.026008,10.053933,10.083304,10.114023,10.145991,10.179112,10.213287,10.248419,10.284410,10.321161,10.358576,10.396556,10.435004,
|
c@120
|
84 10.473821,10.512911,10.552175,10.591516,10.630835,10.670035,10.709018,10.747686,10.785942,10.823688,10.860826,10.897258,10.932886,10.967613,11.001341,
|
c@120
|
85 11.033972,11.065408,11.095552,11.124305,11.151570,11.177249,11.201245,11.223459,11.243793,11.262151,11.278450,11.292676,11.304827,11.314906,11.322913,
|
c@120
|
86 11.328848,11.332713,11.334508,11.334233,11.331889,11.327477,11.320998,11.312453,11.301841,11.289164,11.274422,11.257616,11.238747,11.217816,11.194822,
|
c@120
|
87 11.169767,11.142652,11.113476,11.082241,11.048948,11.013597,10.976189,10.936724,10.895203,10.851627,10.805996,10.758312,10.708574,10.656784,10.602942,
|
c@120
|
88 10.547049,10.489106,10.429113,10.367082,10.303073,10.237155,10.169399,10.099876,10.028655,9.955807,9.881403,9.805512,9.728206,9.649554,9.569627,9.488495,
|
c@120
|
89 9.406228,9.322897,9.238573,9.153325,9.067225,8.980341,8.892745,8.804508,8.715698,8.626388,8.536646,8.446544,8.356152,8.265539,8.174778,8.083937,7.993087,
|
c@120
|
90 7.902299,7.811643,7.721190,7.631008,7.541170,7.451746,7.362804,7.274417,7.186644,7.099504,7.013003,6.927151,6.841956,6.757424,6.673565,6.590385,6.507894,
|
c@120
|
91 6.426099,6.345008,6.264629,6.184970,6.106039,6.027843,5.950392,5.873692,5.797752,5.722579,5.648183,5.574570,5.501748,5.429727,5.358512,5.288114,5.218538,
|
c@120
|
92 5.149794,5.081890,5.014832,4.948630,4.883292,4.818824,4.755236,4.692535,4.630729,4.569826,4.509834,4.450761,4.392616,4.335415,4.279172,4.223905,4.169630,
|
c@120
|
93 4.116362,4.064118,4.012914,3.962766,3.913691,3.865703,3.818820,3.773058,3.728432,3.684960,3.642656,3.601538,3.561621,3.522921,3.485455,3.449239,3.414289,
|
c@120
|
94 3.380620,3.348250,3.317194,3.287469,3.259090,3.232074,3.206437,3.182194,3.159363,3.137959,3.117999,3.099498,3.082473,3.066939,3.052914,3.040413,3.029451,
|
c@120
|
95 3.020039,3.012186,3.005904,3.001201,2.998087,2.996571,2.996665,2.998377,3.001718,3.006696,3.013323,3.021607,3.031559,3.043187,3.056503,3.071516,3.088235,
|
c@120
|
96 3.106671,3.126833,3.148731,3.172374,3.197773,3.224938,3.253877,3.284601,3.317120,3.351444,3.387581,3.425543,3.465339,3.506978,3.550470,3.595826,3.643054,
|
c@120
|
97 3.692166,3.743169,3.796075,3.850896,3.907655,3.966377,4.027088,4.089815,4.154581,4.221415,4.290340,4.361382,4.434569,4.509924,4.587474,4.667245,4.749261,
|
c@120
|
98 4.833550,4.920136,5.009046,5.100305,5.193938,5.289972,5.388432,5.489343,5.592732,5.698625,5.807046,5.918022,6.031578,6.147741,6.266535,6.387986,6.512121,
|
c@120
|
99 6.638964,6.768542,6.900880,7.036004,7.173939,7.314712,7.458348,7.604856,7.754175,7.906227,8.060936,8.218223,8.378012,8.540225,8.704784,8.871612,9.040631,
|
c@120
|
100 9.211765,9.384934,9.560063,9.737073,9.915888,10.096429,10.278619,10.462380,10.647636,10.834309,11.022321,11.211594,11.402052,11.593616,11.786210,11.979755,
|
c@120
|
101 12.174175,12.369392,12.565329,12.761907,12.959049,13.156679,13.354718,13.553089,13.751715,13.950518,14.149420,14.348345,14.547211,14.745925,14.944391,
|
c@120
|
102 15.142512,15.340191,15.537333,15.733840,15.929615,16.124564
|
c@120
|
103 };
|
c@120
|
104 void Transcribe(int Len,int inputLen,double *SoundIn,double *out,double *outArray2,double *outArray3,double SampleRate);
|
c@120
|
105
|
c@120
|
106 Transcription::Transcription(float inputSampleRate) :
|
c@120
|
107 Plugin(inputSampleRate),
|
c@120
|
108 m_stepSize(0)
|
c@120
|
109 {
|
c@120
|
110 m_SoundIn=0;
|
c@120
|
111 m_SampleN=0;
|
c@120
|
112 m_AllocN = 0;
|
c@120
|
113 m_Excess = false;
|
c@120
|
114 }
|
c@120
|
115
|
c@120
|
116 Transcription::~Transcription()
|
c@120
|
117 {
|
c@120
|
118 free(m_SoundIn);
|
c@120
|
119 }
|
c@120
|
120
|
c@120
|
121 string
|
c@120
|
122 Transcription::getIdentifier() const
|
c@120
|
123 {
|
c@120
|
124 return "qm-transcription";
|
c@120
|
125 }
|
c@120
|
126
|
c@120
|
127 string
|
c@120
|
128 Transcription::getName() const
|
c@120
|
129 {
|
c@120
|
130 return "Polyphonic Transcription";
|
c@120
|
131 }
|
c@120
|
132
|
c@120
|
133 string
|
c@120
|
134 Transcription::getDescription() const
|
c@120
|
135 {
|
c@120
|
136 return "Transcribe the input audio to estimated notes";
|
c@120
|
137 }
|
c@120
|
138
|
c@120
|
139 string
|
c@120
|
140 Transcription::getMaker() const
|
c@120
|
141 {
|
c@120
|
142 return "Queen Mary, University of London";
|
c@120
|
143 }
|
c@120
|
144
|
c@120
|
145 int
|
c@120
|
146 Transcription::getPluginVersion() const
|
c@120
|
147 {
|
c@120
|
148 return 1;
|
c@120
|
149 }
|
c@120
|
150
|
c@120
|
151 string
|
c@120
|
152 Transcription::getCopyright() const
|
c@120
|
153 {
|
c@120
|
154 return "Plugin by Dr. Ruohua Zhou. Copyright (c) 2008-2009 QMUL - All Rights Reserved";
|
c@120
|
155 }
|
c@120
|
156
|
c@120
|
157 size_t
|
c@120
|
158 Transcription::getPreferredStepSize() const
|
c@120
|
159 {
|
c@120
|
160 return 441;
|
c@120
|
161 }
|
c@120
|
162
|
c@120
|
163 size_t
|
c@120
|
164 Transcription::getPreferredBlockSize() const
|
c@120
|
165 {
|
c@120
|
166 return 441;
|
c@120
|
167 }
|
c@120
|
168
|
c@120
|
169 bool
|
c@120
|
170 Transcription::initialise(size_t channels, size_t stepSize, size_t blockSize)
|
c@120
|
171 {
|
c@120
|
172 if (channels < getMinChannelCount() ||
|
c@120
|
173 channels > getMaxChannelCount()) return false;
|
c@120
|
174
|
c@120
|
175 if (m_inputSampleRate < 4410 || m_inputSampleRate > 441000) return false;
|
c@120
|
176
|
c@120
|
177 m_stepSize = std::min(stepSize, blockSize);
|
c@120
|
178 m_blockSize=blockSize;
|
c@120
|
179
|
c@120
|
180 m_SampleN = 0;
|
c@120
|
181
|
c@120
|
182 return true;
|
c@120
|
183 }
|
c@120
|
184
|
c@120
|
185 void
|
c@120
|
186 Transcription::reset()
|
c@120
|
187 {
|
c@120
|
188 free(m_SoundIn);
|
c@120
|
189 m_SoundIn = 0;
|
c@120
|
190 m_SampleN = 0;
|
c@120
|
191 m_AllocN = 0;
|
c@120
|
192 m_Excess = false;
|
c@120
|
193 m_Base = Vamp::RealTime();
|
c@120
|
194 }
|
c@120
|
195
|
c@120
|
196 Transcription::OutputList
|
c@120
|
197 Transcription::getOutputDescriptors() const
|
c@120
|
198 {
|
c@120
|
199 OutputList list;
|
c@120
|
200
|
c@120
|
201 OutputDescriptor zc;
|
c@120
|
202 zc.identifier = "transcription";
|
c@120
|
203 zc.name = "Transcription";
|
c@120
|
204 zc.description = "Estimated note pitch (MIDI note number from 0 to 127)";
|
c@120
|
205 zc.unit = "MIDI units";
|
c@120
|
206 zc.hasFixedBinCount = true;
|
c@120
|
207 zc.binCount = 1;
|
c@120
|
208 zc.hasKnownExtents = true;
|
c@120
|
209 zc.minValue = 0;
|
c@120
|
210 zc.maxValue = 127;
|
c@120
|
211 zc.isQuantized = true;
|
c@120
|
212 zc.quantizeStep = 1.0;
|
c@120
|
213 zc.hasDuration = true;
|
c@120
|
214 zc.sampleType = OutputDescriptor::VariableSampleRate;
|
c@120
|
215
|
c@120
|
216 /* no -- this is the result of a confusion between bin indices and values
|
c@120
|
217 {
|
c@120
|
218
|
c@120
|
219 zc.binNames.push_back("A0");// MIDI Note 21
|
c@120
|
220 zc.binNames.push_back("A0#");
|
c@120
|
221 zc.binNames.push_back("B0");
|
c@120
|
222 zc.binNames.push_back("C1");
|
c@120
|
223 zc.binNames.push_back("C1#");
|
c@120
|
224 zc.binNames.push_back("D1");
|
c@120
|
225 zc.binNames.push_back("D1#");
|
c@120
|
226 zc.binNames.push_back("E1");
|
c@120
|
227 zc.binNames.push_back("F1");
|
c@120
|
228 zc.binNames.push_back("F1#");
|
c@120
|
229 zc.binNames.push_back("G1");
|
c@120
|
230 zc.binNames.push_back("G1#");
|
c@120
|
231
|
c@120
|
232 zc.binNames.push_back("A1");// MIDI Note 33
|
c@120
|
233 zc.binNames.push_back("A1#");
|
c@120
|
234 zc.binNames.push_back("B1");
|
c@120
|
235 zc.binNames.push_back("C2");
|
c@120
|
236 zc.binNames.push_back("C2#");
|
c@120
|
237 zc.binNames.push_back("D2");
|
c@120
|
238 zc.binNames.push_back("D2#");
|
c@120
|
239 zc.binNames.push_back("E2");
|
c@120
|
240 zc.binNames.push_back("F2");
|
c@120
|
241 zc.binNames.push_back("F2#");
|
c@120
|
242 zc.binNames.push_back("G2");
|
c@120
|
243 zc.binNames.push_back("G2#");
|
c@120
|
244
|
c@120
|
245 zc.binNames.push_back("A2");// MIDI Note 45
|
c@120
|
246 zc.binNames.push_back("A2#");
|
c@120
|
247 zc.binNames.push_back("B3");
|
c@120
|
248 zc.binNames.push_back("C3");
|
c@120
|
249 zc.binNames.push_back("C3#");
|
c@120
|
250 zc.binNames.push_back("D3");
|
c@120
|
251 zc.binNames.push_back("D3#");
|
c@120
|
252 zc.binNames.push_back("E3");
|
c@120
|
253 zc.binNames.push_back("F3");
|
c@120
|
254 zc.binNames.push_back("F3#");
|
c@120
|
255 zc.binNames.push_back("G3");
|
c@120
|
256 zc.binNames.push_back("G3#");
|
c@120
|
257
|
c@120
|
258 zc.binNames.push_back("A3");// MIDI Note 57
|
c@120
|
259 zc.binNames.push_back("A3#");
|
c@120
|
260 zc.binNames.push_back("B0");
|
c@120
|
261 zc.binNames.push_back("C4");
|
c@120
|
262 zc.binNames.push_back("C4#");
|
c@120
|
263 zc.binNames.push_back("D4");
|
c@120
|
264 zc.binNames.push_back("D4#");
|
c@120
|
265 zc.binNames.push_back("E4");
|
c@120
|
266 zc.binNames.push_back("F4");
|
c@120
|
267 zc.binNames.push_back("F4#");
|
c@120
|
268 zc.binNames.push_back("G4");
|
c@120
|
269 zc.binNames.push_back("G4#");
|
c@120
|
270
|
c@120
|
271 zc.binNames.push_back("A4");// MIDI Note 69
|
c@120
|
272 zc.binNames.push_back("A4#");
|
c@120
|
273 zc.binNames.push_back("B0");
|
c@120
|
274 zc.binNames.push_back("C5");
|
c@120
|
275 zc.binNames.push_back("C5#");
|
c@120
|
276 zc.binNames.push_back("D5");
|
c@120
|
277 zc.binNames.push_back("D5#");
|
c@120
|
278 zc.binNames.push_back("E5");
|
c@120
|
279 zc.binNames.push_back("F5");
|
c@120
|
280 zc.binNames.push_back("F5#");
|
c@120
|
281 zc.binNames.push_back("G5");
|
c@120
|
282 zc.binNames.push_back("G5#");
|
c@120
|
283
|
c@120
|
284 zc.binNames.push_back("A5");// MIDI Note 85
|
c@120
|
285 zc.binNames.push_back("A5#");
|
c@120
|
286 zc.binNames.push_back("B0");
|
c@120
|
287 zc.binNames.push_back("C6");
|
c@120
|
288 zc.binNames.push_back("C6#");
|
c@120
|
289 zc.binNames.push_back("D6");
|
c@120
|
290 zc.binNames.push_back("D6#");
|
c@120
|
291 zc.binNames.push_back("E6");
|
c@120
|
292 zc.binNames.push_back("F6");
|
c@120
|
293 zc.binNames.push_back("F6#");
|
c@120
|
294 zc.binNames.push_back("G6");
|
c@120
|
295 zc.binNames.push_back("G6#");
|
c@120
|
296
|
c@120
|
297 zc.binNames.push_back("A6");// MIDI Note 93
|
c@120
|
298 zc.binNames.push_back("A6#");
|
c@120
|
299 zc.binNames.push_back("B0");
|
c@120
|
300 zc.binNames.push_back("C7");
|
c@120
|
301 zc.binNames.push_back("C7#");
|
c@120
|
302 zc.binNames.push_back("D7");
|
c@120
|
303 zc.binNames.push_back("D7#");
|
c@120
|
304 zc.binNames.push_back("E7");
|
c@120
|
305 zc.binNames.push_back("F7");
|
c@120
|
306 zc.binNames.push_back("F7#");
|
c@120
|
307 zc.binNames.push_back("G7");
|
c@120
|
308 zc.binNames.push_back("G7#");
|
c@120
|
309
|
c@120
|
310 zc.binNames.push_back("A7");// MIDI Note 105
|
c@120
|
311 zc.binNames.push_back("A7#");
|
c@120
|
312 zc.binNames.push_back("B0");
|
c@120
|
313 zc.binNames.push_back("C8");
|
c@120
|
314 }
|
c@120
|
315 */
|
c@120
|
316
|
c@120
|
317 list.push_back(zc);
|
c@120
|
318
|
c@120
|
319 /* zc.identifier = "Transcriptions";
|
c@120
|
320 zc.name = "Polyphonic Transcription";
|
c@120
|
321 zc.description = "Polyphonic Music Transcription";
|
c@120
|
322 zc.unit = "";
|
c@120
|
323 zc.hasFixedBinCount = true;
|
c@120
|
324 zc.binCount = 0;
|
c@120
|
325 zc.sampleType = OutputDescriptor::VariableSampleRate;
|
c@120
|
326 zc.sampleRate = m_inputSampleRate;
|
c@120
|
327 list.push_back(zc);*/
|
c@120
|
328
|
c@120
|
329 return list;
|
c@120
|
330 }
|
c@120
|
331
|
c@120
|
332 Transcription::FeatureSet
|
c@120
|
333 Transcription::process(const float *const *inputBuffers,
|
c@120
|
334 Vamp::RealTime timestamp)
|
c@120
|
335 {
|
c@120
|
336 if (m_stepSize == 0) {
|
c@120
|
337 cerr << "ERROR: Transcription::process: "
|
c@120
|
338 << "Transcription has not been initialised"
|
c@120
|
339 << endl;
|
c@120
|
340 return FeatureSet();
|
c@120
|
341 }
|
c@120
|
342
|
c@120
|
343 if (m_SampleN == 0) {
|
c@120
|
344 m_Base = timestamp;
|
c@120
|
345 }
|
c@120
|
346
|
c@120
|
347 if (m_Excess) return FeatureSet();
|
c@120
|
348
|
c@120
|
349 for (size_t i = 0; i < m_blockSize;i++) {
|
c@120
|
350
|
c@120
|
351 if (m_SampleN >= m_AllocN) {
|
c@120
|
352 size_t newsize = m_AllocN * 2;
|
c@120
|
353 if (newsize < 10000) newsize = 10000;
|
c@120
|
354 double *newbuf = (double *)realloc(m_SoundIn, newsize * sizeof(double));
|
c@120
|
355 if (!newbuf) {
|
c@120
|
356 m_Excess = true;
|
c@120
|
357 break;
|
c@120
|
358 }
|
c@120
|
359 m_SoundIn = newbuf;
|
c@120
|
360 m_AllocN = newsize;
|
c@120
|
361 }
|
c@120
|
362
|
c@120
|
363 m_SoundIn[m_SampleN]=inputBuffers[0][i];
|
c@120
|
364 m_SampleN=m_SampleN+1;
|
c@120
|
365 }
|
c@120
|
366
|
c@120
|
367 return FeatureSet();
|
c@120
|
368 }
|
c@120
|
369
|
c@120
|
370 Transcription::FeatureSet
|
c@120
|
371 Transcription::getRemainingFeatures()
|
c@120
|
372 {
|
c@120
|
373 FeatureSet returnFeatures;
|
c@120
|
374
|
c@120
|
375 double * OutArray;
|
c@120
|
376 double *OutArray2;
|
c@120
|
377 double *hello1;
|
c@120
|
378 double *hello2;
|
c@120
|
379 int Msec;
|
c@120
|
380 size_t i;
|
c@120
|
381 size_t j;
|
c@120
|
382 size_t n;
|
c@120
|
383 size_t count;
|
c@120
|
384
|
c@120
|
385 Msec=(int)(100*m_SampleN/m_inputSampleRate);
|
c@120
|
386
|
c@120
|
387 if (Msec < 100) return returnFeatures;
|
c@120
|
388
|
c@120
|
389 OutArray=(double *)malloc(3*3000*sizeof(double));
|
c@120
|
390 OutArray2=(double *)malloc(88*Msec*sizeof(double));
|
c@120
|
391 hello1=(double *)malloc(112*Msec*sizeof(double));
|
c@120
|
392 hello2=(double *)malloc(112*Msec*sizeof(double));
|
c@120
|
393
|
c@120
|
394 for (j = 0; j <Msec; j++) {
|
c@120
|
395
|
c@120
|
396 for(n=0;n<88;n++)
|
c@120
|
397 {
|
c@120
|
398
|
c@120
|
399 OutArray2[j*88+n]=0;
|
c@120
|
400 }
|
c@120
|
401
|
c@120
|
402 }
|
c@120
|
403
|
c@120
|
404
|
c@120
|
405 Transcribe(Msec,m_SampleN,m_SoundIn,hello1,hello2,OutArray,m_inputSampleRate);
|
c@120
|
406 int start;
|
c@120
|
407 int endd;
|
c@120
|
408
|
c@120
|
409
|
c@120
|
410 /* for (i = 0; i < 3000; i++) {
|
c@120
|
411
|
c@120
|
412 if((OutArray[3*i]>0)&&(OutArray[3*i]<88))
|
c@120
|
413 {
|
c@120
|
414 start=OutArray[3*i+1];endd=OutArray[3*i+2];
|
c@120
|
415 for(j=start;j<(start+0.05);j=j+0.01)
|
c@120
|
416 {
|
c@120
|
417
|
c@120
|
418 Feature feature;
|
c@120
|
419 Vamp::RealTime ts;
|
c@120
|
420
|
c@120
|
421 feature.hasTimestamp = true;
|
c@120
|
422
|
c@120
|
423 feature.timestamp =ts.fromSeconds(j);
|
c@120
|
424 feature.values.push_back(OutArray[3*i]+21);
|
c@120
|
425 returnFeatures[0].push_back(feature);
|
c@120
|
426
|
c@120
|
427 }
|
c@120
|
428
|
c@120
|
429
|
c@120
|
430
|
c@120
|
431 }
|
c@120
|
432 else
|
c@120
|
433 {
|
c@120
|
434
|
c@120
|
435 break;
|
c@120
|
436 }
|
c@120
|
437
|
c@120
|
438
|
c@120
|
439 }
|
c@120
|
440
|
c@120
|
441 */
|
c@120
|
442
|
c@120
|
443
|
c@120
|
444 for (i = 0; i < 3000; i++) {
|
c@120
|
445
|
c@120
|
446 if((OutArray[3*i]>0)&&(OutArray[3*i]<88))
|
c@120
|
447 {
|
c@120
|
448 start=100*OutArray[3*i+1];
|
c@120
|
449 endd=100*OutArray[3*i+2]-5;
|
c@120
|
450 for(j=start;j<endd;j++)
|
c@120
|
451 {
|
c@120
|
452 n=OutArray[3*i];
|
c@120
|
453 OutArray2[j*88+n]=OutArray[3*i];
|
c@120
|
454 }
|
c@120
|
455
|
c@120
|
456 }
|
c@120
|
457 else
|
c@120
|
458 {
|
c@120
|
459
|
c@120
|
460 break;
|
c@120
|
461 }
|
c@120
|
462
|
c@120
|
463
|
c@120
|
464 }
|
c@120
|
465
|
c@120
|
466 double starts[88];
|
c@120
|
467 for (n = 0; n < 88; ++n) starts[n] = -1.0;
|
c@120
|
468
|
c@120
|
469 int nn;
|
c@120
|
470 for (j = 0; j <Msec; j++) {
|
c@120
|
471
|
c@120
|
472
|
c@120
|
473 for(n=0;n<88;n++)
|
c@120
|
474 {
|
c@120
|
475 if(OutArray2[j*88+n]>0)
|
c@120
|
476 {
|
c@120
|
477
|
c@120
|
478 if (starts[n] < 0.)
|
c@120
|
479 {
|
c@120
|
480 starts[n] = j * 0.01;
|
c@120
|
481 }
|
c@120
|
482 }
|
c@120
|
483 else
|
c@120
|
484 {
|
c@120
|
485 if (starts[n] > 0.)
|
c@120
|
486 {
|
c@120
|
487 Feature feature;
|
c@120
|
488 feature.hasTimestamp = true;
|
c@120
|
489 feature.timestamp = m_Base + Vamp::RealTime::fromSeconds(starts[n]);
|
c@120
|
490 feature.hasDuration = true;
|
c@120
|
491 feature.duration = Vamp::RealTime::fromSeconds(j * 0.01 - starts[n]);
|
c@120
|
492 feature.values.push_back(n+20);
|
c@120
|
493 returnFeatures[0].push_back(feature);
|
c@120
|
494
|
c@120
|
495 starts[n] = -1.0;
|
c@120
|
496 }
|
c@120
|
497 }
|
c@120
|
498 }
|
c@120
|
499 }
|
c@120
|
500
|
c@120
|
501
|
c@120
|
502 for(n=0;n<88;n++)
|
c@120
|
503 {
|
c@120
|
504 if (starts[n] > 0.)
|
c@120
|
505 {
|
c@120
|
506 Feature feature;
|
c@120
|
507 feature.hasTimestamp = true;
|
c@120
|
508 feature.timestamp = m_Base + Vamp::RealTime::fromSeconds(starts[n]);
|
c@120
|
509 feature.hasDuration = true;
|
c@120
|
510 feature.duration = Vamp::RealTime::fromSeconds(j * 0.01 - starts[n]);
|
c@120
|
511 feature.values.push_back(n+20);
|
c@120
|
512 returnFeatures[0].push_back(feature);
|
c@120
|
513
|
c@120
|
514 starts[n] = -1.0;
|
c@120
|
515 }
|
c@120
|
516 }
|
c@120
|
517
|
c@120
|
518 free(OutArray2);
|
c@120
|
519 free(OutArray);
|
c@120
|
520
|
c@120
|
521 free(hello1);
|
c@120
|
522 free(hello2);
|
c@120
|
523
|
c@120
|
524 return returnFeatures;
|
c@120
|
525
|
c@120
|
526 }
|
c@120
|
527
|
c@120
|
528
|
c@120
|
529
|
c@120
|
530
|
c@120
|
531
|
c@120
|
532 void sofacomplexMex(double *y, double *z, int ncols,double StartNote,double NoteInterval1,double NoteNum,double C,double D,double SR)
|
c@120
|
533 {
|
c@120
|
534 int mseconds,i,j,el,count,count2;
|
c@120
|
535 double Snote,NoteInterval,NoteN, BasicR;
|
c@120
|
536 double *signs;
|
c@120
|
537 double *rwork,*buffer;
|
c@120
|
538 double freq,R,gain,gainI,gainII,coefI,coefM;
|
c@120
|
539 double output,input,outputI,outputM;
|
c@120
|
540 double *x;
|
c@120
|
541 double *sum,*sum2;
|
c@120
|
542 double power;
|
c@120
|
543 double temp;
|
c@120
|
544
|
c@120
|
545
|
c@120
|
546 //SR=44100;
|
c@120
|
547 Snote=StartNote;
|
c@120
|
548 NoteInterval=NoteInterval1;
|
c@120
|
549 NoteN=NoteNum;
|
c@120
|
550
|
c@120
|
551 signs=(double*)malloc((int)NoteN*5*sizeof(double));
|
c@120
|
552
|
c@120
|
553 for (i = 0; i <NoteN; i++) {
|
c@120
|
554
|
c@120
|
555 freq=exp((log(2.0))*(Snote+i*NoteInterval-69)/12)*440;
|
c@120
|
556 R=exp(-(D+C*freq*2*3.1415926)/(SR*3.1415926));
|
c@120
|
557 gain=(1*(sqrt(1+R*R-2*R*cos(2*freq*2*3.1415926/SR)))-1*R*(sqrt(1+R*R-2*R*cos(2*freq*2*3.1415926/SR))))/sin(freq*2*3.1415926/SR);
|
c@120
|
558 gainI=-2*R*cos(freq*2*3.1415926/SR);
|
c@120
|
559 gainII =R*R ;
|
c@120
|
560 coefI=cos(freq*2*3.1415926/SR);
|
c@120
|
561 coefM=sin(freq*2*3.1415926/SR);
|
c@120
|
562
|
c@120
|
563 signs[i*5+0]=gain*gain;
|
c@120
|
564 signs[i*5+1]=gainI;
|
c@120
|
565 signs[i*5+2]=gainII;
|
c@120
|
566 signs[i*5+3]=coefI;
|
c@120
|
567 signs[i*5+4]=coefM;
|
c@120
|
568
|
c@120
|
569 }
|
c@120
|
570
|
c@120
|
571 x=(double*)malloc((int)NoteN*2*sizeof(double));
|
c@120
|
572 rwork=(double*)malloc((int)NoteN*sizeof(double));
|
c@120
|
573 sum=(double*)malloc((int)NoteN*sizeof(double));
|
c@120
|
574 sum2=(double*)malloc((int)NoteN*sizeof(double));
|
c@120
|
575 mseconds=(int)(100*ncols/SR);
|
c@120
|
576 power=0;
|
c@120
|
577 for (i=0;i<mseconds*(int)(SR/100);i++)
|
c@120
|
578 {
|
c@120
|
579 power=power+y[i]*y[i];
|
c@120
|
580 }
|
c@120
|
581 power=sqrt(power);
|
c@120
|
582 for(i=0;i<NoteN*2;i++)
|
c@120
|
583 x[i]=0;
|
c@120
|
584 for (i=0;i<NoteN;i++)
|
c@120
|
585 {
|
c@120
|
586 sum[i]=0;
|
c@120
|
587 sum2[i]=0;
|
c@120
|
588 };
|
c@120
|
589 count=0;
|
c@120
|
590 count2=0;
|
c@120
|
591 for (i=0;i<(mseconds*(int)(SR/100));i++)
|
c@120
|
592 {
|
c@120
|
593 count=count+1;
|
c@120
|
594 input=y[i];
|
c@120
|
595 for(el=0;el<NoteN;el++)
|
c@120
|
596 {
|
c@120
|
597 output=(input-signs[5*el+1]*x[2*el+0]-signs[5*el+2]*x[2*el+1]);
|
c@120
|
598 outputI=output-signs[5*el+3]*x[2*el+0];
|
c@120
|
599 outputM=signs[5*el+4]*x[2*el+0];
|
c@120
|
600 sum[el]=sum[el]+signs[5*el+0]*(outputI*outputI+ outputM*outputM);
|
c@120
|
601 rwork[el]=output;
|
c@120
|
602 x[el+el+1]=x[el+el+0];
|
c@120
|
603 x[el+el+0]=rwork[el];
|
c@120
|
604
|
c@120
|
605 }
|
c@120
|
606 if(count==(int)(SR/100))
|
c@120
|
607 {
|
c@120
|
608 for(el=0;el<NoteN;el++)
|
c@120
|
609 {
|
c@120
|
610 *(z+count2*(int)NoteN+el)=1000000*(sum[el]+sum2[el])/(2*(int)(SR/100))+0.00001;
|
c@120
|
611 sum2[el]=sum[el];
|
c@120
|
612 sum[el]=0;
|
c@120
|
613 }
|
c@120
|
614 count2=count2+1;
|
c@120
|
615 count=0;
|
c@120
|
616 }
|
c@120
|
617
|
c@120
|
618 }
|
c@120
|
619 for (i=0;i<NoteN;i++)
|
c@120
|
620 {
|
c@120
|
621 sum[i]=0;
|
c@120
|
622 sum2[i]=0;
|
c@120
|
623 };
|
c@120
|
624 for (el=0;el<NoteN;el++)
|
c@120
|
625 {
|
c@120
|
626 for (i=0;i<mseconds;i++)
|
c@120
|
627 {
|
c@120
|
628 sum[el]=sum[el]+*(z+i*(int)NoteN+el);
|
c@120
|
629 }
|
c@120
|
630
|
c@120
|
631 }
|
c@120
|
632
|
c@120
|
633 free(x);
|
c@120
|
634 free(rwork);
|
c@120
|
635 free(sum);
|
c@120
|
636 free(sum2);
|
c@120
|
637 free(signs);
|
c@120
|
638
|
c@120
|
639 }
|
c@120
|
640
|
c@120
|
641 void FindMaxN( double *InputArray, int InputLen,int MaxOrder)
|
c@120
|
642 {
|
c@120
|
643 int i,j,MaxIndex = 0;
|
c@120
|
644 double MaxValue;
|
c@120
|
645 double *In2;
|
c@120
|
646
|
c@120
|
647 In2=(double*)malloc(InputLen*sizeof(double));
|
c@120
|
648 for (i=0;i<InputLen;i++)
|
c@120
|
649 {
|
c@120
|
650 In2[i]=InputArray[i];
|
c@120
|
651 InputArray[i]=0;
|
c@120
|
652 }
|
c@120
|
653 for (i=0;i<MaxOrder;i++)
|
c@120
|
654 {
|
c@120
|
655 MaxValue=0;
|
c@120
|
656 for (j=0;j<InputLen;j++)
|
c@120
|
657 {
|
c@120
|
658 if(In2[j]>MaxValue)
|
c@120
|
659 {
|
c@120
|
660 MaxValue=In2[j];
|
c@120
|
661 MaxIndex=j;
|
c@120
|
662 }
|
c@120
|
663 }
|
c@120
|
664 InputArray[MaxIndex]=In2[MaxIndex];
|
c@120
|
665 In2[MaxIndex]=0;
|
c@120
|
666 }
|
c@120
|
667
|
c@120
|
668 free(In2);
|
c@120
|
669 }
|
c@120
|
670
|
c@120
|
671 double SumF(double *InputArray,int Start, int End)
|
c@120
|
672 {
|
c@120
|
673 double Value;
|
c@120
|
674 int i;
|
c@120
|
675 Value=0;
|
c@120
|
676 for (i=Start;i<(End+1);i++)
|
c@120
|
677 {
|
c@120
|
678 Value=Value+InputArray[i];
|
c@120
|
679 }
|
c@120
|
680
|
c@120
|
681 return Value;
|
c@120
|
682
|
c@120
|
683 }
|
c@120
|
684
|
c@120
|
685 int round10(int x)
|
c@120
|
686 {
|
c@120
|
687 int I,I2;
|
c@120
|
688 I=((int)(x/10));
|
c@120
|
689 I2=x-I*10;
|
c@120
|
690
|
c@120
|
691 if(I2>5)
|
c@120
|
692 return (I+1);
|
c@120
|
693 else
|
c@120
|
694 return I;
|
c@120
|
695
|
c@120
|
696 }
|
c@120
|
697
|
c@120
|
698
|
c@120
|
699 void ConToPitch1250(double *In, int InLen)
|
c@120
|
700 {
|
c@120
|
701 int i,j,k, nn,col;
|
c@120
|
702 double *Out;
|
c@120
|
703 const int A[12]={0, 120, 190, 240, 279, 310, 337, 360, 380, 399, 415, 430};
|
c@120
|
704 Out=(double*)malloc(InLen*sizeof(double));
|
c@120
|
705
|
c@120
|
706
|
c@120
|
707 col=InLen;
|
c@120
|
708
|
c@120
|
709 for (i=0;i<col;i++)
|
c@120
|
710 {
|
c@120
|
711 Out[i]=0;
|
c@120
|
712 }
|
c@120
|
713
|
c@120
|
714 for (i=0;i<col;i++)
|
c@120
|
715 {
|
c@120
|
716 k=0;
|
c@120
|
717 nn=5;
|
c@120
|
718 for (j=0;j<nn;j++)
|
c@120
|
719 {
|
c@120
|
720 if((i+A[j])<col)
|
c@120
|
721 {
|
c@120
|
722 k=k+1;
|
c@120
|
723 Out[i]=Out[i]+In[i+A[j]];
|
c@120
|
724 }
|
c@120
|
725
|
c@120
|
726 if((i+A[j])>(col-1))
|
c@120
|
727 {
|
c@120
|
728 k=k+1;
|
c@120
|
729 Out[i]=Out[i]+In[col-1];
|
c@120
|
730 }
|
c@120
|
731 }
|
c@120
|
732 if(k>0)
|
c@120
|
733 {
|
c@120
|
734 Out[i]=Out[i]/k;
|
c@120
|
735 }
|
c@120
|
736 }
|
c@120
|
737 for (i=0;i<col;i++)
|
c@120
|
738 {
|
c@120
|
739 In[i]=Out[i];
|
c@120
|
740 }
|
c@120
|
741
|
c@120
|
742
|
c@120
|
743 free(Out);
|
c@120
|
744 }
|
c@120
|
745
|
c@120
|
746 void Norm1(double *In, int InLen)
|
c@120
|
747 {
|
c@120
|
748 double MaxValue;
|
c@120
|
749 int i;
|
c@120
|
750 double *Out;
|
c@120
|
751 Out=(double*)malloc(InLen*sizeof(double));
|
c@120
|
752
|
c@120
|
753 MaxValue=In[0];
|
c@120
|
754 for (i=1;i<InLen;i++)
|
c@120
|
755 {
|
c@120
|
756 if(In[i]>MaxValue)
|
c@120
|
757 MaxValue=In[i];
|
c@120
|
758 }
|
c@120
|
759
|
c@120
|
760 for (i=0;i<InLen;i++)
|
c@120
|
761 {
|
c@120
|
762 Out[i]=In[i]-MaxValue;
|
c@120
|
763 }
|
c@120
|
764
|
c@120
|
765 for (i=0;i<InLen;i++)
|
c@120
|
766 {
|
c@120
|
767 In[i]=Out[i];
|
c@120
|
768 }
|
c@120
|
769
|
c@120
|
770 free(Out);
|
c@120
|
771 }
|
c@120
|
772
|
c@120
|
773 void Smooth(double *In, int InLen,int smoothLen)
|
c@120
|
774 {
|
c@120
|
775 double sum;
|
c@120
|
776 int i,j,nn,n,count;
|
c@120
|
777 double *Out;
|
c@120
|
778 Out=(double*)malloc(InLen*sizeof(double));
|
c@120
|
779 nn=InLen;
|
c@120
|
780 n=(smoothLen-1)/2;
|
c@120
|
781 for (i=0;i<nn;i++)
|
c@120
|
782 {
|
c@120
|
783 sum=0;
|
c@120
|
784 count=0;
|
c@120
|
785 for (j=0;j<(n+1);j++)
|
c@120
|
786 {
|
c@120
|
787 if ((i-j)>-1)
|
c@120
|
788 {
|
c@120
|
789 sum=sum+In[i-j];
|
c@120
|
790 count=count+1;
|
c@120
|
791 }
|
c@120
|
792 }
|
c@120
|
793
|
c@120
|
794 for (j=1;j<(n+1);j++)
|
c@120
|
795 {
|
c@120
|
796 if ((i+j)<nn)
|
c@120
|
797 {
|
c@120
|
798 sum=sum+In[i+j];
|
c@120
|
799 count=count+1;
|
c@120
|
800 }
|
c@120
|
801 }
|
c@120
|
802 Out[i]=sum/count;
|
c@120
|
803 }
|
c@120
|
804 for (i=0;i<InLen;i++)
|
c@120
|
805 In[i]=Out[i];
|
c@120
|
806
|
c@120
|
807 free(Out);
|
c@120
|
808 }
|
c@120
|
809
|
c@120
|
810
|
c@120
|
811 void FindPeaks(double *In, int InLen,double *Out1,double *Out2, int db, int db2, int db3)
|
c@120
|
812 {
|
c@120
|
813 int i,lastout;
|
c@120
|
814 for (i=0;i<InLen;i++)
|
c@120
|
815 {
|
c@120
|
816 Out1[i]=0;
|
c@120
|
817 Out2[1]=0;
|
c@120
|
818 }
|
c@120
|
819
|
c@120
|
820 for (i=20;i<(InLen-20-1);i++)
|
c@120
|
821 {
|
c@120
|
822 if( /**/ ((In[i]>(db2+In[i-6]))||(In[i]>(db2+In[i+6]))
|
c@120
|
823 ||(In[i]>(db3+In[i+20]))||(In[i]>(db3+In[i-20])))
|
c@120
|
824 /*&&(In[i]>db)*/&&(In[i]>In[i+3])&&(In[i]>In[i-3])
|
c@120
|
825 &&(In[i]>In[i+2])&&(In[i]>In[i-2])
|
c@120
|
826 &&(In[i]>In[i+1])&&(In[i]>In[i-1]))
|
c@120
|
827 {
|
c@120
|
828 Out1[i]=In[i];
|
c@120
|
829 Out2[i]=1;
|
c@120
|
830 }
|
c@120
|
831
|
c@120
|
832 }
|
c@120
|
833
|
c@120
|
834 lastout=1;
|
c@120
|
835 for(i=0;i<InLen;i++)
|
c@120
|
836 {
|
c@120
|
837
|
c@120
|
838 if(Out2[i]==1)
|
c@120
|
839 {
|
c@120
|
840 if((i-lastout)<5)
|
c@120
|
841 {
|
c@120
|
842 if(Out1[i]>Out1[lastout])
|
c@120
|
843 {
|
c@120
|
844 Out2[lastout]=0;
|
c@120
|
845 Out1[lastout]=0;
|
c@120
|
846 lastout=i;
|
c@120
|
847 }
|
c@120
|
848 else
|
c@120
|
849 {
|
c@120
|
850 Out2[i]=0;
|
c@120
|
851 Out1[i]=0;
|
c@120
|
852 }
|
c@120
|
853
|
c@120
|
854 }
|
c@120
|
855 else
|
c@120
|
856 {
|
c@120
|
857 lastout=i;
|
c@120
|
858 }
|
c@120
|
859 }
|
c@120
|
860
|
c@120
|
861 }
|
c@120
|
862
|
c@120
|
863 }
|
c@120
|
864
|
c@120
|
865
|
c@120
|
866 void ConFrom1050To960(double *In, double *out, int InputLen)
|
c@120
|
867 {
|
c@120
|
868 int i,j;
|
c@120
|
869
|
c@120
|
870 for(i=0;i<960;i++)
|
c@120
|
871 {
|
c@120
|
872 for (j=0;j<InputLen;j++)
|
c@120
|
873 {
|
c@120
|
874 out[i+j*960]=In[i+j*1050];
|
c@120
|
875
|
c@120
|
876 }
|
c@120
|
877 }
|
c@120
|
878
|
c@120
|
879
|
c@120
|
880 }
|
c@120
|
881
|
c@120
|
882 void Move( double *InputArray, int InputLen,int m)
|
c@120
|
883 {
|
c@120
|
884 int i;
|
c@120
|
885 double *OutArray;
|
c@120
|
886
|
c@120
|
887 OutArray=(double *)malloc(InputLen*sizeof(double));
|
c@120
|
888 for (i=0;i<InputLen;i++)
|
c@120
|
889 OutArray[i]=0;
|
c@120
|
890
|
c@120
|
891 for (i=0;i<InputLen;i++)
|
c@120
|
892 { if(((i+m)>-1)&&((i+m)<InputLen))
|
c@120
|
893 OutArray[i+m]=InputArray[i];
|
c@120
|
894 }
|
c@120
|
895
|
c@120
|
896 for (i=0;i<InputLen;i++)
|
c@120
|
897 {
|
c@120
|
898 InputArray[i]=OutArray[i];
|
c@120
|
899 }
|
c@120
|
900
|
c@120
|
901 free(OutArray);
|
c@120
|
902 }
|
c@120
|
903
|
c@120
|
904
|
c@120
|
905 double SumArray( double *InputArray, int InputHLen, int InputVLen)
|
c@120
|
906 {
|
c@120
|
907 int i;
|
c@120
|
908 int j;
|
c@120
|
909 double sum;
|
c@120
|
910 int count;
|
c@120
|
911 count=0;
|
c@120
|
912 sum=0;
|
c@120
|
913 for (j=0;j<InputHLen;j++)
|
c@120
|
914 {
|
c@120
|
915 for (i=0;i<InputVLen;i++)
|
c@120
|
916 {
|
c@120
|
917 count=count+1;
|
c@120
|
918 sum=sum+InputArray[i+j*InputVLen];
|
c@120
|
919
|
c@120
|
920 }
|
c@120
|
921 }
|
c@120
|
922 return sum;
|
c@120
|
923 }
|
c@120
|
924
|
c@120
|
925 double Sum( double *InputArray, int InputHLen)
|
c@120
|
926 {
|
c@120
|
927 int i;
|
c@120
|
928 double sum;
|
c@120
|
929 int count;
|
c@120
|
930 count=0;
|
c@120
|
931 sum=0;
|
c@120
|
932 for (i=0;i<InputHLen;i++)
|
c@120
|
933 {
|
c@120
|
934 count=count+1;
|
c@120
|
935 sum=sum+InputArray[i];
|
c@120
|
936
|
c@120
|
937 }
|
c@120
|
938 return sum;
|
c@120
|
939 }
|
c@120
|
940
|
c@120
|
941 void MeanV2( double *InputArray, int InputHLen, int InputVLen, double *OutArray)
|
c@120
|
942 {
|
c@120
|
943 int i;
|
c@120
|
944 int j;
|
c@120
|
945 double sum;
|
c@120
|
946 for (i=0;i<InputVLen;i++)
|
c@120
|
947 {
|
c@120
|
948 sum=0;
|
c@120
|
949 for (j=0;j<InputHLen;j++)
|
c@120
|
950 {
|
c@120
|
951
|
c@120
|
952 sum=sum+InputArray[i+j*InputVLen];
|
c@120
|
953
|
c@120
|
954 }
|
c@120
|
955 OutArray[i]=sum/InputHLen;
|
c@120
|
956 }
|
c@120
|
957
|
c@120
|
958 }
|
c@120
|
959
|
c@120
|
960 void SumV( double *InputArray, int InputHLen, int InputVLen, double *OutArray)
|
c@120
|
961 {
|
c@120
|
962 int i;
|
c@120
|
963 int j;
|
c@120
|
964 double sum;
|
c@120
|
965
|
c@120
|
966 for (j=0;j<InputHLen;j++)
|
c@120
|
967 {
|
c@120
|
968 sum=0;
|
c@120
|
969 for (i=0;i<InputVLen;i++)
|
c@120
|
970 {
|
c@120
|
971
|
c@120
|
972 sum=sum+InputArray[i+j*InputVLen];
|
c@120
|
973
|
c@120
|
974 }
|
c@120
|
975 OutArray[j]=sum;
|
c@120
|
976 }
|
c@120
|
977
|
c@120
|
978 }
|
c@120
|
979
|
c@120
|
980
|
c@120
|
981
|
c@120
|
982 void SumV2( double *InputArray, int InputHLen, int InputVLen, double *OutArray)
|
c@120
|
983 {
|
c@120
|
984 int i;
|
c@120
|
985 int j;
|
c@120
|
986 double sum;
|
c@120
|
987 for (i=0;i<InputVLen;i++)
|
c@120
|
988 {
|
c@120
|
989 sum=0;
|
c@120
|
990 for (j=0;j<InputHLen;j++)
|
c@120
|
991 {
|
c@120
|
992
|
c@120
|
993 sum=sum+InputArray[i+j*InputVLen];
|
c@120
|
994
|
c@120
|
995 }
|
c@120
|
996 OutArray[i]=sum;
|
c@120
|
997 }
|
c@120
|
998
|
c@120
|
999 }
|
c@120
|
1000
|
c@120
|
1001 void MaxV( double *InputArray, int InputHLen, int InputVLen, double *OutArray)
|
c@120
|
1002 {
|
c@120
|
1003 int i;
|
c@120
|
1004 int j;
|
c@120
|
1005 double MaxVal;
|
c@120
|
1006
|
c@120
|
1007 for (j=0;j<InputHLen;j++)
|
c@120
|
1008 {
|
c@120
|
1009 MaxVal=InputArray[j*InputVLen];
|
c@120
|
1010 for (i=0;i<InputVLen;i++)
|
c@120
|
1011 {
|
c@120
|
1012 if(InputArray[i+j*InputVLen]>MaxVal)
|
c@120
|
1013 {
|
c@120
|
1014 MaxVal=InputArray[i+j*InputVLen];
|
c@120
|
1015 }
|
c@120
|
1016
|
c@120
|
1017 }
|
c@120
|
1018 OutArray[j]=MaxVal;
|
c@120
|
1019 }
|
c@120
|
1020
|
c@120
|
1021 }
|
c@120
|
1022
|
c@120
|
1023 void MaxV2( double *InputArray, int InputHLen, int InputVLen, double *OutArray)
|
c@120
|
1024 {
|
c@120
|
1025 int i;
|
c@120
|
1026 int j;
|
c@120
|
1027 double MaxVal;
|
c@120
|
1028 for (i=0;i<InputVLen;i++)
|
c@120
|
1029 {
|
c@120
|
1030 MaxVal=InputArray[i];
|
c@120
|
1031 for (j=0;j<InputHLen;j++)
|
c@120
|
1032 {
|
c@120
|
1033 if(InputArray[i+j*InputVLen]>MaxVal)
|
c@120
|
1034 {
|
c@120
|
1035 MaxVal=InputArray[i+j*InputVLen];
|
c@120
|
1036 }
|
c@120
|
1037
|
c@120
|
1038 }
|
c@120
|
1039 OutArray[i]=MaxVal;
|
c@120
|
1040 }
|
c@120
|
1041
|
c@120
|
1042 }
|
c@120
|
1043
|
c@120
|
1044
|
c@120
|
1045
|
c@120
|
1046 void MinArray( double *InputArray, int InputHLen, int InputVLen, double MinValue)
|
c@120
|
1047 {
|
c@120
|
1048 int i;
|
c@120
|
1049 int j;
|
c@120
|
1050
|
c@120
|
1051 for (i=0;i<InputVLen;i++)
|
c@120
|
1052 {
|
c@120
|
1053 for (j=0;j<InputHLen;j++)
|
c@120
|
1054 {
|
c@120
|
1055 if(InputArray[i+j*InputVLen]<MinValue)
|
c@120
|
1056 InputArray[i+j*InputVLen]=MinValue;
|
c@120
|
1057
|
c@120
|
1058 }
|
c@120
|
1059
|
c@120
|
1060 }
|
c@120
|
1061
|
c@120
|
1062 }
|
c@120
|
1063
|
c@120
|
1064
|
c@120
|
1065 void MaxArray( double *InputArray, int InputHLen, int InputVLen, double MaxValue)
|
c@120
|
1066 {
|
c@120
|
1067 int i;
|
c@120
|
1068 int j;
|
c@120
|
1069
|
c@120
|
1070 for (i=0;i<InputVLen;i++)
|
c@120
|
1071 {
|
c@120
|
1072 for (j=0;j<InputHLen;j++)
|
c@120
|
1073 {
|
c@120
|
1074 if(InputArray[i+j*InputVLen]>MaxValue)
|
c@120
|
1075 InputArray[i+j*InputVLen]=MaxValue;
|
c@120
|
1076
|
c@120
|
1077 }
|
c@120
|
1078
|
c@120
|
1079 }
|
c@120
|
1080
|
c@120
|
1081 }
|
c@120
|
1082
|
c@120
|
1083 double GetMaxValue( double *InputArray, int InputHLen, int InputVLen)
|
c@120
|
1084 {
|
c@120
|
1085 int i;
|
c@120
|
1086 int j;
|
c@120
|
1087
|
c@120
|
1088 double MaxValue;
|
c@120
|
1089 MaxValue=InputArray[0];
|
c@120
|
1090 for (i=0;i<InputVLen;i++)
|
c@120
|
1091 {
|
c@120
|
1092 for (j=0;j<InputHLen;j++)
|
c@120
|
1093 {
|
c@120
|
1094 if(InputArray[i*InputHLen+j]>MaxValue)
|
c@120
|
1095 MaxValue=InputArray[i*InputHLen+j];
|
c@120
|
1096
|
c@120
|
1097 }
|
c@120
|
1098
|
c@120
|
1099 }
|
c@120
|
1100
|
c@120
|
1101 return MaxValue;
|
c@120
|
1102 }
|
c@120
|
1103
|
c@120
|
1104 void RemoveNoise( double *InputArray, int InputHLen, int InputVLen)
|
c@120
|
1105 {
|
c@120
|
1106 int i;
|
c@120
|
1107 int j;
|
c@120
|
1108
|
c@120
|
1109 for (i=0;i<InputVLen;i++)
|
c@120
|
1110 {
|
c@120
|
1111 for (j=0;j<InputHLen;j++)
|
c@120
|
1112 {
|
c@120
|
1113
|
c@120
|
1114 InputArray[i+j*InputVLen]=InputArray[i+j*InputVLen]-EualCurve960[i];
|
c@120
|
1115
|
c@120
|
1116 }
|
c@120
|
1117
|
c@120
|
1118 }
|
c@120
|
1119
|
c@120
|
1120 }
|
c@120
|
1121 double MeanArray( double *InputArray, int InputHLen, int InputVLen)
|
c@120
|
1122 {
|
c@120
|
1123 int i;
|
c@120
|
1124 int j;
|
c@120
|
1125 double sum;
|
c@120
|
1126 int count;
|
c@120
|
1127 count=0;
|
c@120
|
1128 sum=0;
|
c@120
|
1129 for (j=0;j<InputHLen;j++)
|
c@120
|
1130 {
|
c@120
|
1131 for (i=0;i<InputVLen;i++)
|
c@120
|
1132 {
|
c@120
|
1133 count=count+1;
|
c@120
|
1134 sum=sum+InputArray[i+j*InputVLen];
|
c@120
|
1135
|
c@120
|
1136 }
|
c@120
|
1137 }
|
c@120
|
1138 return sum/count;
|
c@120
|
1139 }
|
c@120
|
1140 void Mydiff( double *InputArray, int InputHLen, int InputVLen,int n)
|
c@120
|
1141 {
|
c@120
|
1142 int i;
|
c@120
|
1143 int j;
|
c@120
|
1144 double * OutArray;
|
c@120
|
1145
|
c@120
|
1146 OutArray=(double*)malloc(InputHLen*InputVLen*sizeof(double));
|
c@120
|
1147
|
c@120
|
1148 for (i=0;i<InputVLen;i++)
|
c@120
|
1149 {
|
c@120
|
1150 for (j=n;j<InputHLen;j++)
|
c@120
|
1151 {
|
c@120
|
1152 OutArray[i+j*InputVLen]=InputArray[i+j*InputVLen]-InputArray[i+(j-n)*InputVLen];
|
c@120
|
1153
|
c@120
|
1154 }
|
c@120
|
1155 }
|
c@120
|
1156
|
c@120
|
1157 for (i=0;i<InputVLen;i++)
|
c@120
|
1158 {
|
c@120
|
1159 for (j=n;j<InputHLen;j++)
|
c@120
|
1160 {
|
c@120
|
1161 InputArray[i+j*InputVLen]=OutArray[i+j*InputVLen];
|
c@120
|
1162
|
c@120
|
1163 }
|
c@120
|
1164 }
|
c@120
|
1165
|
c@120
|
1166 for (i=0;i<InputVLen;i++)
|
c@120
|
1167 {
|
c@120
|
1168 for (j=0;j<n;j++)
|
c@120
|
1169 {
|
c@120
|
1170 InputArray[i+j*InputVLen]=0;
|
c@120
|
1171
|
c@120
|
1172 }
|
c@120
|
1173 }
|
c@120
|
1174
|
c@120
|
1175 free(OutArray);
|
c@120
|
1176 }
|
c@120
|
1177
|
c@120
|
1178 void PeakDetect(double *In, int InLen)
|
c@120
|
1179 {
|
c@120
|
1180 int i,j;
|
c@120
|
1181 double *Out1;
|
c@120
|
1182
|
c@120
|
1183 Out1=(double*)malloc(InLen*sizeof(double));
|
c@120
|
1184 for (i=0;i<InLen;i++)
|
c@120
|
1185 {
|
c@120
|
1186 Out1[i]=0;
|
c@120
|
1187 }
|
c@120
|
1188
|
c@120
|
1189
|
c@120
|
1190
|
c@120
|
1191 for (i=2;i<(InLen-3);i++)
|
c@120
|
1192 {
|
c@120
|
1193 if( (In[i]>In[i+2])&&(In[i]>In[i-2])
|
c@120
|
1194 &&(In[i]>In[i+1])&&(In[i]>In[i-1]))
|
c@120
|
1195 {
|
c@120
|
1196 Out1[i]=In[i];
|
c@120
|
1197 }
|
c@120
|
1198
|
c@120
|
1199 }
|
c@120
|
1200
|
c@120
|
1201 for(i=0;i<InLen;i++)
|
c@120
|
1202 {
|
c@120
|
1203
|
c@120
|
1204 In[i]=Out1[i];
|
c@120
|
1205 }
|
c@120
|
1206
|
c@120
|
1207 free(Out1);
|
c@120
|
1208 }
|
c@120
|
1209 void MeanV( double *InputArray, int InputHLen, int InputVLen, double *OutArray)
|
c@120
|
1210 {
|
c@120
|
1211 int i;
|
c@120
|
1212 int j;
|
c@120
|
1213 double sum;
|
c@120
|
1214
|
c@120
|
1215 for (j=0;j<InputHLen;j++)
|
c@120
|
1216 {
|
c@120
|
1217 sum=0;
|
c@120
|
1218 for (i=0;i<InputVLen;i++)
|
c@120
|
1219 {
|
c@120
|
1220
|
c@120
|
1221 sum=sum+InputArray[i+j*InputVLen];
|
c@120
|
1222
|
c@120
|
1223 }
|
c@120
|
1224 OutArray[j]=sum/InputVLen;
|
c@120
|
1225 }
|
c@120
|
1226
|
c@120
|
1227 }
|
c@120
|
1228 void Edetect(double *InputArray, int InputHLen, int InputVLen, double MinT, double db1,double *OutOne)
|
c@120
|
1229 {
|
c@120
|
1230 int i;
|
c@120
|
1231 int j;
|
c@120
|
1232 double MaxValue;
|
c@120
|
1233
|
c@120
|
1234 // printf(" Starting Energy Onset Detection.. %f\n",db1);
|
c@120
|
1235 RemoveNoise(InputArray, InputHLen, InputVLen);
|
c@120
|
1236
|
c@120
|
1237
|
c@120
|
1238 MaxValue=GetMaxValue(InputArray,InputHLen,InputVLen);
|
c@120
|
1239
|
c@120
|
1240 for (i=0;i<InputVLen;i++)
|
c@120
|
1241 {
|
c@120
|
1242 for (j=0;j<InputHLen;j++)
|
c@120
|
1243 {
|
c@120
|
1244 InputArray[i*InputHLen+j]=InputArray[i*InputHLen+j]-MaxValue;
|
c@120
|
1245
|
c@120
|
1246 }
|
c@120
|
1247
|
c@120
|
1248 }
|
c@120
|
1249
|
c@120
|
1250 MinArray(InputArray, InputHLen, InputVLen, -100);
|
c@120
|
1251 Mydiff(InputArray, InputHLen, InputVLen,3);
|
c@120
|
1252 MinArray(InputArray, InputHLen, InputVLen, MinT);
|
c@120
|
1253
|
c@120
|
1254 for (i=0;i<InputVLen;i++)
|
c@120
|
1255 {
|
c@120
|
1256 for (j=0;j<InputHLen;j++)
|
c@120
|
1257 {
|
c@120
|
1258 InputArray[i*InputHLen+j]=InputArray[i*InputHLen+j]-MinT;
|
c@120
|
1259
|
c@120
|
1260 }
|
c@120
|
1261
|
c@120
|
1262 }
|
c@120
|
1263
|
c@120
|
1264 MeanV(InputArray,InputHLen,InputVLen,OutOne);
|
c@120
|
1265 Smooth(OutOne, InputHLen,3);
|
c@120
|
1266 Smooth(OutOne, InputHLen,3);
|
c@120
|
1267 Move(OutOne,InputHLen,-2);
|
c@120
|
1268 PeakDetect(OutOne,InputHLen);
|
c@120
|
1269 MinArray(OutOne, InputHLen,1, db1);
|
c@120
|
1270
|
c@120
|
1271 for (j=0;j<InputHLen;j++)
|
c@120
|
1272 {
|
c@120
|
1273 OutOne[j]=OutOne[j]-db1;
|
c@120
|
1274
|
c@120
|
1275 }
|
c@120
|
1276 }
|
c@120
|
1277
|
c@120
|
1278
|
c@120
|
1279
|
c@120
|
1280 void OnsetDetection2(double *In,int InputLen,double *OutOne,double a,double b)
|
c@120
|
1281 {
|
c@120
|
1282 int mseconds;
|
c@120
|
1283 double *Input;
|
c@120
|
1284
|
c@120
|
1285
|
c@120
|
1286 mseconds=InputLen;
|
c@120
|
1287
|
c@120
|
1288 Input=(double *)malloc(mseconds*960*sizeof(double));
|
c@120
|
1289
|
c@120
|
1290 ConFrom1050To960(In,Input,InputLen);
|
c@120
|
1291
|
c@120
|
1292
|
c@120
|
1293
|
c@120
|
1294
|
c@120
|
1295 if(a>0)
|
c@120
|
1296 {
|
c@120
|
1297 Edetect(Input,mseconds,960, a,b,OutOne);
|
c@120
|
1298 }
|
c@120
|
1299
|
c@120
|
1300
|
c@120
|
1301 free(Input);
|
c@120
|
1302
|
c@120
|
1303 }
|
c@120
|
1304
|
c@120
|
1305 void PitchEstimation(double *In, int InLen, double *OutArray,double *OutArray2)
|
c@120
|
1306 {
|
c@120
|
1307 double *xx,*x,*y,*y1,*PeakPitch1, *PeakPitch2,*PeakInput1, *PeakInput2;
|
c@120
|
1308 double *out,*outValue;
|
c@120
|
1309 double *output,*output1;
|
c@120
|
1310 double notefloat,hh0,hh1,hh28;
|
c@120
|
1311 double outM12[12];
|
c@120
|
1312 int *outc;
|
c@120
|
1313 int *yI;
|
c@120
|
1314 double temp;
|
c@120
|
1315 int i,j,sumI;
|
c@120
|
1316 int Len;
|
c@120
|
1317 int NN,NN2;
|
c@120
|
1318 int count;
|
c@120
|
1319 double Th;
|
c@120
|
1320
|
c@120
|
1321 Len=1050;
|
c@120
|
1322 xx=(double*)malloc(Len*sizeof(double));
|
c@120
|
1323 x=(double*)malloc(Len*sizeof(double));
|
c@120
|
1324 y=(double*)malloc(Len*sizeof(double));
|
c@120
|
1325 y1=(double*)malloc(Len*sizeof(double));
|
c@120
|
1326 PeakPitch1=(double*)malloc(Len*sizeof(double));
|
c@120
|
1327 PeakPitch2=(double*)malloc(Len*sizeof(double));
|
c@120
|
1328 PeakInput1=(double*)malloc(Len*sizeof(double));
|
c@120
|
1329 PeakInput2=(double*)malloc(Len*sizeof(double));
|
c@120
|
1330 out=(double*)malloc(Len*sizeof(double));
|
c@120
|
1331 outValue=(double*)malloc(Len*sizeof(double));
|
c@120
|
1332 output=(double*)malloc(112*sizeof(double));
|
c@120
|
1333 output1=(double*)malloc(112*sizeof(double));
|
c@120
|
1334 outc=(int*)malloc(112*sizeof(int));
|
c@120
|
1335 // yI=(double*)malloc(12*sizeof(double));
|
c@120
|
1336
|
c@120
|
1337
|
c@120
|
1338 for (i=0;i<Len;i++)
|
c@120
|
1339 {
|
c@120
|
1340 x[i]=In[i];
|
c@120
|
1341 }
|
c@120
|
1342
|
c@120
|
1343 for (i=0;i<Len;i++)
|
c@120
|
1344 {
|
c@120
|
1345 y1[i]=x[i];
|
c@120
|
1346 }
|
c@120
|
1347
|
c@120
|
1348 ConToPitch1250(y1,Len);
|
c@120
|
1349
|
c@120
|
1350 for (i=0;i<Len;i++)
|
c@120
|
1351 {
|
c@120
|
1352 y[i]=y1[i];
|
c@120
|
1353 }
|
c@120
|
1354
|
c@120
|
1355 Smooth(y,Len,30);
|
c@120
|
1356
|
c@120
|
1357 for (i=0;i<Len;i++)
|
c@120
|
1358 {
|
c@120
|
1359 y1[i]=y1[i]-y[i];
|
c@120
|
1360 }
|
c@120
|
1361
|
c@120
|
1362 for (i=0;i<Len;i++)
|
c@120
|
1363 {
|
c@120
|
1364 y1[i]=y1[i]+20;
|
c@120
|
1365 }
|
c@120
|
1366
|
c@120
|
1367 temp=0;
|
c@120
|
1368 for (i=0;i<Len;i++)
|
c@120
|
1369 {
|
c@120
|
1370 temp=temp+x[i];
|
c@120
|
1371 }
|
c@120
|
1372 temp=temp/Len;
|
c@120
|
1373 for (i=0;i<Len;i++)
|
c@120
|
1374 {
|
c@120
|
1375 y[i]=x[i]-temp;
|
c@120
|
1376 }
|
c@120
|
1377
|
c@120
|
1378
|
c@120
|
1379 for (i=0;i<Len;i++)
|
c@120
|
1380 {
|
c@120
|
1381 PeakPitch2[i]=0;
|
c@120
|
1382 PeakPitch1[i]=0;
|
c@120
|
1383 PeakInput1[i]=0;
|
c@120
|
1384 PeakInput2[i]=0;
|
c@120
|
1385 }
|
c@120
|
1386 FindPeaks(y1, Len,PeakPitch1,PeakPitch2, 0, -1000, -1000);
|
c@120
|
1387 FindPeaks(y, Len,PeakInput1,PeakInput2, 0, 6, 15);
|
c@120
|
1388
|
c@120
|
1389
|
c@120
|
1390
|
c@120
|
1391 sumI=0;
|
c@120
|
1392 for (i=0;i<Len;i++)
|
c@120
|
1393 {
|
c@120
|
1394 sumI=sumI+PeakPitch2[i];
|
c@120
|
1395 }
|
c@120
|
1396
|
c@120
|
1397
|
c@120
|
1398 if (sumI>12)
|
c@120
|
1399 {
|
c@120
|
1400 FindMaxN(PeakPitch1,Len,12);
|
c@120
|
1401
|
c@120
|
1402 for (i=0;i<Len;i++)
|
c@120
|
1403 {
|
c@120
|
1404 if(PeakPitch1[i]==0)
|
c@120
|
1405 {
|
c@120
|
1406 PeakPitch2[i]=0;
|
c@120
|
1407 }
|
c@120
|
1408 }
|
c@120
|
1409
|
c@120
|
1410 }
|
c@120
|
1411
|
c@120
|
1412 for (i=0;i<Len;i++)
|
c@120
|
1413 {
|
c@120
|
1414 out[i]=0;
|
c@120
|
1415 outValue[i]=0;
|
c@120
|
1416 }
|
c@120
|
1417
|
c@120
|
1418 for (i=0;i<(Len-300);i++)
|
c@120
|
1419 {
|
c@120
|
1420 if(PeakPitch2[i]==1)
|
c@120
|
1421
|
c@120
|
1422 {
|
c@120
|
1423 if (
|
c@120
|
1424 ((SumF(PeakInput2,i-4,i+4)>0)&&(SumF(PeakInput2,i+120-4,i+120+4)>0))
|
c@120
|
1425 ||((SumF(PeakInput2,i-4,i+4)>0)&&(SumF(PeakInput2,i+190-4,i+190+4)>0))
|
c@120
|
1426 ||((SumF(PeakInput2,i+190-4,i+190+4)>0)&&(SumF(PeakInput2,i+120-4,i+120+4)>0))
|
c@120
|
1427 )
|
c@120
|
1428 {
|
c@120
|
1429 out[i]=1;
|
c@120
|
1430 outValue[i]=y1[i];
|
c@120
|
1431
|
c@120
|
1432 }
|
c@120
|
1433 }
|
c@120
|
1434 }
|
c@120
|
1435
|
c@120
|
1436 for (i=0;i<112;i++)
|
c@120
|
1437 {
|
c@120
|
1438 output[i]=0;
|
c@120
|
1439 outc[i]=0;
|
c@120
|
1440 }
|
c@120
|
1441
|
c@120
|
1442
|
c@120
|
1443
|
c@120
|
1444 for (i=0;i<Len;i++)
|
c@120
|
1445 {
|
c@120
|
1446 if(out[i]==1)
|
c@120
|
1447 {
|
c@120
|
1448 output[20+round10(i+1)-1]=1;
|
c@120
|
1449 outc[20+round10(i+1)-1]=i;
|
c@120
|
1450 }
|
c@120
|
1451 }
|
c@120
|
1452
|
c@120
|
1453
|
c@120
|
1454 for (i=0;i<112;i++)
|
c@120
|
1455 {
|
c@120
|
1456 output1[i]=output[i];
|
c@120
|
1457 }
|
c@120
|
1458
|
c@120
|
1459
|
c@120
|
1460
|
c@120
|
1461 for (i=20;i<(112-28);i++)
|
c@120
|
1462 {
|
c@120
|
1463 if((output[i]>0)&&(SumF(PeakInput2,outc[i]-5,outc[i]+5)==0))
|
c@120
|
1464 {
|
c@120
|
1465 output1[i]=0;
|
c@120
|
1466 }
|
c@120
|
1467 }
|
c@120
|
1468
|
c@120
|
1469
|
c@120
|
1470 for (i=0;i<112;i++)
|
c@120
|
1471 {
|
c@120
|
1472 OutArray[i]=0;
|
c@120
|
1473 OutArray2[i]=0;
|
c@120
|
1474
|
c@120
|
1475 }
|
c@120
|
1476
|
c@120
|
1477 Th=30;
|
c@120
|
1478 for(i=20;i<105;i++)
|
c@120
|
1479 {
|
c@120
|
1480 if(output1[i]==1)
|
c@120
|
1481 {
|
c@120
|
1482 OutArray[i]=outc[i]+200+2;
|
c@120
|
1483 OutArray2[i]=y[outc[i]];
|
c@120
|
1484
|
c@120
|
1485 }
|
c@120
|
1486
|
c@120
|
1487 }
|
c@120
|
1488
|
c@120
|
1489 free(xx); // xx=(double*)malloc(Len*sizeof(double));
|
c@120
|
1490 free(x); // x=(double*)malloc(Len*sizeof(double));
|
c@120
|
1491 free(y); // y=(double*)malloc(Len*sizeof(double));
|
c@120
|
1492 free(y1); // y1=(double*)malloc(Len*sizeof(double));
|
c@120
|
1493 free(PeakPitch1); //=(double*)malloc(Len*sizeof(double));
|
c@120
|
1494 free(PeakPitch2); //=(double*)malloc(Len*sizeof(double));
|
c@120
|
1495 free(PeakInput1); //=(double*)malloc(Len*sizeof(double));
|
c@120
|
1496 free(PeakInput2); //=(double*)malloc(Len*sizeof(double));
|
c@120
|
1497 free(out); //=(double*)malloc(Len*sizeof(double));
|
c@120
|
1498 free(outValue); //=(double*)malloc(Len*sizeof(double));
|
c@120
|
1499 free(output); //=(double*)malloc(112*sizeof(double));
|
c@120
|
1500 free(output1); //=(double*)malloc(112*sizeof(double));
|
c@120
|
1501 free(outc); //=(double*)malloc(112*sizeof(int));
|
c@120
|
1502 //free(yI); //=(double*)malloc(12*sizeof(int));
|
c@120
|
1503 // printf(" end free \n");
|
c@120
|
1504 }
|
c@120
|
1505
|
c@120
|
1506 void DoMultiPitch(double *In, int RLen,int CLen, double *Out1, double *Out2)
|
c@120
|
1507 {
|
c@120
|
1508
|
c@120
|
1509 int i, j;
|
c@120
|
1510 double *sum1,*mean1;
|
c@120
|
1511 double MaxV;
|
c@120
|
1512 double *OutArray1, *OutArray2,*tempArray;
|
c@120
|
1513
|
c@120
|
1514 OutArray1=(double *)malloc(112*sizeof(double));
|
c@120
|
1515 OutArray2=(double *)malloc(112*sizeof(double));
|
c@120
|
1516 tempArray=(double *)malloc(RLen*sizeof(double));
|
c@120
|
1517
|
c@120
|
1518 sum1=(double*)malloc(CLen*sizeof(double));
|
c@120
|
1519 mean1=(double*)malloc(CLen*sizeof(double));
|
c@120
|
1520
|
c@120
|
1521 for (j=0;j<CLen;j++)
|
c@120
|
1522 {
|
c@120
|
1523 sum1[j]=0;
|
c@120
|
1524 for (i=0;i<RLen;i++)
|
c@120
|
1525 {
|
c@120
|
1526 sum1[j]=sum1[j]+In[j*RLen+i];
|
c@120
|
1527 }
|
c@120
|
1528
|
c@120
|
1529 mean1[j]=sum1[j]/CLen;
|
c@120
|
1530 }
|
c@120
|
1531 MaxV=mean1[0];
|
c@120
|
1532 for (j=0;j<CLen;j++)
|
c@120
|
1533 {
|
c@120
|
1534 if(mean1[j]>MaxV)
|
c@120
|
1535 {
|
c@120
|
1536 MaxV=mean1[j];
|
c@120
|
1537 }
|
c@120
|
1538 }
|
c@120
|
1539
|
c@120
|
1540 for (j=0;j<CLen;j++)
|
c@120
|
1541 {
|
c@120
|
1542 mean1[j]=mean1[j]-MaxV;
|
c@120
|
1543 }
|
c@120
|
1544
|
c@120
|
1545
|
c@120
|
1546 for (j=0;j<CLen;j++)
|
c@120
|
1547 {
|
c@120
|
1548
|
c@120
|
1549 for (i=0;i<112;i++)
|
c@120
|
1550 {
|
c@120
|
1551
|
c@120
|
1552 OutArray1[i]=0;
|
c@120
|
1553 OutArray2[i]=0;;
|
c@120
|
1554
|
c@120
|
1555 }
|
c@120
|
1556 MaxV=In[j*RLen];
|
c@120
|
1557 for(i=0;i<RLen;i++)
|
c@120
|
1558 {
|
c@120
|
1559 tempArray[i]=In[j*RLen+i];
|
c@120
|
1560 if(tempArray[i]>MaxV)
|
c@120
|
1561 MaxV=tempArray[i];
|
c@120
|
1562 }
|
c@120
|
1563
|
c@120
|
1564 if(mean1[j]>-55)
|
c@120
|
1565 {
|
c@120
|
1566
|
c@120
|
1567 PitchEstimation(tempArray,RLen,OutArray1,OutArray2);
|
c@120
|
1568
|
c@120
|
1569 for(i=0;i<112;i++)
|
c@120
|
1570 {
|
c@120
|
1571 if(OutArray1[i]>0)
|
c@120
|
1572 {
|
c@120
|
1573 if((MaxV-tempArray[(int)OutArray1[i]-201-1])>40)
|
c@120
|
1574 {
|
c@120
|
1575 OutArray1[i]=0;
|
c@120
|
1576 OutArray2[i]=0;
|
c@120
|
1577 }
|
c@120
|
1578
|
c@120
|
1579 }
|
c@120
|
1580 }
|
c@120
|
1581
|
c@120
|
1582 }
|
c@120
|
1583
|
c@120
|
1584 for (i=0;i<112;i++)
|
c@120
|
1585 {
|
c@120
|
1586
|
c@120
|
1587 Out1[j*112+i]=OutArray1[i];
|
c@120
|
1588 Out2[j*112+i]=OutArray2[i];
|
c@120
|
1589
|
c@120
|
1590 }
|
c@120
|
1591
|
c@120
|
1592 }
|
c@120
|
1593
|
c@120
|
1594 free(OutArray1);
|
c@120
|
1595 free(OutArray2);
|
c@120
|
1596 free(tempArray);
|
c@120
|
1597 free(sum1);
|
c@120
|
1598 free(mean1);
|
c@120
|
1599 }
|
c@120
|
1600
|
c@120
|
1601
|
c@120
|
1602 int OnsetToArray(double *In, int Len, double *OutStart,double *OutEnd)
|
c@120
|
1603 {
|
c@120
|
1604 int count,i;
|
c@120
|
1605
|
c@120
|
1606 count=0;
|
c@120
|
1607
|
c@120
|
1608 for (i=0;i<Len;i++)
|
c@120
|
1609 {
|
c@120
|
1610 if(In[i]>0)
|
c@120
|
1611 {
|
c@120
|
1612 OutStart[count]=i+1;
|
c@120
|
1613 if(count>0)
|
c@120
|
1614 {
|
c@120
|
1615 OutEnd[count-1]=i+1;
|
c@120
|
1616 }
|
c@120
|
1617 count=count+1;
|
c@120
|
1618 }
|
c@120
|
1619 }
|
c@120
|
1620 if (count>0)
|
c@120
|
1621 {
|
c@120
|
1622 OutEnd[count-1]=Len;
|
c@120
|
1623 }
|
c@120
|
1624 return count;
|
c@120
|
1625
|
c@120
|
1626 }
|
c@120
|
1627 void dbfunction( double *InputArray, int InputHLen, int InputVLen,double *OutArray)
|
c@120
|
1628 {
|
c@120
|
1629 int i;
|
c@120
|
1630 int j;
|
c@120
|
1631 double temp;
|
c@120
|
1632
|
c@120
|
1633 for (i=0;i<InputVLen;i++)
|
c@120
|
1634 {
|
c@120
|
1635 for (j=0;j<InputHLen;j++)
|
c@120
|
1636 {
|
c@120
|
1637 OutArray[i*InputHLen+j]=20*log10(InputArray[i*InputHLen+j]);
|
c@120
|
1638
|
c@120
|
1639 }
|
c@120
|
1640
|
c@120
|
1641 }
|
c@120
|
1642 }
|
c@120
|
1643
|
c@120
|
1644 void Transcribe(int Len,int inputLen,double *SoundIn,double *out,double *outArray2,double *outArray3,double SampleRate)
|
c@120
|
1645 {
|
c@120
|
1646 int OnsetN;
|
c@120
|
1647 int i,j,k;
|
c@120
|
1648 int count;
|
c@120
|
1649 int index;
|
c@120
|
1650 double *OutStart,*OutEnd;
|
c@120
|
1651 int start,endd,startb=1,start2,endd2;
|
c@120
|
1652 double *A1,*A2,*A3,*A4,*A5,*A6,*D,*D2;
|
c@120
|
1653 double *A6A;
|
c@120
|
1654 double *out2, *PitchOut1,*PitchOut2,*PitchOut3;
|
c@120
|
1655 double sum,maxV,maxVal;
|
c@120
|
1656 double *tempArray;
|
c@120
|
1657 double temp;
|
c@120
|
1658 double p;
|
c@120
|
1659 double M1,M2;
|
c@120
|
1660 double *In;
|
c@120
|
1661 int Len2;
|
c@120
|
1662 double *dbs,*ss,*dbs1,*jj;
|
c@120
|
1663 int TempInt;
|
c@120
|
1664
|
c@120
|
1665
|
c@120
|
1666 A1=(double *)malloc(112*sizeof(double));
|
c@120
|
1667 A2=(double *)malloc(112*sizeof(double));
|
c@120
|
1668 A3=(double *)malloc(112*sizeof(double));
|
c@120
|
1669 A4=(double *)malloc(112*sizeof(double));
|
c@120
|
1670 A5=(double *)malloc(112*sizeof(double));
|
c@120
|
1671 A6=(double *)malloc(112*sizeof(double));
|
c@120
|
1672 D=(double *)malloc(112*sizeof(double));
|
c@120
|
1673 D2=(double *)malloc(112*sizeof(double));
|
c@120
|
1674 PitchOut1=(double *)malloc(112*Len*sizeof(double));
|
c@120
|
1675 PitchOut2=(double *)malloc(112*Len*sizeof(double));
|
c@120
|
1676 PitchOut3=(double *)malloc(112*Len*sizeof(double));
|
c@120
|
1677 OutStart=(double *)malloc(Len*sizeof(double));
|
c@120
|
1678 OutEnd=(double *)malloc(Len*sizeof(double));
|
c@120
|
1679 tempArray=(double *)malloc(sizeof(double)*Len);
|
c@120
|
1680 In=(double *)malloc(sizeof(double)*Len);
|
c@120
|
1681 dbs=(double *)malloc(1050*sizeof(double)*Len);
|
c@120
|
1682 dbs1=(double *)malloc(210*sizeof(double)*Len);
|
c@120
|
1683 ss=(double *)malloc(210*sizeof(double)*Len);
|
c@120
|
1684 jj=(double *)malloc(1050*sizeof(double));
|
c@120
|
1685
|
c@120
|
1686
|
c@120
|
1687
|
c@120
|
1688
|
c@120
|
1689 for(k=0;k<1050;k++)
|
c@120
|
1690 {
|
c@120
|
1691
|
c@120
|
1692 jj[k]=k/5.0;
|
c@120
|
1693
|
c@120
|
1694 }
|
c@120
|
1695
|
c@120
|
1696 sofacomplexMex(SoundIn,ss,inputLen,20,0.5,210,0.03,20,SampleRate);
|
c@120
|
1697 dbfunction(ss, Len, 210,dbs1);
|
c@120
|
1698
|
c@120
|
1699 for(i=0;i<Len;i++)
|
c@120
|
1700 {
|
c@120
|
1701 for(k=0;k<1045;k++)
|
c@120
|
1702 {
|
c@120
|
1703 TempInt=(int)jj[k];
|
c@120
|
1704 dbs[k+i*1050]=(jj[k]-TempInt)*dbs1[TempInt+1+i*210]+(TempInt+1-jj[k])*dbs1[TempInt+i*210];
|
c@120
|
1705
|
c@120
|
1706 }
|
c@120
|
1707
|
c@120
|
1708 for (k=1045;k<1050;k++)
|
c@120
|
1709 {
|
c@120
|
1710 dbs[k+i*1050]=dbs[1044+i*1050];
|
c@120
|
1711 }
|
c@120
|
1712
|
c@120
|
1713 }
|
c@120
|
1714
|
c@120
|
1715 OnsetDetection2(dbs,Len,In,3,1.2);
|
c@120
|
1716 for (i=0;i<Len;i++)
|
c@120
|
1717 {
|
c@120
|
1718 outArray2[i]=In[i];
|
c@120
|
1719
|
c@120
|
1720 }
|
c@120
|
1721
|
c@120
|
1722 OnsetN=0;
|
c@120
|
1723 count=0;
|
c@120
|
1724 for (i=0;i<Len;i++)
|
c@120
|
1725 {
|
c@120
|
1726 if(In[i]>0)
|
c@120
|
1727 {
|
c@120
|
1728 OnsetN=OnsetN+1;
|
c@120
|
1729 count=count+1;
|
c@120
|
1730 }
|
c@120
|
1731 }
|
c@120
|
1732 Len2=count;
|
c@120
|
1733 out2=(double *)malloc(112*Len2*sizeof(double));
|
c@120
|
1734 A6A=(double *)malloc(112*Len2*sizeof(double));
|
c@120
|
1735 OnsetToArray(In,Len,OutStart,OutEnd);
|
c@120
|
1736 DoMultiPitch(dbs,1050,Len, PitchOut1, PitchOut2);
|
c@120
|
1737
|
c@120
|
1738
|
c@120
|
1739 for (i=0;i<Len;i++)
|
c@120
|
1740 {
|
c@120
|
1741 for (j=0;j<112;j++)
|
c@120
|
1742 {
|
c@120
|
1743 PitchOut3[i*112+j]=PitchOut1[i*112+j];
|
c@120
|
1744 if(PitchOut3[i*112+j]>1)
|
c@120
|
1745 PitchOut3[i*112+j]=1;
|
c@120
|
1746 }
|
c@120
|
1747
|
c@120
|
1748 }
|
c@120
|
1749
|
c@120
|
1750
|
c@120
|
1751 for (i=0;i<OnsetN;i++)
|
c@120
|
1752 {
|
c@120
|
1753 for(j=0;j<112;j++)
|
c@120
|
1754 {
|
c@120
|
1755 A1[j]=0;A2[j]=0;A3[j]=0;A4[j]=0;A5[j]=0;A6[j]=0;
|
c@120
|
1756
|
c@120
|
1757 }
|
c@120
|
1758 maxV=0;
|
c@120
|
1759 start=(int)OutStart[i];
|
c@120
|
1760 endd=(int)OutEnd[i];
|
c@120
|
1761 if(i>0)
|
c@120
|
1762 {
|
c@120
|
1763 startb=(int)OutStart[i-1];
|
c@120
|
1764 }
|
c@120
|
1765
|
c@120
|
1766 for (j=0;j<112;j++)
|
c@120
|
1767 {
|
c@120
|
1768 sum=0;
|
c@120
|
1769 count=0;
|
c@120
|
1770 for (k=(start-1);k<endd;k++)
|
c@120
|
1771 {
|
c@120
|
1772 sum=sum+PitchOut3[k*112+j];
|
c@120
|
1773 count=count+1;
|
c@120
|
1774 }
|
c@120
|
1775
|
c@120
|
1776 A1[j]=sum;
|
c@120
|
1777 A6[j]=sum/count;
|
c@120
|
1778 A6A[i*112+j]=sum/count;
|
c@120
|
1779
|
c@120
|
1780 }
|
c@120
|
1781
|
c@120
|
1782 for (j=0;j<112;j++)
|
c@120
|
1783 {
|
c@120
|
1784 maxVal=PitchOut2[start*112+j];
|
c@120
|
1785 for (k=(start-1);k<endd;k++)
|
c@120
|
1786 {
|
c@120
|
1787 if(PitchOut2[k*112+j]>maxVal)
|
c@120
|
1788 {
|
c@120
|
1789 maxVal=PitchOut2[k*112+j];
|
c@120
|
1790 }
|
c@120
|
1791
|
c@120
|
1792 }
|
c@120
|
1793
|
c@120
|
1794 A3[j]=maxVal;
|
c@120
|
1795
|
c@120
|
1796 }
|
c@120
|
1797
|
c@120
|
1798 for (j=0;j<112;j++)
|
c@120
|
1799 {
|
c@120
|
1800 sum=0;
|
c@120
|
1801 count=0;
|
c@120
|
1802 for (k=(start-1);k<endd;k++)
|
c@120
|
1803 {
|
c@120
|
1804 if(PitchOut2[k*112+j]>0)
|
c@120
|
1805 {
|
c@120
|
1806 sum=sum+PitchOut2[k*112+j];
|
c@120
|
1807 count=count+1;
|
c@120
|
1808 }
|
c@120
|
1809 }
|
c@120
|
1810 if(count>0)
|
c@120
|
1811 A4[j]=sum/count;
|
c@120
|
1812 else
|
c@120
|
1813 A4[j]=0;
|
c@120
|
1814 }
|
c@120
|
1815
|
c@120
|
1816
|
c@120
|
1817 for (j=0;j<112;j++)
|
c@120
|
1818 {
|
c@120
|
1819 sum=0;
|
c@120
|
1820 count=0;
|
c@120
|
1821 for (k=(start-1);k<endd;k++)
|
c@120
|
1822 {
|
c@120
|
1823 if(PitchOut1[k*112+j]>0)
|
c@120
|
1824 {
|
c@120
|
1825 sum=sum+PitchOut1[k*112+j];
|
c@120
|
1826 count=count+1;
|
c@120
|
1827 }
|
c@120
|
1828 }
|
c@120
|
1829 if(count>0)
|
c@120
|
1830 A5[j]=sum/count;
|
c@120
|
1831 else
|
c@120
|
1832 A5[j]=0;
|
c@120
|
1833 }
|
c@120
|
1834
|
c@120
|
1835 maxV=A3[0];
|
c@120
|
1836 for (j=0;j<112;j++)
|
c@120
|
1837 {
|
c@120
|
1838 if(A3[j]>maxV)
|
c@120
|
1839 maxV=A3[j];
|
c@120
|
1840 }
|
c@120
|
1841
|
c@120
|
1842 for (j=0;j<112;j++)
|
c@120
|
1843 {
|
c@120
|
1844
|
c@120
|
1845 if(A1[j]>0)
|
c@120
|
1846 {
|
c@120
|
1847 D[j]=A1[j];D2[j]=A1[j];
|
c@120
|
1848 }
|
c@120
|
1849
|
c@120
|
1850 else
|
c@120
|
1851 {
|
c@120
|
1852 D[j]=A1[j];D2[j]=A1[j];
|
c@120
|
1853 }
|
c@120
|
1854 }
|
c@120
|
1855
|
c@120
|
1856 for (j=0;j<112;j++)
|
c@120
|
1857 {
|
c@120
|
1858 if(A1[j]<8)
|
c@120
|
1859 {
|
c@120
|
1860 D[j]=0;D2[j]=0;
|
c@120
|
1861 }
|
c@120
|
1862
|
c@120
|
1863 }
|
c@120
|
1864
|
c@120
|
1865 for(j=0;j<112;j++)
|
c@120
|
1866 {
|
c@120
|
1867
|
c@120
|
1868 if ((j>12)&&(D[j]>0)&&(D[j-12]>0))
|
c@120
|
1869 {
|
c@120
|
1870 D[j]=0; D2[j]=0;
|
c@120
|
1871 if((A3[j]>45)&&(A3[j]>(A3[j-12]+3)))
|
c@120
|
1872 {
|
c@120
|
1873 D[j]=1;
|
c@120
|
1874 }
|
c@120
|
1875 }
|
c@120
|
1876
|
c@120
|
1877
|
c@120
|
1878 if ((j>19)&&(D[j]>0)&&(D[j-19]>0))
|
c@120
|
1879 {
|
c@120
|
1880
|
c@120
|
1881 D[j]=0; D2[j]=0;
|
c@120
|
1882 if((A3[j]>50))
|
c@120
|
1883 {
|
c@120
|
1884 D[j]=1;
|
c@120
|
1885 }
|
c@120
|
1886 }
|
c@120
|
1887
|
c@120
|
1888 if ((j>24)&&(D[j]>0)&&(D[j-24]>0))
|
c@120
|
1889 {
|
c@120
|
1890
|
c@120
|
1891 D[j]=0; D2[j]=0;
|
c@120
|
1892 if((A3[j]>50))
|
c@120
|
1893 {
|
c@120
|
1894 D[j]=1;
|
c@120
|
1895 }
|
c@120
|
1896 }
|
c@120
|
1897
|
c@120
|
1898 if ((j>28)&&(D[j]>0)&&(D[j-28]>0))
|
c@120
|
1899 {
|
c@120
|
1900
|
c@120
|
1901 D[j]=0; D2[j]=0;
|
c@120
|
1902 if((A3[j]>50))
|
c@120
|
1903 {
|
c@120
|
1904 D[j]=1;
|
c@120
|
1905 }
|
c@120
|
1906 }
|
c@120
|
1907
|
c@120
|
1908 if ((j>34)&&(abs(A5[j]-337.0-A5[j-34])<3.0)&&(D[j]>0)&&(D[j-34]>0))
|
c@120
|
1909 {
|
c@120
|
1910
|
c@120
|
1911 D[j]=0; D2[j]=0;
|
c@120
|
1912 if((A4[j]>25)&&(A3[j]>40)&&(A3[j]>(A3[j-34]-3))&&((A1[j]>8)||(A6[j]>0.8)))
|
c@120
|
1913 {
|
c@120
|
1914 D[j]=1;
|
c@120
|
1915 }
|
c@120
|
1916 }
|
c@120
|
1917
|
c@120
|
1918 if((j>48)&&(j<59)&&(A3[j]<20))
|
c@120
|
1919 {
|
c@120
|
1920 D[j]=0;
|
c@120
|
1921 }
|
c@120
|
1922
|
c@120
|
1923 if((j>58)&&(j<69)&&(A3[j]<28))
|
c@120
|
1924 {
|
c@120
|
1925 D[j]=0;
|
c@120
|
1926 }
|
c@120
|
1927
|
c@120
|
1928
|
c@120
|
1929 if((j>68)&&(j<79)&&(A3[j]<40))
|
c@120
|
1930 {
|
c@120
|
1931 D[j]=0;
|
c@120
|
1932 }
|
c@120
|
1933
|
c@120
|
1934 if((j>78)&&(A3[j]<50))
|
c@120
|
1935 {
|
c@120
|
1936 D[j]=0;
|
c@120
|
1937 }
|
c@120
|
1938
|
c@120
|
1939 if((j>85)&&(A3[j]<55))
|
c@120
|
1940 {
|
c@120
|
1941 D[j]=0;
|
c@120
|
1942 }
|
c@120
|
1943
|
c@120
|
1944 if((D2[j]>0)&&(A1[j]>15))
|
c@120
|
1945 {
|
c@120
|
1946 D[j]=1;
|
c@120
|
1947 }
|
c@120
|
1948 if(i>1)
|
c@120
|
1949 {
|
c@120
|
1950
|
c@120
|
1951 for (k=(startb-1);k<start;k++)
|
c@120
|
1952 {
|
c@120
|
1953 tempArray[k-startb+1]=PitchOut3[j+k*112];
|
c@120
|
1954
|
c@120
|
1955 }
|
c@120
|
1956 temp=Sum(tempArray,start-startb+1);
|
c@120
|
1957 if(((maxV-A3[j])>20)&&(temp>3))
|
c@120
|
1958 {
|
c@120
|
1959 D[j]=0;
|
c@120
|
1960 }
|
c@120
|
1961
|
c@120
|
1962 }
|
c@120
|
1963
|
c@120
|
1964 }
|
c@120
|
1965
|
c@120
|
1966 for(j=0;j<112;j++)
|
c@120
|
1967 {
|
c@120
|
1968 out[j+i*112]=D[j];
|
c@120
|
1969 out2[j+i*112]=D[j];
|
c@120
|
1970 }
|
c@120
|
1971 }
|
c@120
|
1972
|
c@120
|
1973 for (i=1;i<OnsetN;i++)
|
c@120
|
1974 {
|
c@120
|
1975 start2=(int)OutStart[i];
|
c@120
|
1976 endd2=(int)OutEnd[i];
|
c@120
|
1977
|
c@120
|
1978 for (j=0;j<112;j++)
|
c@120
|
1979 {
|
c@120
|
1980 sum=0;
|
c@120
|
1981 count=0;
|
c@120
|
1982 for (k=(start2-1);k<endd2;k++)
|
c@120
|
1983 {
|
c@120
|
1984 sum=sum+PitchOut3[k*112+j];
|
c@120
|
1985 count=count+1;
|
c@120
|
1986 }
|
c@120
|
1987
|
c@120
|
1988 A1[j]=sum;
|
c@120
|
1989 }
|
c@120
|
1990
|
c@120
|
1991 for (j=0;j<112;j++)
|
c@120
|
1992 {
|
c@120
|
1993 if((out2[(i-1)*112+j]>0)&&(out[j+i*112]>0))
|
c@120
|
1994 {
|
c@120
|
1995 out[j+i*112]=0;
|
c@120
|
1996 sum=0;
|
c@120
|
1997 for(k=(start2-1);k<endd2;k++)
|
c@120
|
1998 {
|
c@120
|
1999 sum=sum+PitchOut1[j+k*112];
|
c@120
|
2000
|
c@120
|
2001 }
|
c@120
|
2002 p=sum/A1[j];
|
c@120
|
2003
|
c@120
|
2004 index=(int)(p+0.5)-200;
|
c@120
|
2005
|
c@120
|
2006 if((index>0)&&(i<(OnsetN-1))&&(start2>5))
|
c@120
|
2007 {
|
c@120
|
2008
|
c@120
|
2009 M1=dbs[index+(start2-1)*1050];
|
c@120
|
2010 for (k=(start2-1);k<(start2+10);k++)
|
c@120
|
2011 {
|
c@120
|
2012 if(dbs[index+k*1050]>M1)
|
c@120
|
2013 M1=dbs[index+k*1050];
|
c@120
|
2014
|
c@120
|
2015 }
|
c@120
|
2016
|
c@120
|
2017 M2=dbs[index+(start2-5-1)*1050];
|
c@120
|
2018 for (k=(start2-5-1);k<start2;k++)
|
c@120
|
2019 {
|
c@120
|
2020 if(dbs[index+k*1050]<M2)
|
c@120
|
2021 M2=dbs[index+k*1050];
|
c@120
|
2022
|
c@120
|
2023 }
|
c@120
|
2024
|
c@120
|
2025 if((M1-M2)>10)
|
c@120
|
2026 {
|
c@120
|
2027 out[j+i*112]=1;
|
c@120
|
2028 }
|
c@120
|
2029 }
|
c@120
|
2030 }
|
c@120
|
2031 }
|
c@120
|
2032 }
|
c@120
|
2033
|
c@120
|
2034 count=0;
|
c@120
|
2035 for (i=0;i<OnsetN;i++)
|
c@120
|
2036 {
|
c@120
|
2037
|
c@120
|
2038 start=(int)OutStart[i];
|
c@120
|
2039 endd=(int)OutEnd[i];
|
c@120
|
2040
|
c@120
|
2041 for(j=0;j<112;j++)
|
c@120
|
2042 {
|
c@120
|
2043 if(out[j+i*112]>0)
|
c@120
|
2044 {
|
c@120
|
2045 outArray3[count*3+0]=j+1-21;//exp((log(2.0))*(j+1-69)/12)*440;
|
c@120
|
2046 outArray3[count*3+1]=start*0.01;
|
c@120
|
2047
|
c@120
|
2048 if(i==(OnsetN-1))
|
c@120
|
2049 {
|
c@120
|
2050 outArray3[count*3+2]=0.01*OutEnd[i];
|
c@120
|
2051 }
|
c@120
|
2052 else
|
c@120
|
2053 {
|
c@120
|
2054
|
c@120
|
2055 for(k=(i+1);k<OnsetN;k++)
|
c@120
|
2056 {
|
c@120
|
2057
|
c@120
|
2058 if(k==(OnsetN-1))
|
c@120
|
2059 {
|
c@120
|
2060 outArray3[count*3+2]=0.01*OutEnd[k];
|
c@120
|
2061 }
|
c@120
|
2062
|
c@120
|
2063 if(out[j+k*112]>0)
|
c@120
|
2064 {
|
c@120
|
2065 outArray3[count*3+2]=0.01*OutStart[k];
|
c@120
|
2066 break;
|
c@120
|
2067 }
|
c@120
|
2068
|
c@120
|
2069 if(A6A[k*112+j]<0.5)
|
c@120
|
2070 {
|
c@120
|
2071 outArray3[count*3+2]=0.01*OutStart[k];
|
c@120
|
2072 break;
|
c@120
|
2073
|
c@120
|
2074 }
|
c@120
|
2075
|
c@120
|
2076 }
|
c@120
|
2077
|
c@120
|
2078 }
|
c@120
|
2079
|
c@120
|
2080 count=count+1;
|
c@120
|
2081 }
|
c@120
|
2082
|
c@120
|
2083 }
|
c@120
|
2084
|
c@120
|
2085 }
|
c@120
|
2086 outArray3[count*3+0]=0;
|
c@120
|
2087 outArray3[count*3+1]=0;
|
c@120
|
2088 outArray3[count*3+2]=0;
|
c@120
|
2089
|
c@120
|
2090 free(tempArray);
|
c@120
|
2091 free(OutStart);
|
c@120
|
2092 free(OutEnd);
|
c@120
|
2093 free(A1);
|
c@120
|
2094 free(A2);
|
c@120
|
2095 free(A3);
|
c@120
|
2096 free(A4);
|
c@120
|
2097 free(A5);
|
c@120
|
2098 free(A6);
|
c@120
|
2099 free(A6A);
|
c@120
|
2100 free(D);
|
c@120
|
2101 free(D2);
|
c@120
|
2102 free(out2);
|
c@120
|
2103 free(PitchOut1);
|
c@120
|
2104 free(PitchOut2);
|
c@120
|
2105 free(PitchOut3);
|
c@120
|
2106 free(In);
|
c@120
|
2107 free(dbs);
|
c@120
|
2108 free(dbs1);
|
c@120
|
2109 free(ss);
|
c@120
|
2110 free(jj);
|
c@120
|
2111 }
|
c@120
|
2112
|