Codechange: automatic adding of _t to (u)int types, and WChar to char32_t
for i in `find src -type f|grep -v 3rdparty/fmt|grep -v 3rdparty/catch2|grep -v 3rdparty/opengl|grep -v stdafx.h`; do sed 's/uint16& /uint16 \&/g;s/int8\([ >*),;[]\)/int8_t\1/g;s/int16\([ >*),;[]\)/int16_t\1/g;s/int32\([ >*),;[]\)/int32_t\1/g;s/int64\([ >*),;[]\)/int64_t\1/g;s/ uint32(/ uint32_t(/g;s/_uint8_t/_uint8/;s/Uint8_t/Uint8/;s/ft_int64_t/ft_int64/g;s/uint64$/uint64_t/;s/WChar/char32_t/g;s/char32_t char32_t/char32_t WChar/' -i $i; done
This commit is contained in:
@@ -19,13 +19,13 @@
|
||||
|
||||
struct MixerChannel {
|
||||
/* pointer to allocated buffer memory */
|
||||
int8 *memory;
|
||||
int8_t *memory;
|
||||
|
||||
/* current position in memory */
|
||||
uint32 pos;
|
||||
uint32 frac_pos;
|
||||
uint32 frac_speed;
|
||||
uint32 samples_left;
|
||||
uint32_t pos;
|
||||
uint32_t frac_pos;
|
||||
uint32_t frac_speed;
|
||||
uint32_t samples_left;
|
||||
|
||||
/* Mixing volume */
|
||||
int volume_left;
|
||||
@@ -34,13 +34,13 @@ struct MixerChannel {
|
||||
bool is16bit;
|
||||
};
|
||||
|
||||
static std::atomic<uint8> _active_channels;
|
||||
static std::atomic<uint8_t> _active_channels;
|
||||
static MixerChannel _channels[8];
|
||||
static uint32 _play_rate = 11025;
|
||||
static uint32 _max_size = UINT_MAX;
|
||||
static uint32_t _play_rate = 11025;
|
||||
static uint32_t _max_size = UINT_MAX;
|
||||
static MxStreamCallback _music_stream = nullptr;
|
||||
static std::mutex _music_stream_mutex;
|
||||
static std::atomic<uint8> _effect_vol;
|
||||
static std::atomic<uint8_t> _effect_vol;
|
||||
|
||||
/**
|
||||
* The theoretical maximum volume for a single sound sample. Multiple sound
|
||||
@@ -63,15 +63,15 @@ static int RateConversion(T *b, int frac_pos)
|
||||
return ((b[0] * ((1 << 16) - frac_pos)) + (b[1] * frac_pos)) >> 16;
|
||||
}
|
||||
|
||||
static void mix_int16(MixerChannel *sc, int16 *buffer, uint samples, uint8 effect_vol)
|
||||
static void mix_int16(MixerChannel *sc, int16_t *buffer, uint samples, uint8_t effect_vol)
|
||||
{
|
||||
if (samples > sc->samples_left) samples = sc->samples_left;
|
||||
sc->samples_left -= samples;
|
||||
assert(samples > 0);
|
||||
|
||||
const int16 *b = (const int16 *)sc->memory + sc->pos;
|
||||
uint32 frac_pos = sc->frac_pos;
|
||||
uint32 frac_speed = sc->frac_speed;
|
||||
const int16_t *b = (const int16_t *)sc->memory + sc->pos;
|
||||
uint32_t frac_pos = sc->frac_pos;
|
||||
uint32_t frac_speed = sc->frac_speed;
|
||||
int volume_left = sc->volume_left * effect_vol / 255;
|
||||
int volume_right = sc->volume_right * effect_vol / 255;
|
||||
|
||||
@@ -96,18 +96,18 @@ static void mix_int16(MixerChannel *sc, int16 *buffer, uint samples, uint8 effec
|
||||
}
|
||||
|
||||
sc->frac_pos = frac_pos;
|
||||
sc->pos = b - (const int16 *)sc->memory;
|
||||
sc->pos = b - (const int16_t *)sc->memory;
|
||||
}
|
||||
|
||||
static void mix_int8_to_int16(MixerChannel *sc, int16 *buffer, uint samples, uint8 effect_vol)
|
||||
static void mix_int8_to_int16(MixerChannel *sc, int16_t *buffer, uint samples, uint8_t effect_vol)
|
||||
{
|
||||
if (samples > sc->samples_left) samples = sc->samples_left;
|
||||
sc->samples_left -= samples;
|
||||
assert(samples > 0);
|
||||
|
||||
const int8 *b = sc->memory + sc->pos;
|
||||
uint32 frac_pos = sc->frac_pos;
|
||||
uint32 frac_speed = sc->frac_speed;
|
||||
const int8_t *b = sc->memory + sc->pos;
|
||||
uint32_t frac_pos = sc->frac_pos;
|
||||
uint32_t frac_speed = sc->frac_speed;
|
||||
int volume_left = sc->volume_left * effect_vol / 255;
|
||||
int volume_right = sc->volume_right * effect_vol / 255;
|
||||
|
||||
@@ -135,7 +135,7 @@ static void mix_int8_to_int16(MixerChannel *sc, int16 *buffer, uint samples, uin
|
||||
sc->pos = b - sc->memory;
|
||||
}
|
||||
|
||||
static void MxCloseChannel(uint8 channel_index)
|
||||
static void MxCloseChannel(uint8_t channel_index)
|
||||
{
|
||||
_active_channels.fetch_and(~(1 << channel_index), std::memory_order_release);
|
||||
}
|
||||
@@ -150,31 +150,31 @@ void MxMixSamples(void *buffer, uint samples)
|
||||
}
|
||||
|
||||
/* Clear the buffer */
|
||||
memset(buffer, 0, sizeof(int16) * 2 * samples);
|
||||
memset(buffer, 0, sizeof(int16_t) * 2 * samples);
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock{ _music_stream_mutex };
|
||||
/* Fetch music if a sampled stream is available */
|
||||
if (_music_stream) _music_stream((int16*)buffer, samples);
|
||||
if (_music_stream) _music_stream((int16_t*)buffer, samples);
|
||||
}
|
||||
|
||||
/* Apply simple x^3 scaling to master effect volume. This increases the
|
||||
* perceived difference in loudness to better match expectations. effect_vol
|
||||
* is expected to be in the range 0-127 hence the division by 127 * 127 to
|
||||
* get back into range. */
|
||||
uint8 effect_vol_setting = _effect_vol.load(std::memory_order_relaxed);
|
||||
uint8 effect_vol = (effect_vol_setting *
|
||||
uint8_t effect_vol_setting = _effect_vol.load(std::memory_order_relaxed);
|
||||
uint8_t effect_vol = (effect_vol_setting *
|
||||
effect_vol_setting *
|
||||
effect_vol_setting) / (127 * 127);
|
||||
|
||||
/* Mix each channel */
|
||||
uint8 active = _active_channels.load(std::memory_order_acquire);
|
||||
for (uint8 idx : SetBitIterator(active)) {
|
||||
uint8_t active = _active_channels.load(std::memory_order_acquire);
|
||||
for (uint8_t idx : SetBitIterator(active)) {
|
||||
MixerChannel *mc = &_channels[idx];
|
||||
if (mc->is16bit) {
|
||||
mix_int16(mc, (int16*)buffer, samples, effect_vol);
|
||||
mix_int16(mc, (int16_t*)buffer, samples, effect_vol);
|
||||
} else {
|
||||
mix_int8_to_int16(mc, (int16*)buffer, samples, effect_vol);
|
||||
mix_int8_to_int16(mc, (int16_t*)buffer, samples, effect_vol);
|
||||
}
|
||||
if (mc->samples_left == 0) MxCloseChannel(idx);
|
||||
}
|
||||
@@ -182,11 +182,11 @@ void MxMixSamples(void *buffer, uint samples)
|
||||
|
||||
MixerChannel *MxAllocateChannel()
|
||||
{
|
||||
uint8 currently_active = _active_channels.load(std::memory_order_acquire);
|
||||
uint8 available = ~currently_active;
|
||||
uint8_t currently_active = _active_channels.load(std::memory_order_acquire);
|
||||
uint8_t available = ~currently_active;
|
||||
if (available == 0) return nullptr;
|
||||
|
||||
uint8 channel_index = FindFirstBit(available);
|
||||
uint8_t channel_index = FindFirstBit(available);
|
||||
|
||||
MixerChannel *mc = &_channels[channel_index];
|
||||
free(mc->memory);
|
||||
@@ -194,7 +194,7 @@ MixerChannel *MxAllocateChannel()
|
||||
return mc;
|
||||
}
|
||||
|
||||
void MxSetChannelRawSrc(MixerChannel *mc, int8 *mem, size_t size, uint rate, bool is16bit)
|
||||
void MxSetChannelRawSrc(MixerChannel *mc, int8_t *mem, size_t size, uint rate, bool is16bit)
|
||||
{
|
||||
mc->memory = mem;
|
||||
mc->frac_pos = 0;
|
||||
@@ -231,7 +231,7 @@ void MxSetChannelVolume(MixerChannel *mc, uint volume, float pan)
|
||||
|
||||
void MxActivateChannel(MixerChannel *mc)
|
||||
{
|
||||
uint8 channel_index = mc - _channels;
|
||||
uint8_t channel_index = mc - _channels;
|
||||
_active_channels.fetch_or((1 << channel_index), std::memory_order_release);
|
||||
}
|
||||
|
||||
@@ -240,7 +240,7 @@ void MxActivateChannel(MixerChannel *mc)
|
||||
* @param music_callback Function that will be called to fill sample buffers with music data.
|
||||
* @return Sample rate of mixer, which the buffers supplied to the callback must be rendered at.
|
||||
*/
|
||||
uint32 MxSetMusicSource(MxStreamCallback music_callback)
|
||||
uint32_t MxSetMusicSource(MxStreamCallback music_callback)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock{ _music_stream_mutex };
|
||||
_music_stream = music_callback;
|
||||
@@ -257,7 +257,7 @@ bool MxInitialize(uint rate)
|
||||
return true;
|
||||
}
|
||||
|
||||
void SetEffectVolume(uint8 volume)
|
||||
void SetEffectVolume(uint8_t volume)
|
||||
{
|
||||
_effect_vol.store(volume, std::memory_order_relaxed);
|
||||
}
|
||||
|
Reference in New Issue
Block a user