Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Alternative key detection algorithm #2135

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

daschuer
Copy link
Member

@daschuer daschuer commented Jun 2, 2019

This is a first prototype of a new key detection algorithm.

Highlights:

  • Only reliable results, returns Invalid if no reliable detection is possible.
  • improved reaction for short key changes.
  • More Minor affinity
  • Uses all notes with a 85 ms resolution, 1/32 Notes of a 160 BPM track. Originally we uses only one of eight notes. Drawback: 8 times more CPU.
  • clean up chrome from off tune notes before detecting any patterns
  • Use a combined scale and chord progression detection.
  • recognize Gipsy/Melodic/Harmonic scales (currently returned as invalid)

Compare results:

Green Day - Good Riddance (Time Of Your Life)
(A easy pure G major)
before:

1 : "C" 655360
8 : "G" 6.07757e+06

now:

0 : "INVALID" 72832
8 : "G" 6.66419e+06

Alan Walker - Faded
(Changing Minor/Major key)
before:

7 : "F♯/G♭" 9.21459e+06
16 : "D♯m/E♭m" 131072

now:

0 : "INVALID" 191104
2 : "D♭" 425984
7 : "F♯/G♭" 2.52314e+06
16 : "D♯m/E♭m" 5.90234e+06
23 : "B♭m" 311296

REM - Losing my religion
(previously wrong detected)
before:

1 : "C" 655360
6 : "F" 884736
8 : "G" 1.60563e+06
15 : "Dm" 1.5401e+06
17 : "Em" 4.16154e+06
22 : "Am" 2.98432e+06

now:

0 : "INVALID" 166272
1 : "C" 2.42074e+06
3 : "D" 32768
6 : "F" 217088
15 : "Dm" 4096
17 : "Em" 3.64954e+06
22 : "Am" 5.33709e+06

Moby - Bodyrock (Olav Basoskis Da Hot Funk Da Freak Funk Remix)
(Undetectable because of sweeping tones)
before:

2 : "D♭" 950272
3 : "D" 4.9152e+06
6 : "F" 65536
8 : "G" 5.12653e+06
9 : "A♭" 819200
10 : "A" 655360
11 : "B♭" 360448
15 : "Dm" 262144
17 : "Em" 2.75251e+06
19 : "F♯m" 294912
22 : "Am" 327680
23 : "B♭m" 131072
24 : "Bm" 294912

now:

0 : "INVALID" 1.69312e+07
2 : "D♭" 12288
10 : "A" 12288

Michael Jackson - Man in the Mirror
(known for its famous key change from G to Ab)
before:

1 : "C" 720896
2 : "D♭" 4.37389e+06
7 : "F♯/G♭" 65536
8 : "G" 7.11066e+06
9 : "A♭" 1.14688e+06
16 : "D♯m/E♭m" 65536
21 : "G♯m" 655360
24 : "Bm" 98304

now:

0 : "INVALID" 6.53658e+06
2 : "D♭" 61440
8 : "G" 2.01523e+06
9 : "A♭" 3.53485e+06
12 : "B" 16384
17 : "Em" 1.85958e+06
24 : "Bm" 204800

@daschuer
Copy link
Member Author

daschuer commented Jun 2, 2019

Christina Perri - Jar of Heards
(with a Melodic/Harmonic Minor bridge = Invalid)
before:

4 : "E♭" 1.06824e+07
10 : "A" 441600
13 : "Cm" 1.83501e+06
18 : "Fm" 32768

now:

0 : "INVALID" 2.37082e+06
1 : "C" 4096
4 : "E♭" 6.8649e+06
6 : "F" 163840
11 : "B♭" 1.06086e+06
13 : "Cm" 1.79814e+06
17 : "Em" 16384
20 : "Gm" 401408
23 : "B♭m" 4096
24 : "Bm" 299008

@uklotzde
Copy link
Contributor

uklotzde commented Jun 4, 2019

This patch is neither part of #2136 or #2137? I got lost.

@daschuer
Copy link
Member Author

daschuer commented Jun 4, 2019

I am currently rebasing this on top of #2137

@daschuer daschuer changed the title Improved key detection algorithm Alternative key detection algorithm Jun 9, 2019
@daschuer
Copy link
Member Author

daschuer commented Jun 9, 2019

Now rebased on the upstream fixes. And even better :-)

We can improve it more by a two pass analysis, forward and backward. And then sync key changes with phrases. Than a visualization in the overview widget will make the feature perfect.

