1
0
Fork 0

Codechange: Use std::byte for sound buffers.

pull/12096/head
Peter Nelson 2025-05-13 01:08:07 +01:00 committed by Peter Nelson
parent 5585363407
commit 87fa1e41d5
8 changed files with 11 additions and 11 deletions

View File

@ -19,7 +19,7 @@
struct MixerChannel { struct MixerChannel {
/* pointer to allocated buffer memory */ /* pointer to allocated buffer memory */
std::shared_ptr<std::vector<uint8_t>> memory; std::shared_ptr<std::vector<std::byte>> memory;
/* current position in memory */ /* current position in memory */
uint32_t pos; uint32_t pos;
@ -180,7 +180,7 @@ MixerChannel *MxAllocateChannel()
return mc; return mc;
} }
void MxSetChannelRawSrc(MixerChannel *mc, const std::shared_ptr<std::vector<uint8_t>> &mem, uint rate, bool is16bit) void MxSetChannelRawSrc(MixerChannel *mc, const std::shared_ptr<std::vector<std::byte>> &mem, uint rate, bool is16bit)
{ {
mc->memory = mem; mc->memory = mem;
mc->frac_pos = 0; mc->frac_pos = 0;

View File

@ -24,7 +24,7 @@ bool MxInitialize(uint rate);
void MxMixSamples(void *buffer, uint samples); void MxMixSamples(void *buffer, uint samples);
MixerChannel *MxAllocateChannel(); MixerChannel *MxAllocateChannel();
void MxSetChannelRawSrc(MixerChannel *mc, const std::shared_ptr<std::vector<uint8_t>> &mem, uint rate, bool is16bit); void MxSetChannelRawSrc(MixerChannel *mc, const std::shared_ptr<std::vector<std::byte>> &mem, uint rate, bool is16bit);
void MxSetChannelVolume(MixerChannel *mc, uint volume, float pan); void MxSetChannelVolume(MixerChannel *mc, uint volume, float pan);
void MxActivateChannel(MixerChannel*); void MxActivateChannel(MixerChannel*);
void MxCloseAllChannels(); void MxCloseAllChannels();

View File

@ -17,7 +17,7 @@ enum class SoundSource : uint8_t {
}; };
struct SoundEntry { struct SoundEntry {
std::shared_ptr<std::vector<uint8_t>> data; std::shared_ptr<std::vector<std::byte>> data;
class RandomAccessFile *file; class RandomAccessFile *file;
size_t file_offset; size_t file_offset;
size_t file_size; size_t file_size;

View File

@ -26,7 +26,7 @@ bool LoadSoundData(SoundEntry &sound, bool new_format, SoundID sound_id, const s
if (sound.file_size == 0 || sound.file_size > SIZE_MAX - 2) return false; if (sound.file_size == 0 || sound.file_size > SIZE_MAX - 2) return false;
size_t pos = sound.file->GetPos(); size_t pos = sound.file->GetPos();
sound.data = std::make_shared<std::vector<uint8_t>>(); sound.data = std::make_shared<std::vector<std::byte>>();
for (auto &loader : ProviderManager<SoundLoader>::GetProviders()) { for (auto &loader : ProviderManager<SoundLoader>::GetProviders()) {
sound.file->SeekTo(pos, SEEK_SET); sound.file->SeekTo(pos, SEEK_SET);
if (loader->Load(sound, new_format, *sound.data)) break; if (loader->Load(sound, new_format, *sound.data)) break;

View File

@ -32,7 +32,7 @@ public:
static constexpr size_t DECODE_BUFFER_SAMPLES = 5760 * 2; static constexpr size_t DECODE_BUFFER_SAMPLES = 5760 * 2;
static constexpr size_t DECODE_BUFFER_BYTES = DECODE_BUFFER_SAMPLES * sizeof(opus_int16); static constexpr size_t DECODE_BUFFER_BYTES = DECODE_BUFFER_SAMPLES * sizeof(opus_int16);
bool Load(SoundEntry &sound, bool new_format, std::vector<uint8_t> &data) override bool Load(SoundEntry &sound, bool new_format, std::vector<std::byte> &data) override
{ {
if (!new_format) return false; if (!new_format) return false;

View File

@ -22,7 +22,7 @@ public:
static constexpr uint16_t RAW_SAMPLE_RATE = 11025; ///< Sample rate of raw pcm samples. static constexpr uint16_t RAW_SAMPLE_RATE = 11025; ///< Sample rate of raw pcm samples.
static constexpr uint8_t RAW_SAMPLE_BITS = 8; ///< Bit depths of raw pcm samples. static constexpr uint8_t RAW_SAMPLE_BITS = 8; ///< Bit depths of raw pcm samples.
bool Load(SoundEntry &sound, bool new_format, std::vector<uint8_t> &data) override bool Load(SoundEntry &sound, bool new_format, std::vector<std::byte> &data) override
{ {
/* Raw sounds are apecial case for the jackhammer sound (name in Windows sample.cat is "Corrupt sound") /* Raw sounds are apecial case for the jackhammer sound (name in Windows sample.cat is "Corrupt sound")
* It's not a RIFF file, but raw PCM data. * It's not a RIFF file, but raw PCM data.
@ -42,7 +42,7 @@ public:
/* Convert 8-bit samples from unsigned to signed. */ /* Convert 8-bit samples from unsigned to signed. */
for (auto &sample : data) { for (auto &sample : data) {
sample = sample - 128; sample ^= std::byte{0x80};
} }
return true; return true;

View File

@ -26,7 +26,7 @@ public:
ProviderManager<SoundLoader>::Unregister(*this); ProviderManager<SoundLoader>::Unregister(*this);
} }
virtual bool Load(SoundEntry &sound, bool new_format, std::vector<uint8_t> &data) = 0; virtual bool Load(SoundEntry &sound, bool new_format, std::vector<std::byte> &data) = 0;
}; };
#endif /* SOUNDLOADER_TYPE_H */ #endif /* SOUNDLOADER_TYPE_H */

View File

@ -23,7 +23,7 @@ public:
static constexpr uint16_t DEFAULT_SAMPLE_RATE = 11025; static constexpr uint16_t DEFAULT_SAMPLE_RATE = 11025;
bool Load(SoundEntry &sound, bool new_format, std::vector<uint8_t> &data) override bool Load(SoundEntry &sound, bool new_format, std::vector<std::byte> &data) override
{ {
RandomAccessFile &file = *sound.file; RandomAccessFile &file = *sound.file;
@ -71,7 +71,7 @@ public:
case 8: case 8:
/* Convert 8-bit samples from unsigned to signed. */ /* Convert 8-bit samples from unsigned to signed. */
for (auto &sample : data) { for (auto &sample : data) {
sample = sample - 128; sample ^= std::byte{0x80};
} }
break; break;