2016-09-18 23:47:48 +00:00
|
|
|
#include "AGSC.hpp"
|
2018-09-03 00:46:16 +00:00
|
|
|
#include "amuse/AudioGroup.hpp"
|
|
|
|
#include "amuse/AudioGroupData.hpp"
|
2016-09-18 23:47:48 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace DataSpec::DNAMP2 {
|
|
|
|
|
|
|
|
bool AGSC::Extract(PAKEntryReadStream& rs, const hecl::ProjectPath& dir) {
|
|
|
|
dir.makeDirChain(true);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
/* Extract samples */
|
|
|
|
group.getSdir().extractAllCompressed(dir.getAbsolutePath(), data.getSamp());
|
|
|
|
|
|
|
|
/* Write out project/pool */
|
|
|
|
{
|
|
|
|
auto projd = group.getProj().toYAML();
|
2021-06-30 18:20:45 +00:00
|
|
|
athena::io::FileWriter fo(hecl::ProjectPath(dir, "!project.yaml").getAbsolutePath());
|
2018-12-08 05:30:43 +00:00
|
|
|
if (fo.hasError())
|
|
|
|
return false;
|
|
|
|
fo.writeUBytes(projd.data(), projd.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
auto poold = group.getPool().toYAML();
|
2021-06-30 18:20:45 +00:00
|
|
|
athena::io::FileWriter fo(hecl::ProjectPath(dir, "!pool.yaml").getAbsolutePath());
|
2018-12-08 05:30:43 +00:00
|
|
|
if (fo.hasError())
|
|
|
|
return false;
|
|
|
|
fo.writeUBytes(poold.data(), poold.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2016-09-18 23:47:48 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool AGSC::Cook(const hecl::ProjectPath& dir, const hecl::ProjectPath& outPath) {
|
|
|
|
athena::io::FileWriter w(outPath.getAbsolutePath());
|
|
|
|
if (w.hasError())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
amuse::ProjectDatabase projDb;
|
|
|
|
projDb.setIdDatabases();
|
|
|
|
amuse::AudioGroupDatabase group(dir.getAbsolutePath());
|
|
|
|
|
|
|
|
auto proj = group.getProj().toGCNData(group.getPool(), group.getSdir());
|
2019-09-14 14:53:08 +00:00
|
|
|
auto pool = group.getPool().toData<athena::Endian::Big>();
|
2018-12-08 05:30:43 +00:00
|
|
|
auto sdirSamp = group.getSdir().toGCNData(group);
|
|
|
|
|
|
|
|
Header head;
|
2021-06-30 18:20:45 +00:00
|
|
|
head.groupName = dir.getLastComponent();
|
2018-12-08 05:30:43 +00:00
|
|
|
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();
|
|
|
|
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());
|
|
|
|
|
|
|
|
return true;
|
2016-09-18 23:47:48 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace DataSpec::DNAMP2
|