metaforce/DataSpec/DNAMP2/AGSC.cpp

85 lines
2.5 KiB
C++
Raw Normal View History

2016-09-18 23:47:48 +00:00
#include "AGSC.hpp"
#include "amuse/AudioGroup.hpp"
#include "amuse/AudioGroupData.hpp"
2016-09-18 23:47:48 +00:00
2017-12-29 08:08:12 +00:00
namespace DataSpec::DNAMP2
2016-09-18 23:47:48 +00:00
{
bool AGSC::Extract(PAKEntryReadStream& rs, const hecl::ProjectPath& dir)
2016-09-18 23:47:48 +00:00
{
dir.makeDirChain(true);
2016-09-18 23:47:48 +00:00
Header head;
head.read(rs);
auto pool = rs.readUBytes(head.poolSz);
auto proj = rs.readUBytes(head.projSz);
auto sdir = rs.readUBytes(head.sdirSz);
auto samp = rs.readUBytes(head.sampSz);
2016-09-18 23:47:48 +00:00
amuse::AudioGroupData data(proj.get(), head.projSz, pool.get(), head.poolSz,
sdir.get(), head.sdirSz, samp.get(), head.sampSz, amuse::GCNDataTag{});
/* Load into amuse representation */
amuse::ProjectDatabase projDb;
projDb.setIdDatabases();
amuse::AudioGroupDatabase group(data);
group.setGroupPath(dir.getAbsolutePath());
2016-09-18 23:47:48 +00:00
/* Extract samples */
group.getSdir().extractAllCompressed(dir.getAbsolutePath(), data.getSamp());
/* Write out project/pool */
2016-09-18 23:47:48 +00:00
{
auto projd = group.getProj().toYAML();
2018-10-14 20:16:21 +00:00
athena::io::FileWriter fo(hecl::ProjectPath(dir, _SYS_STR("!project.yaml")).getAbsolutePath());
if (fo.hasError())
return false;
fo.writeUBytes(projd.data(), projd.size());
2016-09-18 23:47:48 +00:00
}
{
auto poold = group.getPool().toYAML();
2018-10-14 20:16:21 +00:00
athena::io::FileWriter fo(hecl::ProjectPath(dir, _SYS_STR("!pool.yaml")).getAbsolutePath());
if (fo.hasError())
return false;
fo.writeUBytes(poold.data(), poold.size());
2016-09-18 23:47:48 +00:00
}
return true;
}
bool AGSC::Cook(const hecl::ProjectPath& dir, const hecl::ProjectPath& outPath)
2016-09-18 23:47:48 +00:00
{
athena::io::FileWriter w(outPath.getAbsolutePath());
if (w.hasError())
return false;
amuse::ProjectDatabase projDb;
projDb.setIdDatabases();
amuse::AudioGroupDatabase group(dir.getAbsolutePath());
2016-09-18 23:47:48 +00:00
auto proj = group.getProj().toGCNData(group.getPool(), group.getSdir());
auto pool = group.getPool().toData<athena::Big>();
auto sdirSamp = group.getSdir().toGCNData(group);
2016-09-18 23:47:48 +00:00
Header head;
head.groupName = dir.getLastComponentUTF8();
for (const auto& p : group.getProj().sfxGroups())
head.groupId = p.first.id;
head.poolSz = pool.size();
head.projSz = proj.size();
head.sdirSz = sdirSamp.first.size();
head.sampSz = sdirSamp.second.size();
2016-09-18 23:47:48 +00:00
head.write(w);
w.writeUBytes(pool.data(), pool.size());
w.writeUBytes(proj.data(), proj.size());
w.writeUBytes(sdirSamp.first.data(), sdirSamp.first.size());
w.writeUBytes(sdirSamp.second.data(), sdirSamp.second.size());
2016-09-18 23:47:48 +00:00
return true;
}
}