Skip to content

Commit

Permalink
- fixed endless loop in replay gain analyzer when getting passed musi…
Browse files Browse the repository at this point in the history
…c with an unhandled sample rate.
  • Loading branch information
coelckers authored and mjr4077au committed Jul 17, 2021
1 parent 45dcbbc commit 3748f60
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
19 changes: 11 additions & 8 deletions source/common/audio/music/music.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,17 +613,20 @@ static void CheckReplayGain(const char *musicname, EMidiDevice playertype, const
ZMusic_Close(handle);

GainAnalyzer analyzer;
analyzer.InitGainAnalysis(fmt.mSampleRate);
int result = analyzer.AnalyzeSamples(lbuffer.Data(), rbuffer.Size() == 0 ? nullptr : rbuffer.Data(), lbuffer.Size(), rbuffer.Size() == 0? 1: 2);
int result = analyzer.InitGainAnalysis(fmt.mSampleRate);
if (result == GAIN_ANALYSIS_OK)
{
auto gain = analyzer.GetTitleGain();
Printf("Calculated replay gain for %s at %f dB\n", hash.GetChars(), gain);
result = analyzer.AnalyzeSamples(lbuffer.Data(), rbuffer.Size() == 0 ? nullptr : rbuffer.Data(), lbuffer.Size(), rbuffer.Size() == 0 ? 1 : 2);
if (result == GAIN_ANALYSIS_OK)
{
auto gain = analyzer.GetTitleGain();
Printf("Calculated replay gain for %s at %f dB\n", hash.GetChars(), gain);

gainMap.Insert(hash, gain);
mus_playing.replayGain = gain;
mus_playing.replayGainFactor = dBToAmplitude(mus_playing.replayGain + mus_gainoffset);
SaveGains();
gainMap.Insert(hash, gain);
mus_playing.replayGain = gain;
mus_playing.replayGainFactor = dBToAmplitude(mus_playing.replayGain + mus_gainoffset);
SaveGains();
}
}
}

Expand Down
1 change: 1 addition & 0 deletions source/common/thirdparty/gain_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ GainAnalyzer::ResetSampleFrequency(int samplefreq) {
freqindex = 9;
break;
case 11025:
case 11111: // SW shareware tries to play a VOC with this frequency as music. This is close enough to 11025 to use the same table.
freqindex = 10;
break;
case 8000:
Expand Down

0 comments on commit 3748f60

Please sign in to comment.