23#define __WIZARD_ENGINE_INTERNAL__
28int8_t wze::audio::volume() {
29 return (int8_t)Mix_MasterVolume(-1);
32void wze::audio::set_volume(int8_t volume) {
33 Mix_MasterVolume(volume);
36std::vector<std::shared_ptr<wze::speaker>>& wze::audio::speakers() {
40void wze::audio::update() {
42 std::remove_if(speakers().begin(), speakers().end(),
43 [](std::shared_ptr<speaker>
const& speaker) ->
bool {
44 return !speaker || !speaker->playing();
48 std::for_each(speaker::instances().begin(), speaker::instances().end(),
49 [](speaker* instance) ->
void {
50 if (instance->auto_panning()) {
51 instance->align_panning();
56int32_t wze::audio::request_channel() {
60 channel != std::numeric_limits<int32_t>::max() - MIX_CHANNELS;
62 if (std::find(_channels.begin(), _channels.end(), channel) ==
64 _channels.push_back(channel);
65 if (_maximum_channel < channel) {
66 _maximum_channel = channel;
67 Mix_AllocateChannels(MIX_CHANNELS + _maximum_channel + 1);
69 return MIX_CHANNELS + channel;
73 throw exception(
"Channel allocation failed");
76void wze::audio::drop_channel(int32_t channel) {
77 if (!(
bool)Mix_UnregisterAllEffects(channel) ||
78 (
bool)Mix_HaltChannel(channel)) {
79 throw exception(Mix_GetError());
83 std::find(_channels.begin(), _channels.end(), channel -= MIX_CHANNELS));
84 if (channel == _maximum_channel) {
88 : *std::max_element(_channels.begin(), _channels.end());
89 Mix_AllocateChannels(MIX_CHANNELS + _maximum_channel + 1);
93void wze::audio::pause() {
97void wze::audio::resume() {
101void wze::audio::stop() {
102 if ((
bool)Mix_HaltChannel(-1)) {
103 throw exception(Mix_GetError());
107int32_t wze::audio::_maximum_channel = -1;
108std::vector<int32_t> wze::audio::_channels = {};
109std::vector<std::shared_ptr<wze::speaker>> wze::audio::_speakers = {};
Subsystem to handle global audio.