annotate 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
rev   line source
Chris@298 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@298 2
Chris@298 3 /*
Chris@298 4 Silvet
Chris@298 5
Chris@298 6 A Vamp plugin for note transcription.
Chris@298 7 Centre for Digital Music, Queen Mary University of London.
Chris@298 8
Chris@298 9 This program is free software; you can redistribute it and/or
Chris@298 10 modify it under the terms of the GNU General Public License as
Chris@298 11 published by the Free Software Foundation; either version 2 of the
Chris@298 12 License, or (at your option) any later version. See the file
Chris@298 13 COPYING included with this distribution for more information.
Chris@298 14 */
Chris@298 15
Chris@298 16 #include "LiveInstruments.h"
Chris@298 17
Chris@298 18 #include "data/include/templates.h"
Chris@298 19
Chris@301 20 #include <iostream>
Chris@301 21
Chris@298 22 using namespace std;
Chris@298 23
Chris@298 24 InstrumentPack
Chris@298 25 LiveAdapter::adapt(const InstrumentPack &original)
Chris@298 26 {
Chris@298 27 vector<InstrumentPack::Templates> templates;
Chris@298 28
Chris@303 29 // cerr << "LiveAdapter: reduced template height is " << SILVET_TEMPLATE_HEIGHT/5 << endl;
Chris@298 30
Chris@322 31 bool merge = false;
Chris@322 32 // The live template for piano has only one piano in it, so as
Chris@322 33 // to process faster. We make it by averaging the originals
Chris@322 34 if (original.name == "Piano") {
Chris@322 35 merge = true;
Chris@322 36 }
Chris@298 37
Chris@322 38 InstrumentPack::Templates t;
Chris@322 39 bool first = true;
Chris@327 40
Chris@327 41 // The live instrument template is one octave shorter than the
Chris@327 42 // original, as well as having only 12 bpo instead of 60
Chris@327 43 int height = SILVET_TEMPLATE_HEIGHT/5 - 12;
Chris@322 44
Chris@322 45 for (const auto &origt: original.templates) {
Chris@322 46
Chris@327 47 t.lowestNote = origt.lowestNote + 12;
Chris@322 48 t.highestNote = origt.highestNote;
Chris@322 49 t.data.resize(origt.data.size());
Chris@322 50
Chris@322 51 for (int j = 0; j < int(origt.data.size()); ++j) {
Chris@301 52
Chris@327 53 t.data[j].resize(height);
Chris@301 54
Chris@327 55 for (int k = 0; k < height; ++k) {
Chris@301 56
Chris@322 57 if (!merge || first) {
Chris@322 58 t.data[j][k] = 0.f;
Chris@322 59 }
Chris@301 60
Chris@327 61 for (int m = 2; m < 3; ++m) {
Chris@327 62 t.data[j][k] += origt.data[j][60 + k * 5 + m + 2];
Chris@301 63 }
Chris@298 64 }
Chris@298 65 }
Chris@299 66
Chris@322 67 if (!merge) {
Chris@322 68 templates.push_back(t);
Chris@322 69 t = InstrumentPack::Templates();
Chris@322 70 }
Chris@315 71
Chris@322 72 first = false;
Chris@322 73 }
Chris@322 74
Chris@322 75 if (merge) {
Chris@322 76 templates.push_back(t);
Chris@322 77 }
Chris@322 78
Chris@322 79 // re-normalise
Chris@327 80
Chris@322 81 for (auto &t: templates) {
Chris@322 82 for (auto &d: t.data) {
Chris@322 83 float sum = 0.f;
Chris@322 84 for (auto v: d) sum += v;
Chris@322 85 for (auto &v: d) v /= sum;
Chris@315 86 }
Chris@298 87 }
Chris@327 88
Chris@298 89 InstrumentPack live(original.lowestNote,
Chris@298 90 original.highestNote,
Chris@298 91 original.name,
Chris@298 92 templates);
Chris@298 93
Chris@327 94 live.templateHeight = height;
Chris@298 95 live.templateMaxShift = 0;
Chris@327 96 live.templateSize = height;
Chris@298 97
Chris@298 98 live.maxPolyphony = original.maxPolyphony;
Chris@298 99 live.pitchSparsity = original.pitchSparsity;
Chris@298 100 live.sourceSparsity = original.sourceSparsity;
Chris@327 101 live.levelThreshold = original.levelThreshold / 20;
Chris@298 102
Chris@298 103 return live;
Chris@298 104 }
Chris@298 105
Chris@298 106 vector<InstrumentPack>
Chris@298 107 LiveAdapter::adaptAll(const vector<InstrumentPack> &v)
Chris@298 108 {
Chris@298 109 vector<InstrumentPack> out;
Chris@298 110 for (int i = 0; i < (int)v.size(); ++i) {
Chris@298 111 InstrumentPack p(LiveAdapter::adapt(v[i]));
Chris@298 112 out.push_back(p);
Chris@298 113 }
Chris@298 114 return out;
Chris@298 115 }