commit 756e0b376e71aecc515638a68be5b819c6b52bcc
Author: DPS2004 <dpsophinos@gmail.com>
AuthorDate: Wed Mar 9 15:53:11 2022 -0500
Commit: DPS2004 <dpsophinos@gmail.com>
CommitDate: Wed Mar 9 15:53:11 2022 -0500
fix pattern playback with a nonstandard length
---
platform/windows/FAKE08.exe | Bin 0 -> 8375815 bytes
platform/windows/FAKE08.exe.stackdump | 24 ++++++++++++++++++++++++
source/Audio.cpp | 15 ++++++++++++++-
source/PicoRam.h | 1 +
4 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/platform/windows/FAKE08.exe b/platform/windows/FAKE08.exe
new file mode 100644
index 0000000..6e0d754
Binary files /dev/null and b/platform/windows/FAKE08.exe differ
diff --git a/platform/windows/FAKE08.exe.stackdump b/platform/windows/FAKE08.exe.stackdump
new file mode 100644
index 0000000..48031b5
--- /dev/null
+++ b/platform/windows/FAKE08.exe.stackdump
@@ -0,0 +1,24 @@
+Stack trace:
+Frame Function Args
+000FFFFB800 00180062C27 (000FFFFBA08, 00000000002, 00000000002, 000FFFFDE50)
+00000000000 00180064CE5 (00000000064, 00000000000, 00000000A0C, 00000000000)
+000FFFFBF10 00180134268 (00000000000, 00000000000, 00000000073, 000FFFFFFFF)
+00000000041 0018012F99B (00000000000, 00000000000, 00000000000, 00000000000)
+000FFFFC2E0 0018012FDA5 (00000000D21, 000FFFFC2C0, 00000000000, 000FFFFC2E0)
+000FFFFC2E0 00180216CC8 (001004DB24F, 000FFFFC2E0, 00000000037, 0080013EB48)
+000FFFFC2E0 0010040372B (05D00000002, 00000000000, 00000000000, 00000000000)
+000FFFFC340 0010040C853 (0080013EB48, 000FFFFC3C0, 00000000000, 0080010FFD0)
+000FFFFC380 0010040C8AC (001004DB1B0, 001004DB1F8, 001004DB08C, 008000E2CE8)
+000FFFFC3E0 0010041024F (0080012A350, 001004DB1F8, 00800071580, 00000000000)
+000FFFFC430 001004124AD (0080012A350, 0080012A350, 0080012A370, 0080000000D)
+000FFFFC4C0 00100403FEE (0080012A370, 0080012A350, 0080012A370, 0000000000D)
+000FFFFC550 00100409307 (0080012A2D0, 00000000000, 0010040DEFF, 000FFFFCA50)
+000FFFFCA10 0010041EEFC (0080012A2D0, 00800000000, 00800000000, 0080006D8E0)
+000FFFFCA50 0010041FC68 (00100000000, 00000000000, 00000000000, 00000000000)
+000FFFFCAC0 0010045405A (0080000001E, 0080008C8A0, 000FFFFCB00, 0080008C8A0)
+000FFFFCB10 001004551D8 (00000000000, 000FFFFC884, 00000000000, 0080006E650)
+000FFFFCBC0 001004A42F7 (000FFFFCC20, 000FFFFCC30, 00100000002, 00180326FE0)
+000FFFFCD30 00180049B91 (00000000000, 00000000000, 00000000000, 00000000000)
+000FFFFFFF0 00180047716 (00000000000, 00000000000, 00000000000, 00000000000)
+000FFFFFFF0 001800477C4 (00000000000, 00000000000, 00000000000, 00000000000)
+End of stack trace
diff --git a/source/Audio.cpp b/source/Audio.cpp
index 1098e7c..3d943fe 100644
--- a/source/Audio.cpp
+++ b/source/Audio.cpp
@@ -9,6 +9,8 @@
#include <cmath>
#include <float.h> // std::max
+
+
//playback implemenation based on zetpo 8's
//https://github.com/samhocevar/zepto8/blob/master/src/pico8/sfx.cpp
@@ -152,7 +154,9 @@ void Audio::set_music_pattern(int pattern) {
};
// Find music speed; it’s the speed of the fastest sfx
+ // While we are looping through this, find the lowest *valid* sfx length
_audioState._musicChannel.master = _audioState._musicChannel.speed = -1;
+ _audioState._musicChannel.length = 32; //as far as i can tell, there is no way to make an sfx longer than 32.
for (int i = 0; i < 4; ++i)
{
uint8_t n = channels[i];
@@ -166,7 +170,16 @@ void Audio::set_music_pattern(int pattern) {
_audioState._musicChannel.master = i;
_audioState._musicChannel.speed = std::max(1, (int)sfx.speed);
}
+
+ if(sfx.loopRangeStart != 0 && sfx.loopRangeEnd == 0){
+ _audioState._musicChannel.length = std::min(_audioState._musicChannel.length, sfx.loopRangeStart);
+ }
+
+
+
}
+
+
// Play music sfx on active channels
for (int i = 0; i < 4; ++i)
@@ -289,7 +302,7 @@ int16_t Audio::getSampleForChannel(int channel){
}
_audioState._musicChannel.pattern = -1;
}
- else if (_audioState._musicChannel.offset >= 32.f)
+ else if (_audioState._musicChannel.offset >= _audioState._musicChannel.length)
{
int16_t next_pattern = _audioState._musicChannel.pattern + 1;
int16_t next_count = _audioState._musicChannel.count + 1;
diff --git a/source/PicoRam.h b/source/PicoRam.h
index 8df5ccd..a5d2eb3 100644
--- a/source/PicoRam.h
+++ b/source/PicoRam.h
@@ -127,6 +127,7 @@ struct musicChannel {
float volume = 0.f;
float volume_step = 0.f;
float offset = 0.f;
+ uint8_t length = 0;
};
struct sfxChannel {