mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-01-11 03:01:49 +00:00
refactor: streamline sound dumping
This commit is contained in:
@@ -17,8 +17,8 @@
|
||||
#include "RawFile/RawFileDumperIW4.h"
|
||||
#include "Shader/AssetDumperPixelShader.h"
|
||||
#include "Shader/AssetDumperVertexShader.h"
|
||||
#include "Sound/AssetDumperLoadedSound.h"
|
||||
#include "Sound/AssetDumperSndCurve.h"
|
||||
#include "Sound/LoadedSoundDumperIW4.h"
|
||||
#include "Sound/SndCurveDumperIW4.h"
|
||||
#include "StringTable/StringTableDumperIW4.h"
|
||||
#include "StructuredDataDef/AssetDumperStructuredDataDefSet.h"
|
||||
#include "Techset/TechsetDumperIW4.h"
|
||||
@@ -52,8 +52,8 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const
|
||||
DUMP_ASSET_POOL(techset::Dumper, m_technique_set, ASSET_TYPE_TECHNIQUE_SET)
|
||||
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::SndCurveDumper, m_sound_curve, ASSET_TYPE_SOUND_CURVE)
|
||||
DUMP_ASSET_POOL(sound::LoadedSoundDumper, m_loaded_sound, ASSET_TYPE_LOADED_SOUND)
|
||||
// DUMP_ASSET_POOL(AssetDumperClipMap, m_clip_map, ASSET_TYPE_CLIPMAP_MP)
|
||||
// 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 IW4;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
#include "AssetDumperSndCurve.h"
|
||||
|
||||
#include "Dumping/SndCurve/SndCurveDumper.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
std::string AssetDumperSndCurve::GetAssetFilename(const std::string& assetName)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
|
||||
ss << "soundaliases/" << assetName << ".vfcurve";
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
bool AssetDumperSndCurve::ShouldDump(XAssetInfo<SndCurve>* asset)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void AssetDumperSndCurve::DumpAsset(AssetDumpingContext& context, XAssetInfo<SndCurve>* asset)
|
||||
{
|
||||
const auto* sndCurve = asset->Asset();
|
||||
|
||||
const auto assetFile = context.OpenAssetFile(GetAssetFilename(sndCurve->filename));
|
||||
|
||||
if (!assetFile)
|
||||
return;
|
||||
|
||||
SndCurveDumper dumper(*assetFile);
|
||||
|
||||
const auto knotCount = std::min(static_cast<size_t>(sndCurve->knotCount), std::extent_v<decltype(SndCurve::knots)>);
|
||||
dumper.Init(knotCount);
|
||||
|
||||
for (auto i = 0u; i < knotCount; i++)
|
||||
dumper.WriteKnot(sndCurve->knots[i][0], sndCurve->knots[i][1]);
|
||||
}
|
||||
52
src/ObjWriting/Game/IW4/Sound/LoadedSoundDumperIW4.cpp
Normal file
52
src/ObjWriting/Game/IW4/Sound/LoadedSoundDumperIW4.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "LoadedSoundDumperIW4.h"
|
||||
|
||||
#include "Sound/WavTypes.h"
|
||||
#include "Sound/WavWriter.h"
|
||||
|
||||
#include <format>
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
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 IW4::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 IW4::sound
|
||||
@@ -3,14 +3,12 @@
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/IW4/IW4.h"
|
||||
|
||||
namespace IW4
|
||||
namespace IW4::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 IW4
|
||||
} // namespace IW4::sound
|
||||
45
src/ObjWriting/Game/IW4/Sound/SndCurveDumperIW4.cpp
Normal file
45
src/ObjWriting/Game/IW4/Sound/SndCurveDumperIW4.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "SndCurveDumperIW4.h"
|
||||
|
||||
#include "Dumping/SndCurve/SndCurveDumper.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
namespace
|
||||
{
|
||||
std::string GetAssetFilename(const std::string& assetName)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
|
||||
ss << "soundaliases/" << assetName << ".vfcurve";
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace IW4::sound
|
||||
{
|
||||
bool SndCurveDumper::ShouldDump(XAssetInfo<SndCurve>* asset)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void SndCurveDumper::DumpAsset(AssetDumpingContext& context, XAssetInfo<SndCurve>* asset)
|
||||
{
|
||||
const auto* sndCurve = asset->Asset();
|
||||
|
||||
const auto assetFile = context.OpenAssetFile(GetAssetFilename(sndCurve->filename));
|
||||
|
||||
if (!assetFile)
|
||||
return;
|
||||
|
||||
::SndCurveDumper dumper(*assetFile);
|
||||
|
||||
const auto knotCount = std::min(static_cast<size_t>(sndCurve->knotCount), std::extent_v<decltype(SndCurve::knots)>);
|
||||
dumper.Init(knotCount);
|
||||
|
||||
for (auto i = 0u; i < knotCount; i++)
|
||||
dumper.WriteKnot(sndCurve->knots[i][0], sndCurve->knots[i][1]);
|
||||
}
|
||||
} // namespace IW4::sound
|
||||
@@ -3,14 +3,12 @@
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/IW4/IW4.h"
|
||||
|
||||
namespace IW4
|
||||
namespace IW4::sound
|
||||
{
|
||||
class AssetDumperSndCurve final : public AbstractAssetDumper<SndCurve>
|
||||
class SndCurveDumper final : public AbstractAssetDumper<SndCurve>
|
||||
{
|
||||
static std::string GetAssetFilename(const std::string& assetName);
|
||||
|
||||
protected:
|
||||
bool ShouldDump(XAssetInfo<SndCurve>* asset) override;
|
||||
void DumpAsset(AssetDumpingContext& context, XAssetInfo<SndCurve>* asset) override;
|
||||
};
|
||||
} // namespace IW4
|
||||
} // namespace IW4::sound
|
||||
Reference in New Issue
Block a user