summaryrefslogtreecommitdiff
path: root/src/tag
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2018-08-10 18:06:50 +0200
committerMax Kellermann <max@musicpd.org>2018-10-24 10:52:45 +0200
commit30e22b753b06660d888eb42a8c74d950d044d6dd (patch)
tree3f19a698a757949c4562bf1b8b7f08e6df151dbd /src/tag
parentf7141c920121e9c6cef6582c89a73da74b814e2e (diff)
tag/Chromaprint: OO wrapper for a ChromaprintContext
Diffstat (limited to 'src/tag')
-rw-r--r--src/tag/Chromaprint.hxx73
-rw-r--r--src/tag/meson.build3
2 files changed, 76 insertions, 0 deletions
diff --git a/src/tag/Chromaprint.hxx b/src/tag/Chromaprint.hxx
new file mode 100644
index 000000000..3aaeb74d9
--- /dev/null
+++ b/src/tag/Chromaprint.hxx
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2003-2018 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPD_CHROMAPRINT_HXX
+#define MPD_CHROMAPRINT_HXX
+
+#include "util/ScopeExit.hxx"
+
+#include <chromaprint.h>
+
+#include <stdexcept>
+#include <string>
+
+namespace Chromaprint {
+
+class Context {
+ ChromaprintContext *const ctx;
+
+public:
+ Context() noexcept
+ :ctx(chromaprint_new(CHROMAPRINT_ALGORITHM_DEFAULT)) {}
+
+ ~Context() noexcept {
+ chromaprint_free(ctx);
+ }
+
+ Context(const Context &) = delete;
+ Context &operator=(const Context &) = delete;
+
+ void Start(unsigned sample_rate, unsigned num_channels) {
+ if (chromaprint_start(ctx, sample_rate, num_channels) != 1)
+ throw std::runtime_error("chromaprint_start() failed");
+ }
+
+ void Feed(const int16_t *data, size_t size) {
+ if (chromaprint_feed(ctx, data, size) != 1)
+ throw std::runtime_error("chromaprint_feed() failed");
+ }
+
+ void Finish() {
+ if (chromaprint_finish(ctx) != 1)
+ throw std::runtime_error("chromaprint_finish() failed");
+ }
+
+ std::string GetFingerprint() const {
+ char *fingerprint;
+ if (chromaprint_get_fingerprint(ctx, &fingerprint) != 1)
+ throw std::runtime_error("chromaprint_get_fingerprint() failed");
+
+ AtScopeExit(fingerprint) { chromaprint_dealloc(fingerprint); };
+ return fingerprint;
+ }
+};
+
+} //namespace Chromaprint
+
+#endif
diff --git a/src/tag/meson.build b/src/tag/meson.build
index c423417d1..08b9e5e92 100644
--- a/src/tag/meson.build
+++ b/src/tag/meson.build
@@ -33,6 +33,9 @@ if libid3tag_dep.found()
]
endif
+chromaprint_dep = dependency('libchromaprint', required: get_option('chromaprint'))
+conf.set('ENABLE_CHROMAPRINT', chromaprint_dep.found())
+
tag = static_library(
'tag',
tag_sources,