summaryrefslogtreecommitdiff
path: root/include/nw4r/snd/snd_SoundArchiveLoader.h
blob: 4c55479c4d19a03f415965c6e7c78c187dc79906 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef NW4R_SND_SOUND_ARCHIVE_LOADER_H
#define NW4R_SND_SOUND_ARCHIVE_LOADER_H
#include "nw4r/types_nw4r.h"
#include "nw4r/ut.h" // IWYU pragma: export
#include "rvl/OS.h"  // IWYU pragma: export

namespace nw4r {
namespace snd {

// Forward declarations
class SoundMemoryAllocatable;

namespace detail {

class FileStreamHandle {
public:
    FileStreamHandle(ut::FileStream *pFileStream) : mStream(pFileStream) {}

    ~FileStreamHandle() {
        if (mStream != NULL) {
            mStream->Close();
        }
    }

    ut::FileStream *GetFileStream() {
        return mStream;
    }

    ut::FileStream *operator->() {
        return mStream;
    }

    operator bool() const {
        return mStream;
    }

private:
    ut::FileStream *mStream; // at 0x0
};

class SoundArchiveLoader {
public:
    explicit SoundArchiveLoader(const SoundArchive &rArchive);
    ~SoundArchiveLoader();

    void *LoadGroup(u32 id, SoundMemoryAllocatable *pAllocatable, void **ppWaveBuffer, u32 blockSize);
    s32 ReadFile(u32, void *, s32, s32);
    void *LoadFile(u32 id, SoundMemoryAllocatable* pAllocatable);

private:
    mutable OSMutex mMutex;   // at 0x0
    const SoundArchive &mArc; // at 0x18
    u8 mStreamArea[512];      // at 0x1C
    ut::FileStream *mStream;  // at 0x21C
};

} // namespace detail
} // namespace snd
} // namespace nw4r

#endif