// Port of pflib/external/openal/oalBuffer.h (Apple OpenAL, Playground SDK 4.0): OALBuffer, the object behind an // AL buffer name (the audio data, its format, and the sources it is attached to), with AttachedSourceList and // SourceAttachedInfo. Layouts from the DWARF of parity-out/sdk/dbgobj/oalBuffer.o (game offsets identical): // // OALBuffer (size 192): +0x00 mSelfToken, +0x04 mSourceListGuard (CAGuard), +0x58 mData, +0x5c mAppOwnsBufferMemory, // +0x60 mDataSize, +0x64 mDataFormat, +0x8c mPreConvertedDataSize, +0x90 mPreConvertedDataFormat, // +0xb8 mDataHasBeenConverted, +0xbc mAttachedSourceList. // SourceAttachedInfo (size 8): +0x00 mSource, +0x04 mAttachedCount. // AttachedSourceList (size 8): a std::list (gcc 4.0 libstdc++; the port uses the host list, // whose observable behaviour is the same). // // The inline members defined below are header code. The SDK build emits them out of line (oalSource.o / oalBuffer.o // __textcoal_nt, addresses at each member); the game inlines all of them except AttachedSourceList's constructor // (game @0x00192410, __textcoal_nt). AttachedSourceList::Size counts the nodes (gcc 4.0 list::size), as in the // game's inlined loops. GetPreConvertedBitsPerChannel, GetPreConvertedDataSize, GetFramesToBytes, // CanBufferDataBeModified, AddAudioDataStatic and PrintFormat are only declared (no game code, not ported). #ifndef OALBUFFER_H_INCLUDED #define OALBUFFER_H_INCLUDED #include "oal_sysdecls.h" #include "CAGuard.h" #include "CAStreamBasicDescription.h" #include #include class OALSource; struct SourceAttachedInfo { OALSource* mSource; UInt32 mAttachedCount; }; class AttachedSourceList : std::list { public: // game @0x00192410 sdk @0x1d7d4 (oalBuffer.o) AttachedSourceList() {} // sdk @0x1d928 (oalBuffer.o) void Add(SourceAttachedInfo& inSourceInfo) { push_back(inSourceInfo); } // sdk @0x1d60e (oalBuffer.o) void Remove(OALSource* inSource) { iterator it = begin(); while (it != end()) { if ((*it).mSource == inSource) { erase(it); return; } else { ++it; } } return; } // sdk @0x1d002 (oalBuffer.o) bool SourceExists(OALSource* inSource) { iterator it = begin(); while (it != end()) { if ((*it).mSource == inSource) { return true; } ++it; } return false; } // sdk @0x1d106 (oalBuffer.o) void IncreaseAttachmentCount(OALSource* inSource) { iterator it = begin(); while (it != end()) { if ((*it).mSource == inSource) { (*it).mAttachedCount++; return; } ++it; } return; } // sdk @0x1d074 (oalBuffer.o) UInt32 DecreaseAttachmentCount(OALSource* inSource) { iterator it = begin(); while (it != end()) { if ((*it).mSource == inSource) { (*it).mAttachedCount--; return (*it).mAttachedCount; } ++it; } return 0; } // sdk @0x1d264 (oalBuffer.o) OALSource* GetSourceByIndex(short inIndex) { iterator it = begin(); std::advance(it, inIndex); if (it != end()) { return ((*it).mSource); } return (NULL); } // sdk @0x1d4e6 (oalBuffer.o) UInt32 Size() const { return (UInt32)size(); } bool Empty() const { return empty(); } }; class OALBuffer { public: OALBuffer(const ALuint inSelfToken); ~OALBuffer(); OSStatus AddAudioData(char* inAudioData, UInt32 inAudioDataSize, ALenum format, ALsizei freq, bool inPreConvertToHalFormat); OSStatus AddAudioDataStatic(char* inAudioData, UInt32 inAudioDataSize, ALenum format, ALsizei freq); bool IsPurgable(); // sdk @0x34df4 (oalSource.o) bool HasBeenConverted() { return mDataHasBeenConverted; } // sdk @0x34e0a (oalSource.o) UInt32 GetToken() { return mSelfToken; } UInt32 GetFrameCount(); UInt32 GetFramesToBytes(UInt32 inOffsetInFrames); // sdk @0x34e18 (oalSource.o) Float64 GetSampleRate() { return mDataFormat.mSampleRate; } // sdk @0x34e30 (oalSource.o) UInt32 GetBytesPerPacket() { return mDataFormat.mBytesPerPacket; } // sdk @0x34e3e (oalSource.o) UInt32 GetFramesPerPacket() { return mDataFormat.mFramesPerPacket; } UInt32 GetPreConvertedBitsPerChannel(); // sdk @0x34e4c (oalSource.o) UInt32 GetNumberChannels() { return mDataFormat.NumberChannels(); } UInt32 GetPreConvertedDataSize(); // sdk @0x34e62 (oalSource.o) UInt8* GetDataPtr() { return mData; } // sdk @0x34e70 (oalSource.o) UInt32 GetDataSize() { return mDataSize; } // sdk @0x34e7e (oalSource.o) CAStreamBasicDescription* GetFormat() { return &mDataFormat; } bool CanBufferDataBeModified(); bool CanBeRemovedFromBufferMap(); bool UseThisBuffer(OALSource* inSource); bool ReleaseBuffer(OALSource* inSource); void PrintFormat(); private: OSStatus ConvertDataForBuffer(void* inData, UInt32 inDataSize, UInt32 inDataFormat, UInt32 inDataSampleRate); ALuint mSelfToken; CAGuard mSourceListGuard; UInt8* mData; bool mAppOwnsBufferMemory; UInt32 mDataSize; CAStreamBasicDescription mDataFormat; UInt32 mPreConvertedDataSize; CAStreamBasicDescription mPreConvertedDataFormat; bool mDataHasBeenConverted; AttachedSourceList* mAttachedSourceList; }; // The buffer maps of oalImp.cpp (gOALBufferMap and gDeadOALBufferMap). Every member with out-of-line code has // it in the SDK's oalImp.o (sdk @ below); the game inlines all of them. GetFirstItem and Empty have no // out-of-line code in either build (nothing calls them) and neither map is ever deleted (no ~OALBufferMap // symbol in either build). class OALBufferMap : std::multimap > { public: // sdk @0x5cda0 (oalImp.o) OALBufferMap() {} // sdk @0x5de98 (oalImp.o) void Add(const ALuint inBufferToken, OALBuffer** inBuffer) { iterator it = upper_bound(inBufferToken); insert(it, value_type(inBufferToken, *inBuffer)); } // sdk @0x5b24c (oalImp.o) OALBuffer* GetBufferByIndex(UInt32 inIndex) { iterator it = begin(); for (UInt32 i = 0; i < inIndex; i++) { if (it != end()) { it++; } else { i = inIndex; } } if (it != end()) { return ((*it).second); } return (NULL); } // sdk @0x5bf1e (oalImp.o) OALBuffer* Get(ALuint inBufferToken) { iterator it = find(inBufferToken); if (it != end()) { return ((*it).second); } return (NULL); } // sdk @0x5c902 (oalImp.o) void Remove(const ALuint inBufferToken) { iterator it = find(inBufferToken); if (it != end()) { erase(it); } } // no out-of-line code in either build (nothing calls it) OALBuffer* GetFirstItem() { iterator it = begin(); if (it != end()) { return ((*it).second); } return (NULL); } // sdk @0x5aeee (oalImp.o) UInt32 Size() const { return (UInt32)size(); } // no out-of-line code in either build (nothing calls it) bool Empty() const { return empty(); } }; #endif