comparison src/LiveInstruments.cpp @ 342:ad45b18427e0

Merge from branch livemode
author Chris Cannam
date Mon, 06 Jul 2015 09:15:21 +0100
parents 4cf4313d7e30
children df9a8e16bae6 5acce45e2ec6
comparison
equal deleted inserted replaced
313:fa2ffbb786df 342:ad45b18427e0
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Silvet
5
6 A Vamp plugin for note transcription.
7 Centre for Digital Music, Queen Mary University of London.
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information.
14 */
15
16 #include "LiveInstruments.h"
17
18 #include "data/include/templates.h"
19
20 #include <iostream>
21
22 using namespace std;
23
24 InstrumentPack
25 LiveAdapter::adapt(const InstrumentPack &original)
26 {
27 vector<InstrumentPack::Templates> templates;
28
29 // cerr << "LiveAdapter: reduced template height is " << SILVET_TEMPLATE_HEIGHT/5 << endl;
30
31 bool merge = false;
32 // The live template for piano has only one piano in it, so as
33 // to process faster. We make it by averaging the originals
34 if (original.name == "Piano") {
35 merge = true;
36 }
37
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) {
48
49 t.data[j].resize(SILVET_TEMPLATE_HEIGHT/5);
50
51 for (int k = 0; k < SILVET_TEMPLATE_HEIGHT/5; ++k) {
52
53 if (!merge || first) {
54 t.data[j][k] = 0.f;
55 }
56
57 for (int m = 0; m < 5; ++m) {
58 t.data[j][k] += origt.data[j][k * 5 + m + 2];
59 }
60 }
61 }
62
63 if (!merge) {
64 templates.push_back(t);
65 t = InstrumentPack::Templates();
66 }
67
68 first = false;
69 }
70
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;
81 }
82 }
83
84 InstrumentPack live(original.lowestNote,
85 original.highestNote,
86 original.name,
87 templates);
88
89 live.templateHeight = SILVET_TEMPLATE_HEIGHT/5;
90 live.templateMaxShift = 0;
91 live.templateSize = live.templateHeight;
92
93 live.maxPolyphony = original.maxPolyphony;
94 live.pitchSparsity = original.pitchSparsity;
95 live.sourceSparsity = original.sourceSparsity;
96 live.levelThreshold = original.levelThreshold / 15;
97
98 return live;
99 }
100
101 vector<InstrumentPack>
102 LiveAdapter::adaptAll(const vector<InstrumentPack> &v)
103 {
104 vector<InstrumentPack> out;
105 for (int i = 0; i < (int)v.size(); ++i) {
106 InstrumentPack p(LiveAdapter::adapt(v[i]));
107 out.push_back(p);
108 }
109 return out;
110 }