Expose all hash types, remove thread lock

This commit is contained in:
DataHoarder 2022-07-13 22:29:34 +02:00
parent 893bfbf139
commit 2177c747aa
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk
8 changed files with 45 additions and 40 deletions

2
go.mod
View file

@ -4,7 +4,7 @@ go 1.18
require (
git.gammaspectra.live/S.O.N.G/Kirika v0.0.0-20220713142734-894d8db69758
git.gammaspectra.live/S.O.N.G/goborator v0.0.0-20220713183340-736a80d773e7
git.gammaspectra.live/S.O.N.G/goborator v0.0.0-20220713201545-e92f79a950b7
)
require (

4
go.sum
View file

@ -2,8 +2,8 @@ git.gammaspectra.live/S.O.N.G/Kirika v0.0.0-20220713142734-894d8db69758 h1:e5mVs
git.gammaspectra.live/S.O.N.G/Kirika v0.0.0-20220713142734-894d8db69758/go.mod h1:HrYZb1M5dv2hOfpUhLOYkK4qQqBu+7hg7p14R19ebvs=
git.gammaspectra.live/S.O.N.G/go-pus v0.0.0-20220227175608-6cc027f24dba h1:JEaxCVgdr3XXAuDCPAx7ttLFZaaHzTEzG+oRnVUtUKU=
git.gammaspectra.live/S.O.N.G/go-pus v0.0.0-20220227175608-6cc027f24dba/go.mod h1:vkoHSHVM9p6vAUmXAik0gvaLcIfiQYrD6bQqVpOulUk=
git.gammaspectra.live/S.O.N.G/goborator v0.0.0-20220713183340-736a80d773e7 h1:jom+1roxWOAuyd77Xx7FAXrfkYAnZgQqv233Vk/2emE=
git.gammaspectra.live/S.O.N.G/goborator v0.0.0-20220713183340-736a80d773e7/go.mod h1:1Z/lAswjpOdysSp/lABpASPPuaaBFIK8L5Fu1SwO37E=
git.gammaspectra.live/S.O.N.G/goborator v0.0.0-20220713201545-e92f79a950b7 h1:eArmPzjU8Mf0f44mqhzeOcpK1OsnARikYymctgU3Ukw=
git.gammaspectra.live/S.O.N.G/goborator v0.0.0-20220713201545-e92f79a950b7/go.mod h1:1Z/lAswjpOdysSp/lABpASPPuaaBFIK8L5Fu1SwO37E=
git.gammaspectra.live/S.O.N.G/goflac v0.0.0-20220515172202-6e490998d2a0 h1:imcnwHUqaAJzws41B8sCSp/sUmVranNjAX205Jr4Jc0=
git.gammaspectra.live/S.O.N.G/goflac v0.0.0-20220515172202-6e490998d2a0/go.mod h1:/po1QgOh3xynbvi4sxdY6Iw8m5WPJfGGmry2boZD8fs=
github.com/cocoonlife/testify v0.0.0-20160218172820-792cc1faeb64 h1:LjPYdzoFSAJ5Tr/ElL8kzTJghXgpnOjJVbgd1UvZB1o=

View file

@ -19,6 +19,19 @@ type Fingerprint struct {
modHash uint32
}
type FingerprintHashType int
const (
//Hash An uint64. Space is not fully used.
Hash = FingerprintHashType(iota)
//CompactHash An uint32. Slightly changed fingerprint with f1Range as 6-bit instead of 8-bit, so it fits into 32-bit values
CompactHash
//RobustHash An uint32. Uses Morton2D functions. Experimental.
RobustHash
)
func NewFingerprint(p1, p2, p3 *EventPoint) *Fingerprint {
if p2.DeltaTime(p1) < 0 {
log.Panicf("p2.Time < p1.Time : %d < %d", p2.Time, p1.Time)
@ -61,6 +74,19 @@ func (f *Fingerprint) m3() float32 {
return f.entries[2].Magnitude
}
func (f *Fingerprint) GetHash(hashType FingerprintHashType) uint64 {
switch hashType {
case Hash:
return f.Hash()
case CompactHash:
return uint64(f.CompactHash())
case RobustHash:
return uint64(f.RobustHash())
default:
return 0
}
}
func (f *Fingerprint) RobustHash() uint32 {
f1LargerThanF2 := 0
if f.F1() > f.f2() {
@ -275,7 +301,7 @@ func (f *Fingerprint) Hash() uint64 {
return f.hash
}
// CompactHash Slightly changed fingerprint with f1Range as 6-bit instead of 8-bit so it fits into 32-bit values
// CompactHash Slightly changed fingerprint with f1Range as 6-bit instead of 8-bit, so it fits into 32-bit values
func (f *Fingerprint) CompactHash() uint32 {
if f.modHash != 0 {
return f.modHash

View file

@ -70,8 +70,8 @@ type Instance struct {
PointFilterMaximumFrequencyDistance Cent
//Other options
//CompactHash select whether to use Fingerprint.Hash or Fingerprint.CompactHash method when creating StoreRecord
CompactHash bool
//HashType select whether to use Fingerprint.Hash, Fingerprint.RobustHash or Fingerprint.CompactHash method when creating StoreRecord
HashType FingerprintHashType
}
func NewDefaultPackedInstance() *Instance {
@ -80,7 +80,7 @@ func NewDefaultPackedInstance() *Instance {
i.QueryMinimumHitsBeforeFiltering = 5
i.QueryMinimumHitsAfterFiltering = 3
i.QueryHitListDivisor = 2
i.CompactHash = true
i.HashType = CompactHash
return i
}
@ -112,7 +112,7 @@ func NewDefaultInstance() *Instance {
PointFilterMinimumFrequencyDistance: 1,
PointFilterMaximumFrequencyDistance: 128,
CompactHash: false,
HashType: Hash,
}
}

View file

@ -6,7 +6,6 @@ import (
"git.gammaspectra.live/S.O.N.G/Hibiki/utilities"
"git.gammaspectra.live/S.O.N.G/Kirika/audio"
"git.gammaspectra.live/S.O.N.G/goborator"
"runtime"
)
type EventPointProcessor struct {
@ -107,8 +106,6 @@ func (e *EventPointProcessor) GetLatency() int64 {
}
func (e *EventPointProcessor) processResultChannel(allMagnitudes chan []float32) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
for currentMagnitudes := range allMagnitudes {
e.magnitudes[e.magnitudesIndex] = currentMagnitudes

View file

@ -23,7 +23,7 @@ type StoreRecord struct {
Frequency uint32
}
// GetCompactPackedPrint Only use this when the Strategy option useCompactHash is true, and bounds range is known for Time (limited to 20-bit) and Frequency (limited to 12-bit)
// GetCompactPackedPrint Only use this when the Strategy instance option Instance.HashType is CompactHash, and bounds range is known for Time (limited to 20-bit) and Frequency (limited to 12-bit)
// This lets most of the max range for Frequency, and several hours of uninterrupted timestamps for Time
func (r *StoreRecord) GetCompactPackedPrint() (uint32, uint32) {
return uint32(r.Hash), (r.Time & 0b1111_1111_1111_1111_1111) | ((r.Frequency & 0b1111_1111_1111) << 20)

View file

@ -84,7 +84,7 @@ func (s *Strategy) QueryFingerprintsAsync(prints []*Fingerprint, callback func(q
}
func (s *Strategy) QueryFingerprints(prints []*Fingerprint) []QueryResult {
return s.QueryStoreRecords(getRecordsFromPrints(ResourceId(0), prints, s.instance.CompactHash))
return s.QueryStoreRecords(getRecordsFromPrints(ResourceId(0), prints, s.instance.HashType))
}
func (s *Strategy) QueryStoreRecords(records []StoreRecord) (queryResults []QueryResult) {
hitsPerResource := make(map[ResourceId][]*MatchedRecord)
@ -298,30 +298,19 @@ func mostCommonDeltaTforHitList(hitList []*MatchedRecord) int64 {
return mostCommonDeltaT
}
func getRecordsFromPrints(resourceId ResourceId, prints []*Fingerprint, useCompactHash bool) []StoreRecord {
func getRecordsFromPrints(resourceId ResourceId, prints []*Fingerprint, hashType FingerprintHashType) []StoreRecord {
records := make([]StoreRecord, 0, len(prints))
if useCompactHash {
for _, p := range prints {
records = append(records, StoreRecord{
ResourceId: resourceId,
Hash: uint64(p.CompactHash()),
Time: p.T1(),
Frequency: p.F1(),
})
}
} else {
for _, p := range prints {
records = append(records, StoreRecord{
ResourceId: resourceId,
Hash: p.Hash(),
Time: p.T1(),
Frequency: p.F1(),
})
}
for _, p := range prints {
records = append(records, StoreRecord{
ResourceId: resourceId,
Hash: p.GetHash(hashType),
Time: p.T1(),
Frequency: p.F1(),
})
}
return records
}
func (s *Strategy) StoreFingerprints(resourceId ResourceId, prints []*Fingerprint) {
s.store.StorePanakoPrints(getRecordsFromPrints(resourceId, prints, s.instance.CompactHash))
s.store.StorePanakoPrints(getRecordsFromPrints(resourceId, prints, s.instance.HashType))
}

View file

@ -1,12 +1,5 @@
package utilities
func AbsInt32(x int32) int32 {
if x < 0 {
return -x
}
return x
}
func AbsInt64(x int64) int64 {
if x < 0 {
return -x