| ... | ... |
@@ -9,8 +9,8 @@ SampleData::SampleData() |
| 9 | 9 |
// initializers only |
| 10 | 10 |
} |
| 11 | 11 |
|
| 12 |
-SampleData::SampleData(uint32_t baseAddr, uint16_t loopStart, uint32_t loopLength, Format format) |
|
| 13 |
-: std::vector<int32_t>(), baseAddr(baseAddr), loopStart(loopStart), loopLength(loopLength) |
|
| 12 |
+SampleData::SampleData(uint32_t _baseAddr, uint16_t _loopStart, uint32_t _loopLength, Format format) |
|
| 13 |
+: std::vector<int32_t>(), baseAddr(_baseAddr), loopStart(_loopStart), loopLength(_loopLength) |
|
| 14 | 14 |
{
|
| 15 | 15 |
if (format == Pcm8) {
|
| 16 | 16 |
loadPcm8(); |
| ... | ... |
@@ -25,11 +25,11 @@ void SampleData::loadPcm8() |
| 25 | 25 |
{
|
| 26 | 26 |
loopStart += 3; |
| 27 | 27 |
resize(loopStart + (loopLength << 2)); |
| 28 |
- for (int i = 3; i < loopStart; i++) {
|
|
| 28 |
+ for (uint32_t i = 3; i < loopStart; i++) {
|
|
| 29 | 29 |
(*this)[i] = int8_t(_MMU_read08<ARMCPU_ARM7, MMU_AT_DEBUG>(baseAddr + i - 3)) << 8; |
| 30 | 30 |
} |
| 31 | 31 |
uint32_t length = loopStart + loopLength; |
| 32 |
- for (int i = loopStart; i < length; i++) {
|
|
| 32 |
+ for (uint32_t i = loopStart; i < length; i++) {
|
|
| 33 | 33 |
(*this)[i] = (*this)[length + i] = int8_t(_MMU_read08<ARMCPU_ARM7, MMU_AT_DEBUG>(baseAddr + i - 3)) << 8; |
| 34 | 34 |
} |
| 35 | 35 |
} |
| ... | ... |
@@ -41,12 +41,12 @@ void SampleData::loadPcm16() |
| 41 | 41 |
loopStart += 3; |
| 42 | 42 |
resize(loopStart + (loopLength << 2)); |
| 43 | 43 |
uint32_t addr = baseAddr; |
| 44 |
- for (int i = 3; i < loopStart; i++) {
|
|
| 44 |
+ for (uint32_t i = 3; i < loopStart; i++) {
|
|
| 45 | 45 |
(*this)[i] = int16_t(_MMU_read16<ARMCPU_ARM7, MMU_AT_DEBUG>(addr)); |
| 46 | 46 |
addr += 2; |
| 47 | 47 |
} |
| 48 | 48 |
uint32_t length = loopStart + loopLength; |
| 49 |
- for (int i = loopStart; i < length; i++) {
|
|
| 49 |
+ for (uint32_t i = loopStart; i < length; i++) {
|
|
| 50 | 50 |
(*this)[i] = (*this)[length + i] = int16_t(_MMU_read16<ARMCPU_ARM7, MMU_AT_DEBUG>(addr)); |
| 51 | 51 |
addr += 2; |
| 52 | 52 |
} |
| ... | ... |
@@ -62,8 +62,8 @@ void SampleData::loadAdpcm() |
| 62 | 62 |
int16_t(_MMU_read16<ARMCPU_ARM7, MMU_AT_DEBUG>(baseAddr)), |
| 63 | 63 |
int16_t(_MMU_read16<ARMCPU_ARM7, MMU_AT_DEBUG>(baseAddr + 2)) |
| 64 | 64 |
); |
| 65 |
- int j = 11; |
|
| 66 |
- for (int i = 4; i < length; i++) {
|
|
| 65 |
+ uint32_t j = 11; |
|
| 66 |
+ for (uint32_t i = 4; i < length; i++) {
|
|
| 67 | 67 |
uint8_t data = uint8_t(_MMU_read08<ARMCPU_ARM7, MMU_AT_DEBUG>(baseAddr + i)); |
| 68 | 68 |
(*this)[j++] = adpcm.getNextSample(uint8_t(data & 0x0f)); |
| 69 | 69 |
(*this)[j++] = adpcm.getNextSample(uint8_t(data & 0xf0) >> 4); |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,86 @@ |
| 1 |
+#include "sampledata.h" |
|
| 2 |
+#include "adpcmdecoder.h" |
|
| 3 |
+#include "interpolator.h" |
|
| 4 |
+#include "../desmume/MMU.h" |
|
| 5 |
+ |
|
| 6 |
+SampleData::SampleData() |
|
| 7 |
+: std::vector<int32_t>(), baseAddr(0), loopStart(0), loopLength(0) |
|
| 8 |
+{
|
|
| 9 |
+ // initializers only |
|
| 10 |
+} |
|
| 11 |
+ |
|
| 12 |
+SampleData::SampleData(uint32_t baseAddr, uint16_t loopStart, uint32_t loopLength, Format format) |
|
| 13 |
+: std::vector<int32_t>(), baseAddr(baseAddr), loopStart(loopStart), loopLength(loopLength) |
|
| 14 |
+{
|
|
| 15 |
+ if (format == Pcm8) {
|
|
| 16 |
+ loadPcm8(); |
|
| 17 |
+ } else if (format == Pcm16) {
|
|
| 18 |
+ loadPcm16(); |
|
| 19 |
+ } else {
|
|
| 20 |
+ loadAdpcm(); |
|
| 21 |
+ } |
|
| 22 |
+} |
|
| 23 |
+ |
|
| 24 |
+void SampleData::loadPcm8() |
|
| 25 |
+{
|
|
| 26 |
+ loopStart += 3; |
|
| 27 |
+ resize(loopStart + (loopLength << 2)); |
|
| 28 |
+ for (int i = 3; i < loopStart; i++) {
|
|
| 29 |
+ (*this)[i] = int8_t(_MMU_read08<ARMCPU_ARM7, MMU_AT_DEBUG>(baseAddr + i - 3)) << 8; |
|
| 30 |
+ } |
|
| 31 |
+ uint32_t length = loopStart + loopLength; |
|
| 32 |
+ for (int i = loopStart; i < length; i++) {
|
|
| 33 |
+ (*this)[i] = (*this)[length + i] = int8_t(_MMU_read08<ARMCPU_ARM7, MMU_AT_DEBUG>(baseAddr + i - 3)) << 8; |
|
| 34 |
+ } |
|
| 35 |
+} |
|
| 36 |
+ |
|
| 37 |
+void SampleData::loadPcm16() |
|
| 38 |
+{
|
|
| 39 |
+ loopStart >>= 1; |
|
| 40 |
+ loopLength >>= 1; |
|
| 41 |
+ loopStart += 3; |
|
| 42 |
+ resize(loopStart + (loopLength << 2)); |
|
| 43 |
+ uint32_t addr = baseAddr; |
|
| 44 |
+ for (int i = 3; i < loopStart; i++) {
|
|
| 45 |
+ (*this)[i] = int16_t(_MMU_read16<ARMCPU_ARM7, MMU_AT_DEBUG>(addr)); |
|
| 46 |
+ addr += 2; |
|
| 47 |
+ } |
|
| 48 |
+ uint32_t length = loopStart + loopLength; |
|
| 49 |
+ for (int i = loopStart; i < length; i++) {
|
|
| 50 |
+ (*this)[i] = (*this)[length + i] = int16_t(_MMU_read16<ARMCPU_ARM7, MMU_AT_DEBUG>(addr)); |
|
| 51 |
+ addr += 2; |
|
| 52 |
+ } |
|
| 53 |
+} |
|
| 54 |
+ |
|
| 55 |
+void SampleData::loadAdpcm() |
|
| 56 |
+{
|
|
| 57 |
+ uint32_t length = loopStart + loopLength; |
|
| 58 |
+ loopStart = ((loopStart - 4) << 1) + 11; |
|
| 59 |
+ loopLength <<= 1; |
|
| 60 |
+ resize(loopStart + (loopLength << 2)); |
|
| 61 |
+ AdpcmDecoder adpcm( |
|
| 62 |
+ int16_t(_MMU_read16<ARMCPU_ARM7, MMU_AT_DEBUG>(baseAddr)), |
|
| 63 |
+ int16_t(_MMU_read16<ARMCPU_ARM7, MMU_AT_DEBUG>(baseAddr + 2)) |
|
| 64 |
+ ); |
|
| 65 |
+ int j = 11; |
|
| 66 |
+ for (int i = 4; i < length; i++) {
|
|
| 67 |
+ uint8_t data = uint8_t(_MMU_read08<ARMCPU_ARM7, MMU_AT_DEBUG>(baseAddr + i)); |
|
| 68 |
+ (*this)[j++] = adpcm.getNextSample(uint8_t(data & 0x0f)); |
|
| 69 |
+ (*this)[j++] = adpcm.getNextSample(uint8_t(data & 0xf0) >> 4); |
|
| 70 |
+ } |
|
| 71 |
+ uint32_t loopEnd = loopStart + loopLength; |
|
| 72 |
+ for (j = loopStart; j < loopEnd; j++) {
|
|
| 73 |
+ (*this)[j + loopLength] = (*this)[j]; |
|
| 74 |
+ } |
|
| 75 |
+} |
|
| 76 |
+ |
|
| 77 |
+int32_t SampleData::sampleAt(double time, IInterpolator* interp) const |
|
| 78 |
+{
|
|
| 79 |
+ if (!baseAddr) {
|
|
| 80 |
+ return 0; |
|
| 81 |
+ } |
|
| 82 |
+ if (!interp) {
|
|
| 83 |
+ return (*this)[uint32_t(time)]; |
|
| 84 |
+ } |
|
| 85 |
+ return interp->interpolate(*this, time); |
|
| 86 |
+} |