mirror of
https://github.com/cgzirim/seek-tune.git
synced 2025-12-17 08:54:19 +00:00
refactor: improve variable names and update comments for clarity
This commit is contained in:
parent
854b94fca6
commit
f1430ffb8b
1 changed files with 12 additions and 8 deletions
|
|
@ -18,21 +18,21 @@ type Match struct {
|
||||||
Score float64
|
Score float64
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindMatches processes the audio samples and finds matches in the database
|
// FindMatches analyzes the audio sample to find matching songs in the database.
|
||||||
func FindMatches(audioSamples []float64, audioDuration float64, sampleRate int) ([]Match, time.Duration, error) {
|
func FindMatches(audioSample []float64, audioDuration float64, sampleRate int) ([]Match, time.Duration, error) {
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
logger := utils.GetLogger()
|
logger := utils.GetLogger()
|
||||||
|
|
||||||
spectrogram, err := Spectrogram(audioSamples, sampleRate)
|
spectrogram, err := Spectrogram(audioSample, sampleRate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, time.Since(startTime), fmt.Errorf("failed to get spectrogram of samples: %v", err)
|
return nil, time.Since(startTime), fmt.Errorf("failed to get spectrogram of samples: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
peaks := ExtractPeaks(spectrogram, audioDuration)
|
peaks := ExtractPeaks(spectrogram, audioDuration)
|
||||||
fingerprints := Fingerprint(peaks, utils.GenerateUniqueID())
|
sampleFingerprint := Fingerprint(peaks, utils.GenerateUniqueID())
|
||||||
|
|
||||||
addresses := make([]uint32, 0, len(fingerprints))
|
addresses := make([]uint32, 0, len(sampleFingerprint))
|
||||||
for address := range fingerprints {
|
for address := range sampleFingerprint {
|
||||||
addresses = append(addresses, address)
|
addresses = append(addresses, address)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -53,7 +53,10 @@ func FindMatches(audioSamples []float64, audioDuration float64, sampleRate int)
|
||||||
|
|
||||||
for address, couples := range m {
|
for address, couples := range m {
|
||||||
for _, couple := range couples {
|
for _, couple := range couples {
|
||||||
matches[couple.SongID] = append(matches[couple.SongID], [2]uint32{fingerprints[address].AnchorTimeMs, couple.AnchorTimeMs})
|
matches[couple.SongID] = append(
|
||||||
|
matches[couple.SongID],
|
||||||
|
[2]uint32{sampleFingerprint[address].AnchorTimeMs, couple.AnchorTimeMs},
|
||||||
|
)
|
||||||
timestamps[couple.SongID] = append(timestamps[couple.SongID], couple.AnchorTimeMs)
|
timestamps[couple.SongID] = append(timestamps[couple.SongID], couple.AnchorTimeMs)
|
||||||
|
|
||||||
if _, ok := targetZones[couple.SongID]; !ok {
|
if _, ok := targetZones[couple.SongID]; !ok {
|
||||||
|
|
@ -122,7 +125,8 @@ func filterMatches(
|
||||||
return filteredMatches
|
return filteredMatches
|
||||||
}
|
}
|
||||||
|
|
||||||
// AnalyzeRelativeTiming checks for consistent relative timing and returns a score
|
// analyzeRelativeTiming calculates a score for each song based on the
|
||||||
|
// relative timing between the song and the sample's anchor times.
|
||||||
func analyzeRelativeTiming(matches map[uint32][][2]uint32) map[uint32]float64 {
|
func analyzeRelativeTiming(matches map[uint32][][2]uint32) map[uint32]float64 {
|
||||||
scores := make(map[uint32]float64)
|
scores := make(map[uint32]float64)
|
||||||
for songID, times := range matches {
|
for songID, times := range matches {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue