diff options
| author | Max Roncace <me@caseif.net> | 2026-02-20 05:53:27 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-20 02:53:27 -0800 |
| commit | 803bc041c7e228e2b7c88afd1121550e51db3f82 (patch) | |
| tree | 5462e8061bc8a8084db8ea2fc677a0fef5bb16d1 /include/Z2AudioCS | |
| parent | 0558bde1e61374f5a1b54453f07fe6cc15525bc1 (diff) | |
Implement Z2AudioCS (#3103)
Diffstat (limited to 'include/Z2AudioCS')
| -rw-r--r-- | include/Z2AudioCS/SpkData.h | 23 | ||||
| -rw-r--r-- | include/Z2AudioCS/SpkMixingBuffer.h | 20 | ||||
| -rw-r--r-- | include/Z2AudioCS/SpkSound.h | 119 | ||||
| -rw-r--r-- | include/Z2AudioCS/SpkSpeakerCtrl.h | 47 | ||||
| -rw-r--r-- | include/Z2AudioCS/SpkSystem.h | 38 | ||||
| -rw-r--r-- | include/Z2AudioCS/SpkTable.h | 41 | ||||
| -rw-r--r-- | include/Z2AudioCS/SpkWave.h | 32 | ||||
| -rw-r--r-- | include/Z2AudioCS/Z2AudioCS.h | 28 |
8 files changed, 348 insertions, 0 deletions
diff --git a/include/Z2AudioCS/SpkData.h b/include/Z2AudioCS/SpkData.h new file mode 100644 index 0000000000..8162b8f619 --- /dev/null +++ b/include/Z2AudioCS/SpkData.h @@ -0,0 +1,23 @@ +#ifndef Z2AUDIOCS_SPKDATA_H +#define Z2AUDIOCS_SPKDATA_H + +#include "Z2AudioCS/SpkTable.h" +#include "Z2AudioCS/SpkWave.h" +#include "JSystem/JKernel/JKRArchive.h" + +class SpkData { +public: + SpkData(JKRArchive*); + void loadTable(u16 chan); + void loadWave(u16 chan); + BOOL isValid(void) const; + + inline SpkTable& getTableMgr(void) { return mTableMgr; } + inline SpkWave& getWaveMgr(void) { return mWaveMgr; } + + /* 0x00 */ SpkTable mTableMgr; + /* 0x10 */ SpkWave mWaveMgr; + /* 0x14 */ JKRArchive* mResArc; +}; + +#endif /* Z2AUDIOCS_SPKDATA_H */ diff --git a/include/Z2AudioCS/SpkMixingBuffer.h b/include/Z2AudioCS/SpkMixingBuffer.h new file mode 100644 index 0000000000..ccdb8902b0 --- /dev/null +++ b/include/Z2AudioCS/SpkMixingBuffer.h @@ -0,0 +1,20 @@ +#ifndef Z2AUDIOCS_SPKMIXINGBUFFER_H +#define Z2AUDIOCS_SPKMIXINGBUFFER_H + +#include "JSystem/JKernel/JKRHeap.h" + +static const s32 cSamplesPerAudioPacket = 40; + +class SpkMixingBuffer { +public: + SpkMixingBuffer(JKRHeap* heap); + void mix(s32 chan, s16* src, s32 len, f32 weight, s32 offset); + s16* getSamples(s32 chan) const; + bool update(s32 chan); + void bzeroBuffer(s32 chan); + +private: + /* 0x00 */ s16* mBuffer[4]; +}; + +#endif /* Z2AUDIOCS_SPKMIXINGBUFFER_H */ diff --git a/include/Z2AudioCS/SpkSound.h b/include/Z2AudioCS/SpkSound.h new file mode 100644 index 0000000000..66af341f0b --- /dev/null +++ b/include/Z2AudioCS/SpkSound.h @@ -0,0 +1,119 @@ +#ifndef Z2AUDIOCS_SPKSOUND_H +#define Z2AUDIOCS_SPKSOUND_H + +#include "Z2AudioCS/SpkTable.h" +#include "JSystem/JAudio2/JASGadget.h" +#include "JSystem/JAudio2/JASHeapCtrl.h" +#include "JSystem/JSupport/JSUList.h" +#include <revolution/types.h> + +class SpkSound; + +class SpkSoundHandle { +public: + SpkSoundHandle(void) : mSound(NULL) {} + ~SpkSoundHandle(void) { + releaseSound(); + } + void releaseSound(void); + + inline bool isSoundAttached() const { + return mSound != NULL; + } + inline SpkSound* operator->(void) const { + JUT_ASSERT(62, mSound != NULL); + return mSound; + } + inline operator bool() const { + return isSoundAttached(); + } + + /* 0x00 */ SpkSound* mSound; +}; + +class SpkSoundVolume { +public: + SpkSoundVolume(void); + void setRelease(s32); + void setFadeOut(s32); + f32 calc(bool&); + void setTableVolume(f32); + + /* 0x00 */ f32 field_0x00; + /* 0x04 */ f32 field_0x04; + /* 0x08 */ f32 field_0x08; + /* 0x0C */ f32 field_0x0c; + /* 0x10 */ f32 field_0x10; + /* 0x14 */ f32 field_0x14; + /* 0x18 */ f32 field_0x18; + /* 0x1C */ f32 mTableVolume; +}; + +class SpkSound : public JASPoolAllocObject<SpkSound>, public JSULink<SpkSound> { +public: + SpkSound(void); + ~SpkSound(void); + void update(f32 vol); + void stop(s32 msec); + void startRelease(void); + bool isHandleAttached(void) const; + void attachHandle(SpkSoundHandle* handle); + void releaseHandle(void); + bool start(s32 chan, s32 soundNum); + void kill(void); + bool isStopping(void) const; + bool isDead(void) const; + bool isLocked(void) const; + void unlock(void); + s32 getLifeTime(void); + void setLifeTime(s32 lifeTime); + void updateLifeTime(void); + s32 convertMsecToFrames(s32 msec); + bool isLoopWave(void); + bool setWaveData(s32 soundNum); + + inline s32 getPriority(void) const { return mPriority; } + inline void setPriority(s32 priority) { mPriority = priority; } + inline s32 getSoundNum(void) const { return mSoundNum; } + inline void setSoundNum(s32 soundNum) { mSoundNum = soundNum; } + + /* 0x10 */ SpkSoundHandle* mHandle; + /* 0x14 */ s32 mSoundNum; + /* 0x18 */ s16* mWaveData; + /* 0x1C */ s32 mCurPos; + /* 0x20 */ u32 field_0x20; + /* 0x24 */ s32 mPriority; + /* 0x28 */ u32 field_0x28; + /* 0x2C */ s32 mWaveSize; + /* 0x30 */ s32 mWaveLoopStart; + /* 0x34 */ s32 mWaveLoopEnd; + /* 0x38 */ s32 mState; + /* 0x3C */ s32 mLifeTime; + /* 0x40 */ SpkSoundVolume mVolume; +}; + +class SpkSoundHolder : JASGlobalInstance<SpkSoundHolder> { +public: + SpkSoundHolder(void); + bool startSound(s32 chan, s32 soundNum, SpkSoundHandle* handle); + bool startLevelSound(s32 chan, s32 soundNum, SpkSoundHandle* handle); + void stopAll(s32 chan, s32 msec); + bool update(s32 chan); + bool updateEachSound(s32 chan); + void freeDeadSound(s32 chan); + void appendSound(s32 chan, SpkSound* sound); + void framework(void); + + inline f32 getMasterVolume(void) const { return mMasterVolume; } + inline void setMasterVolume(f32 vol) { mMasterVolume = vol; } + inline s32 getConfigVolume(void) const { return mConfigVolume; } + inline void setConfigVolume(s32 vol) { mConfigVolume = vol; } + inline f32 getConfigVolumeF32(void) const { return (f32)mConfigVolume / 15.0f; } + + /* 0x00 */ JSUList<SpkSound> mSoundList[WPAD_MAX_CONTROLLERS]; + /* 0x30 */ f32 mSoundVolumes[WPAD_MAX_CONTROLLERS]; + /* 0x40 */ f32 mMasterVolume; + /* 0x44 */ s32 mConfigVolume; +}; + +#endif /* Z2AUDIOCS_SPKSOUND_H */ diff --git a/include/Z2AudioCS/SpkSpeakerCtrl.h b/include/Z2AudioCS/SpkSpeakerCtrl.h new file mode 100644 index 0000000000..7216eed07d --- /dev/null +++ b/include/Z2AudioCS/SpkSpeakerCtrl.h @@ -0,0 +1,47 @@ +#ifndef Z2AUDIOCS_SPKSPEAKERCTRL_H +#define Z2AUDIOCS_SPKSPEAKERCTRL_H + +#include "Z2AudioCS/SpkMixingBuffer.h" +#include <revolution/os.h> +#include <revolution/types.h> +#include <revolution/wenc.h> + +struct SpeakerInfo { + /* 0x00 */ bool mIsConnected; + /* 0x01 */ bool mIsPlaying; + /* 0x02 */ WENCInfo mEncInfo; + /* 0x22 */ bool field_0x22; + /* 0x23 */ bool mIsMuted; +#if VERSION != VERSION_WII_USA_R0 + /* 0x24 */ s32 mState; +#endif + /* 0x28 */ s32 mRadioSensitivityTimer; + /* 0x2C */ s32 mExtensionTimer; + /* 0x30 */ u8 mVolume; +}; + +class SpkSpeakerCtrl { +public: + static void setMixingBuffer(SpkMixingBuffer*); + static void setup(void); + static void connect(s32 chan); + static void disconnect(s32 chan); + static void setSpeakerOn(s32 chan); + static void setSpeakerOnCallback(s32 chan, s32 param_1); + static void setSpeakerPlay(s32 chan); + static void startPlayCallback(s32 chan, s32 param_1); + static void setSpeakerOff(s32 chan); + static void retryConnection(s32 chan); + static void framework(void); + static void updateSpeaker(OSAlarm* alarm, OSContext* ctx); + static bool isEnable(s32 chan); + static void extensionProcess(s32 chan, s32 param_1); + static bool updateExtensionProcess(s32 chan); + static bool isSubmitPlayByExtensionConnect(s32 chan); + static bool checkRadioSensitivity(s32 chan); + static bool isSubmitPlayByRadioSensitivity(s32 chan); + +private: +}; + +#endif /* Z2AUDIOCS_SPKSPEAKERCTRL_H */ diff --git a/include/Z2AudioCS/SpkSystem.h b/include/Z2AudioCS/SpkSystem.h new file mode 100644 index 0000000000..05541c72e5 --- /dev/null +++ b/include/Z2AudioCS/SpkSystem.h @@ -0,0 +1,38 @@ +#ifndef Z2AUDIOCS_SPKSYSTEM_H +#define Z2AUDIOCS_SPKSYSTEM_H + +#include "Z2AudioCS/SpkData.h" +#include "Z2AudioCS/SpkMixingBuffer.h" +#include "Z2AudioCS/SpkSound.h" +#include "JSystem/JAudio2/JASGadget.h" +#include "JSystem/JKernel/JKRArchive.h" +#include "JSystem/JKernel/JKRHeap.h" +#include <revolution/types.h> + +class SpkSystem : protected JASGlobalInstance<SpkSystem> { +public: + SpkSystem(JKRHeap* heap); + void setResource(JKRArchive* resArc, u16, u16); + void framework(void); + void startSound(s32 chan, s32 param_1, SpkSoundHandle* handle); + void startLevelSound(s32 chan, s32 param_1, SpkSoundHandle* handle); + void stopAll(s32 chan, s32 msec); + void setMasterVolume(f32 vol); + f32 getMasterVolume(void); + void setConfigVolume(s32 vol); + static void newSoundMemPool(s32 numOfSound); + static void connect(s32 chan); + static void disconnect(s32 chan); + static void extensionProcess(s32, s32); + + inline SpkData* getData(void) const { return mData; } + inline SpkMixingBuffer* getMixingBuffer(void) const { return mMixingBuffer; } + +private: + /* 0x00 */ JKRHeap* mHeap; + /* 0x04 */ SpkData* mData; + /* 0x08 */ SpkMixingBuffer* mMixingBuffer; + /* 0x0C */ SpkSoundHolder* mSoundHolder; +}; + +#endif /* Z2AUDIOCS_SPKSYSTEM_H */ diff --git a/include/Z2AudioCS/SpkTable.h b/include/Z2AudioCS/SpkTable.h new file mode 100644 index 0000000000..8fc12bd735 --- /dev/null +++ b/include/Z2AudioCS/SpkTable.h @@ -0,0 +1,41 @@ +#ifndef Z2AUDIOCS_SPKTABLE_H +#define Z2AUDIOCS_SPKTABLE_H + +#include "JSystem/JUtility/JUTAssert.h" +#include <revolution/types.h> +#include <revolution/wpad.h> + +struct SpkTableParams { + /* 0x00 */ u16 mWaveNum; + /* 0x02 */ u8 field_0x02; + /* 0x03 */ u8 mVolume; + /* 0x04 */ u16 mMsec; + /* 0x06 */ u8 pad_0x06[2]; +}; + +class SpkTable { +public: + SpkTable(void); + void setResource(void* res); + + inline s32 getName(s32 num) { + JUT_ASSERT(0x35, num >= 0); + JUT_ASSERT(0x36, num < mNumOfSound); + return *(mDataOffsets + num); + } + inline s32 getNumOfSound() const { return mNumOfSound; } + inline bool isValid(void) const { return mIsInitialized; } + inline SpkTableParams* getParams(s32 num) { + JUT_ASSERT(46, num >= 0); + JUT_ASSERT(47, num < mNumOfSound); + return (SpkTableParams*)mEntryOffset + num; + } + + // private: + /* 0x00 */ bool mIsInitialized; + /* 0x04 */ s32 mNumOfSound; + /* 0x08 */ u32 mEntryOffset; + /* 0x0C */ s32* mDataOffsets; +}; + +#endif /* Z2AUDIOCS_SPKTABLE_H */ diff --git a/include/Z2AudioCS/SpkWave.h b/include/Z2AudioCS/SpkWave.h new file mode 100644 index 0000000000..6a604d8a50 --- /dev/null +++ b/include/Z2AudioCS/SpkWave.h @@ -0,0 +1,32 @@ +#ifndef Z2AUDIOCS_SPKWAVE_H +#define Z2AUDIOCS_SPKWAVE_H + +#include <revolution/types.h> + +struct WaveData { + s32 size; + u32 loopStartPos; + u32 loopEndPos; + s16 wave[0]; +}; + +class SpkWave { +public: + SpkWave(void); + void setResource(void*); + s32 getNumOfWaves(void) const; + s32 getWaveSize(s32 num) const; + u32 getLoopStartPos(s32 num) const; + u32 getLoopEndPos(s32 num) const; + s16* getWave(s32 num) const; + WaveData* getWaveData(s32 num) const; + + inline bool isValid(void) const { return mWaveData != NULL; } + inline const void* getResource(void) const { return mWaveData; } + inline void* getResource(void) { return mWaveData; } + +private: + /* 0x00 */ void* mWaveData; +}; + +#endif /* Z2AUDIOCS_SPKWAVE_H */ diff --git a/include/Z2AudioCS/Z2AudioCS.h b/include/Z2AudioCS/Z2AudioCS.h new file mode 100644 index 0000000000..b0788de786 --- /dev/null +++ b/include/Z2AudioCS/Z2AudioCS.h @@ -0,0 +1,28 @@ +#ifndef Z2AUDIOCS_H +#define Z2AUDIOCS_H + +#include "Z2AudioCS/SpkTable.h" +#include "Z2AudioCS/SpkSound.h" +#include <dolphin/types.h> + +class JKRHeap; +class JKRArchive; + +class Z2AudioCS { +public: + static void newSpkSoundMemPool(); + static int init(JKRHeap* heap, JKRArchive* res, s32 param_2, s32 param_3); + static void update(); + static void connect(s32 chan); + static void disconnect(s32 chan); + static void extensionProcess(s32 chan, s32 param_1); + static SpkSoundHandle* getHandleSoundID(s32 soundNum); + static SpkSoundHandle* start(s32 id, s32 chan); + static SpkSoundHandle* startLevel(s32 id, s32 chan); + static s32 getName(s32 num); + static s32 getNumOfSound(void); + static void stopAll(s32 chan, s32 msec); + static void stop(s32 chan); +}; + +#endif /* Z2AUDIOCS_H */ |
