Skip to content

Commit

Permalink
Fix sample rate calculation in RWAV and RSTM
Browse files Browse the repository at this point in the history
  • Loading branch information
em-eight committed Dec 27, 2024
1 parent 99156f6 commit 265ac8b
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion external/vgmtrans/SF2File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,4 +557,4 @@ bool SF2File::SaveSF2File(const std::filesystem::path &filepath) {
auto buf = SaveToMem();
rsnd::writeBinary(filepath, buf.data(), buf.size());
return true;
}
}
4 changes: 2 additions & 2 deletions external/vgmtrans/WaveAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ std::vector<WaveAudio> toWaveCollection(const rsnd::SoundBank *bankfile, void* w
WaveAudio& newWave = waveAudios[waveAudios.size() - 1];
newWave.data = pcmBuffer;
newWave.dataLength = sampleBufferSize;
newWave.sampleRate = waveInfo->sampleRate;
newWave.sampleRate = waveInfo->getSampleRate();
newWave.loop = waveInfo->loop;
newWave.loopStart = waveInfo->loopStart;
newWave.loopEnd = waveInfo->loopEnd;
Expand All @@ -47,7 +47,7 @@ WaveAudio toWaveAudio(const rsnd::SoundWave *waveFile) {

waveAudio.data = pcmBuffer;
waveAudio.dataLength = sampleBufferSize;
waveAudio.sampleRate = waveInfo->sampleRate;
waveAudio.sampleRate = waveInfo->getSampleRate();
waveAudio.loop = waveInfo->loop;
waveAudio.loopStart = waveInfo->loopStart;
waveAudio.loopEnd = waveInfo->loopEnd;
Expand Down
4 changes: 3 additions & 1 deletion include/rsnd/SoundStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct StreamDataInfo {
u8 format;
u8 loop;
u8 channelCount;
u8 sampleRate24;
u16 sampleRate;
u16 blockHeaderOffset;
u32 loopStart;
Expand All @@ -71,6 +72,7 @@ struct StreamDataInfo {
u32 adpcmDataSize;

void bswap();
u32 getSampleRate() const { return (sampleRate24 << 16) + sampleRate; }
};

struct TrackTable {
Expand Down Expand Up @@ -148,4 +150,4 @@ class SoundStream {
s16* getTrackPcm(u8 trackIdx, u8& channelCount) const;
void trackToWaveFile(u8 trackIdx, std::filesystem::path wavePath) const;
};
}
}
1 change: 1 addition & 0 deletions include/rsnd/soundCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ struct WaveInfo {
u32 _18;

void bswap();
u32 getSampleRate() const { return (sampleRate24 << 16) + sampleRate; }
};

inline u32 dspAddressToSamples(u32 samples) {
Expand Down
4 changes: 2 additions & 2 deletions src/rsnd/SoundStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ s16* SoundStream::getTrackPcm(u8 trackIdx, u8& channelCount) const {
void SoundStream::trackToWaveFile(u8 trackIdx, std::filesystem::path wavePath) const {
u8 channelCount;
void* data = getTrackPcm(trackIdx, channelCount);
createWaveFile(wavePath, data, getSampleCount(), strmDataInfo->sampleRate, channelCount);
createWaveFile(wavePath, data, getSampleCount(), strmDataInfo->getSampleRate(), channelCount);
free(data);
}
}
}
2 changes: 1 addition & 1 deletion src/rsnd/SoundWave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ s16* SoundWave::getTrackPcm() const {

void SoundWave::toWaveFile(std::filesystem::path wavePath) const {
void* data = getTrackPcm();
createWaveFile(wavePath, data, getTrackSampleCount(), info->sampleRate, info->channelCount);
createWaveFile(wavePath, data, getTrackSampleCount(), info->getSampleRate(), info->channelCount);
free(data);
}
}
2 changes: 1 addition & 1 deletion src/rsnd/SoundWsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void SoundWsd::trackToWaveFile(u8 trackIdx, void* waveData, std::filesystem::pat
decodeBlock(blockData, loopEnd, pcmBuffer + j, channelCount, waveInfo->format, adpcParams);
}

createWaveFile(wavePath, pcmBuffer, loopEnd, waveInfo->sampleRate, channelCount);
createWaveFile(wavePath, pcmBuffer, loopEnd, waveInfo->getSampleRate(), channelCount);

free(pcmBuffer);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,4 @@ void rsndExtract(const CliOpts& cliOpts) {

free(inputData);
}
}
}
6 changes: 3 additions & 3 deletions src/tools/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void rsndListRbnk(const SoundBank& soundBank, CliOpts& cliOpts) {
void rsndListRstm(const SoundStream& soundStream, CliOpts& cliOpts) {
const int trackCount = soundStream.trackTable->trackCount;
std::cout << "Track count: " << trackCount << '\n';
std::cout << "Sample rate: " << (int)soundStream.strmDataInfo->sampleRate << '\n';
std::cout << "Sample rate: " << soundStream.strmDataInfo->getSampleRate() << '\n';
std::cout << "Sample count: " << (int)soundStream.getSampleCount() << '\n';

for (int i = 0; i < trackCount; i++) {
Expand All @@ -203,7 +203,7 @@ void rsndListRstm(const SoundStream& soundStream, CliOpts& cliOpts) {

void rsndListRwav(const SoundWave& soundWave, CliOpts& cliOpts) {
std::cout << "Channel count: " << (int)soundWave.getChannelCount() << '\n';
std::cout << "Sample rate: " << (int)soundWave.info->sampleRate << '\n';
std::cout << "Sample rate: " << soundWave.info->getSampleRate() << '\n';
std::cout << "Sample count: " << (int)soundWave.getTrackSampleCount() << '\n';
}

Expand Down Expand Up @@ -285,4 +285,4 @@ void rsndList(CliOpts& cliOpts) {

free(inputData);
}
}
}

0 comments on commit 265ac8b

Please sign in to comment.