lib/chromaprint: use std::span instead of ConstBuffer

This commit is contained in:
Max Kellermann
2022-07-04 18:30:46 +02:00
parent 8fa212f04d
commit d097babe73
2 changed files with 9 additions and 13 deletions

View File

@@ -34,6 +34,7 @@
#include <chromaprint.h> #include <chromaprint.h>
#include <span>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
@@ -58,8 +59,8 @@ public:
throw std::runtime_error("chromaprint_start() failed"); throw std::runtime_error("chromaprint_start() failed");
} }
void Feed(const int16_t *data, size_t size) { void Feed(std::span<const int16_t> src) {
if (chromaprint_feed(ctx, data, size) != 1) if (chromaprint_feed(ctx, src.data(), src.size()) != 1)
throw std::runtime_error("chromaprint_feed() failed"); throw std::runtime_error("chromaprint_feed() failed");
} }

View File

@@ -20,7 +20,7 @@
#include "DecoderClient.hxx" #include "DecoderClient.hxx"
#include "pcm/Convert.hxx" #include "pcm/Convert.hxx"
#include "input/InputStream.hxx" #include "input/InputStream.hxx"
#include "util/ConstBuffer.hxx" #include "util/SpanCast.hxx"
ChromaprintDecoderClient::ChromaprintDecoderClient() = default; ChromaprintDecoderClient::ChromaprintDecoderClient() = default;
ChromaprintDecoderClient::~ChromaprintDecoderClient() noexcept = default; ChromaprintDecoderClient::~ChromaprintDecoderClient() noexcept = default;
@@ -36,8 +36,7 @@ ChromaprintDecoderClient::Finish()
if (convert) { if (convert) {
auto flushed = convert->Flush(); auto flushed = convert->Flush();
auto data = ConstBuffer<int16_t>::FromVoid(flushed); chromaprint.Feed(FromBytesStrict<const int16_t>(flushed));
chromaprint.Feed(data.data, data.size);
} }
chromaprint.Finish(); chromaprint.Finish();
@@ -75,16 +74,12 @@ ChromaprintDecoderClient::SubmitData(InputStream *,
else else
remaining_bytes -= length; remaining_bytes -= length;
ConstBuffer<void> src{_data, length}; std::span<const std::byte> src{(const std::byte *)_data, length};
ConstBuffer<int16_t> data;
if (convert) { if (convert)
auto result = convert->Convert(src); src = convert->Convert(src);
data = ConstBuffer<int16_t>::FromVoid(result);
} else
data = ConstBuffer<int16_t>::FromVoid(src);
chromaprint.Feed(data.data, data.size); chromaprint.Feed(FromBytesStrict<const int16_t>(src));
return GetCommand(); return GetCommand();
} }