Skip to content

Commit

Permalink
Add ShazamKit signature sample
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekseyMartynov committed Sep 17, 2023
1 parent be82d47 commit bec59b5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
21 changes: 15 additions & 6 deletions Tagging/Sig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,18 @@ static class Sig {
using var mem = new MemoryStream(data);
using var reader = new BinaryReader(mem);

var magicKey = reader.ReadUInt32();
var legacyFormat = false;

if(reader.ReadUInt32() != 0xcafe2580) {
if(magicKey == 0x25802580) {
var w1 = reader.ReadInt32(); // count?
var w2 = reader.ReadInt32(); // offset?
if(w1 != 1 || w2 != 12)
throw new NotSupportedException();
magicKey = reader.ReadUInt32();
}

if(magicKey != 0xcafe2580) {
if(reader.ReadUInt32() == 0x789abc05) {
legacyFormat = true;
} else {
Expand All @@ -133,18 +142,18 @@ static class Sig {
if(legacyFormat) {
sampleRate = 16000;

mem.Position = 21 * 4;
mem.Position += 19 * 4;
sampleCount = 2 * reader.ReadInt32();

mem.Position = 26 * 4;
mem.Position += 4 * 4;
} else {
mem.Position = 7 * 4;
mem.Position += 6 * 4;
sampleRate = SampleRateFromCode(reader.ReadInt32() >> 27);

mem.Position = 10 * 4;
mem.Position += 2 * 4;
sampleCount = reader.ReadInt32();

mem.Position = 14 * 4;
mem.Position += 3 * 4;
}

var writableBands = new List<PeakInfo>[4];
Expand Down
1 change: 1 addition & 0 deletions Test/SignatureComparisonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Project.Test {
public class SignatureComparisonTests {

[Theory]
[InlineData("10.2.1")] // https://developer.apple.com/shazamkit/android/
[InlineData("10.1.3")] // APK v13.45
[InlineData("7.2.0")] // APK v8.66
[InlineData("6.0.4", false)] // APK v8.3
Expand Down
Binary file added TestData/test-sigx-10.2.1.bin
Binary file not shown.

0 comments on commit bec59b5

Please sign in to comment.