comparison src/LiveInstruments.cpp @ 327:df9a8e16bae6 livemode-octave-higher

Experiment with dropping the bottom octave off each template (since most of the information is in higher harmonics anyway!) -- this is about 15% faster again and has half the latency, but per
author Chris Cannam
date Tue, 19 May 2015 09:29:00 +0100
parents 4cf4313d7e30
children 8545b883775e
comparison
equal deleted inserted replaced
326:caaac814c22a 327:df9a8e16bae6
35 merge = true; 35 merge = true;
36 } 36 }
37 37
38 InstrumentPack::Templates t; 38 InstrumentPack::Templates t;
39 bool first = true; 39 bool first = true;
40
41 // The live instrument template is one octave shorter than the
42 // original, as well as having only 12 bpo instead of 60
43 int height = SILVET_TEMPLATE_HEIGHT/5 - 12;
40 44
41 for (const auto &origt: original.templates) { 45 for (const auto &origt: original.templates) {
42 46
43 t.lowestNote = origt.lowestNote; 47 t.lowestNote = origt.lowestNote + 12;
44 t.highestNote = origt.highestNote; 48 t.highestNote = origt.highestNote;
45 t.data.resize(origt.data.size()); 49 t.data.resize(origt.data.size());
46 50
47 for (int j = 0; j < int(origt.data.size()); ++j) { 51 for (int j = 0; j < int(origt.data.size()); ++j) {
48 52
49 t.data[j].resize(SILVET_TEMPLATE_HEIGHT/5); 53 t.data[j].resize(height);
50 54
51 for (int k = 0; k < SILVET_TEMPLATE_HEIGHT/5; ++k) { 55 for (int k = 0; k < height; ++k) {
52 56
53 if (!merge || first) { 57 if (!merge || first) {
54 t.data[j][k] = 0.f; 58 t.data[j][k] = 0.f;
55 } 59 }
56 60
57 for (int m = 0; m < 5; ++m) { 61 for (int m = 2; m < 3; ++m) {
58 t.data[j][k] += origt.data[j][k * 5 + m + 2]; 62 t.data[j][k] += origt.data[j][60 + k * 5 + m + 2];
59 } 63 }
60 } 64 }
61 } 65 }
62 66
63 if (!merge) { 67 if (!merge) {
71 if (merge) { 75 if (merge) {
72 templates.push_back(t); 76 templates.push_back(t);
73 } 77 }
74 78
75 // re-normalise 79 // re-normalise
80
76 for (auto &t: templates) { 81 for (auto &t: templates) {
77 for (auto &d: t.data) { 82 for (auto &d: t.data) {
78 float sum = 0.f; 83 float sum = 0.f;
79 for (auto v: d) sum += v; 84 for (auto v: d) sum += v;
80 for (auto &v: d) v /= sum; 85 for (auto &v: d) v /= sum;
81 } 86 }
82 } 87 }
83 88
84 InstrumentPack live(original.lowestNote, 89 InstrumentPack live(original.lowestNote,
85 original.highestNote, 90 original.highestNote,
86 original.name, 91 original.name,
87 templates); 92 templates);
88 93
89 live.templateHeight = SILVET_TEMPLATE_HEIGHT/5; 94 live.templateHeight = height;
90 live.templateMaxShift = 0; 95 live.templateMaxShift = 0;
91 live.templateSize = live.templateHeight; 96 live.templateSize = height;
92 97
93 live.maxPolyphony = original.maxPolyphony; 98 live.maxPolyphony = original.maxPolyphony;
94 live.pitchSparsity = original.pitchSparsity; 99 live.pitchSparsity = original.pitchSparsity;
95 live.sourceSparsity = original.sourceSparsity; 100 live.sourceSparsity = original.sourceSparsity;
96 live.levelThreshold = original.levelThreshold / 15; 101 live.levelThreshold = original.levelThreshold / 20;
97 102
98 return live; 103 return live;
99 } 104 }
100 105
101 vector<InstrumentPack> 106 vector<InstrumentPack>