Skip to content

Commit

Permalink
Merge pull request #28 from Laupetin/feature/t6-sound-dumping
Browse files Browse the repository at this point in the history
T6 sound data dumping
  • Loading branch information
Laupetin authored Oct 26, 2023
2 parents 4ac04dc + 51899d4 commit 1c56bf4
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 122 deletions.
8 changes: 4 additions & 4 deletions src/ObjLoading/ObjContainer/SoundBank/SoundBankTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ struct SoundAssetBankEntry
unsigned int size;
unsigned int offset;
unsigned int frameCount;
char frameRateIndex;
char channelCount;
char looping;
char format;
unsigned char frameRateIndex;
unsigned char channelCount;
unsigned char looping;
unsigned char format;
};
42 changes: 8 additions & 34 deletions src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperLoadedSound.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "AssetDumperLoadedSound.h"

#include "Sound/WavTypes.h"
#include "Sound/WavWriter.h"

using namespace IW4;

Expand All @@ -11,43 +12,16 @@ bool AssetDumperLoadedSound::ShouldDump(XAssetInfo<LoadedSound>* asset)

void AssetDumperLoadedSound::DumpWavPcm(AssetDumpingContext& context, const LoadedSound* asset, std::ostream& stream)
{
const auto riffMasterChunkSize = sizeof(WAV_CHUNK_ID_RIFF)
+ sizeof(uint32_t)
+ sizeof(WAV_WAVE_ID)
+ sizeof(WavChunkHeader)
+ sizeof(WavFormatChunkPcm)
+ sizeof(WavChunkHeader)
+ sizeof(asset->sound.info.data_len);
const WavWriter writer(stream);

stream.write(reinterpret_cast<const char*>(&WAV_CHUNK_ID_RIFF), sizeof(WAV_CHUNK_ID_RIFF));
stream.write(reinterpret_cast<const char*>(&riffMasterChunkSize), sizeof(riffMasterChunkSize));
stream.write(reinterpret_cast<const char*>(&WAV_WAVE_ID), sizeof(WAV_WAVE_ID));

const WavChunkHeader formatChunkHeader
{
WAV_CHUNK_ID_FMT,
sizeof(WavFormatChunkPcm)
const WavMetaData metaData{
static_cast<unsigned>(asset->sound.info.channels),
static_cast<unsigned>(asset->sound.info.rate),
static_cast<unsigned>(asset->sound.info.bits)
};
stream.write(reinterpret_cast<const char*>(&formatChunkHeader), sizeof(formatChunkHeader));

WavFormatChunkPcm formatChunk
{
WavFormat::PCM,
static_cast<uint16_t>(asset->sound.info.channels),
asset->sound.info.rate,
asset->sound.info.rate * asset->sound.info.channels * asset->sound.info.bits / 8,
static_cast<uint16_t>(asset->sound.info.block_size),
static_cast<uint16_t>(asset->sound.info.bits)
};
stream.write(reinterpret_cast<const char*>(&formatChunk), sizeof(formatChunk));

const WavChunkHeader dataChunkHeader
{
WAV_CHUNK_ID_DATA,
asset->sound.info.data_len
};
stream.write(reinterpret_cast<const char*>(&dataChunkHeader), sizeof(dataChunkHeader));
stream.write(asset->sound.data, asset->sound.info.data_len);
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)
Expand Down
Loading

0 comments on commit 1c56bf4

Please sign in to comment.