commit 9155c5299850ef2f18250d066221f169d00db2ed
Author: jtothebell <j.to.the.bell@gmail.com>
AuthorDate: Fri Jun 18 22:55:28 2021 -0600
Commit: jtothebell <j.to.the.bell@gmail.com>
CommitDate: Fri Jun 18 22:55:28 2021 -0600
implement audio stat calls
---
source/Audio.cpp | 22 ++++++++++++++++++++++
source/Audio.h | 6 ++++++
source/picoluaapi.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 77 insertions(+)
diff --git a/source/Audio.cpp b/source/Audio.cpp
index c9bb01b..5319303 100644
--- a/source/Audio.cpp
+++ b/source/Audio.cpp
@@ -213,6 +213,28 @@ static float key_to_freq(float key)
return 440.f * exp2((key - 33.f) / 12.f);
}
+int16_t Audio::getCurrentSfxId(int channel){
+ return _audioState._sfxChannels[channel].sfxId;
+}
+
+int Audio::getCurrentNoteNumber(int channel){
+ return _audioState._sfxChannels[channel].sfxId < 0
+ ? -1
+ : _audioState._sfxChannels[channel].offset;
+}
+
+int16_t Audio::getCurrentMusic(){
+ return _audioState._musicChannel.pattern;
+}
+
+int16_t Audio::getMusicPatternCount(){
+ return _audioState._musicChannel.count;
+}
+
+int16_t Audio::getMusicTickCount(){
+ return _audioState._musicChannel.offset * _audioState._musicChannel.speed;
+}
+
//adapted from zepto8 sfx.cpp (wtfpl license)
int16_t Audio::getSampleForChannel(int channel){
using std::fabs;
diff --git a/source/Audio.h b/source/Audio.h
index c6482b0..8ca851d 100644
--- a/source/Audio.h
+++ b/source/Audio.h
@@ -91,6 +91,12 @@ class Audio {
void api_sfx(int sfx, int channel, int offset);
void api_music(int pattern, int16_t fade_len, int16_t mask);
+ int16_t getCurrentSfxId(int channel);
+ int getCurrentNoteNumber(int channel);
+ int16_t getCurrentMusic();
+ int16_t getMusicPatternCount();
+ int16_t getMusicTickCount();
+
void FillAudioBuffer(void *audioBuffer,size_t offset, size_t size);
};
diff --git a/source/picoluaapi.cpp b/source/picoluaapi.cpp
index 2e5ec02..2fc0ce4 100644
--- a/source/picoluaapi.cpp
+++ b/source/picoluaapi.cpp
@@ -798,6 +798,55 @@ int stat(lua_State *L) {
lua_pushnumber(L, _vmForLuaApi->getTargetFps());
return 1;
break;
+ //16-19 audio sfx currently playing
+ case 16:
+ lua_pushnumber(L, _audioForLuaApi->getCurrentSfxId(0));
+ return 1;
+ break;
+ case 17:
+ lua_pushnumber(L, _audioForLuaApi->getCurrentSfxId(1));
+ return 1;
+ break;
+ case 18:
+ lua_pushnumber(L, _audioForLuaApi->getCurrentSfxId(2));
+ return 1;
+ break;
+ case 19:
+ lua_pushnumber(L, _audioForLuaApi->getCurrentSfxId(3));
+ return 1;
+ break;
+ //20-23 note idx of sfx currently playing
+ case 20:
+ lua_pushnumber(L, _audioForLuaApi->getCurrentNoteNumber(0));
+ return 1;
+ break;
+ case 21:
+ lua_pushnumber(L, _audioForLuaApi->getCurrentNoteNumber(1));
+ return 1;
+ break;
+ case 22:
+ lua_pushnumber(L, _audioForLuaApi->getCurrentNoteNumber(2));
+ return 1;
+ break;
+ case 23:
+ lua_pushnumber(L, _audioForLuaApi->getCurrentNoteNumber(3));
+ return 1;
+ break;
+ //current music pattern
+ case 24:
+ lua_pushnumber(L, _audioForLuaApi->getCurrentMusic());
+ return 1;
+ break;
+ //current music count
+ case 25:
+ lua_pushnumber(L, _audioForLuaApi->getMusicPatternCount());
+ return 1;
+ break;
+ //current music tick count
+ case 26:
+ lua_pushnumber(L, _audioForLuaApi->getMusicTickCount());
+ return 1;
+ break;
//was a key pressed (always false)
case 30:
lua_pushboolean(L, false);