-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 754e8a5
Showing
56 changed files
with
3,012 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.dockerignore | ||
.idea | ||
project/project | ||
project/target | ||
target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
FROM ubuntu:18.04 | ||
|
||
ENV SBT_VERSION 1.2.8 | ||
ENV SCALA_VERSION 2.12 | ||
ENV CHROMAPRINT_VERSION 0.1.0-SNAPSHOT | ||
|
||
RUN \ | ||
sed -i 's/# \(.*multiverse$\)/\1/g' /etc/apt/sources.list && \ | ||
apt-get update && \ | ||
apt-get -y upgrade && \ | ||
apt-get install -y \ | ||
build-essential \ | ||
software-properties-common \ | ||
curl \ | ||
default-jdk \ | ||
ffmpeg \ | ||
libavcodec-extra | ||
|
||
RUN \ | ||
curl -L -o sbt-$SBT_VERSION.deb https://dl.bintray.com/sbt/debian/sbt-$SBT_VERSION.deb && \ | ||
dpkg -i sbt-$SBT_VERSION.deb && \ | ||
rm sbt-$SBT_VERSION.deb && \ | ||
apt-get update && \ | ||
apt-get install -y \ | ||
sbt | ||
|
||
RUN mkdir /chromaprint | ||
ADD . /chromaprint | ||
WORKDIR /chromaprint | ||
|
||
RUN sbt package | ||
RUN sbt assembly | ||
|
||
RUN echo "#!/bin/sh\n\ | ||
set -e\n\ | ||
sh -c \"java -jar /chromaprint/target/scala-$SCALA_VERSION/chromaprint-assembly-$CHROMAPRINT_VERSION.jar \$@\"\n\ | ||
" > /docker-entrypoint.sh && \ | ||
chmod +x /docker-entrypoint.sh | ||
|
||
ENTRYPOINT ["/docker-entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Copyright (c) 2019 Mike Gibson, https://github.com/mgdigital | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
|
||
Original Chromaprint algorithm Copyright (c) Lukáš Lalinský. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# Chromaprint.scala | ||
|
||
An implementation of the [Chromaprint][1]/[AcoustID][2] audio fingerprinting algorithm for the JVM, created originally in C++ by [Lukáš Lalinský][3]. | ||
|
||
## What does it do? | ||
|
||
It creates an [audio fingerprint][4] designed to identify near-identical audio tracks in the [AcoustID][2] and [MusicBrainz][5] databases. This can be used to identify unknown tracks, find duplicates and look up metadata. | ||
|
||
## How does it work? | ||
|
||
The algorithm performs a pipeline of operations on an audio stream to extract its fingerprint: | ||
|
||
- The audio is resampled to mono at 11500Hz | ||
- It is split into a series of short _frames_ | ||
- A [Fast Fourier Transform][6] is performed on each frame to extract components of different frequencies | ||
- Audio features such as notes are extracted from each frame | ||
- An image is created from the series of features | ||
- A fingerprint is extracted from the image as a long series of numbers | ||
- This raw fingerprint is compressed into a shorter string | ||
- The string can be compared with other fingerprints to obtain a similarity score | ||
|
||
## Installation and usage | ||
|
||
### Build and run with SBT | ||
|
||
Install [SBT][7] and run the command line app: | ||
|
||
```bash | ||
$ sbt run "/path/to/myaudiofile.mp3" | ||
[info] Running chromaprint.Main /path/to/myaudiofile.mp3 | ||
Fingerprinting... | ||
Created fingerprint in 4.177s | ||
Duration: 296.80008 | ||
Fingerprint (raw): 829534504,829526824,829526808,... | ||
Fingerprint (compressed): AQADtNQYhYkYnGhw7X.... | ||
Hash: 813035563 | ||
``` | ||
|
||
Build an executable JAR: | ||
|
||
```bash | ||
$ sbt assembly | ||
``` | ||
|
||
### Build the Docker image | ||
|
||
```bash | ||
$ docker build -t chromaprint-scala . | ||
``` | ||
|
||
Then run the command line app (assuming audio file in current folder, double quotes needed for filenames containing spaces). | ||
|
||
```bash | ||
$ docker run -ti -v $(pwd):/audio/ chromaprint-scala '"/audio/02 Pocket Calculator.flac"' | ||
``` | ||
|
||
## Identify track with AcoustID | ||
|
||
Get an [AcoustID][2] client ID and provide the `acoustid-client` option in the command line app to lookup matches in the AcoustID database: | ||
|
||
```bash | ||
$ sbt run "/audio/Pocket Calculator.flac" --acoustid-client=MyClientId | ||
[info] Running chromaprint.Main /audio/Pocket Calculator.flac --acoustid-client=MyClientId | ||
Fingerprinting... | ||
Created fingerprint in 4.177s | ||
Duration: 296.80008 | ||
Fingerprint (raw): 829534504,829526824,829526808,... | ||
Fingerprint (compressed): AQADtNQYhYkYnGhw7X.... | ||
Hash: 813035563 | ||
AcoustID response received | ||
Result 1 with score 0.923195: | ||
867cf1a1-c46a-4ad5-916f-0c5397ff65e5 'Pocket Calculator' by 'Kraftwerk' | ||
``` | ||
|
||
## Using the library in a Scala application | ||
|
||
(SBT repository details to be published shortly) | ||
|
||
```scala | ||
import chromaprint.core.{AudioSource,fingerprinter} | ||
import java.io.File | ||
|
||
val source = AudioSource(new File("/audio/Pocket Calculator.flac")) | ||
val Right(fingerprint) = fingerprinter(source)(fftProvider = chromaprint.breeze.FFT) | ||
|
||
println(fingerprint.compressed) | ||
// AQADtNQYhYkYnGhw7X... | ||
|
||
``` | ||
See the code for the command line app under `chromaprint.fpcalc` for further examples. | ||
|
||
Note that the fingerprinter requires an implicit for the FFT (Fast Fourier Transform) implementation. Adapters are provided for [Breeze][8] and through [FFTW][9] via [JavaCPP Presets][10]. I have seen intermittent errors in the FFTW adapter so would recommend using Breeze. | ||
|
||
--- | ||
|
||
Copyright (c) 2019 Mike Gibson, https://github.com/mgdigital. Original Chromaprint algorithm Copyright (c) Lukáš Lalinský. | ||
|
||
--- | ||
|
||
For Chris. | ||
|
||
--- | ||
|
||
[1]: https://github.com/acoustid/chromaprint | ||
[2]: https://acoustid.org/ | ||
[3]: https://oxygene.sk/ | ||
[4]: https://en.wikipedia.org/wiki/Acoustic_fingerprint | ||
[5]: https://musicbrainz.org/ | ||
[6]: https://en.wikipedia.org/wiki/Fast_Fourier_transform | ||
[7]: https://www.scala-sbt.org/download.html | ||
[8]: https://github.com/scalanlp/breeze | ||
[9]: http://www.fftw.org/ | ||
[10]: https://github.com/bytedeco/javacpp-presets/tree/master/fftw |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import Dependencies._ | ||
|
||
ThisBuild / scalaVersion := "2.12.8" | ||
ThisBuild / version := "0.1.0-SNAPSHOT" | ||
ThisBuild / organization := "com.mgdigital" | ||
ThisBuild / organizationName := "chromaprint" | ||
|
||
lazy val root = (project in file(".")) | ||
.settings( | ||
name := "chromaprint", | ||
resolvers ++= | ||
Seq( | ||
Resolver.mavenCentral, | ||
Resolver.sonatypeRepo("releases"), | ||
Resolver.sonatypeRepo("snapshots") | ||
), | ||
libraryDependencies ++= Seq( | ||
"org.scalanlp" %% "breeze" % "0.13.2", | ||
"org.scalanlp" %% "breeze-natives" % "0.13.2", | ||
"com.googlecode.soundlibs" % "mp3spi" % "1.9.5.4", | ||
"org.jflac" % "jflac-codec" % "1.5.2", | ||
"com.googlecode.soundlibs" % "tritonus-share" % "0.3.7.4", | ||
"com.googlecode.soundlibs" % "tritonus-all" % "0.3.7.2", | ||
"com.github.scopt" %% "scopt" % "4.0.0-RC2", | ||
"com.softwaremill.sttp" %% "core" % "1.5.15", | ||
"com.typesafe.play" %% "play-json" % "2.7.2", | ||
scalaTest % Test | ||
), | ||
parallelExecution in Test := false, | ||
javaCppPresetLibs := Seq( | ||
"fftw" -> "3.3.7" | ||
), | ||
javaCppVersion := "1.4.4" | ||
) | ||
|
||
|
||
// Uncomment the following for publishing to Sonatype. | ||
// See https://www.scala-sbt.org/1.x/docs/Using-Sonatype.html for more detail. | ||
|
||
// ThisBuild / description := "Some descripiton about your project." | ||
// ThisBuild / licenses := List("Apache 2" -> new URL("http://www.apache.org/licenses/LICENSE-2.0.txt")) | ||
// ThisBuild / homepage := Some(url("https://github.com/example/project")) | ||
// ThisBuild / scmInfo := Some( | ||
// ScmInfo( | ||
// url("https://github.com/your-account/your-project"), | ||
// "scm:git@github.com:your-account/your-project.git" | ||
// ) | ||
// ) | ||
// ThisBuild / developers := List( | ||
// Developer( | ||
// id = "Your identifier", | ||
// name = "Your Name", | ||
// email = "your@email", | ||
// url = url("http://your.url") | ||
// ) | ||
// ) | ||
// ThisBuild / pomIncludeRepository := { _ => false } | ||
// ThisBuild / publishTo := { | ||
// val nexus = "https://oss.sonatype.org/" | ||
// if (isSnapshot.value) Some("snapshots" at nexus + "content/repositories/snapshots") | ||
// else Some("releases" at nexus + "service/local/staging/deploy/maven2") | ||
// } | ||
// ThisBuild / publishMavenStyle := true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import sbt._ | ||
|
||
object Dependencies { | ||
lazy val scalaTest = "org.scalatest" %% "scalatest" % "3.0.5" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.9") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version=1.2.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0") | ||
addSbtPlugin("org.bytedeco" % "sbt-javacpp" % "1.13") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<scalastyle> | ||
<name>Scalastyle standard configuration</name> | ||
<check level="warning" class="org.scalastyle.file.FileTabChecker" enabled="true"></check> | ||
<check level="warning" class="org.scalastyle.file.FileLengthChecker" enabled="true"> | ||
<parameters> | ||
<parameter name="maxFileLength"><![CDATA[800]]></parameter> | ||
</parameters> | ||
</check> | ||
<check level="warning" class="org.scalastyle.scalariform.SpacesAfterPlusChecker" enabled="true"></check> | ||
<check level="warning" class="org.scalastyle.file.WhitespaceEndOfLineChecker" enabled="true"></check> | ||
<check level="warning" class="org.scalastyle.scalariform.SpacesBeforePlusChecker" enabled="true"></check> | ||
<check level="warning" class="org.scalastyle.file.FileLineLengthChecker" enabled="true"> | ||
<parameters> | ||
<parameter name="maxLineLength"><![CDATA[160]]></parameter> | ||
<parameter name="tabSize"><![CDATA[4]]></parameter> | ||
</parameters> | ||
</check> | ||
<check level="warning" class="org.scalastyle.scalariform.ClassNamesChecker" enabled="true"> | ||
<parameters> | ||
<parameter name="regex"><![CDATA[[A-Z][A-Za-z]*]]></parameter> | ||
</parameters> | ||
</check> | ||
<check level="warning" class="org.scalastyle.scalariform.ObjectNamesChecker" enabled="true"> | ||
<parameters> | ||
<parameter name="regex"><![CDATA[[A-Za-z]*]]></parameter> | ||
</parameters> | ||
</check> | ||
<check level="warning" class="org.scalastyle.scalariform.PackageObjectNamesChecker" enabled="true"> | ||
<parameters> | ||
<parameter name="regex"><![CDATA[^[a-z][A-Za-z]*$]]></parameter> | ||
</parameters> | ||
</check> | ||
<check level="warning" class="org.scalastyle.scalariform.EqualsHashCodeChecker" enabled="true"></check> | ||
<check level="warning" class="org.scalastyle.scalariform.IllegalImportsChecker" enabled="true"> | ||
<parameters> | ||
<parameter name="illegalImports"><![CDATA[sun._,java.awt._]]></parameter> | ||
</parameters> | ||
</check> | ||
<check level="warning" class="org.scalastyle.scalariform.ParameterNumberChecker" enabled="true"> | ||
<parameters> | ||
<parameter name="maxParameters"><![CDATA[8]]></parameter> | ||
</parameters> | ||
</check> | ||
<check level="warning" class="org.scalastyle.scalariform.MagicNumberChecker" enabled="true"> | ||
<parameters> | ||
<parameter name="ignore"><![CDATA[-1,0,1,2,3]]></parameter> | ||
</parameters> | ||
</check> | ||
<check level="warning" class="org.scalastyle.scalariform.NoWhitespaceBeforeLeftBracketChecker" enabled="true"></check> | ||
<check level="warning" class="org.scalastyle.scalariform.NoWhitespaceAfterLeftBracketChecker" enabled="true"></check> | ||
<check level="warning" class="org.scalastyle.scalariform.ReturnChecker" enabled="true"></check> | ||
<check level="warning" class="org.scalastyle.scalariform.NullChecker" enabled="true"></check> | ||
<check level="warning" class="org.scalastyle.scalariform.NoCloneChecker" enabled="true"></check> | ||
<check level="warning" class="org.scalastyle.scalariform.NoFinalizeChecker" enabled="true"></check> | ||
<check level="warning" class="org.scalastyle.scalariform.CovariantEqualsChecker" enabled="true"></check> | ||
<check level="warning" class="org.scalastyle.scalariform.StructuralTypeChecker" enabled="true"></check> | ||
<check level="warning" class="org.scalastyle.file.RegexChecker" enabled="true"> | ||
<parameters> | ||
<parameter name="regex"><![CDATA[println]]></parameter> | ||
</parameters> | ||
</check> | ||
<check level="warning" class="org.scalastyle.scalariform.NumberOfTypesChecker" enabled="true"> | ||
<parameters> | ||
<parameter name="maxTypes"><![CDATA[30]]></parameter> | ||
</parameters> | ||
</check> | ||
<check level="warning" class="org.scalastyle.scalariform.CyclomaticComplexityChecker" enabled="true"> | ||
<parameters> | ||
<parameter name="maximum"><![CDATA[10]]></parameter> | ||
</parameters> | ||
</check> | ||
<check level="warning" class="org.scalastyle.scalariform.UppercaseLChecker" enabled="true"></check> | ||
<check level="warning" class="org.scalastyle.scalariform.SimplifyBooleanExpressionChecker" enabled="true"></check> | ||
<check level="warning" class="org.scalastyle.scalariform.IfBraceChecker" enabled="true"> | ||
<parameters> | ||
<parameter name="singleLineAllowed"><![CDATA[true]]></parameter> | ||
<parameter name="doubleLineAllowed"><![CDATA[false]]></parameter> | ||
</parameters> | ||
</check> | ||
<check level="warning" class="org.scalastyle.scalariform.MethodLengthChecker" enabled="true"> | ||
<parameters> | ||
<parameter name="maxLength"><![CDATA[50]]></parameter> | ||
</parameters> | ||
</check> | ||
<check level="warning" class="org.scalastyle.scalariform.MethodNamesChecker" enabled="true"> | ||
<parameters> | ||
<parameter name="regex"><![CDATA[^[a-z][A-Za-z0-9]*$]]></parameter> | ||
</parameters> | ||
</check> | ||
<check level="warning" class="org.scalastyle.scalariform.NumberOfMethodsInTypeChecker" enabled="true"> | ||
<parameters> | ||
<parameter name="maxMethods"><![CDATA[30]]></parameter> | ||
</parameters> | ||
</check> | ||
<check level="warning" class="org.scalastyle.scalariform.PublicMethodsHaveTypeChecker" enabled="true"></check> | ||
<check level="warning" class="org.scalastyle.file.NewLineAtEofChecker" enabled="true"></check> | ||
<check level="warning" class="org.scalastyle.file.NoNewLineAtEofChecker" enabled="false"></check> | ||
</scalastyle> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package chromaprint | ||
|
||
object Main extends App { | ||
|
||
override def main(args: Array[String]): Unit = | ||
fpcalc.Command(args.toVector)(breeze.FFT) | ||
|
||
} |
Oops, something went wrong.