mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-12-29 13:31:51 +00:00
refactor: streamline sound dumping
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
#include "Maps/MapEntsDumperIW3.h"
|
||||
#include "ObjWriting.h"
|
||||
#include "RawFile/RawFileDumperIW3.h"
|
||||
#include "Sound/AssetDumperLoadedSound.h"
|
||||
#include "Sound/LoadedSoundDumperIW3.h"
|
||||
#include "StringTable/StringTableDumperIW3.h"
|
||||
#include "Weapon/AssetDumperWeapon.h"
|
||||
|
||||
@@ -33,7 +33,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const
|
||||
DUMP_ASSET_POOL(image::Dumper, m_image, ASSET_TYPE_IMAGE)
|
||||
// DUMP_ASSET_POOL(AssetDumpersnd_alias_list_t, m_sound, ASSET_TYPE_SOUND)
|
||||
// DUMP_ASSET_POOL(AssetDumperSndCurve, m_sound_curve, ASSET_TYPE_SOUND_CURVE)
|
||||
DUMP_ASSET_POOL(AssetDumperLoadedSound, m_loaded_sound, ASSET_TYPE_LOADED_SOUND)
|
||||
DUMP_ASSET_POOL(sound::LoadedSoundDumper, m_loaded_sound, ASSET_TYPE_LOADED_SOUND)
|
||||
// DUMP_ASSET_POOL(AssetDumperClipMap, m_clip_map, ASSET_TYPE_CLIPMAP_PVS)
|
||||
// DUMP_ASSET_POOL(AssetDumperComWorld, m_com_world, ASSET_TYPE_COMWORLD)
|
||||
// DUMP_ASSET_POOL(AssetDumperGameWorldSp, m_game_world_sp, ASSET_TYPE_GAMEWORLD_SP)
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
#include "AssetDumperLoadedSound.h"
|
||||
|
||||
#include "Sound/WavTypes.h"
|
||||
#include "Sound/WavWriter.h"
|
||||
|
||||
#include <format>
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
bool AssetDumperLoadedSound::ShouldDump(XAssetInfo<LoadedSound>* asset)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void AssetDumperLoadedSound::DumpWavPcm(const LoadedSound* asset, std::ostream& stream)
|
||||
{
|
||||
const WavWriter writer(stream);
|
||||
|
||||
const WavMetaData metaData{.channelCount = static_cast<unsigned>(asset->sound.info.channels),
|
||||
.samplesPerSec = static_cast<unsigned>(asset->sound.info.rate),
|
||||
.bitsPerSample = static_cast<unsigned>(asset->sound.info.bits)};
|
||||
|
||||
writer.WritePcmHeader(metaData, asset->sound.info.data_len);
|
||||
writer.WritePcmData(asset->sound.data, asset->sound.info.data_len);
|
||||
}
|
||||
|
||||
void AssetDumperLoadedSound::DumpAsset(AssetDumpingContext& context, XAssetInfo<LoadedSound>* asset)
|
||||
{
|
||||
const auto* loadedSound = asset->Asset();
|
||||
const auto assetFile = context.OpenAssetFile(std::format("sound/{}", asset->m_name));
|
||||
|
||||
if (!assetFile)
|
||||
return;
|
||||
|
||||
auto& stream = *assetFile;
|
||||
switch (static_cast<WavFormat>(loadedSound->sound.info.format))
|
||||
{
|
||||
case WavFormat::PCM:
|
||||
DumpWavPcm(loadedSound, stream);
|
||||
break;
|
||||
|
||||
default:
|
||||
std::cerr << std::format("Unknown format {} for loaded sound: {}\n", loadedSound->sound.info.format, loadedSound->name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
52
src/ObjWriting/Game/IW3/Sound/LoadedSoundDumperIW3.cpp
Normal file
52
src/ObjWriting/Game/IW3/Sound/LoadedSoundDumperIW3.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "LoadedSoundDumperIW3.h"
|
||||
|
||||
#include "Sound/WavTypes.h"
|
||||
#include "Sound/WavWriter.h"
|
||||
|
||||
#include <format>
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
namespace
|
||||
{
|
||||
void DumpWavPcm(const LoadedSound* asset, std::ostream& stream)
|
||||
{
|
||||
const WavWriter writer(stream);
|
||||
|
||||
const WavMetaData metaData{.channelCount = static_cast<unsigned>(asset->sound.info.channels),
|
||||
.samplesPerSec = static_cast<unsigned>(asset->sound.info.rate),
|
||||
.bitsPerSample = static_cast<unsigned>(asset->sound.info.bits)};
|
||||
|
||||
writer.WritePcmHeader(metaData, asset->sound.info.data_len);
|
||||
writer.WritePcmData(asset->sound.data, asset->sound.info.data_len);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace IW3::sound
|
||||
{
|
||||
bool LoadedSoundDumper::ShouldDump(XAssetInfo<LoadedSound>* asset)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void LoadedSoundDumper::DumpAsset(AssetDumpingContext& context, XAssetInfo<LoadedSound>* asset)
|
||||
{
|
||||
const auto* loadedSound = asset->Asset();
|
||||
const auto assetFile = context.OpenAssetFile(std::format("sound/{}", asset->m_name));
|
||||
|
||||
if (!assetFile)
|
||||
return;
|
||||
|
||||
auto& stream = *assetFile;
|
||||
switch (static_cast<WavFormat>(loadedSound->sound.info.format))
|
||||
{
|
||||
case WavFormat::PCM:
|
||||
DumpWavPcm(loadedSound, stream);
|
||||
break;
|
||||
|
||||
default:
|
||||
std::cerr << std::format("Unknown format {} for loaded sound: {}\n", loadedSound->sound.info.format, loadedSound->name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // namespace IW3::sound
|
||||
@@ -3,14 +3,12 @@
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/IW3/IW3.h"
|
||||
|
||||
namespace IW3
|
||||
namespace IW3::sound
|
||||
{
|
||||
class AssetDumperLoadedSound final : public AbstractAssetDumper<LoadedSound>
|
||||
class LoadedSoundDumper final : public AbstractAssetDumper<LoadedSound>
|
||||
{
|
||||
static void DumpWavPcm(const LoadedSound* asset, std::ostream& stream);
|
||||
|
||||
protected:
|
||||
bool ShouldDump(XAssetInfo<LoadedSound>* asset) override;
|
||||
void DumpAsset(AssetDumpingContext& context, XAssetInfo<LoadedSound>* asset) override;
|
||||
};
|
||||
} // namespace IW3
|
||||
} // namespace IW3::sound
|
||||
Reference in New Issue
Block a user