//go:build cgo package replaygain import ( "fmt" "git.gammaspectra.live/S.O.N.G/Kirika/audio" "git.gammaspectra.live/S.O.N.G/Kirika/audio/format/guess" "git.gammaspectra.live/S.O.N.G/Kirika/test" "os" "path" "testing" ) func TestReplayGainNormalization24(t *testing.T) { fp, err := os.Open(test.SingleSample24) if err != nil { t.Error(err) return } defer fp.Close() source, err := guess.GetDecoder("flac").Open(fp) if err != nil { t.Error(err) return } source = NewNormalizationFilter(5).Process(source) gain, peak, err := GetTrackReplayGain(source) if err != nil { t.Error(err) return } expect := "-0.033242 dB, 0.627992" result := fmt.Sprintf("%f dB, %f", gain, peak) if result != expect { t.Errorf("Wrong ReplayGain %s != %s", result, expect) } } func TestReplayGain24(t *testing.T) { fp, err := os.Open(test.SingleSample24) if err != nil { t.Error(err) return } defer fp.Close() source, err := guess.GetDecoder("flac").Open(fp) if err != nil { t.Error(err) return } gain, peak, err := GetTrackReplayGain(source) if err != nil { t.Error(err) return } expect := "-11.590849 dB, 1.000000" result := fmt.Sprintf("%f dB, %f", gain, peak) if result != expect { t.Errorf("Wrong ReplayGain %s != %s", result, expect) } } func TestReplayGain16(t *testing.T) { fp, err := os.Open(test.SingleSample16) if err != nil { t.Error(err) return } defer fp.Close() source, err := guess.GetDecoder("flac").Open(fp) if err != nil { t.Error(err) return } gain, peak, err := GetTrackReplayGain(source) if err != nil { t.Error(err) return } expect := "-7.747937 dB, 0.942108" result := fmt.Sprintf("%f dB, %f", gain, peak) if result != expect { t.Errorf("Wrong ReplayGain %s != %s", result, expect) } } func TestAlbumReplayGain(t *testing.T) { location := test.SampleLocations[1] entries, err := os.ReadDir(location) if err != nil { t.Error(err) return } var sources []audio.Source for _, f := range entries { if path.Ext(f.Name()) == ".flac" { fullPath := path.Join(location, f.Name()) fp, err := os.Open(fullPath) if err != nil { t.Error(err) return } defer fp.Close() decoders, err := guess.GetDecoders(fp, fullPath) if err != nil { t.Error(err) return } source, err := guess.Open(fp, decoders) if err != nil { t.Error(err) return } sources = append(sources, source) } } albumGain, albumPeak, trackGains, trackPeaks, err := GetAlbumReplayGain(sources) if err != nil { t.Error(err) return } expect := "-8.539515 dB, 0.970886, [-7.747937 -9.020477 -9.192292 -8.015346 -8.302924 -9.071570 -9.355825 -8.114620 -7.760179 -7.316909 -8.339533 -8.906009 -8.000808], [0.942108 0.970886 0.970886 0.970886 0.942078 0.970886 0.970886 0.965576 0.970886 0.970886 0.942108 0.970886 0.942108]" result := fmt.Sprintf("%f dB, %f, %f, %f", albumGain, albumPeak, trackGains, trackPeaks) if result != expect { t.Errorf("Wrong ReplayGain %s != %s", result, expect) } }