mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-08 10:27:08 +02:00
Merge 0038bcd7f3 into 52135913d4
This commit is contained in:
commit
53986cd7f0
2 changed files with 56 additions and 0 deletions
|
|
@ -11,6 +11,16 @@ const calculateReplayGain = (preAmp, gain, peak) => {
|
|||
export const calculateGain = (gainInfo, song) => {
|
||||
switch (gainInfo.gainMode) {
|
||||
case 'album': {
|
||||
// Fall back to track gain when the album gain is missing (singles, or
|
||||
// tracks without album ReplayGain tags), matching common ReplayGain
|
||||
// players instead of applying no adjustment at all.
|
||||
if (song.rgAlbumGain === undefined || song.rgAlbumPeak === undefined) {
|
||||
return calculateReplayGain(
|
||||
gainInfo.preAmp,
|
||||
song.rgTrackGain,
|
||||
song.rgTrackPeak,
|
||||
)
|
||||
}
|
||||
return calculateReplayGain(
|
||||
gainInfo.preAmp,
|
||||
song.rgAlbumGain,
|
||||
|
|
|
|||
46
ui/src/utils/calculateReplayGain.test.js
Normal file
46
ui/src/utils/calculateReplayGain.test.js
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import { describe, it, expect } from 'vitest'
|
||||
import { calculateGain } from './calculateReplayGain'
|
||||
|
||||
describe('calculateGain', () => {
|
||||
const preAmp = 0
|
||||
|
||||
const albumSong = {
|
||||
rgAlbumGain: -6,
|
||||
rgAlbumPeak: 1,
|
||||
rgTrackGain: -3,
|
||||
rgTrackPeak: 1,
|
||||
}
|
||||
const trackOnlySong = {
|
||||
rgTrackGain: -3,
|
||||
rgTrackPeak: 1,
|
||||
}
|
||||
const noGainSong = {}
|
||||
|
||||
it('uses album gain in album mode when it is present', () => {
|
||||
const result = calculateGain({ gainMode: 'album', preAmp }, albumSong)
|
||||
expect(result).toBeCloseTo(10 ** (-6 / 20))
|
||||
})
|
||||
|
||||
it('falls back to track gain in album mode when the album gain is missing', () => {
|
||||
const result = calculateGain({ gainMode: 'album', preAmp }, trackOnlySong)
|
||||
// Without the fallback this returned 1 (no adjustment). It should now use
|
||||
// the track gain instead.
|
||||
expect(result).toBeCloseTo(10 ** (-3 / 20))
|
||||
expect(result).not.toBe(1)
|
||||
})
|
||||
|
||||
it('returns 1 in album mode when neither album nor track gain is present', () => {
|
||||
const result = calculateGain({ gainMode: 'album', preAmp }, noGainSong)
|
||||
expect(result).toBe(1)
|
||||
})
|
||||
|
||||
it('uses track gain in track mode', () => {
|
||||
const result = calculateGain({ gainMode: 'track', preAmp }, albumSong)
|
||||
expect(result).toBeCloseTo(10 ** (-3 / 20))
|
||||
})
|
||||
|
||||
it('returns 1 when gain is disabled', () => {
|
||||
const result = calculateGain({ gainMode: 'none', preAmp }, albumSong)
|
||||
expect(result).toBe(1)
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue