/[svn]/linuxsampler/trunk/src/engines/sfz/LookupTable.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/engines/sfz/LookupTable.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2106 - (show annotations) (download) (as text)
Sun Jul 4 12:50:51 2010 UTC (13 years, 9 months ago) by persson
File MIME type: text/x-c++hdr
File size: 4138 byte(s)
* sfz engine: optimized sample lookup
* sfz engine: fixed bug introduced in previous commit: sample lookup
  returned wrong sample

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2010 Andreas Persson *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the Free Software *
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
20 * MA 02110-1301 USA *
21 ***************************************************************************/
22
23 #ifndef SFZ_LOOKUPTABLE_H
24 #define SFZ_LOOKUPTABLE_H
25
26 #include <vector>
27
28 #include "sfz.h"
29 #include "../../common/ArrayList.h"
30
31 namespace sfz {
32
33 /**
34 * Lookup table for fast access to regions in an sfz instrument.
35 *
36 * The table is organized in two levels. First, the values of the
37 * dimensions actually in use by the instrument (could be key,
38 * velocity, controller values, etc) are used as indexes in a set
39 * of integer arrays. The resulting integers are then added
40 * together and the sum is used as an index in an array of lists
41 * of regions.
42 *
43 * The first level is used to make the second array smaller. An
44 * instrument with three key zones and two velocity zones will
45 * have two integer arrays, each of size 128, one for key number,
46 * one for velocity. The region array only needs to be six items
47 * big, as there are only 2 * 3 possible zone variations.
48 */
49 class LookupTable {
50 public:
51 LookupTable(const Instrument* instrument);
52 ~LookupTable();
53
54 /**
55 * Performs a lookup in the table of regions.
56 *
57 * @param q - query with constraints on key, velocity, etc.
58 * @returns list of regions matching the query
59 */
60 LinuxSampler::ArrayList<Region*>& query(const Query& q) const;
61
62 private:
63 struct DimDef;
64
65 static const DimDef dimDefs[]; // list of possible dimensions
66 std::vector<int> dims; // dimensions used by the instrument
67
68 // control change dimensions used by the instrument
69 std::vector<int> ccs;
70
71 // arrays mapping dimension values to regionArr offsets
72 int** mapArr;
73
74 // second level array with lists of regions
75 LinuxSampler::ArrayList<Region*>* regionArr;
76
77 // pointers to used dimension arguments in the Query object
78 const uint8_t Query::** qargs;
79
80 // array with CCs used by the instrument
81 int* ccargs;
82
83
84 // helper functions for the constructor
85 static int fillMapArr(const std::vector<Region*>& regions,
86 const int Definition::* lo,
87 const int Definition::* hi,
88 int min, int max, int* a);
89 static int fillMapArr(const std::vector<Region*>& regions,
90 int cc, int* a);
91 void fillRegionArr(const int* len, Region* region,
92 std::vector<int>::size_type dim, int j);
93 };
94 }
95
96 #endif

  ViewVC Help
Powered by ViewVC