Skip to content

Commit

Permalink
- fix issue of false initialization of audio file resources when prev…
Browse files Browse the repository at this point in the history
…ious errors occurred during initialization
  • Loading branch information
TimGroeneboom committed Aug 25, 2022
1 parent 569c6c2 commit 0083ff4
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions modules/napaudio/src/audio/utility/audiofileutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ namespace nap
}

// Set the format settings for the handle
errorState.check(mpg123_format_none(mpgHandle) == MPG123_OK, "Error loading mp3 while setting format.");
errorState.check(mpg123_format(mpgHandle, 44100, MPG123_MONO | MPG123_STEREO, MPG123_ENC_FLOAT_32) == MPG123_OK, "Error loading mp3 while setting format.");
errorState.check(mpg123_format(mpgHandle, 48000, MPG123_MONO | MPG123_STEREO, MPG123_ENC_FLOAT_32) == MPG123_OK, "Error loading mp3 while setting format.");

// Clean up when an error has occured
if (!errorState.toString().empty())
{
mpg123_delete(mpgHandle);
return false;
}
if(!errorState.check(mpg123_format_none(mpgHandle) == MPG123_OK, "Error loading mp3 while setting format.") ||
!errorState.check(mpg123_format(mpgHandle, 44100, MPG123_MONO | MPG123_STEREO, MPG123_ENC_FLOAT_32) == MPG123_OK, "Error loading mp3 while setting format.") ||
!errorState.check(mpg123_format(mpgHandle, 48000, MPG123_MONO | MPG123_STEREO, MPG123_ENC_FLOAT_32) == MPG123_OK, "Error loading mp3 while setting format."))
{
// Clean up when an error has occured
mpg123_delete(mpgHandle);
return false;
}

// Request the buffersize
auto bufferSize = mpg123_outblock(mpgHandle);
Expand Down

0 comments on commit 0083ff4

Please sign in to comment.