mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-09 07:29:44 +00:00
Codechange: Use a type alias for mixer channel masking.
This commit is contained in:
parent
cba329d9e2
commit
bccf5343f4
@ -34,8 +34,10 @@ struct MixerChannel {
|
||||
bool is16bit;
|
||||
};
|
||||
|
||||
static std::atomic<uint8_t> _active_channels;
|
||||
static std::atomic<uint8_t> _stop_channels;
|
||||
using MixerChannelMask = uint8_t; ///< Type representing a bitmask of mixer channels.
|
||||
|
||||
static std::atomic<MixerChannelMask> _active_channels;
|
||||
static std::atomic<MixerChannelMask> _stop_channels;
|
||||
static MixerChannel _channels[8];
|
||||
static uint32_t _play_rate = 11025;
|
||||
static uint32_t _max_size = UINT_MAX;
|
||||
@ -106,7 +108,7 @@ static void mix_int16(MixerChannel *sc, int16_t *buffer, uint samples, uint8_t e
|
||||
|
||||
static void MxCloseChannel(uint8_t channel_index)
|
||||
{
|
||||
_active_channels.fetch_and(~(1 << channel_index), std::memory_order_release);
|
||||
_active_channels.fetch_and(~(1U << channel_index), std::memory_order_release);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -138,7 +140,7 @@ void MxMixSamples(void *buffer, uint samples)
|
||||
}
|
||||
|
||||
/* Check if any channels should be stopped. */
|
||||
uint8_t stop = _stop_channels.load(std::memory_order_acquire);
|
||||
MixerChannelMask stop = _stop_channels.load(std::memory_order_acquire);
|
||||
for (uint8_t idx : SetBitIterator(stop)) {
|
||||
MxCloseChannel(idx);
|
||||
}
|
||||
@ -153,7 +155,7 @@ void MxMixSamples(void *buffer, uint samples)
|
||||
effect_vol_setting) / (127 * 127);
|
||||
|
||||
/* Mix each channel */
|
||||
uint8_t active = _active_channels.load(std::memory_order_acquire);
|
||||
MixerChannelMask active = _active_channels.load(std::memory_order_acquire);
|
||||
for (uint8_t idx : SetBitIterator(active)) {
|
||||
MixerChannel *mc = &_channels[idx];
|
||||
if (mc->is16bit) {
|
||||
@ -167,8 +169,8 @@ void MxMixSamples(void *buffer, uint samples)
|
||||
|
||||
MixerChannel *MxAllocateChannel()
|
||||
{
|
||||
uint8_t currently_active = _active_channels.load(std::memory_order_acquire);
|
||||
uint8_t available = ~currently_active;
|
||||
MixerChannelMask currently_active = _active_channels.load(std::memory_order_acquire);
|
||||
MixerChannelMask available = ~currently_active;
|
||||
if (available == 0) return nullptr;
|
||||
|
||||
uint8_t channel_index = FindFirstBit(available);
|
||||
@ -217,8 +219,8 @@ void MxSetChannelVolume(MixerChannel *mc, uint volume, float pan)
|
||||
void MxActivateChannel(MixerChannel *mc)
|
||||
{
|
||||
uint8_t channel_index = mc - _channels;
|
||||
_stop_channels.fetch_and(~(1 << channel_index), std::memory_order_release);
|
||||
_active_channels.fetch_or((1 << channel_index), std::memory_order_release);
|
||||
_stop_channels.fetch_and(~(1U << channel_index), std::memory_order_release);
|
||||
_active_channels.fetch_or((1U << channel_index), std::memory_order_release);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user