For now we need a reasonable number of tests and identify miss detection.

How to handle key changes?

The Minor Major border within on scale (C<->Am) if fuzzy anyway and does not matter at all when looking for a compatible track. Even the far most common change to a neighbor scale in the circle of fifth is not that relevant, because of only one note of scale. So I think it OK to use only the major key for finding a compatible successor.

Problematic tracks are the rare tracks, recorded in a harmonic melodic and gypsy scale or tracks jumping in the circle of fifth like Michael Jackson's Man in the Mirror.

I propose not automatic to show a key for these tracks. I think it is in the responds of the DJ to set it or leave it blank. Alternative we may invent a new nomenclature for this. But I think it is only a negligible case.

Green Day - Good Riddance (Time Of Your Life)
(A easy pure G major)
before:

0 : "INVALID" 1.55864
8 : "G" 151.301

Alan Walker - Faded
(Changing Minor/Major key)

0 : "INVALID" 4.24054
2 : "D♭" 9.84526
7 : "F♯/G♭" 88.2358
16 : "D♯m/E♭m" 104.304
23 : "B♭m" 5.47991

REM - Losing my religion
(previously wrong detected)

0 : "INVALID" 3.4917
1 : "C" 16.7184
3 : "D" 0.278639
6 : "F" 3.06503
8 : "G" 0.650159
17 : "Em" 86.4711
22 : "Am" 157.617

Moby - Bodyrock (Olav Basoskis Da Hot Funk Da Freak Funk Remix)
(Undetectable because of sweeping tones)

0 : "INVALID" 383.37
2 : "D♭" 0.278639
10 : "A" 0.835918

Michael Jackson - Man in the Mirror
(known for its famous key change from G to Ab)

Debug [AnalyzerThread 0 #1]: 0 : "INVALID" 180.73
Debug [AnalyzerThread 0 #1]: 2 : "D♭" 0.743039
Debug [AnalyzerThread 0 #1]: 8 : "G" 17.0899
Debug [AnalyzerThread 0 #1]: 9 : "A♭" 38.0807
Debug [AnalyzerThread 0 #1]: 17 : "Em" 36.2231
Debug [AnalyzerThread 0 #1]: 18 : "Fm" 6.87311

Christina Perri - Jar of Heards
(with a Melodic/Harmonic Minor bridge = Invalid)

0 : "INVALID" 51.0133
1 : "C" 0.0853333
4 : "E♭" 171.264
11 : "B♭" 10.9227
13 : "Cm" 28.5013
17 : "Em" 0.0853333
20 : "Gm" 2.38933
24 : "Bm" 6.22933

@uklotzde
Copy link
Contributor

uklotzde commented Sep 1, 2019

Please rebase once again.

Is this a candidate for 2.3.0 or 2.4.0?

@Be-ing
Copy link
Contributor

Be-ing commented Sep 1, 2019

2.4. This is a big change that requires extensive testing and feedback.

@daschuer
Copy link
Member Author

daschuer commented Sep 1, 2019

This is a 2.4.0 candidate. This needs to be tweaked and tested a lot. Currently it works better for some tracks and worse for others by taking more CPU. No good trade ...

@daschuer daschuer changed the title Alternative key detection algorithm [WIP] Alternative key detection algorithm Sep 1, 2019
@uklotzde uklotzde added this to the 2.4.0 milestone Sep 1, 2019
@Be-ing Be-ing marked this pull request as draft June 15, 2020 03:54
@poelzi
Copy link
Contributor

poelzi commented Aug 26, 2020

@daschuer is it possible to implement a confidence level and in cases the confidence is very low, try the other algorithms. Or if computation power does not matter, try all in parallel and calculate the most likely result with confidence in mind.

@daschuer
Copy link
Member Author

Yes, that should be possible.

@daschuer
Copy link
Member Author

I even consider to not annotate the track at all if the confidence it so low for both. This is even better than clutter the library with misleading key values.

@Be-ing Be-ing changed the base branch from master to main October 23, 2020 23:26
@github-actions
Copy link

This PR is marked as stale because it has been open 90 days with no activity.

@github-actions github-actions bot added the stale Stale issues that haven't been updated for a long time. label Jan 23, 2021
@Be-ing Be-ing removed this from the 2.4.0 milestone Nov 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Stale issues that haven't been updated for a long time.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants