Skip to content

Commit

Permalink
DvdSoundArchive
Browse files Browse the repository at this point in the history
  • Loading branch information
robojumper committed Nov 6, 2024
1 parent bb16b53 commit dd78fce
Show file tree
Hide file tree
Showing 5 changed files with 302 additions and 9 deletions.
3 changes: 3 additions & 0 deletions config/SOUE01/splits.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1512,9 +1512,12 @@ nw4r/snd/snd_Channel.cpp:

nw4r/snd/snd_DisposeCallbackManager.cpp:
.text start:0x8046B7D0 end:0x8046BB5C
.sbss start:0x80576688 end:0x80576690
.bss start:0x806593F8 end:0x80659410

nw4r/snd/snd_DvdSoundArchive.cpp:
.text start:0x8046BB60 end:0x8046C1C8
.data start:0x8056DBE8 end:0x8056DC70

nw4r/snd/snd_EnvGenerator.cpp:
.text start:0x8046C1D0 end:0x8046C5A0
Expand Down
14 changes: 7 additions & 7 deletions config/SOUE01/symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25202,7 +25202,7 @@ __ct__Q34nw4r3snd15DvdSoundArchiveFv = .text:0x8046BB60; // type:function size:0
__dt__Q34nw4r3snd15DvdSoundArchiveFv = .text:0x8046BBB0; // type:function size:0x8C
Open__Q34nw4r3snd15DvdSoundArchiveFPCc = .text:0x8046BC40; // type:function size:0x14C
Close__Q34nw4r3snd15DvdSoundArchiveFv = .text:0x8046BD90; // type:function size:0x4C
fn_8046BDE0 = .text:0x8046BDE0; // type:function size:0xA8
OpenStream__Q34nw4r3snd15DvdSoundArchiveCFPviUlUl = .text:0x8046BDE0; // type:function size:0xA8
OpenExtStream__Q34nw4r3snd15DvdSoundArchiveCFPviPCcUlUl = .text:0x8046BE90; // type:function size:0xB8
detail_GetRequiredStreamBufferSize__Q34nw4r3snd15DvdSoundArchiveCFv = .text:0x8046BF50; // type:function size:0x8
LoadHeader__Q34nw4r3snd15DvdSoundArchiveFPvUl = .text:0x8046BF60; // type:function size:0x88
Expand Down Expand Up @@ -37119,8 +37119,8 @@ lbl_8056DBA8 = .data:0x8056DBA8; // type:object size:0x10
lbl_8056DBB8 = .data:0x8056DBB8; // type:object size:0x10
lbl_8056DBC8 = .data:0x8056DBC8; // type:object size:0x10
lbl_8056DBD8 = .data:0x8056DBD8; // type:object size:0x10
lbl_8056DBE8 = .data:0x8056DBE8; // type:object size:0x68
lbl_8056DC50 = .data:0x8056DC50; // type:object size:0x20
__vt__Q44nw4r3snd15DvdSoundArchive13DvdFileStream = .data:0x8056DBE8; // type:object size:0x64
__vt__Q34nw4r3snd15DvdSoundArchive = .data:0x8056DC50; // type:object size:0x20
lbl_8056DC70 = .data:0x8056DC70; // type:object size:0x28
lbl_8056DC98 = .data:0x8056DC98; // type:object size:0x60
lbl_8056DCF8 = .data:0x8056DCF8; // type:object size:0x20
Expand All @@ -37142,7 +37142,7 @@ lbl_8056E0D8 = .data:0x8056E0D8; // type:object size:0x10
__vt__Q34nw4r3snd12Sound3DActor = .data:0x8056E0E8; // type:object size:0x30
lbl_8056E118 = .data:0x8056E118; // type:object size:0x20
lbl_8056E138 = .data:0x8056E138; // type:object size:0x38
__vt__Q34nw4r3snd10SoundActor = .data:0x8056E170; // type:object size:0x20
__vt__Q34nw4r3snd10SoundActor = .data:0x8056E170; // type:object size:0x1C
lbl_8056E190 = .data:0x8056E190; // type:object size:0x20
lbl_8056E1B0 = .data:0x8056E1B0; // type:object size:0x30
WSDCallback = .data:0x8056E1E0; // type:object size:0x10
Expand Down Expand Up @@ -40949,7 +40949,7 @@ mCurrentFx__Q44nw4r3snd6detail8AxfxImpl = .sbss:0x80576670; // type:object size:
mAllocatedSize__Q44nw4r3snd6detail8AxfxImpl = .sbss:0x80576674; // type:object size:0x4 data:4byte
typeInfo__Q44nw4r3snd6detail10BasicSound = .sbss:0x80576678; // type:object size:0x8 data:4byte
@GUARD@GetInstance__Q44nw4r3snd6detail14ChannelManagerFv@instance = .sbss:0x80576680; // type:object size:0x8 data:byte
lbl_80576688 = .sbss:0x80576688; // type:object size:0x8 data:byte
@GUARD@GetInstance__Q44nw4r3snd6detail22DisposeCallbackManagerFv@instance = .sbss:0x80576688; // type:object size:0x1 data:byte
lbl_80576690 = .sbss:0x80576690; // type:object size:0x8 data:byte
lbl_80576698 = .sbss:0x80576698; // type:object size:0x4 data:4byte
lbl_8057669C = .sbss:0x8057669C; // type:object size:0x1 data:byte
Expand Down Expand Up @@ -49428,11 +49428,11 @@ lbl_80659390 = .bss:0x80659390; // type:object size:0xC
lbl_806593C8 = .bss:0x806593C8; // type:object size:0xC
@LOCAL@GetInstance__Q44nw4r3snd6detail14ChannelManagerFv@instance = .bss:0x806593D8; // type:object size:0x20 data:4byte
lbl_806593F8 = .bss:0x806593F8; // type:object size:0xC
lbl_80659404 = .bss:0x80659404; // type:object size:0xC data:4byte
@LOCAL@GetInstance__Q44nw4r3snd6detail22DisposeCallbackManagerFv@instance = .bss:0x80659404; // type:object size:0xC data:4byte
lbl_80659410 = .bss:0x80659410; // type:object size:0x2D8 data:byte
mGlobalVariable__Q44nw4r3snd6detail9SeqPlayer = .bss:0x806596E8; // type:object size:0x20 data:2byte
lbl_80659708 = .bss:0x80659708; // type:object size:0x18
lbl_80659720 = .bss:0x80659720; // type:object size:0x10
lbl_80659720 = .bss:0x80659720; // type:object size:0xC
@LOCAL@detail_SortPriorityList__Q34nw4r3snd11SoundPlayerFv@listsByPrio = .bss:0x80659730; // type:object size:0x600 data:4byte
lbl_80659D40 = .bss:0x80659D40; // type:object size:0xC
sTaskThread__Q34nw4r3snd11SoundSystem = .bss:0x80659D50; // type:object size:0x330
Expand Down
4 changes: 2 additions & 2 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,9 +710,9 @@ def nw4rLib(lib_name, objects, extra_cflags=[], mw_version="Wii/1.3"):
Object(NonMatching, "nw4r/snd/snd_BasicSound.cpp"),
Object(NonMatching, "nw4r/snd/snd_BiquadFilterPreset.cpp"),
Object(Matching, "nw4r/snd/snd_Channel.cpp"),
Object(NonMatching, "nw4r/snd/snd_DisposeCallbackManager.cpp"),
Object(Matching, "nw4r/snd/snd_DisposeCallbackManager.cpp"),
Object(NonMatching, "nw4r/snd/snd_debug.cpp"),
Object(NonMatching, "nw4r/snd/snd_DvdSoundArchive.cpp"),
Object(Matching, "nw4r/snd/snd_DvdSoundArchive.cpp"),
Object(Matching, "nw4r/snd/snd_EnvGenerator.cpp"),
Object(NonMatching, "nw4r/snd/snd_ExternalSoundPlayer.cpp"),
Object(Matching, "nw4r/snd/snd_FrameHeap.cpp"),
Expand Down
60 changes: 60 additions & 0 deletions src/nw4r/snd/snd_DisposeCallbackManager.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,61 @@
#include "nw4r/snd/snd_DisposeCallbackManager.h"
#include "nw4r/snd/snd_SoundThread.h"

namespace nw4r {
namespace snd {
namespace detail {

DisposeCallbackManager& DisposeCallbackManager::GetInstance() {
ut::AutoInterruptLock lock;
static DisposeCallbackManager instance;
return instance;
}

DisposeCallbackManager::DisposeCallbackManager() {}

void DisposeCallbackManager::RegisterDisposeCallback(
DisposeCallback* pCallback) {
mCallbackList.PushBack(pCallback);
}

void DisposeCallbackManager::UnregisterDisposeCallback(
DisposeCallback* pCallback) {
mCallbackList.Erase(pCallback);
}

void DisposeCallbackManager::Dispose(void* pData, u32 size, void* pArg) {
#pragma unused(pArg)

const void* pStart = pData;
const void* pEnd = static_cast<u8*>(pData) + size;

SoundThread::AutoLock lock;

DisposeCallbackList::Iterator it =
GetInstance().mCallbackList.GetBeginIter();

while (it != GetInstance().mCallbackList.GetEndIter()) {
DisposeCallbackList::Iterator curr = it++;
curr->InvalidateData(pStart, pEnd);
}
}

void DisposeCallbackManager::DisposeWave(void* pData, u32 size, void* pArg) {
#pragma unused(pArg)
const void* pStart = pData;
const void* pEnd = static_cast<u8*>(pData) + size;

SoundThread::AutoLock lock;

DisposeCallbackList::Iterator it =
GetInstance().mCallbackList.GetBeginIter();

while (it != GetInstance().mCallbackList.GetEndIter()) {
DisposeCallbackList::Iterator curr = it++;
curr->InvalidateWaveData(pStart, pEnd);
}
}

} // namespace detail
} // namespace snd
} // namespace nw4r
230 changes: 230 additions & 0 deletions src/nw4r/snd/snd_DvdSoundArchive.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,231 @@
#include "nw4r/snd/snd_DvdSoundArchive.h"
#include <string.h>
#include <new.h>

