diff --git a/es-core/src/AudioManager.cpp b/es-core/src/AudioManager.cpp index 1d8dec2ac..bfe69108e 100644 --- a/es-core/src/AudioManager.cpp +++ b/es-core/src/AudioManager.cpp @@ -59,7 +59,7 @@ void AudioManager::init() sRequestedAudioFormat.callback = mixAudio; sRequestedAudioFormat.userdata = nullptr; - for (int i = 0; i < SDL_GetNumAudioDevices(0); ++i) { + for (int i {0}; i < SDL_GetNumAudioDevices(0); ++i) { LOG(LogInfo) << "Detected playback device: " << SDL_GetAudioDeviceName(i, 0); } @@ -126,7 +126,7 @@ void AudioManager::deinit() void AudioManager::mixAudio(void* /*unused*/, Uint8* stream, int len) { // Process navigation sounds. - bool stillPlaying = false; + bool stillPlaying {false}; // Initialize the buffer to "silence". SDL_memset(stream, 0, len); @@ -134,10 +134,10 @@ void AudioManager::mixAudio(void* /*unused*/, Uint8* stream, int len) // Iterate through all our samples. std::vector>::const_iterator soundIt = sSoundVector.cbegin(); while (soundIt != sSoundVector.cend()) { - std::shared_ptr sound = *soundIt; + std::shared_ptr sound {*soundIt}; if (sound->isPlaying()) { // Calculate rest length of current sample. - Uint32 restLength = (sound->getLength() - sound->getPosition()); + Uint32 restLength {sound->getLength() - sound->getPosition()}; if (restLength > static_cast(len)) { // If stream length is smaller than sample length, clip it. restLength = len; @@ -159,7 +159,7 @@ void AudioManager::mixAudio(void* /*unused*/, Uint8* stream, int len) } // Process video stream audio generated by VideoFFmpegComponent. - int streamLength = SDL_AudioStreamAvailable(sConversionStream); + int streamLength {SDL_AudioStreamAvailable(sConversionStream)}; if (streamLength <= 0) { // If nothing is playing, pause the device until there is more audio to output. @@ -168,7 +168,7 @@ void AudioManager::mixAudio(void* /*unused*/, Uint8* stream, int len) return; } - int chunkLength = 0; + int chunkLength {0}; // Cap the chunk length to the buffer size. if (streamLength > len) @@ -178,8 +178,8 @@ void AudioManager::mixAudio(void* /*unused*/, Uint8* stream, int len) std::vector converted(chunkLength); - int processedLength = - SDL_AudioStreamGet(sConversionStream, static_cast(&converted.at(0)), chunkLength); + int processedLength { + SDL_AudioStreamGet(sConversionStream, static_cast(&converted.at(0)), chunkLength)}; if (processedLength < 0) { LOG(LogError) << "AudioManager::mixAudio(): Couldn't convert sound chunk:"; @@ -196,7 +196,7 @@ void AudioManager::mixAudio(void* /*unused*/, Uint8* stream, int len) // stream is not played when the video player has been stopped. Otherwise there would // be a short time period when the audio would keep playing after the video was stopped // and before the stream was cleared in clearStream(). - bool muteStream = sMuteStream; + bool muteStream {sMuteStream}; if (muteStream) { SDL_MixAudioFormat(stream, &converted.at(0), sAudioFormat.format, processedLength, 0); } @@ -219,14 +219,13 @@ void AudioManager::registerSound(std::shared_ptr sound) void AudioManager::unregisterSound(std::shared_ptr sound) { - for (unsigned int i = 0; i < sSoundVector.size(); ++i) { + for (unsigned int i {0}; i < sSoundVector.size(); ++i) { if (sSoundVector.at(i) == sound) { sSoundVector[i]->stop(); sSoundVector.erase(sSoundVector.cbegin() + i); return; } } - LOG(LogError) << "AudioManager - tried to unregister a sound that wasn't registered"; } void AudioManager::play() @@ -238,7 +237,7 @@ void AudioManager::play() void AudioManager::stop() { // Stop playing all Sounds. - for (unsigned int i = 0; i < sSoundVector.size(); ++i) { + for (unsigned int i {0}; i < sSoundVector.size(); ++i) { if (sSoundVector.at(i)->isPlaying()) sSoundVector[i]->stop(); } @@ -248,7 +247,7 @@ void AudioManager::stop() void AudioManager::setupAudioStream(int sampleRate) { - SDL_AudioStatus audioStatus = SDL_GetAudioDeviceStatus(sAudioDevice); + SDL_AudioStatus audioStatus {SDL_GetAudioDeviceStatus(sAudioDevice)}; // It's very important to pause the audio device before setting up the stream, // or we may get random crashes if attempting to play samples at the same time.