Some small changes to the audio code.

This commit is contained in:
Leon Styhre 2020-12-23 15:32:10 +01:00
parent bde34ddffd
commit f7c33ecd26
2 changed files with 13 additions and 6 deletions

View file

@ -71,6 +71,7 @@ Many bugs have been fixed, and numerous features that were only partially implem
* Refactoring, cleanup and documentation of the source code, removal of deprecated files etc. * Refactoring, cleanup and documentation of the source code, removal of deprecated files etc.
* All required fonts bundled with the application, no dependencies on the OS to provide them any longer * All required fonts bundled with the application, no dependencies on the OS to provide them any longer
* Made pugixml an external dependency instead of bundling it * Made pugixml an external dependency instead of bundling it
* Modernized the audio code, for example using SDL_AudioStream instead of the older SDL_AudioCVT
* Overhaul of application settings, now the configuration file is only updated when there have been actual configuration changes * Overhaul of application settings, now the configuration file is only updated when there have been actual configuration changes
* Decreased CPU usage dramatically by only rendering the currently visible view (previously all views were always rendered) * Decreased CPU usage dramatically by only rendering the currently visible view (previously all views were always rendered)
* Updated the CMake/CPack install and package build script to work as expected (it can now generate .deb, .rpm, .dmg and NSIS installation packages) * Updated the CMake/CPack install and package build script to work as expected (it can now generate .deb, .rpm, .dmg and NSIS installation packages)

View file

@ -59,7 +59,10 @@ void AudioManager::init()
SDL_memset(&sRequestedAudioFormat, 0, sizeof(sRequestedAudioFormat)); SDL_memset(&sRequestedAudioFormat, 0, sizeof(sRequestedAudioFormat));
SDL_memset(&sAudioFormat, 0, sizeof(sAudioFormat)); SDL_memset(&sAudioFormat, 0, sizeof(sAudioFormat));
// Set up format and callback. Play 16-bit stereo audio at 44.1Khz. // Set up format and callback. SDL will negotiate these settings with the audio driver, so
// if for instance the driver/hardware does not support 32-bit floating point output, 16-bit
// integer may be selected instead. ES-DE will handle this automatically as there are no
// hardcoded audio settings elsewhere in the code.
sRequestedAudioFormat.freq = 44100; sRequestedAudioFormat.freq = 44100;
sRequestedAudioFormat.format = AUDIO_F32; sRequestedAudioFormat.format = AUDIO_F32;
sRequestedAudioFormat.channels = 2; sRequestedAudioFormat.channels = 2;
@ -94,8 +97,8 @@ void AudioManager::init()
std::to_string(sRequestedAudioFormat.channels) << " could not be " std::to_string(sRequestedAudioFormat.channels) << " could not be "
"set, obtained " << std::to_string(sAudioFormat.channels) << "."; "set, obtained " << std::to_string(sAudioFormat.channels) << ".";
} }
#if defined(_WIN64) #if defined(_WIN64) || defined(__APPLE__)
// Beats me why the buffer size is not divided by the channel count on Windows. // Beats me why the buffer size is not divided by the channel count on some operating systems.
if (sAudioFormat.samples != sRequestedAudioFormat.samples) { if (sAudioFormat.samples != sRequestedAudioFormat.samples) {
#else #else
if (sAudioFormat.samples != sRequestedAudioFormat.samples / sRequestedAudioFormat.channels) { if (sAudioFormat.samples != sRequestedAudioFormat.samples / sRequestedAudioFormat.channels) {
@ -170,6 +173,8 @@ void AudioManager::mixAudio(void* /*unused*/, Uint8* stream, int len)
} }
// Process video stream audio. // Process video stream audio.
// The calling function in VideoVlcComponent is currently disabled as the internal
// handling of audio streaming from videos does not work correctly.
int chunkLength = SDL_AudioStreamAvailable(sConversionStream); int chunkLength = SDL_AudioStreamAvailable(sConversionStream);
if (chunkLength != 0) { if (chunkLength != 0) {
@ -199,13 +204,14 @@ void AudioManager::mixAudio(void* /*unused*/, Uint8* stream, int len)
return; return;
} }
// Currently disabled as it generates a lot of debug output. // Enable only when needed, as it generates a lot of debug output.
// LOG(LogDebug) << "AudioManager::mixAudio(): chunkLength / chunkSegment " // LOG(LogDebug) << "AudioManager::mixAudio(): chunkLength / chunkSegment "
// "/ processedLength: " << chunkLength << " / " << chunkSegment << // "/ processedLength: " << chunkLength << " / " << chunkSegment <<
// " / " << processedLength; // " / " << processedLength;
if (processedLength > 0) if (processedLength > 0)
SDL_MixAudioFormat(stream, converted, sAudioFormat.format, processedLength, 128); SDL_MixAudioFormat(stream, converted, sAudioFormat.format, processedLength,
Settings::getInstance()->getInt("SoundVolumeVideos") * 1.28);
} }
delete[] converted; delete[] converted;
@ -246,7 +252,7 @@ void AudioManager::stop()
{ {
// Stop playing all Sounds. // 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) && sSoundVector.at(i)->isPlaying()) if (sSoundVector.at(i)->isPlaying())
sSoundVector[i]->stop(); sSoundVector[i]->stop();
} }
// Pause audio. // Pause audio.