I am making a C++ sdl based game engine, so I am doing the Audio system right now, can…
- User
I am making a C++ sdl based game engine, so I am doing the Audio system right now, can you evaluate my code and check if everything is correct or what I could improve? Let's start with the AudioManager class: I will paste the header and the larger function, the rest are short so no problem with those:
class AudioManager { public: ~AudioManager(); AudioManager(const AudioManager&) = delete; AudioManager operator=(const AudioManager&) = delete; static AudioManager& GetInstance() noexcept; int ReserveChannel(); void ReleaseChannel(int channel); void SetChannelMasterVolume(int volume); void SetChannelVolume(int channel, int volume); void PauseChannel(int channel); void ResumeChannel(int channel); void StopChannel(int channel); void ExpireChannel(int channel, int ms); void FadeOutChannel(int channel, int ms); bool IsChannelUsed(int channel) const; void SetChannelEffectPanning(int channel, uint8_t left, uint8_t right); void SetChannelEffectDistance(int channel, uint8_t distance); void SetChannelEffectPosition(int channel, int16_t angle, uint8_t distance); void RemoveChannelEffects(int channel); SoundEffect& GetSoundEffect(const std::string& filePath); void PlaySound(const std::string& filePath, int loops = 0, int channel = -1); void PlaySoundFadeIn(const std::string& filePath, int ms, int loops = 0, int channel = -1); void FreeSound(const std::string& filePath); void FreeAllSound(); Music& GetMusic(const std::string& filePath); void FreeMusic(const std::string& filePath); void SetMusicMasterVolume(int volume); void CrossFade(const std::string& oldMusic, const std::string& newMusic, int ms, int loops = -1); void PauseAllMusic(); void ResumeAllMusic(); void StopAllMusic(); void FreeAllMusics(); void PauseAll(); void ResumeAll(); void StopAll();
codeprivate: AudioManager(); void AllocateChannels(int channels); int GetNextFreeChannel(); void SetChannelUsage(int channel, bool used); static void OnChannelFinish(int channel); void PlaySoundCommon(const std::string& filePath, std::function<void(SoundEffect&, int channel, int loops)> playAction, int loops = 0, int channel = -1); //private members};
void AudioManager::PlaySoundCommon(const std::string& filePath, std::function<void(SoundEffect&, int channel, int loops)> playAction, int loops, int channel) { SoundEffect sound = GetSoundEffect(filePath);
code - Assistant