comparison src/LiveInstruments.cpp @ 322:7dda913d820b livemode

For piano instrument in live mode, merge the templates rather than only using one (seems to give better results)
author Chris Cannam
date Wed, 29 Apr 2015 10:34:44 +0100
parents dec47312ed40
children 4cf4313d7e30
comparison
equal deleted inserted replaced
321:213a51e197c8 322:7dda913d820b
25 LiveAdapter::adapt(const InstrumentPack &original) 25 LiveAdapter::adapt(const InstrumentPack &original)
26 { 26 {
27 vector<InstrumentPack::Templates> templates; 27 vector<InstrumentPack::Templates> templates;
28 28
29 // cerr << "LiveAdapter: reduced template height is " << SILVET_TEMPLATE_HEIGHT/5 << endl; 29 // cerr << "LiveAdapter: reduced template height is " << SILVET_TEMPLATE_HEIGHT/5 << endl;
30
31 for (vector<InstrumentPack::Templates>::const_iterator i =
32 original.templates.begin();
33 i != original.templates.end(); ++i) {
34 30
35 InstrumentPack::Templates t; 31 bool merge = false;
36 t.lowestNote = i->lowestNote; 32 // The live template for piano has only one piano in it, so as
37 t.highestNote = i->highestNote; 33 // to process faster. We make it by averaging the originals
38 t.data.resize(i->data.size()); 34 if (original.name == "Piano") {
35 merge = true;
36 }
39 37
40 for (int j = 0; j < int(i->data.size()); ++j) { 38 InstrumentPack::Templates t;
39 bool first = true;
40
41 for (const auto &origt: original.templates) {
42
43 t.lowestNote = origt.lowestNote;
44 t.highestNote = origt.highestNote;
45 t.data.resize(origt.data.size());
46
47 for (int j = 0; j < int(origt.data.size()); ++j) {
41 48
42 t.data[j].resize(SILVET_TEMPLATE_HEIGHT/5); 49 t.data[j].resize(SILVET_TEMPLATE_HEIGHT/5);
43 50
44 float sum = 0.f;
45
46 for (int k = 0; k < SILVET_TEMPLATE_HEIGHT/5; ++k) { 51 for (int k = 0; k < SILVET_TEMPLATE_HEIGHT/5; ++k) {
47 52
48 t.data[j][k] = 0.f; 53 if (!merge || first) {
54 t.data[j][k] = 0.f;
55 }
49 56
50 for (int m = 0; m < 5; ++m) { 57 for (int m = 0; m < 5; ++m) {
51 t.data[j][k] += i->data[j][k * 5 + m + 2]; 58 t.data[j][k] += origt.data[j][k * 5 + m + 2];
52 } 59 }
53
54 sum += t.data[j][k];
55 } 60 }
56
57 // re-normalise
58 if (sum > 0.f) {
59 for (int k = 0; k < (int)t.data[j].size(); ++k) {
60 t.data[j][k] *= 1.f / sum;
61 }
62 }
63 } 61 }
64 62
65 templates.push_back(t); 63 if (!merge) {
64 templates.push_back(t);
65 t = InstrumentPack::Templates();
66 }
66 67
67 // The live template for piano has only one piano in it, so as 68 first = false;
68 // to process faster 69 }
69 if (original.name == "Piano") { 70
70 break; 71 if (merge) {
72 templates.push_back(t);
73 }
74
75 // re-normalise
76 for (auto &t: templates) {
77 for (auto &d: t.data) {
78 float sum = 0.f;
79 for (auto v: d) sum += v;
80 for (auto &v: d) v /= sum;
71 } 81 }
72 } 82 }
73 83
74 InstrumentPack live(original.lowestNote, 84 InstrumentPack live(original.lowestNote,
75 original.highestNote, 85 original.highestNote,