10#include <SDL2/SDL_mixer.h>
34 constexpr I32 flags = MIX_INIT_OGG | MIX_INIT_MP3 | MIX_INIT_FLAC;
36 const I32 ret = Mix_Init(flags);
37 if ((ret & flags) == flags)
40 if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 4096) == -1)
44 if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 2048) == -1)
63 for (
const MusicMap::value_type& it :
_musicMap)
65 Mix_FreeMusic(it.second);
67 for (
const SoundMap::value_type& it :
_soundMap)
69 Mix_FreeChunk(it.second);
73 g_sfxDevice =
nullptr;
87 if (music != INVALID_HANDLE<AudioDescriptor>)
95 mixMusicPtr = Mix_LoadMUS((musicPtr->assetLocation() / musicPtr->assetName()).string().c_str() );
101 if ( musicPtr->dirty())
103 mixMusicPtr = Mix_LoadMUS( (musicPtr->assetLocation() / musicPtr->assetName()).string().c_str() );
104 Mix_FreeMusic(it->second);
105 it->second = mixMusicPtr;
110 mixMusicPtr = it->second;
116 Mix_VolumeMusic( musicPtr->volume());
117 if (Mix_PlayMusic( mixMusicPtr, musicPtr->isLooping() ? -1 : 0) == -1)
131 if (sound != INVALID_HANDLE<AudioDescriptor> )
135 Mix_Chunk* mixSoundPtr =
nullptr;
139 mixSoundPtr = Mix_LoadWAV( (soundPtr->assetLocation() / soundPtr->assetName()).string().c_str() );
145 if ( soundPtr->dirty())
147 mixSoundPtr = Mix_LoadWAV( (soundPtr->assetLocation() / soundPtr->assetName()).string().c_str() );
148 Mix_FreeChunk(it->second);
149 it->second = mixSoundPtr;
154 mixSoundPtr = it->second;
160 Mix_Volume( soundPtr->channelID(), soundPtr->volume());
161 if (Mix_PlayChannel( soundPtr->channelID(), mixSoundPtr, soundPtr->isLooping() ? -1 : 0) == -1)
struct _Mix_Music Mix_Music
Audio Programming Interface.
PlatformContext & _context
SFXDevice & sfx() noexcept
void playMusic(const Handle< AudioDescriptor > music) override
SDL_API(PlatformContext &context)
void closeAudioAPI() override
ErrorCode initAudioAPI() override
void musicFinished() noexcept override
void playSound(const Handle< AudioDescriptor > sound) override
void stopMusic() noexcept override
void musicFinished() noexcept override
Handle console commands that start with a forward slash.
void insert(eastl::vector< T, A1 > &target, const eastl::vector< T, A2 > &source)
@ SDL_AUDIO_MIX_INIT_ERROR
FORCE_INLINE T * Get(const Handle< T > handle)
void musicFinishedHook() noexcept
static NO_INLINE void errorfn(const char *format, T &&... args)