c@120: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ c@120: c@120: /* c@120: QM Vamp Plugin Set c@120: c@120: Centre for Digital Music, Queen Mary, University of London. c@135: c@135: This program is free software; you can redistribute it and/or c@135: modify it under the terms of the GNU General Public License as c@135: published by the Free Software Foundation; either version 2 of the c@135: License, or (at your option) any later version. See the file c@135: COPYING included with this distribution for more information. c@120: */ c@120: c@120: /*transcription vamp plugin: Ruohua Zhou, Josh Reiss, josh.reiss@elec.qmul.ac.uk */ c@120: c@120: #include "Transcription.h" c@120: #include c@120: #include c@120: #include c@190: #include c@120: c@120: using std::string; c@120: using std::vector; c@120: using std::cerr; c@120: using std::endl; c@120: c@120: const double EualCurve960[960] = { c@120: 83.750025,83.532690,83.315770,83.099260,82.883159,82.667463,82.452170,82.237276,82.022779,81.808675, c@120: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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.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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 15.142512,15.340191,15.537333,15.733840,15.929615,16.124564 c@120: }; c@120: void Transcribe(int Len,int inputLen,double *SoundIn,double *out,double *outArray2,double *outArray3,double SampleRate); c@120: c@120: Transcription::Transcription(float inputSampleRate) : c@120: Plugin(inputSampleRate), c@120: m_stepSize(0) c@120: { c@120: m_SoundIn=0; c@120: m_SampleN=0; c@120: m_AllocN = 0; c@120: m_Excess = false; c@120: } c@120: c@120: Transcription::~Transcription() c@120: { c@120: free(m_SoundIn); c@120: } c@120: c@120: string c@120: Transcription::getIdentifier() const c@120: { c@120: return "qm-transcription"; c@120: } c@120: c@120: string c@120: Transcription::getName() const c@120: { c@120: return "Polyphonic Transcription"; c@120: } c@120: c@120: string c@120: Transcription::getDescription() const c@120: { c@120: return "Transcribe the input audio to estimated notes"; c@120: } c@120: c@120: string c@120: Transcription::getMaker() const c@120: { c@120: return "Queen Mary, University of London"; c@120: } c@120: c@120: int c@120: Transcription::getPluginVersion() const c@120: { c@120: return 1; c@120: } c@120: c@120: string c@120: Transcription::getCopyright() const c@120: { c@120: return "Plugin by Dr. Ruohua Zhou. Copyright (c) 2008-2009 QMUL - All Rights Reserved"; c@120: } c@120: c@120: size_t c@120: Transcription::getPreferredStepSize() const c@120: { c@120: return 441; c@120: } c@120: c@120: size_t c@120: Transcription::getPreferredBlockSize() const c@120: { c@120: return 441; c@120: } c@120: c@120: bool c@120: Transcription::initialise(size_t channels, size_t stepSize, size_t blockSize) c@120: { c@120: if (channels < getMinChannelCount() || c@120: channels > getMaxChannelCount()) return false; c@120: c@120: if (m_inputSampleRate < 4410 || m_inputSampleRate > 441000) return false; c@120: c@120: m_stepSize = std::min(stepSize, blockSize); c@120: m_blockSize=blockSize; c@120: c@120: m_SampleN = 0; c@120: c@120: return true; c@120: } c@120: c@120: void c@120: Transcription::reset() c@120: { c@120: free(m_SoundIn); c@120: m_SoundIn = 0; c@120: m_SampleN = 0; c@120: m_AllocN = 0; c@120: m_Excess = false; c@120: m_Base = Vamp::RealTime(); c@120: } c@120: c@120: Transcription::OutputList c@120: Transcription::getOutputDescriptors() const c@120: { c@120: OutputList list; c@120: c@120: OutputDescriptor zc; c@120: zc.identifier = "transcription"; c@120: zc.name = "Transcription"; c@120: zc.description = "Estimated note pitch (MIDI note number from 0 to 127)"; c@120: zc.unit = "MIDI units"; c@120: zc.hasFixedBinCount = true; c@120: zc.binCount = 1; c@120: zc.hasKnownExtents = true; c@120: zc.minValue = 0; c@120: zc.maxValue = 127; c@120: zc.isQuantized = true; c@120: zc.quantizeStep = 1.0; c@120: zc.hasDuration = true; c@120: zc.sampleType = OutputDescriptor::VariableSampleRate; c@120: c@120: /* no -- this is the result of a confusion between bin indices and values c@120: { c@120: c@120: zc.binNames.push_back("A0");// MIDI Note 21 c@120: zc.binNames.push_back("A0#"); c@120: zc.binNames.push_back("B0"); c@120: zc.binNames.push_back("C1"); c@120: zc.binNames.push_back("C1#"); c@120: zc.binNames.push_back("D1"); c@120: zc.binNames.push_back("D1#"); c@120: zc.binNames.push_back("E1"); c@120: zc.binNames.push_back("F1"); c@120: zc.binNames.push_back("F1#"); c@120: zc.binNames.push_back("G1"); c@120: zc.binNames.push_back("G1#"); c@120: c@120: zc.binNames.push_back("A1");// MIDI Note 33 c@120: zc.binNames.push_back("A1#"); c@120: zc.binNames.push_back("B1"); c@120: zc.binNames.push_back("C2"); c@120: zc.binNames.push_back("C2#"); c@120: zc.binNames.push_back("D2"); c@120: zc.binNames.push_back("D2#"); c@120: zc.binNames.push_back("E2"); c@120: zc.binNames.push_back("F2"); c@120: zc.binNames.push_back("F2#"); c@120: zc.binNames.push_back("G2"); c@120: zc.binNames.push_back("G2#"); c@120: c@120: zc.binNames.push_back("A2");// MIDI Note 45 c@120: zc.binNames.push_back("A2#"); c@120: zc.binNames.push_back("B3"); c@120: zc.binNames.push_back("C3"); c@120: zc.binNames.push_back("C3#"); c@120: zc.binNames.push_back("D3"); c@120: zc.binNames.push_back("D3#"); c@120: zc.binNames.push_back("E3"); c@120: zc.binNames.push_back("F3"); c@120: zc.binNames.push_back("F3#"); c@120: zc.binNames.push_back("G3"); c@120: zc.binNames.push_back("G3#"); c@120: c@120: zc.binNames.push_back("A3");// MIDI Note 57 c@120: zc.binNames.push_back("A3#"); c@120: zc.binNames.push_back("B0"); c@120: zc.binNames.push_back("C4"); c@120: zc.binNames.push_back("C4#"); c@120: zc.binNames.push_back("D4"); c@120: zc.binNames.push_back("D4#"); c@120: zc.binNames.push_back("E4"); c@120: zc.binNames.push_back("F4"); c@120: zc.binNames.push_back("F4#"); c@120: zc.binNames.push_back("G4"); c@120: zc.binNames.push_back("G4#"); c@120: c@120: zc.binNames.push_back("A4");// MIDI Note 69 c@120: zc.binNames.push_back("A4#"); c@120: zc.binNames.push_back("B0"); c@120: zc.binNames.push_back("C5"); c@120: zc.binNames.push_back("C5#"); c@120: zc.binNames.push_back("D5"); c@120: zc.binNames.push_back("D5#"); c@120: zc.binNames.push_back("E5"); c@120: zc.binNames.push_back("F5"); c@120: zc.binNames.push_back("F5#"); c@120: zc.binNames.push_back("G5"); c@120: zc.binNames.push_back("G5#"); c@120: c@120: zc.binNames.push_back("A5");// MIDI Note 85 c@120: zc.binNames.push_back("A5#"); c@120: zc.binNames.push_back("B0"); c@120: zc.binNames.push_back("C6"); c@120: zc.binNames.push_back("C6#"); c@120: zc.binNames.push_back("D6"); c@120: zc.binNames.push_back("D6#"); c@120: zc.binNames.push_back("E6"); c@120: zc.binNames.push_back("F6"); c@120: zc.binNames.push_back("F6#"); c@120: zc.binNames.push_back("G6"); c@120: zc.binNames.push_back("G6#"); c@120: c@120: zc.binNames.push_back("A6");// MIDI Note 93 c@120: zc.binNames.push_back("A6#"); c@120: zc.binNames.push_back("B0"); c@120: zc.binNames.push_back("C7"); c@120: zc.binNames.push_back("C7#"); c@120: zc.binNames.push_back("D7"); c@120: zc.binNames.push_back("D7#"); c@120: zc.binNames.push_back("E7"); c@120: zc.binNames.push_back("F7"); c@120: zc.binNames.push_back("F7#"); c@120: zc.binNames.push_back("G7"); c@120: zc.binNames.push_back("G7#"); c@120: c@120: zc.binNames.push_back("A7");// MIDI Note 105 c@120: zc.binNames.push_back("A7#"); c@120: zc.binNames.push_back("B0"); c@120: zc.binNames.push_back("C8"); c@120: } c@120: */ c@120: c@120: list.push_back(zc); c@120: c@120: /* zc.identifier = "Transcriptions"; c@120: zc.name = "Polyphonic Transcription"; c@120: zc.description = "Polyphonic Music Transcription"; c@120: zc.unit = ""; c@120: zc.hasFixedBinCount = true; c@120: zc.binCount = 0; c@120: zc.sampleType = OutputDescriptor::VariableSampleRate; c@120: zc.sampleRate = m_inputSampleRate; c@120: list.push_back(zc);*/ c@120: c@120: return list; c@120: } c@120: c@120: Transcription::FeatureSet c@120: Transcription::process(const float *const *inputBuffers, c@120: Vamp::RealTime timestamp) c@120: { c@120: if (m_stepSize == 0) { c@120: cerr << "ERROR: Transcription::process: " c@120: << "Transcription has not been initialised" c@120: << endl; c@120: return FeatureSet(); c@120: } c@120: c@120: if (m_SampleN == 0) { c@120: m_Base = timestamp; c@120: } c@120: c@120: if (m_Excess) return FeatureSet(); c@120: c@178: for (int i = 0; i < m_blockSize;i++) { c@120: c@120: if (m_SampleN >= m_AllocN) { c@178: int newsize = m_AllocN * 2; c@120: if (newsize < 10000) newsize = 10000; c@120: double *newbuf = (double *)realloc(m_SoundIn, newsize * sizeof(double)); c@120: if (!newbuf) { c@120: m_Excess = true; c@120: break; c@120: } c@120: m_SoundIn = newbuf; c@120: m_AllocN = newsize; c@120: } c@120: c@120: m_SoundIn[m_SampleN]=inputBuffers[0][i]; c@120: m_SampleN=m_SampleN+1; c@120: } c@120: c@120: return FeatureSet(); c@120: } c@120: c@120: Transcription::FeatureSet c@120: Transcription::getRemainingFeatures() c@120: { c@120: FeatureSet returnFeatures; c@120: c@120: double * OutArray; c@120: double *OutArray2; c@120: double *hello1; c@120: double *hello2; c@120: int Msec; c@178: int i; c@178: int j; c@178: int n; c@120: c@120: Msec=(int)(100*m_SampleN/m_inputSampleRate); c@120: c@120: if (Msec < 100) return returnFeatures; c@120: c@120: OutArray=(double *)malloc(3*3000*sizeof(double)); c@120: OutArray2=(double *)malloc(88*Msec*sizeof(double)); c@120: hello1=(double *)malloc(112*Msec*sizeof(double)); c@120: hello2=(double *)malloc(112*Msec*sizeof(double)); c@120: c@120: for (j = 0; j 0)&&(OutArray[3*i]<88)) c@120: { c@120: start=OutArray[3*i+1];endd=OutArray[3*i+2]; c@120: for(j=start;j<(start+0.05);j=j+0.01) c@120: { c@120: c@120: Feature feature; c@120: Vamp::RealTime ts; c@120: c@120: feature.hasTimestamp = true; c@120: c@120: feature.timestamp =ts.fromSeconds(j); c@120: feature.values.push_back(OutArray[3*i]+21); c@120: returnFeatures[0].push_back(feature); c@120: c@120: } c@120: c@120: c@120: c@120: } c@120: else c@120: { c@120: c@120: break; c@120: } c@120: c@120: c@120: } c@120: c@120: */ c@120: c@120: c@120: for (i = 0; i < 3000; i++) { c@120: c@120: if((OutArray[3*i]>0)&&(OutArray[3*i]<88)) c@120: { c@120: start=100*OutArray[3*i+1]; c@120: endd=100*OutArray[3*i+2]-5; c@120: for(j=start;j0) c@120: { c@120: c@120: if (starts[n] < 0.) c@120: { c@120: starts[n] = j * 0.01; c@120: } c@120: } c@120: else c@120: { c@120: if (starts[n] > 0.) c@120: { c@120: Feature feature; c@120: feature.hasTimestamp = true; c@120: feature.timestamp = m_Base + Vamp::RealTime::fromSeconds(starts[n]); c@120: feature.hasDuration = true; c@120: feature.duration = Vamp::RealTime::fromSeconds(j * 0.01 - starts[n]); c@120: feature.values.push_back(n+20); c@120: returnFeatures[0].push_back(feature); c@120: c@120: starts[n] = -1.0; c@120: } c@120: } c@120: } c@120: } c@120: c@120: c@120: for(n=0;n<88;n++) c@120: { c@120: if (starts[n] > 0.) c@120: { c@120: Feature feature; c@120: feature.hasTimestamp = true; c@120: feature.timestamp = m_Base + Vamp::RealTime::fromSeconds(starts[n]); c@120: feature.hasDuration = true; c@120: feature.duration = Vamp::RealTime::fromSeconds(j * 0.01 - starts[n]); c@120: feature.values.push_back(n+20); c@120: returnFeatures[0].push_back(feature); c@120: c@120: starts[n] = -1.0; c@120: } c@120: } c@120: c@120: free(OutArray2); c@120: free(OutArray); c@120: c@120: free(hello1); c@120: free(hello2); c@120: c@120: return returnFeatures; c@120: c@120: } c@120: c@120: c@120: c@120: c@120: c@120: void sofacomplexMex(double *y, double *z, int ncols,double StartNote,double NoteInterval1,double NoteNum,double C,double D,double SR) c@120: { c@178: int mseconds,i,el,count,count2; c@178: double Snote,NoteInterval,NoteN; c@120: double *signs; c@178: double *rwork; c@120: double freq,R,gain,gainI,gainII,coefI,coefM; c@120: double output,input,outputI,outputM; c@120: double *x; c@120: double *sum,*sum2; c@120: double power; c@120: c@120: //SR=44100; c@120: Snote=StartNote; c@120: NoteInterval=NoteInterval1; c@120: NoteN=NoteNum; c@120: c@120: signs=(double*)malloc((int)NoteN*5*sizeof(double)); c@120: c@120: for (i = 0; i MaxValue) c@120: { c@120: MaxValue=In2[j]; c@120: MaxIndex=j; c@120: } c@120: } c@120: InputArray[MaxIndex]=In2[MaxIndex]; c@120: In2[MaxIndex]=0; c@120: } c@120: c@120: free(In2); c@120: } c@120: c@120: double SumF(double *InputArray,int Start, int End) c@120: { c@120: double Value; c@120: int i; c@120: Value=0; c@120: for (i=Start;i<(End+1);i++) c@120: { c@120: Value=Value+InputArray[i]; c@120: } c@120: c@120: return Value; c@120: c@120: } c@120: c@120: int round10(int x) c@120: { c@120: int I,I2; c@120: I=((int)(x/10)); c@120: I2=x-I*10; c@120: c@120: if(I2>5) c@120: return (I+1); c@120: else c@120: return I; c@120: c@120: } c@120: c@120: c@120: void ConToPitch1250(double *In, int InLen) c@120: { c@120: int i,j,k, nn,col; c@120: double *Out; c@120: const int A[12]={0, 120, 190, 240, 279, 310, 337, 360, 380, 399, 415, 430}; c@120: Out=(double*)malloc(InLen*sizeof(double)); c@120: c@120: c@120: col=InLen; c@120: c@120: for (i=0;i(col-1)) c@120: { c@120: k=k+1; c@120: Out[i]=Out[i]+In[col-1]; c@120: } c@120: } c@120: if(k>0) c@120: { c@120: Out[i]=Out[i]/k; c@120: } c@120: } c@120: for (i=0;iMaxValue) c@120: MaxValue=In[i]; c@120: } c@120: c@120: for (i=0;i-1) c@120: { c@120: sum=sum+In[i-j]; c@120: count=count+1; c@120: } c@120: } c@120: c@120: for (j=1;j<(n+1);j++) c@120: { c@120: if ((i+j)(db2+In[i-6]))||(In[i]>(db2+In[i+6])) c@120: ||(In[i]>(db3+In[i+20]))||(In[i]>(db3+In[i-20]))) c@120: /*&&(In[i]>db)*/&&(In[i]>In[i+3])&&(In[i]>In[i-3]) c@120: &&(In[i]>In[i+2])&&(In[i]>In[i-2]) c@120: &&(In[i]>In[i+1])&&(In[i]>In[i-1])) c@120: { c@120: Out1[i]=In[i]; c@120: Out2[i]=1; c@120: } c@120: c@120: } c@120: c@120: lastout=1; c@120: for(i=0;iOut1[lastout]) c@120: { c@120: Out2[lastout]=0; c@120: Out1[lastout]=0; c@120: lastout=i; c@120: } c@120: else c@120: { c@120: Out2[i]=0; c@120: Out1[i]=0; c@120: } c@120: c@120: } c@120: else c@120: { c@120: lastout=i; c@120: } c@120: } c@120: c@120: } c@120: c@120: } c@120: c@120: c@120: void ConFrom1050To960(double *In, double *out, int InputLen) c@120: { c@120: int i,j; c@120: c@120: for(i=0;i<960;i++) c@120: { c@120: for (j=0;j-1)&&((i+m)MaxVal) c@120: { c@120: MaxVal=InputArray[i+j*InputVLen]; c@120: } c@120: c@120: } c@120: OutArray[j]=MaxVal; c@120: } c@120: c@120: } c@120: c@120: void MaxV2( double *InputArray, int InputHLen, int InputVLen, double *OutArray) c@120: { c@120: int i; c@120: int j; c@120: double MaxVal; c@120: for (i=0;iMaxVal) c@120: { c@120: MaxVal=InputArray[i+j*InputVLen]; c@120: } c@120: c@120: } c@120: OutArray[i]=MaxVal; c@120: } c@120: c@120: } c@120: c@120: c@120: c@120: void MinArray( double *InputArray, int InputHLen, int InputVLen, double MinValue) c@120: { c@120: int i; c@120: int j; c@120: c@120: for (i=0;iMaxValue) c@120: InputArray[i+j*InputVLen]=MaxValue; c@120: c@120: } c@120: c@120: } c@120: c@120: } c@120: c@120: double GetMaxValue( double *InputArray, int InputHLen, int InputVLen) c@120: { c@120: int i; c@120: int j; c@120: c@120: double MaxValue; c@120: MaxValue=InputArray[0]; c@120: for (i=0;iMaxValue) c@120: MaxValue=InputArray[i*InputHLen+j]; c@120: c@120: } c@120: c@120: } c@120: c@120: return MaxValue; c@120: } c@120: c@120: void RemoveNoise( double *InputArray, int InputHLen, int InputVLen) c@120: { c@120: int i; c@120: int j; c@120: c@120: for (i=0;iIn[i+2])&&(In[i]>In[i-2]) c@120: &&(In[i]>In[i+1])&&(In[i]>In[i-1])) c@120: { c@120: Out1[i]=In[i]; c@120: } c@120: c@120: } c@120: c@120: for(i=0;i0) c@120: { c@120: Edetect(Input,mseconds,960, a,b,OutOne); c@120: } c@120: c@120: c@120: free(Input); c@120: c@120: } c@120: c@178: void PitchEstimation(double *In, int /* InLen */, double *OutArray,double *OutArray2) c@120: { c@120: double *xx,*x,*y,*y1,*PeakPitch1, *PeakPitch2,*PeakInput1, *PeakInput2; c@120: double *out,*outValue; c@120: double *output,*output1; c@120: int *outc; c@120: double temp; c@178: int i,sumI; c@120: int Len; c@120: c@120: Len=1050; c@120: xx=(double*)malloc(Len*sizeof(double)); c@120: x=(double*)malloc(Len*sizeof(double)); c@120: y=(double*)malloc(Len*sizeof(double)); c@120: y1=(double*)malloc(Len*sizeof(double)); c@120: PeakPitch1=(double*)malloc(Len*sizeof(double)); c@120: PeakPitch2=(double*)malloc(Len*sizeof(double)); c@120: PeakInput1=(double*)malloc(Len*sizeof(double)); c@120: PeakInput2=(double*)malloc(Len*sizeof(double)); c@120: out=(double*)malloc(Len*sizeof(double)); c@120: outValue=(double*)malloc(Len*sizeof(double)); c@120: output=(double*)malloc(112*sizeof(double)); c@120: output1=(double*)malloc(112*sizeof(double)); c@120: outc=(int*)malloc(112*sizeof(int)); c@120: // yI=(double*)malloc(12*sizeof(double)); c@120: c@120: c@120: for (i=0;i12) c@120: { c@120: FindMaxN(PeakPitch1,Len,12); c@120: c@120: for (i=0;i0)&&(SumF(PeakInput2,i+120-4,i+120+4)>0)) c@120: ||((SumF(PeakInput2,i-4,i+4)>0)&&(SumF(PeakInput2,i+190-4,i+190+4)>0)) c@120: ||((SumF(PeakInput2,i+190-4,i+190+4)>0)&&(SumF(PeakInput2,i+120-4,i+120+4)>0)) c@120: ) c@120: { c@120: out[i]=1; c@120: outValue[i]=y1[i]; c@120: c@120: } c@120: } c@120: } c@120: c@120: for (i=0;i<112;i++) c@120: { c@120: output[i]=0; c@120: outc[i]=0; c@120: } c@120: c@120: c@120: c@120: for (i=0;i0)&&(SumF(PeakInput2,outc[i]-5,outc[i]+5)==0)) c@120: { c@120: output1[i]=0; c@120: } c@120: } c@120: c@120: c@120: for (i=0;i<112;i++) c@120: { c@120: OutArray[i]=0; c@120: OutArray2[i]=0; c@120: c@120: } c@120: c@120: for(i=20;i<105;i++) c@120: { c@120: if(output1[i]==1) c@120: { c@120: OutArray[i]=outc[i]+200+2; c@120: OutArray2[i]=y[outc[i]]; c@120: } c@120: } c@120: c@120: free(xx); // xx=(double*)malloc(Len*sizeof(double)); c@120: free(x); // x=(double*)malloc(Len*sizeof(double)); c@120: free(y); // y=(double*)malloc(Len*sizeof(double)); c@120: free(y1); // y1=(double*)malloc(Len*sizeof(double)); c@120: free(PeakPitch1); //=(double*)malloc(Len*sizeof(double)); c@120: free(PeakPitch2); //=(double*)malloc(Len*sizeof(double)); c@120: free(PeakInput1); //=(double*)malloc(Len*sizeof(double)); c@120: free(PeakInput2); //=(double*)malloc(Len*sizeof(double)); c@120: free(out); //=(double*)malloc(Len*sizeof(double)); c@120: free(outValue); //=(double*)malloc(Len*sizeof(double)); c@120: free(output); //=(double*)malloc(112*sizeof(double)); c@120: free(output1); //=(double*)malloc(112*sizeof(double)); c@120: free(outc); //=(double*)malloc(112*sizeof(int)); c@120: //free(yI); //=(double*)malloc(12*sizeof(int)); c@120: // printf(" end free \n"); c@120: } c@120: c@120: void DoMultiPitch(double *In, int RLen,int CLen, double *Out1, double *Out2) c@120: { c@120: c@120: int i, j; c@120: double *sum1,*mean1; c@120: double MaxV; c@120: double *OutArray1, *OutArray2,*tempArray; c@120: c@120: OutArray1=(double *)malloc(112*sizeof(double)); c@120: OutArray2=(double *)malloc(112*sizeof(double)); c@120: tempArray=(double *)malloc(RLen*sizeof(double)); c@120: c@120: sum1=(double*)malloc(CLen*sizeof(double)); c@120: mean1=(double*)malloc(CLen*sizeof(double)); c@120: c@120: for (j=0;jMaxV) c@120: { c@120: MaxV=mean1[j]; c@120: } c@120: } c@120: c@120: for (j=0;jMaxV) c@120: MaxV=tempArray[i]; c@120: } c@120: c@120: if(mean1[j]>-55) c@120: { c@120: c@120: PitchEstimation(tempArray,RLen,OutArray1,OutArray2); c@120: c@120: for(i=0;i<112;i++) c@120: { c@120: if(OutArray1[i]>0) c@120: { c@120: if((MaxV-tempArray[(int)OutArray1[i]-201-1])>40) c@120: { c@120: OutArray1[i]=0; c@120: OutArray2[i]=0; c@120: } c@120: c@120: } c@120: } c@120: c@120: } c@120: c@120: for (i=0;i<112;i++) c@120: { c@120: c@120: Out1[j*112+i]=OutArray1[i]; c@120: Out2[j*112+i]=OutArray2[i]; c@120: c@120: } c@120: c@120: } c@120: c@120: free(OutArray1); c@120: free(OutArray2); c@120: free(tempArray); c@120: free(sum1); c@120: free(mean1); c@120: } c@120: c@120: c@120: int OnsetToArray(double *In, int Len, double *OutStart,double *OutEnd) c@120: { c@120: int count,i; c@120: c@120: count=0; c@120: c@120: for (i=0;i0) c@120: { c@120: OutStart[count]=i+1; c@120: if(count>0) c@120: { c@120: OutEnd[count-1]=i+1; c@120: } c@120: count=count+1; c@120: } c@120: } c@120: if (count>0) c@120: { c@120: OutEnd[count-1]=Len; c@120: } c@120: return count; c@120: c@120: } c@120: void dbfunction( double *InputArray, int InputHLen, int InputVLen,double *OutArray) c@120: { c@120: int i; c@120: int j; c@120: c@120: for (i=0;i0) c@120: { c@120: OnsetN=OnsetN+1; c@120: count=count+1; c@120: } c@120: } c@120: Len2=count; c@120: out2=(double *)malloc(112*Len2*sizeof(double)); c@120: A6A=(double *)malloc(112*Len2*sizeof(double)); c@120: OnsetToArray(In,Len,OutStart,OutEnd); c@120: DoMultiPitch(dbs,1050,Len, PitchOut1, PitchOut2); c@120: c@120: c@120: for (i=0;i1) c@120: PitchOut3[i*112+j]=1; c@120: } c@120: c@120: } c@120: c@120: c@120: for (i=0;i0) c@120: { c@120: startb=(int)OutStart[i-1]; c@120: } c@120: c@120: for (j=0;j<112;j++) c@120: { c@120: sum=0; c@120: count=0; c@120: for (k=(start-1);kmaxVal) c@120: { c@120: maxVal=PitchOut2[k*112+j]; c@120: } c@120: c@120: } c@120: c@120: A3[j]=maxVal; c@120: c@120: } c@120: c@120: for (j=0;j<112;j++) c@120: { c@120: sum=0; c@120: count=0; c@120: for (k=(start-1);k0) c@120: { c@120: sum=sum+PitchOut2[k*112+j]; c@120: count=count+1; c@120: } c@120: } c@120: if(count>0) c@120: A4[j]=sum/count; c@120: else c@120: A4[j]=0; c@120: } c@120: c@120: c@120: for (j=0;j<112;j++) c@120: { c@120: sum=0; c@120: count=0; c@120: for (k=(start-1);k0) c@120: { c@120: sum=sum+PitchOut1[k*112+j]; c@120: count=count+1; c@120: } c@120: } c@120: if(count>0) c@120: A5[j]=sum/count; c@120: else c@120: A5[j]=0; c@120: } c@120: c@120: maxV=A3[0]; c@120: for (j=0;j<112;j++) c@120: { c@120: if(A3[j]>maxV) c@120: maxV=A3[j]; c@120: } c@120: c@120: for (j=0;j<112;j++) c@120: { c@120: c@120: if(A1[j]>0) c@120: { c@120: D[j]=A1[j];D2[j]=A1[j]; c@120: } c@120: c@120: else c@120: { c@120: D[j]=A1[j];D2[j]=A1[j]; c@120: } c@120: } c@120: c@120: for (j=0;j<112;j++) c@120: { c@120: if(A1[j]<8) c@120: { c@120: D[j]=0;D2[j]=0; c@120: } c@120: c@120: } c@120: c@120: for(j=0;j<112;j++) c@120: { c@120: c@120: if ((j>12)&&(D[j]>0)&&(D[j-12]>0)) c@120: { c@120: D[j]=0; D2[j]=0; c@120: if((A3[j]>45)&&(A3[j]>(A3[j-12]+3))) c@120: { c@120: D[j]=1; c@120: } c@120: } c@120: c@120: c@120: if ((j>19)&&(D[j]>0)&&(D[j-19]>0)) c@120: { c@120: c@120: D[j]=0; D2[j]=0; c@120: if((A3[j]>50)) c@120: { c@120: D[j]=1; c@120: } c@120: } c@120: c@120: if ((j>24)&&(D[j]>0)&&(D[j-24]>0)) c@120: { c@120: c@120: D[j]=0; D2[j]=0; c@120: if((A3[j]>50)) c@120: { c@120: D[j]=1; c@120: } c@120: } c@120: c@120: if ((j>28)&&(D[j]>0)&&(D[j-28]>0)) c@120: { c@120: c@120: D[j]=0; D2[j]=0; c@120: if((A3[j]>50)) c@120: { c@120: D[j]=1; c@120: } c@120: } c@120: c@183: if ((j>34)&&(fabs(A5[j]-337.0-A5[j-34])<3.0)&&(D[j]>0)&&(D[j-34]>0)) c@120: { c@120: c@120: D[j]=0; D2[j]=0; c@120: if((A4[j]>25)&&(A3[j]>40)&&(A3[j]>(A3[j-34]-3))&&((A1[j]>8)||(A6[j]>0.8))) c@120: { c@120: D[j]=1; c@120: } c@120: } c@120: c@120: if((j>48)&&(j<59)&&(A3[j]<20)) c@120: { c@120: D[j]=0; c@120: } c@120: c@120: if((j>58)&&(j<69)&&(A3[j]<28)) c@120: { c@120: D[j]=0; c@120: } c@120: c@120: c@120: if((j>68)&&(j<79)&&(A3[j]<40)) c@120: { c@120: D[j]=0; c@120: } c@120: c@120: if((j>78)&&(A3[j]<50)) c@120: { c@120: D[j]=0; c@120: } c@120: c@120: if((j>85)&&(A3[j]<55)) c@120: { c@120: D[j]=0; c@120: } c@120: c@120: if((D2[j]>0)&&(A1[j]>15)) c@120: { c@120: D[j]=1; c@120: } c@120: if(i>1) c@120: { c@120: c@120: for (k=(startb-1);k20)&&(temp>3)) c@120: { c@120: D[j]=0; c@120: } c@120: c@120: } c@120: c@120: } c@120: c@120: for(j=0;j<112;j++) c@120: { c@120: out[j+i*112]=D[j]; c@120: out2[j+i*112]=D[j]; c@120: } c@120: } c@120: c@120: for (i=1;i0)&&(out[j+i*112]>0)) c@120: { c@120: out[j+i*112]=0; c@120: sum=0; c@120: for(k=(start2-1);k0)&&(i<(OnsetN-1))&&(start2>5)) c@120: { c@120: c@120: M1=dbs[index+(start2-1)*1050]; c@120: for (k=(start2-1);k<(start2+10);k++) c@120: { c@120: if(dbs[index+k*1050]>M1) c@120: M1=dbs[index+k*1050]; c@120: c@120: } c@120: c@120: M2=dbs[index+(start2-5-1)*1050]; c@120: for (k=(start2-5-1);k10) c@120: { c@120: out[j+i*112]=1; c@120: } c@120: } c@120: } c@120: } c@120: } c@120: c@120: count=0; c@120: for (i=0;i0) c@120: { c@120: outArray3[count*3+0]=j+1-21;//exp((log(2.0))*(j+1-69)/12)*440; c@120: outArray3[count*3+1]=start*0.01; c@120: c@120: if(i==(OnsetN-1)) c@120: { c@120: outArray3[count*3+2]=0.01*OutEnd[i]; c@120: } c@120: else c@120: { c@120: c@120: for(k=(i+1);k0) c@120: { c@120: outArray3[count*3+2]=0.01*OutStart[k]; c@120: break; c@120: } c@120: c@120: if(A6A[k*112+j]<0.5) c@120: { c@120: outArray3[count*3+2]=0.01*OutStart[k]; c@120: break; c@120: c@120: } c@120: c@120: } c@120: c@120: } c@120: c@120: count=count+1; c@120: } c@120: c@120: } c@120: c@120: } c@120: outArray3[count*3+0]=0; c@120: outArray3[count*3+1]=0; c@120: outArray3[count*3+2]=0; c@120: c@120: free(tempArray); c@120: free(OutStart); c@120: free(OutEnd); c@120: free(A1); c@120: free(A2); c@120: free(A3); c@120: free(A4); c@120: free(A5); c@120: free(A6); c@120: free(A6A); c@120: free(D); c@120: free(D2); c@120: free(out2); c@120: free(PitchOut1); c@120: free(PitchOut2); c@120: free(PitchOut3); c@120: free(In); c@120: free(dbs); c@120: free(dbs1); c@120: free(ss); c@120: free(jj); c@120: } c@120: