mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use std::byte for sound buffers.
parent
5585363407
commit
87fa1e41d5
|
@ -19,7 +19,7 @@
|
|||
|
||||
struct MixerChannel {
|
||||
/* 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 */
|
||||
uint32_t pos;
|
||||
|
@ -180,7 +180,7 @@ MixerChannel *MxAllocateChannel()
|
|||
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->frac_pos = 0;
|
||||
|
|
|
@ -24,7 +24,7 @@ bool MxInitialize(uint rate);
|
|||
void MxMixSamples(void *buffer, uint samples);
|
||||
|
||||
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 MxActivateChannel(MixerChannel*);
|
||||
void MxCloseAllChannels();
|
||||
|
|
|
@ -17,7 +17,7 @@ enum class SoundSource : uint8_t {
|
|||
};
|
||||
|
||||
struct SoundEntry {
|
||||
std::shared_ptr<std::vector<uint8_t>> data;
|
||||
std::shared_ptr<std::vector<std::byte>> data;
|
||||
class RandomAccessFile *file;
|
||||
size_t file_offset;
|
||||
size_t file_size;
|
||||
|
|
|
@ -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;
|
||||
|
||||
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()) {
|
||||
sound.file->SeekTo(pos, SEEK_SET);
|
||||
if (loader->Load(sound, new_format, *sound.data)) break;
|
||||
|
|
|
@ -32,7 +32,7 @@ public:
|
|||
static constexpr size_t DECODE_BUFFER_SAMPLES = 5760 * 2;
|
||||
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;
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ public:
|
|||
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.
|
||||
|
||||
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")
|
||||
* It's not a RIFF file, but raw PCM data.
|
||||
|
@ -42,7 +42,7 @@ public:
|
|||
|
||||
/* Convert 8-bit samples from unsigned to signed. */
|
||||
for (auto &sample : data) {
|
||||
sample = sample - 128;
|
||||
sample ^= std::byte{0x80};
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
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 */
|
||||
|
|
|
@ -23,7 +23,7 @@ public:
|
|||
|
||||
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;
|
||||
|
||||
|
@ -71,7 +71,7 @@ public:
|
|||
case 8:
|
||||
/* Convert 8-bit samples from unsigned to signed. */
|
||||
for (auto &sample : data) {
|
||||
sample = sample - 128;
|
||||
sample ^= std::byte{0x80};
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
Loading…
Reference in New Issue