mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-05-30 16:35:26 -04:00
b289dece80
* fix kankyo UB
* Fix TEV Stage DL writing
BE issue
* BE Fixes in materials/shapes
* Move to Aurora GD impl
* JUTDataFileHeader
* j3d: load vertex and texture not through GD
* Endian swap vertex data (mostly)
* Just exit(0) when closing the game
Fix crashes :godo:
* fix fopAcM_ct_placement and remove memcpy
* J3D: track vertex arrays correctly, swap work
* fix visibility, turn off overridden new/delete when we call into aurora
* event: cut name be
* Default window improvements
Double size, allow OS to decide position
* survive TParse::parseHeader_next
* color swap fix
* swap endian/fixes oob function pointer
* Remove GXGetViewportv stub
Aurora has it now
* Set array pointers via GD again
Relies on https://github.com/encounter/aurora/pull/35
* Let Aurora decide graphics backend
* disable procbar drawing
* Fix TColor endianness conversion issues
Fixes the wrong color for the flashing logo
* cam param swap
* simplify vtx loading, mat/amb color fix
* endian swap stb/fvb data
* aurora stat changes
* fix storage buffer crash
dont unnecessarily reassign vertex buffers in a way that forces aurora to recache things
* set bgobj spec fix
* add camera debug, endian swap more stb data, d_a_bg_obj::spec_data_c swapped
* JKRExpHeap: fix bad allocator slowdown
* solid tex
* texture caching
* log level
* fix window aspect ratio, disable bloom, endian swap camera type data
camera is now actually playing opening cutscene!!!!
* add GXDestroyTexObj to a couple stack init'd GXTexObjs, remove some diag printfs
* endian swap joint weight envelope data
* move to dusk config
* verbose arg errors
* better stub logging (for now)
* less logging, more BE
* more stubbing, move logging stuff around
* move all logging to aurora logging
* fix STUB_LOG, __FUNCTION__ isn't a string literal, wasn't building as it
was.
* update aurora
* fix heap alignment mismatch and always head align for now
* prevent them from fucking up my shit
* forward jut warning to DuskLog
* remove report logging
* maybe and i must emphasize maybe fix JMessage parsing
* this was a dumb idea
* preserve negative alignment for JKRHeap
* use normal free on macos and linux
* ^
* fix JMAHermiteInterpolation c impl
* endian swap J2DScreen mColor (oops)
* swap more J3D anim data, remove weird pointer addr check in J3DMaterial getMaterialAnm
* typo fix
* Fix aligned_alloc() size issues on POSIX
aligned_alloc() requires its input size to be a multiple of alignment. This wasn't being upheld so there were allocation failures in init code that made the game fail to start outside Windows.
Also just cleaned up some of this code a bit and removed fallback cases that *shouldn't* get hit.
* _Exit instead of exit()
Seriously I don't want destructors to run. Let the OS reclaim that shit.
* Reapply "Isolate JKRHeap operator overloads" (#39)
This reverts commit 3623b27f37.
* Fix some oopsies
* Fix hardcoded pointer size in JUTCacheFont::allocArray
* More operator overload fixes
Add void template specialization for jkrDelete
Add new[] placement overload. Apparently.
* Fix delete macros on nullptr
TIL C++ allows that.
* fix delete[]
* fix new(std::nothrow) overload
* fix avoid ub
* swap remaining anim data needed for title logo
* get rid of op 7
* move aurora_end_frame to correct spot
* juttexture destroy tex
* j2d animation be
* shutdown crash
* link warp material fix
* mDoExt_3DlineMat1_c fix
* hacky keyboard controls
* endian swap J2DResReference, add kb_pad to files.cmake
* fix some missing endian swaps in J2D, remove addr alignment check
* Remove heap unsetting in aurora calls
Never worked properly and not the right solution even if it did
* Don't print in DC stubs
They're fine to never implement
* Fix alignment stuff again
* Compile GF from dolphin lib
Doesn't seem to break anything and shuts up some stub warnings
* j3dtexture tlut obj fix
* addTexMtxIndexInDL fix
* don't recreate null tex data every frame
* the actual fix i wanted to push
* its kinda fakematch city over here
* insert hte efb copy
* limited window size / viewport support
* IsDelete FIX
---------
Co-authored-by: madeline <qwertytrogi@gmail.com>
Co-authored-by: Jasper St. Pierre <jstpierre@mecheye.net>
Co-authored-by: Jeffrey Crowell <jeff@crowell.biz>
Co-authored-by: TakaRikka <takarikka@outlook.com>
Co-authored-by: CraftyBoss <talibabdulmaalik@gmail.com>
Co-authored-by: Lurs <2795933+Lurs@users.noreply.github.com>
451 lines
11 KiB
C++
451 lines
11 KiB
C++
#include "Z2AudioCS/SpkSound.h"
|
|
|
|
#include "Z2AudioCS/SpkSpeakerCtrl.h"
|
|
#include "Z2AudioCS/SpkSystem.h"
|
|
#include "JSystem/JAudio2/JASCriticalSection.h"
|
|
#include "JSystem/JAudio2/JASHeapCtrl.h"
|
|
|
|
#define SPK_SOUND_MIX_STEP 40
|
|
|
|
enum SpkSoundState {
|
|
SpkSoundState_STARTING_e,
|
|
SpkSoundState_LOCKED_e,
|
|
SpkSoundState_UNLOCKED_e,
|
|
SpkSoundState_STOPPING_e,
|
|
SpkSoundState_DEAD_e,
|
|
};
|
|
|
|
void SpkSoundHandle::releaseSound() {
|
|
if (!mSound) {
|
|
return;
|
|
}
|
|
|
|
mSound->mHandle = NULL;
|
|
mSound = NULL;
|
|
}
|
|
|
|
SpkSoundVolume::SpkSoundVolume() {
|
|
field_0x00 = 1.0f;
|
|
field_0x04 = 0.0f;
|
|
field_0x08 = 1.0f;
|
|
field_0x0c = 0.0f;
|
|
field_0x10 = 1.0f;
|
|
field_0x14 = 1.0f;
|
|
field_0x18 = 0.0f;
|
|
mTableVolume = 1.0f;
|
|
}
|
|
|
|
void SpkSoundVolume::setRelease(s32 release) {
|
|
if (release > 0) {
|
|
field_0x04 = 1.0f / release;
|
|
} else {
|
|
field_0x04 = 1.0f;
|
|
}
|
|
|
|
field_0x00 = 1.0f;
|
|
}
|
|
|
|
void SpkSoundVolume::setFadeOut(s32 fadeOut) {
|
|
JASCriticalSection cs;
|
|
|
|
if (fadeOut > 0) {
|
|
field_0x0c = 1.0f / fadeOut;
|
|
} else {
|
|
field_0x0c = 1.0f;
|
|
}
|
|
|
|
field_0x08 = 1.0f;
|
|
}
|
|
|
|
f32 SpkSoundVolume::calc(bool& param_0) {
|
|
param_0 = false;
|
|
|
|
if (field_0x04 != 0.0f) {
|
|
field_0x00 -= field_0x04;
|
|
if (field_0x00 <= 0.0f) {
|
|
field_0x00 = 0.0f;
|
|
field_0x04 = 0.0f;
|
|
param_0 = true;
|
|
}
|
|
}
|
|
|
|
if (field_0x0c != 0.0f) {
|
|
field_0x08 -= field_0x0c;
|
|
if (field_0x08 <= 0.0f) {
|
|
field_0x08 = 0.0f;
|
|
field_0x0c = 0.0f;
|
|
param_0 = true;
|
|
}
|
|
}
|
|
|
|
if (field_0x18 != 0.0f) {
|
|
field_0x10 += field_0x18;
|
|
if (field_0x18 >= 0.0f) {
|
|
if (field_0x10 >= field_0x14) {
|
|
field_0x10 = field_0x14;
|
|
field_0x18 = 0.0f;
|
|
}
|
|
} else if (field_0x10 <= field_0x14) {
|
|
field_0x10 = field_0x14;
|
|
field_0x18 = 0.0f;
|
|
}
|
|
}
|
|
|
|
f32 result = mTableVolume * (field_0x10 * (field_0x08 * (field_0x00 * field_0x00)));
|
|
return result;
|
|
}
|
|
|
|
void SpkSoundVolume::setTableVolume(f32 vol) {
|
|
mTableVolume = vol;
|
|
}
|
|
|
|
SpkSound::SpkSound() : JSULink<SpkSound>(this),
|
|
mHandle(NULL), mSoundNum(-1), mWaveData(0), mCurPos(0),
|
|
field_0x20(0), mPriority(100), field_0x28(0), mWaveSize(0),
|
|
mWaveLoopStart(-1), mWaveLoopEnd(-1), mState(SpkSoundState_STARTING_e),
|
|
mLifeTime(-1) {
|
|
}
|
|
|
|
SpkSound::~SpkSound() {
|
|
releaseHandle();
|
|
}
|
|
|
|
void SpkSound::update(f32 param_0) {
|
|
if (!((SpkSoundState)mState != SpkSoundState_UNLOCKED_e &&
|
|
(SpkSoundState)mState != SpkSoundState_STOPPING_e)) {
|
|
SpkSystem* system = JASGlobalInstance<SpkSystem>::getInstance();
|
|
JUT_ASSERT(227, system);
|
|
|
|
SpkMixingBuffer* mixing_buffer = system->getMixingBuffer();
|
|
JUT_ASSERT(230, mixing_buffer);
|
|
|
|
bool calc_flag = false;
|
|
f32 weight = mVolume.calc(calc_flag);
|
|
if (calc_flag) {
|
|
mState = SpkSoundState_DEAD_e;
|
|
}
|
|
weight *= param_0;
|
|
|
|
if (!isLoopWave()) {
|
|
s32 len = SPK_SOUND_MIX_STEP;
|
|
if (mCurPos + len >= mWaveSize) {
|
|
len = mWaveSize - mCurPos;
|
|
}
|
|
|
|
mixing_buffer->mix(field_0x20, mWaveData + mCurPos, len, weight, 0);
|
|
|
|
mCurPos += SPK_SOUND_MIX_STEP;
|
|
|
|
if (mCurPos >= mWaveSize) {
|
|
mState = SpkSoundState_DEAD_e;
|
|
}
|
|
return;
|
|
}
|
|
s32 len = 0;
|
|
s32 processedBytes = 0;
|
|
s32 remainingBytes = SPK_SOUND_MIX_STEP;
|
|
if (mWaveLoopEnd - mCurPos >= SPK_SOUND_MIX_STEP) {
|
|
len = SPK_SOUND_MIX_STEP;
|
|
mixing_buffer->mix(field_0x20, mWaveData + mCurPos, len, weight, 0);
|
|
|
|
mCurPos += SPK_SOUND_MIX_STEP;
|
|
|
|
if (mCurPos >= mWaveLoopEnd) {
|
|
mCurPos = mWaveLoopStart;
|
|
}
|
|
} else {
|
|
while (remainingBytes > 0) {
|
|
len = mWaveLoopEnd - mCurPos;
|
|
if (len >= remainingBytes) {
|
|
len = remainingBytes;
|
|
}
|
|
remainingBytes -= len;
|
|
|
|
mixing_buffer->mix(field_0x20, mWaveData + mCurPos, len, weight,
|
|
processedBytes);
|
|
|
|
processedBytes += len;
|
|
mCurPos += len;
|
|
|
|
if (mCurPos >= mWaveLoopEnd) {
|
|
mCurPos = mWaveLoopStart;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void SpkSound::stop(s32 msec) {
|
|
mState = SpkSoundState_STOPPING_e;
|
|
s32 fade = convertMsecToFrames(msec);
|
|
|
|
if (fade) {
|
|
mVolume.setFadeOut(fade);
|
|
} else {
|
|
startRelease();
|
|
}
|
|
}
|
|
|
|
void SpkSound::startRelease(void) {
|
|
mVolume.setRelease(field_0x28);
|
|
}
|
|
|
|
void SpkSound::attachHandle(SpkSoundHandle* handle) {
|
|
JUT_ASSERT(338, handle);
|
|
if (isHandleAttached()) {
|
|
releaseHandle();
|
|
}
|
|
|
|
mHandle = handle;
|
|
mHandle->mSound = this;
|
|
}
|
|
|
|
bool SpkSound::isHandleAttached(void) const {
|
|
return mHandle != NULL;
|
|
}
|
|
|
|
void SpkSound::releaseHandle() {
|
|
if (!mHandle) {
|
|
return;
|
|
}
|
|
|
|
mHandle->mSound = NULL;
|
|
mHandle = NULL;
|
|
}
|
|
|
|
bool SpkSound::start(s32 param_0, s32 soundNum) {
|
|
field_0x20 = param_0;
|
|
|
|
bool setResult = setWaveData(soundNum);
|
|
if (!setResult) {
|
|
return false;
|
|
}
|
|
|
|
mState = SpkSoundState_LOCKED_e;
|
|
return true;
|
|
}
|
|
|
|
void SpkSound::kill(void) {
|
|
mState = SpkSoundState_DEAD_e;
|
|
}
|
|
|
|
bool SpkSound::isStopping(void) const {
|
|
return mState == SpkSoundState_STOPPING_e;
|
|
}
|
|
|
|
bool SpkSound::isDead(void) const {
|
|
return mState == SpkSoundState_DEAD_e;
|
|
}
|
|
|
|
bool SpkSound::isLocked(void) const {
|
|
return mState == SpkSoundState_LOCKED_e;
|
|
}
|
|
|
|
void SpkSound::unlock() {
|
|
if (mState != SpkSoundState_LOCKED_e) {
|
|
return;
|
|
}
|
|
|
|
mState = SpkSoundState_UNLOCKED_e;
|
|
}
|
|
|
|
s32 SpkSound::getLifeTime(void) {
|
|
return mLifeTime;
|
|
}
|
|
|
|
void SpkSound::setLifeTime(s32 lifeTime) {
|
|
mLifeTime = lifeTime;
|
|
}
|
|
|
|
void SpkSound::updateLifeTime() {
|
|
mLifeTime--;
|
|
}
|
|
|
|
s32 SpkSound::convertMsecToFrames(s32 msec) {
|
|
return 6 * msec / 40;
|
|
}
|
|
|
|
inline bool SpkSound::isLoopWave(void) {
|
|
return mWaveLoopStart >= 0 && mWaveLoopEnd > mWaveLoopStart;
|
|
}
|
|
|
|
bool SpkSound::setWaveData(s32 soundNum) {
|
|
SpkSystem* system = JASGlobalInstance<SpkSystem>::getInstance();
|
|
JUT_ASSERT(432, system);
|
|
|
|
SpkData* data = system->getData();
|
|
JUT_ASSERT(435, data);
|
|
|
|
if (data->isValid() == 0) {
|
|
JUT_WARN(438, "%s", "Speaker data is not valid\n");
|
|
return false;
|
|
}
|
|
|
|
SpkTable& table = data->getTableMgr();
|
|
JUT_ASSERT(444, soundNum < table.getNumOfSound());
|
|
|
|
mSoundNum = soundNum;
|
|
s32 waveNum = table.getParams(soundNum)->mWaveNum;
|
|
mPriority = table.getParams(soundNum)->field_0x02;
|
|
mVolume.setTableVolume(table.getParams(soundNum)->mVolume / 127.0f);
|
|
field_0x28 = convertMsecToFrames(table.getParams(soundNum)->mMsec);
|
|
|
|
SpkWave& wave = data->getWaveMgr();
|
|
JUT_ASSERT(457, mSoundNum < wave.getNumOfWaves());
|
|
mWaveData = wave.getWave(waveNum);
|
|
mCurPos = 0;
|
|
mWaveSize = wave.getWaveSize(waveNum) / 2;
|
|
mWaveLoopStart = wave.getLoopStartPos(waveNum);
|
|
mWaveLoopEnd = wave.getLoopEndPos(waveNum);
|
|
|
|
JUT_ASSERT(466, mWaveLoopEnd <= mWaveSize);
|
|
|
|
return true;
|
|
}
|
|
|
|
SpkSoundHolder::SpkSoundHolder() : JASGlobalInstance(true) {
|
|
mMasterVolume = 1.0f;
|
|
mConfigVolume = 10;
|
|
|
|
for (int i = 0; i < ARRAY_SIZE(mSoundVolumes); i++) {
|
|
mSoundVolumes[i] = 1.0f;
|
|
}
|
|
}
|
|
|
|
bool SpkSoundHolder::startSound(s32 chan, s32 soundNum, SpkSoundHandle* handle) {
|
|
if (!SpkSpeakerCtrl::isEnable(chan)) {
|
|
return false;
|
|
}
|
|
|
|
if (soundNum < 0) {
|
|
return false;
|
|
}
|
|
|
|
if (handle != NULL) {
|
|
if (*handle) {
|
|
if ((*handle)->isLocked()) {
|
|
(*handle)->kill();
|
|
} else {
|
|
(*handle)->stop(0);
|
|
}
|
|
}
|
|
}
|
|
|
|
SpkSound* new_sound_p = JKR_NEW SpkSound();
|
|
if (new_sound_p == NULL) {
|
|
JUT_WARN(520, "%s", "cannot new SpkSound\n");
|
|
return false;
|
|
}
|
|
|
|
if (handle != NULL) {
|
|
new_sound_p->attachHandle(handle);
|
|
}
|
|
|
|
bool startResult = new_sound_p->start(chan, soundNum);
|
|
if (!startResult) {
|
|
JUT_WARN(532, "%s", "cannot start SpkSound\n");
|
|
JKR_DELETE(new_sound_p);
|
|
return false;
|
|
}
|
|
|
|
{
|
|
JASCriticalSection cs;
|
|
appendSound(chan, new_sound_p);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void SpkSoundHolder::appendSound(s32 chan, SpkSound* sound) {
|
|
mSoundList[chan].append(sound);
|
|
}
|
|
|
|
bool SpkSoundHolder::startLevelSound(s32 chan, s32 soundNum, SpkSoundHandle* handle) {
|
|
if (handle == NULL) {
|
|
JUT_WARN(558, "%s", "Spk : No Handle for Level Sound");
|
|
return false;
|
|
}
|
|
|
|
if (*handle) {
|
|
if (!(*handle)->isStopping() && !(*handle)->isDead()) {
|
|
(*handle)->setLifeTime(2);
|
|
}
|
|
return true;
|
|
} else {
|
|
bool startResult = startSound(chan, soundNum, handle);
|
|
if (!startResult) {
|
|
return false;
|
|
}
|
|
|
|
if (*handle) {
|
|
(*handle)->setLifeTime(2);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
void SpkSoundHolder::stopAll(s32 chan, s32 msec) {
|
|
JASCriticalSection cs;
|
|
|
|
for (JSULink<SpkSound>* it = mSoundList[chan].getFirst(); it != NULL; it = it->getNext()) {
|
|
if (it->getObject() != NULL) {
|
|
it->getObject()->stop(msec);
|
|
}
|
|
}
|
|
}
|
|
|
|
bool SpkSoundHolder::update(s32 chan) {
|
|
JASCriticalSection cs;
|
|
bool ret = updateEachSound(chan);
|
|
return ret;
|
|
}
|
|
|
|
bool SpkSoundHolder::updateEachSound(s32 chan) {
|
|
bool retval = false;
|
|
|
|
f32 volume = getMasterVolume() * getConfigVolumeF32();
|
|
|
|
for (JSULink<SpkSound>* it = mSoundList[chan].getFirst(); it != NULL; it = it->getNext()) {
|
|
it->getObject()->update(volume * mSoundVolumes[chan]);
|
|
retval = true;
|
|
}
|
|
|
|
return retval;
|
|
}
|
|
|
|
void SpkSoundHolder::freeDeadSound(s32 chan) {
|
|
JSULink<SpkSound>* it = mSoundList[chan].getFirst();
|
|
while (it != NULL) {
|
|
JSULink<SpkSound>* next = it->getNext();
|
|
if (it->getObject()->isDead()) {
|
|
mSoundList[chan].remove(it);
|
|
JKR_DELETE(it->getObject());
|
|
}
|
|
it = next;
|
|
}
|
|
}
|
|
|
|
void SpkSoundHolder::framework(void) {
|
|
JASCriticalSection cs;
|
|
|
|
for (int i = 0; i < ARRAY_SIZE(mSoundList); i++) {
|
|
for (JSULink<SpkSound>* it = mSoundList[i].getFirst(); it != NULL; it = it->getNext()) {
|
|
if (it->getObject() != NULL) {
|
|
if (it->getObject()->isLocked()) {
|
|
it->getObject()->unlock();
|
|
} else if (it->getObject()->getLifeTime() >= 0) {
|
|
it->getObject()->updateLifeTime();
|
|
if (it->getObject()->getLifeTime() <= 0) {
|
|
it->getObject()->stop(0);
|
|
it->getObject()->setLifeTime(-1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
freeDeadSound(i);
|
|
}
|
|
}
|