From af60d6b7cd60c8855febb0847bd66169780dd1ef Mon Sep 17 00:00:00 2001 From: Rubidium Date: Tue, 30 Jun 2026 22:03:23 +0200 Subject: [PATCH] Codechange: use Label for the tags in a Wave file --- src/soundloader_wav.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/soundloader_wav.cpp b/src/soundloader_wav.cpp index fd9b12846d..68646e5ca2 100644 --- a/src/soundloader_wav.cpp +++ b/src/soundloader_wav.cpp @@ -8,6 +8,7 @@ /** @file soundloader_wav.cpp Loading of wav sounds. */ #include "stdafx.h" +#include "core/label_type.hpp" #include "core/math_func.hpp" #include "debug.h" #include "random_access_file_type.h" @@ -16,6 +17,20 @@ #include "safeguards.h" +using WavTag = Label; ///< Label for different tags in the file + +/** + * Read a \c WavTag from the file. + * @param file The file to read from. + * @return The read \c WavTag. + */ +WavTag ReadWavTag(RandomAccessFile &file) +{ + WavTag tag; + file.ReadBlock(tag.data(), tag.size()); + return tag; +} + /** Wav file (RIFF/WAVE) sound loader. */ class SoundLoader_Wav : public SoundLoader { public: @@ -28,16 +43,16 @@ public: RandomAccessFile &file = *sound.file; /* Check RIFF/WAVE header. */ - if (file.ReadDword() != std::byteswap('RIFF')) return false; + if (ReadWavTag(file) != WavTag{"RIFF"}) return false; file.ReadDword(); // Skip data size - if (file.ReadDword() != std::byteswap('WAVE')) return false; + if (ReadWavTag(file) != WavTag{"WAVE"}) return false; /* Read riff tags */ for (;;) { - uint32_t tag = file.ReadDword(); + WavTag tag = ReadWavTag(file); uint32_t size = file.ReadDword(); - if (tag == std::byteswap('fmt ')) { + if (tag == WavTag{"fmt "}) { uint16_t format = file.ReadWord(); if (format != 1) { Debug(grf, 0, "SoundLoader_Wav: Unsupported format {}, expected 1 (uncompressed PCM).", format); @@ -64,7 +79,7 @@ public: /* We've read 16 bytes of this chunk, we can skip anything extra. */ size -= 16; - } else if (tag == std::byteswap('data')) { + } else if (tag == WavTag{"data"}) { uint align = sound.channels * sound.bits_per_sample / 8; if (Align(size, align) != size) { /* Ensure length is aligned correctly for channels and BPS. */