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

View File

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