mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-10-24 15:25:52 +00:00
refactor: streamline sound dumping
This commit is contained in:
@@ -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