Merge branch 'master' into jgrpp
# Conflicts: # .github/workflows/release-windows.yml # src/autoreplace_gui.cpp # src/cargotype.cpp # src/company_base.h # src/company_cmd.cpp # src/company_gui.cpp # src/currency.h # src/date_gui.cpp # src/dropdown.cpp # src/dropdown_func.h # src/dropdown_type.h # src/game/game_gui.cpp # src/genworld.cpp # src/genworld_gui.cpp # src/ground_vehicle.hpp # src/group_gui.cpp # src/house.h # src/industry_gui.cpp # src/network/network_client.cpp # src/network/network_server.cpp # src/network/network_type.h # src/newgrf_class_func.h # src/newgrf_house.cpp # src/newgrf_roadstop.h # src/openttd.cpp # src/order_gui.cpp # src/saveload/saveload.cpp # src/saveload/saveload.h # src/screenshot_gui.cpp # src/settings_gui.cpp # src/settings_type.h # src/slider.cpp # src/smallmap_gui.cpp # src/station_cmd.cpp # src/stdafx.h # src/survey.cpp # src/tile_map.h # src/town_cmd.cpp # src/town_gui.cpp # src/vehicle.cpp # src/vehicle_gui.cpp # src/vehicle_gui_base.h
This commit is contained in:
@@ -38,6 +38,7 @@ struct MixerChannel {
|
||||
};
|
||||
|
||||
static std::atomic<uint8_t> _active_channels;
|
||||
static std::atomic<uint8_t> _stop_channels;
|
||||
static MixerChannel _channels[8];
|
||||
static uint32_t _play_rate = 11025;
|
||||
static uint32_t _max_size = UINT_MAX;
|
||||
@@ -111,6 +112,16 @@ static void MxCloseChannel(uint8_t channel_index)
|
||||
_active_channels.fetch_and(~(1 << channel_index), std::memory_order_release);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close all mixer channels.
|
||||
* This signals to the mixer that each channel should be closed even if it has not played all remaining samples.
|
||||
* This is safe (and designed) to be called from the main thread.
|
||||
*/
|
||||
void MxCloseAllChannels()
|
||||
{
|
||||
_stop_channels.fetch_or(~0, std::memory_order_release);
|
||||
}
|
||||
|
||||
void MxMixSamples(void *buffer, uint samples)
|
||||
{
|
||||
PerformanceMeasurer framerate(PFE_SOUND);
|
||||
@@ -129,6 +140,12 @@ void MxMixSamples(void *buffer, uint samples)
|
||||
if (_music_stream) _music_stream((int16_t*)buffer, samples);
|
||||
}
|
||||
|
||||
/* Check if any channels should be stopped. */
|
||||
uint8_t stop = _stop_channels.load(std::memory_order_acquire);
|
||||
for (uint8_t idx : SetBitIterator(stop)) {
|
||||
MxCloseChannel(idx);
|
||||
}
|
||||
|
||||
/* 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
|
||||
@@ -203,6 +220,7 @@ 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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user