diff --git a/include/modules/audio/wrap_Source.hpp b/include/modules/audio/wrap_Source.hpp index b812115c..4de5ccaf 100644 --- a/include/modules/audio/wrap_Source.hpp +++ b/include/modules/audio/wrap_Source.hpp @@ -21,4 +21,6 @@ namespace Wrap_Source int stop(lua_State* L); int setLooping(lua_State* L); + + int tell(lua_State* L); } // namespace Wrap_Source diff --git a/platform/cafe/include/driver/DigitalSound.hpp b/platform/cafe/include/driver/DigitalSound.hpp index 7fbd58b2..378be9e4 100644 --- a/platform/cafe/include/driver/DigitalSound.hpp +++ b/platform/cafe/include/driver/DigitalSound.hpp @@ -144,8 +144,14 @@ namespace love if (auto result = AXSetVoiceSrcRatio(this->buffers[index], ratio); result != 0) return false; + AXSetVoiceCurrentOffset(this->buffers[index], 0); AXSetVoiceSrcType(this->buffers[index], AX_VOICE_SRC_TYPE_LINEAR); - this->buffers[index]->offsets.dataType = (AXVoiceFormat)format; + + AXVoiceOffsets offsets {}; + AXGetVoiceOffsets(this->buffers[index], &offsets); + + offsets.dataType = (AXVoiceFormat)format; + AXSetVoiceOffsets(this->buffers[index], &offsets); AXVoiceEnd(this->buffers[index]); } diff --git a/platform/cafe/include/driver/DigitalSoundMix.hpp b/platform/cafe/include/driver/DigitalSoundMix.hpp index a6e24085..ad411fcb 100644 --- a/platform/cafe/include/driver/DigitalSoundMix.hpp +++ b/platform/cafe/include/driver/DigitalSoundMix.hpp @@ -29,7 +29,8 @@ static AXVoiceDeviceMixData STEREO_MIX[2][AX_NUM_CHANNELS] = } }; -static AXVoiceDeviceMixData MONO_MIX[1][AX_NUM_CHANNELS] = { +static AXVoiceDeviceMixData MONO_MIX[1][AX_NUM_CHANNELS] = +{ { // AX_VOICE(0) { // AX_CHANNEL_LEFT .bus = { { .volume = 0x8000 } } diff --git a/platform/cafe/source/driver/DigitalSound.cpp b/platform/cafe/source/driver/DigitalSound.cpp index 2127c2a0..076cc4fc 100644 --- a/platform/cafe/source/driver/DigitalSound.cpp +++ b/platform/cafe/source/driver/DigitalSound.cpp @@ -84,9 +84,9 @@ namespace love if (buffer == nullptr || data == nullptr) return; - AXVoiceBegin(buffer); + DCFlushRange(data, size); - DCStoreRange(data, size); + AXVoiceBegin(buffer); AXSetVoiceState(buffer, AX_VOICE_STATE_STOPPED); AXSetVoiceLoop(buffer, looping ? AX_VOICE_LOOP_ENABLED : AX_VOICE_LOOP_DISABLED); @@ -97,6 +97,7 @@ namespace love offsets.data = (int16_t*)data; offsets.currentOffset = 0; offsets.endOffset = nsamples; + offsets.loopOffset = 0; AXSetVoiceOffsets(buffer, &offsets); diff --git a/source/modules/audio/wrap_Source.cpp b/source/modules/audio/wrap_Source.cpp index ee4aa419..fe92898e 100644 --- a/source/modules/audio/wrap_Source.cpp +++ b/source/modules/audio/wrap_Source.cpp @@ -52,6 +52,21 @@ int Wrap_Source::setLooping(lua_State* L) return 0; } +int Wrap_Source::tell(lua_State* L) +{ + auto* self = luax_checksource(L, 1); + + auto type = Source::UNIT_SECONDS; + const char* name = lua_isnoneornil(L, 2) ? nullptr : lua_tostring(L, 2); + + if (name && !Source::getConstant(name, type)) + return luax_enumerror(L, "time unit", Source::SourceUnits, name); + + lua_pushnumber(L, self->tell(type)); + + return 1; +} + // clang-format off static constexpr luaL_Reg functions[] = { @@ -59,7 +74,8 @@ static constexpr luaL_Reg functions[] = { "play", Wrap_Source::play }, { "pause", Wrap_Source::pause }, { "stop", Wrap_Source::stop }, - { "setLooping", Wrap_Source::setLooping } + { "setLooping", Wrap_Source::setLooping }, + { "tell", Wrap_Source::tell } }; // clang-format on