Skip to content

Commit 607c722

Browse files
committed
Prevent infinite db values
1 parent e88b5d9 commit 607c722

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/AudioTools/AudioStreams.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,11 +1684,19 @@ class VolumeMeter : public ModifyingStream {
16841684
/// Volume Ratio of indicated channel: max amplitude is 1.0
16851685
float volumeRatio(int channel) { return volume(channel) / NumberConverter::maxValue(info.bits_per_sample);}
16861686

1687-
/// Volume in db: max amplitude is 0
1688-
float volumeDB() { return 20.0f * log10(volumeRatio());}
1687+
/// Volume in db: max amplitude is 0 (range: -1000 to 0)
1688+
float volumeDB() {
1689+
// prevent infinite value
1690+
if (volumeRatio()==0) return -1000;
1691+
return 20.0f * log10(volumeRatio());
1692+
}
16891693

16901694
/// Volume of indicated channel in db: max amplitude is 0
1691-
float volumeDB(int channel) { return 20.0f * log10(volumeRatio(channel));}
1695+
float volumeDB(int channel) {
1696+
// prevent infinite value
1697+
if (volumeRatio(channel)==0) return -1000;
1698+
return 20.0f * log10(volumeRatio(channel));
1699+
}
16921700

16931701
/// Volume in %: max amplitude is 100
16941702
float volumePercent() { return 100.0f * volumeRatio();}

0 commit comments

Comments
 (0)