Browse code

update for C++17 compliance, update to latest 2sf, add WINE cross-compile makefiles

Adam Higerd authored on 2021/02/11 15:36:17
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,32 @@
1
+#include "samplecache.h"
2
+
3
+static inline constexpr uint64_t makeKey(uint32_t base, uint16_t loop, uint32_t length)
4
+{
5
+  return
6
+    // has to be 32-bit aligned, so 2 low bits aren't needed
7
+    // has to fit in the memory map, so high 7 bits aren't needed
8
+    (uint64_t(base & 0x01FFFFFC) >> 2) |
9
+    // loop uses the full 16 bits
10
+    uint64_t(loop << 23) |
11
+    // max length is 21 bits
12
+    (uint64_t(length & 0x1FFFFF) << 39);
13
+}
14
+
15
+const SampleData& SampleCache::getSample(uint32_t baseAddr, uint16_t loopStartWords, uint32_t loopLengthWords, SampleData::Format format)
16
+{
17
+  uint64_t key = makeKey(baseAddr, loopStartWords, loopLengthWords);
18
+  auto iter = samples.find(key);
19
+  if (iter == samples.end()) {
20
+    iter = samples.emplace(
21
+      std::piecewise_construct,
22
+      std::forward_as_tuple(key),
23
+      std::forward_as_tuple(baseAddr, loopStartWords << 2, (loopStartWords + loopLengthWords) << 2, format)
24
+    ).first;
25
+  }
26
+  return iter->second;
27
+}
28
+
29
+void SampleCache::clear()
30
+{
31
+  samples.clear();
32
+}