namespace nw4r {
namespace snd {

class DvdSoundArchive::DvdFileStream : public ut::DvdLockedFileStream {
public:
DvdFileStream(const DVDFileInfo* pFileInfo, u32 offset, u32 size);
DvdFileStream(s32 entrynum, u32 offset, u32 size);

virtual s32 Read(void* pDst, u32 size); // at 0x14
virtual void Seek(s32 offset, u32 origin); // at 0x44

virtual u32 Tell() const {
return ut::DvdFileStream::Tell() - mOffset;
} // at 0x58

virtual u32 GetSize() const {
return mSize;
} // at 0x40

private:
s32 mOffset; // at 0x70
s32 mSize; // at 0x74
};

DvdSoundArchive::DvdSoundArchive() : mOpen(false) {}

DvdSoundArchive::~DvdSoundArchive() {
Close();
}

bool DvdSoundArchive::Open(s32 entrynum) {
if (!DVDFastOpen(entrynum, &mFileInfo)) {
return false;
}

mOpen = true;
return LoadFileHeader();
}

bool DvdSoundArchive::Open(const char* pPath) {
s32 entrynum = DVDConvertPathToEntrynum(pPath);
if (entrynum < 0) {
return false;
}

if (!Open(entrynum)) {
return false;
}

char extRoot[FILE_PATH_MAX];
for (int i = strlen(pPath) - 1; i >= 0; i--) {
if (pPath[i] == '/' || pPath[i] == '\\') {
if (i >= FILE_PATH_MAX) {
return false;
}
strncpy(extRoot, pPath, i);
extRoot[i] = '\0';

SetExternalFileRoot(extRoot);
break;
}
}

return true;
}

void DvdSoundArchive::Close() {
if (mOpen) {
DVDClose(&mFileInfo);
mOpen = false;
}
Shutdown();
}

ut::FileStream* DvdSoundArchive::OpenStream(void* pBuffer, int size, u32 offset,
u32 length) const {
if (!mOpen) {
return NULL;
}

if (size < sizeof(DvdFileStream)) {
return NULL;
}

return new (pBuffer) DvdFileStream(&mFileInfo, offset, length);
}

ut::FileStream* DvdSoundArchive::OpenExtStream(void* pBuffer, int size,
const char* pExtPath, u32 offset,
u32 length) const {
if (!mOpen) {
return NULL;
}

if (size < sizeof(DvdFileStream)) {
return NULL;
}

s32 entrynum = DVDConvertPathToEntrynum(pExtPath);
if (entrynum < 0) {
return NULL;
}

return new (pBuffer) DvdFileStream(entrynum, offset, length);
}

int DvdSoundArchive::detail_GetRequiredStreamBufferSize() const {
return sizeof(DvdFileStream);
}

bool DvdSoundArchive::LoadFileHeader() {
u8 headerArea[detail::SoundArchiveFile::HEADER_AREA_SIZE];

const u32 headerAlignSize =
ut::RoundUp(sizeof(detail::SoundArchiveFile::Header), 32);

void* pFile = ut::RoundUp<u8>(headerArea, 32);

s32 bytesRead =
DVDReadPrio(&mFileInfo, pFile, headerAlignSize, 0, DVD_PRIO_MEDIUM);

if (bytesRead != headerAlignSize) {
return false;
}

mFileReader.Init(pFile);
Setup(&mFileReader);

return true;
}

bool DvdSoundArchive::LoadHeader(void* pBuffer, u32 size) {
u32 infoSize = mFileReader.GetInfoChunkSize();
s32 infoOffset = mFileReader.GetInfoChunkOffset();

if (size < infoSize) {
return false;
}

s32 bytesRead =
DVDReadPrio(&mFileInfo, pBuffer, infoSize, infoOffset, DVD_PRIO_MEDIUM);

if (bytesRead != infoSize) {
return false;
}

mFileReader.SetInfoChunk(pBuffer, infoSize);
return true;
}

bool DvdSoundArchive::LoadLabelStringData(void* pBuffer, u32 size) {
u32 labelSize = mFileReader.GetLabelStringChunkSize();
s32 labelOffset = mFileReader.GetLabelStringChunkOffset();

if (size < labelSize) {
return false;
}

s32 bytesRead = DVDReadPrio(&mFileInfo, pBuffer, labelSize, labelOffset,
DVD_PRIO_MEDIUM);

if (bytesRead != labelSize) {
return false;
}

mFileReader.SetStringChunk(pBuffer, labelSize);
return true;
}

DvdSoundArchive::DvdFileStream::DvdFileStream(const DVDFileInfo* pFileInfo,
u32 offset, u32 size)
: DvdLockedFileStream(pFileInfo, false), mOffset(offset), mSize(size) {

ut::DvdFileStream::Seek(mOffset, SEEKORG_BEG);
}

DvdSoundArchive::DvdFileStream::DvdFileStream(s32 entrynum, u32 offset,
u32 size)
: DvdLockedFileStream(entrynum), mOffset(offset), mSize(size) {

ut::DvdFileStream::Seek(mOffset, SEEKORG_BEG);
}

s32 DvdSoundArchive::DvdFileStream::Read(void* pDst, u32 size) {
u32 endOffset = mOffset + mSize;
u32 startOffset = ut::DvdFileStream::Tell();

if (startOffset + size > endOffset) {
size = ut::RoundUp(endOffset - ut::DvdFileStream::Tell(), 32);
}

return DvdLockedFileStream::Read(pDst, size);
}

void DvdSoundArchive::DvdFileStream::Seek(s32 offset, u32 origin) {
switch (origin) {
case SEEKORG_BEG: {
offset += mOffset;
break;
}

case SEEKORG_CUR: {
offset += ut::DvdFileStream::Tell();
break;
}

case SEEKORG_END: {
offset = mOffset + mSize - offset;
break;
}

default: {
return;
}
}

if (offset < mOffset) {
offset = mOffset;
} else if (offset > mOffset + mSize) {
offset = mOffset + mSize;
}

ut::DvdFileStream::Seek(offset, SEEKORG_BEG);
}

} // namespace snd
} // namespace nw4r

0 comments on commit dd78fce

Please sign in to comment.