comparison src/EM.cpp @ 161:6003a9af43af

Introduce InstrumentPack class
author Chris Cannam
date Tue, 20 May 2014 15:31:05 +0100
parents fc06b6f33021
children 629c9525b815
comparison
equal deleted inserted replaced
160:58547262e735 161:6003a9af43af
13 COPYING included with this distribution for more information. 13 COPYING included with this distribution for more information.
14 */ 14 */
15 15
16 #include "EM.h" 16 #include "EM.h"
17 17
18 #include "data/include/templates.h"
19
20 #include <cstdlib> 18 #include <cstdlib>
21 #include <cmath> 19 #include <cmath>
22 20
23 #include <iostream> 21 #include <iostream>
24 22
25 #include "VectorOps.h" 23 #include "VectorOps.h"
26 #include "Allocators.h" 24 #include "Allocators.h"
25 #include "Instruments.h"
27 26
28 using std::vector; 27 using std::vector;
29 using std::cerr; 28 using std::cerr;
30 using std::endl; 29 using std::endl;
31 30
32 using namespace breakfastquay; 31 using namespace breakfastquay;
33 32
34 static float epsilon = 1e-10; 33 static float epsilon = 1e-10;
35 34
36 EM::EM(bool useShifts) : 35 EM::EM(const InstrumentPack *pack, bool useShifts) :
37 m_noteCount(SILVET_TEMPLATE_NOTE_COUNT), 36 m_pack(pack),
38 m_shiftCount(useShifts ? SILVET_TEMPLATE_MAX_SHIFT * 2 + 1 : 1), 37 m_noteCount(pack->templateNoteCount),
39 m_binCount(SILVET_TEMPLATE_HEIGHT), 38 m_shiftCount(useShifts ? pack->templateMaxShift * 2 + 1 : 1),
40 m_sourceCount(SILVET_TEMPLATE_COUNT), 39 m_binCount(pack->templateHeight),
40 m_sourceCount(pack->templates.size()),
41 m_pitchSparsity(1.1), 41 m_pitchSparsity(1.1),
42 //!!! note: slightly less source sparsity might help; also 42 //!!! note: slightly less source sparsity might help; also
43 //!!! consider a modest shift sparsity e.g. 1.1 43 //!!! consider a modest shift sparsity e.g. 1.1
44 m_sourceSparsity(1.3), 44 m_sourceSparsity(1.3),
45 m_lowestPitch(silvet_templates_lowest_note), 45 m_lowestPitch(pack->lowestNote),
46 m_highestPitch(silvet_templates_highest_note) 46 m_highestPitch(pack->highestNote)
47 { 47 {
48 m_pitches = allocate<float>(m_noteCount); 48 m_pitches = allocate<float>(m_noteCount);
49 m_updatePitches = allocate<float>(m_noteCount); 49 m_updatePitches = allocate<float>(m_noteCount);
50 for (int n = 0; n < m_noteCount; ++n) { 50 for (int n = 0; n < m_noteCount; ++n) {
51 m_pitches[n] = drand48(); 51 m_pitches[n] = drand48();
89 } 89 }
90 90
91 void 91 void
92 EM::rangeFor(int instrument, int &minPitch, int &maxPitch) 92 EM::rangeFor(int instrument, int &minPitch, int &maxPitch)
93 { 93 {
94 minPitch = silvet_templates[instrument].lowest; 94 minPitch = m_pack->templates[instrument].lowestNote;
95 maxPitch = silvet_templates[instrument].highest; 95 maxPitch = m_pack->templates[instrument].highestNote;
96 } 96 }
97 97
98 bool 98 bool
99 EM::inRange(int instrument, int pitch) 99 EM::inRange(int instrument, int pitch)
100 { 100 {
140 } 140 }
141 141
142 const float * 142 const float *
143 EM::templateFor(int instrument, int note, int shift) 143 EM::templateFor(int instrument, int note, int shift)
144 { 144 {
145 const float *base = m_pack->templates.at(instrument).data.at(note).data();
145 if (m_shifts) { 146 if (m_shifts) {
146 return silvet_templates[instrument].data[note] + shift; 147 return base + shift;
147 } else { 148 } else {
148 return silvet_templates[instrument].data[note] + 149 return base + m_pack->templateMaxShift;
149 SILVET_TEMPLATE_MAX_SHIFT;
150 } 150 }
151 } 151 }
152 152
153 void 153 void
154 EM::expectation(const float *column) 154 EM::expectation(const float *column)