mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-03 20:47:35 +03:00
ReplayGain support + audio normalization (web player) (#1988)
* ReplayGain support - extract ReplayGain tags from files, expose via native api - use metadata to normalize audio in web player * make pre-push happy * remove unnecessary prints * remove another unnecessary print * add tooltips, see metadata * address comments, use settings instead * remove console.log * use better language for gain modes
This commit is contained in:
parent
9ae156dd82
commit
1324a16fc5
24 changed files with 411 additions and 56 deletions
|
@ -75,6 +75,13 @@ func (s mediaFileMapper) toMediaFile(md metadata.Tags) model.MediaFile {
|
|||
mf.CreatedAt = time.Now()
|
||||
mf.UpdatedAt = md.ModificationTime()
|
||||
|
||||
if conf.Server.EnableReplayGain {
|
||||
mf.RGAlbumGain = md.RGAlbumGain()
|
||||
mf.RGAlbumPeak = md.RGAlbumPeak()
|
||||
mf.RGTrackGain = md.RGTrackGain()
|
||||
mf.RGTrackPeak = md.RGTrackPeak()
|
||||
}
|
||||
|
||||
return *mf
|
||||
}
|
||||
|
||||
|
|
|
@ -302,4 +302,23 @@ Input #0, mp3, from '/Users/deluan/Music/Music/Media/_/Wyclef Jean - From the Hu
|
|||
md, _ := e.extractMetadata("tests/fixtures/test.ogg", output)
|
||||
Expect(md).To(HaveKeyWithValue("fbpm", []string{"141.7"}))
|
||||
})
|
||||
|
||||
It("parses replaygain data correctly", func() {
|
||||
const output = `
|
||||
Input #0, mp3, from 'test.mp3':
|
||||
Metadata:
|
||||
REPLAYGAIN_ALBUM_PEAK: 0.9125
|
||||
REPLAYGAIN_TRACK_PEAK: 0.4512
|
||||
REPLAYGAIN_TRACK_GAIN: -1.48 dB
|
||||
REPLAYGAIN_ALBUM_GAIN: +3.21518 dB
|
||||
Side data:
|
||||
replaygain: track gain - -1.480000, track peak - 0.000011, album gain - 3.215180, album peak - 0.000021,
|
||||
`
|
||||
md, _ := e.extractMetadata("tests/fixtures/test.mp3", output)
|
||||
Expect(md).To(HaveKeyWithValue("replaygain_track_gain", []string{"-1.48 dB"}))
|
||||
Expect(md).To(HaveKeyWithValue("replaygain_track_peak", []string{"0.4512"}))
|
||||
Expect(md).To(HaveKeyWithValue("replaygain_album_gain", []string{"+3.21518 dB"}))
|
||||
Expect(md).To(HaveKeyWithValue("replaygain_album_peak", []string{"0.9125"}))
|
||||
|
||||
})
|
||||
})
|
||||
|
|
|
@ -143,6 +143,39 @@ func (t Tags) Size() int64 { return t.fileInfo.Size() }
|
|||
func (t Tags) FilePath() string { return t.filePath }
|
||||
func (t Tags) Suffix() string { return strings.ToLower(strings.TrimPrefix(path.Ext(t.filePath), ".")) }
|
||||
|
||||
// Replaygain Properties
|
||||
func (t Tags) RGAlbumGain() float64 { return t.getGainValue("replaygain_album_gain") }
|
||||
func (t Tags) RGAlbumPeak() float64 { return t.getPeakValue("replaygain_album_peak") }
|
||||
func (t Tags) RGTrackGain() float64 { return t.getGainValue("replaygain_track_gain") }
|
||||
func (t Tags) RGTrackPeak() float64 { return t.getPeakValue("replaygain_track_peak") }
|
||||
|
||||
func (t Tags) getGainValue(tagName string) float64 {
|
||||
// Gain is in the form [-]a.bb dB
|
||||
var tag = t.getFirstTagValue(tagName)
|
||||
|
||||
if tag == "" {
|
||||
return 0
|
||||
}
|
||||
|
||||
tag = strings.TrimSpace(strings.Replace(tag, "dB", "", 1))
|
||||
|
||||
var value, err = strconv.ParseFloat(tag, 64)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func (t Tags) getPeakValue(tagName string) float64 {
|
||||
var tag = t.getFirstTagValue(tagName)
|
||||
var value, err = strconv.ParseFloat(tag, 64)
|
||||
if err != nil {
|
||||
// A default of 1 for peak value resulds in no changes
|
||||
return 1
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func (t Tags) getTags(tagNames ...string) []string {
|
||||
for _, tag := range tagNames {
|
||||
if v, ok := t.tags[tag]; ok {
|
||||
|
|
|
@ -41,6 +41,10 @@ var _ = Describe("Tags", func() {
|
|||
Expect(m.FilePath()).To(Equal("tests/fixtures/test.mp3"))
|
||||
Expect(m.Suffix()).To(Equal("mp3"))
|
||||
Expect(m.Size()).To(Equal(int64(51876)))
|
||||
Expect(m.RGAlbumGain()).To(Equal(3.21518))
|
||||
Expect(m.RGAlbumPeak()).To(Equal(0.9125))
|
||||
Expect(m.RGTrackGain()).To(Equal(-1.48))
|
||||
Expect(m.RGTrackPeak()).To(Equal(0.4512))
|
||||
|
||||
m = mds["tests/fixtures/test.ogg"]
|
||||
Expect(err).To(BeNil())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue