Replace cpp::span shim with std::span
This commit is contained in:
@@ -8,7 +8,7 @@ idf_component_register(
|
||||
"fatfs_source.cpp" "bt_audio_output.cpp" "readahead_source.cpp"
|
||||
"audio_source.cpp"
|
||||
INCLUDE_DIRS "include"
|
||||
REQUIRES "codecs" "drivers" "cbor" "result" "tasks" "span" "memory" "tinyfsm"
|
||||
REQUIRES "codecs" "drivers" "cbor" "result" "tasks" "memory" "tinyfsm"
|
||||
"database" "system_fsm" "speexdsp" "millershuffle" "libcppbor")
|
||||
|
||||
target_compile_options(${COMPONENT_LIB} PRIVATE ${EXTRA_WARNINGS})
|
||||
|
||||
@@ -76,7 +76,7 @@ auto SampleConverter::beginStream(std::shared_ptr<TrackInfo> track) -> void {
|
||||
xQueueSend(commands_, &args, portMAX_DELAY);
|
||||
}
|
||||
|
||||
auto SampleConverter::continueStream(cpp::span<sample::Sample> input) -> void {
|
||||
auto SampleConverter::continueStream(std::span<sample::Sample> input) -> void {
|
||||
Args args{
|
||||
.track = nullptr,
|
||||
.samples_available = input.size(),
|
||||
@@ -182,7 +182,7 @@ auto SampleConverter::handleContinueStream(size_t samples_available) -> void {
|
||||
}
|
||||
}
|
||||
|
||||
auto SampleConverter::handleSamples(cpp::span<sample::Sample> input) -> size_t {
|
||||
auto SampleConverter::handleSamples(std::span<sample::Sample> input) -> size_t {
|
||||
if (source_format_ == target_format_) {
|
||||
// The happiest possible case: the input format matches the output
|
||||
// format already.
|
||||
@@ -192,7 +192,7 @@ auto SampleConverter::handleSamples(cpp::span<sample::Sample> input) -> size_t {
|
||||
|
||||
size_t samples_used = 0;
|
||||
while (samples_used < input.size()) {
|
||||
cpp::span<sample::Sample> output_source;
|
||||
std::span<sample::Sample> output_source;
|
||||
if (source_format_.sample_rate != target_format_.sample_rate) {
|
||||
if (resampler_ == nullptr) {
|
||||
ESP_LOGI(kTag, "creating new resampler for %lu -> %lu",
|
||||
@@ -245,7 +245,7 @@ auto SampleConverter::handleEndStream() -> void {
|
||||
events::Audio().Dispatch(internal::StreamEnded{});
|
||||
}
|
||||
|
||||
auto SampleConverter::sendToSink(cpp::span<sample::Sample> samples) -> void {
|
||||
auto SampleConverter::sendToSink(std::span<sample::Sample> samples) -> void {
|
||||
// Update the number of samples sunk so far *before* actually sinking them,
|
||||
// since writing to the stream buffer will block when the buffer gets full.
|
||||
samples_sunk_ += samples.size();
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
*/
|
||||
|
||||
#include "audio_decoder.hpp"
|
||||
#include <stdint.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
@@ -17,6 +16,7 @@
|
||||
#include <cstring>
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
#include <span>
|
||||
#include <variant>
|
||||
|
||||
#include "cbor.h"
|
||||
@@ -28,7 +28,6 @@
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/ringbuf.h"
|
||||
#include "i2s_dac.hpp"
|
||||
#include "span.hpp"
|
||||
|
||||
#include "audio_converter.hpp"
|
||||
#include "audio_events.hpp"
|
||||
|
||||
@@ -20,7 +20,7 @@ auto TaggedStream::tags() -> std::shared_ptr<database::TrackTags> {
|
||||
return tags_;
|
||||
}
|
||||
|
||||
auto TaggedStream::Read(cpp::span<std::byte> dest) -> ssize_t {
|
||||
auto TaggedStream::Read(std::span<std::byte> dest) -> ssize_t {
|
||||
return wrapped_->Read(dest);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
@@ -23,7 +24,6 @@
|
||||
#include "freertos/portmacro.h"
|
||||
#include "freertos/projdefs.h"
|
||||
#include "readahead_source.hpp"
|
||||
#include "span.hpp"
|
||||
|
||||
#include "audio_events.hpp"
|
||||
#include "audio_fsm.hpp"
|
||||
@@ -61,7 +61,8 @@ auto FatfsAudioInput::SetPath(std::optional<std::string> path) -> void {
|
||||
}
|
||||
}
|
||||
|
||||
auto FatfsAudioInput::SetPath(const std::string& path,uint32_t offset) -> void {
|
||||
auto FatfsAudioInput::SetPath(const std::string& path, uint32_t offset)
|
||||
-> void {
|
||||
std::lock_guard<std::mutex> guard{new_stream_mutex_};
|
||||
if (OpenFile(path, offset)) {
|
||||
has_new_stream_ = true;
|
||||
@@ -102,7 +103,8 @@ auto FatfsAudioInput::NextStream() -> std::shared_ptr<TaggedStream> {
|
||||
}
|
||||
}
|
||||
|
||||
auto FatfsAudioInput::OpenFile(const std::string& path,uint32_t offset) -> bool {
|
||||
auto FatfsAudioInput::OpenFile(const std::string& path, uint32_t offset)
|
||||
-> bool {
|
||||
ESP_LOGI(kTag, "opening file %s", path.c_str());
|
||||
|
||||
auto tags = tag_parser_.ReadAndParseTags(path);
|
||||
|
||||
@@ -33,7 +33,7 @@ FatfsSource::~FatfsSource() {
|
||||
f_close(file_.get());
|
||||
}
|
||||
|
||||
auto FatfsSource::Read(cpp::span<std::byte> dest) -> ssize_t {
|
||||
auto FatfsSource::Read(std::span<std::byte> dest) -> ssize_t {
|
||||
auto lock = drivers::acquire_spi();
|
||||
if (f_eof(file_.get())) {
|
||||
return 0;
|
||||
|
||||
@@ -33,7 +33,7 @@ class SampleConverter {
|
||||
auto SetOutput(std::shared_ptr<IAudioOutput>) -> void;
|
||||
|
||||
auto beginStream(std::shared_ptr<TrackInfo>) -> void;
|
||||
auto continueStream(cpp::span<sample::Sample>) -> void;
|
||||
auto continueStream(std::span<sample::Sample>) -> void;
|
||||
auto endStream() -> void;
|
||||
|
||||
private:
|
||||
@@ -43,9 +43,9 @@ class SampleConverter {
|
||||
auto handleContinueStream(size_t samples_available) -> void;
|
||||
auto handleEndStream() -> void;
|
||||
|
||||
auto handleSamples(cpp::span<sample::Sample>) -> size_t;
|
||||
auto handleSamples(std::span<sample::Sample>) -> size_t;
|
||||
|
||||
auto sendToSink(cpp::span<sample::Sample>) -> void;
|
||||
auto sendToSink(std::span<sample::Sample>) -> void;
|
||||
|
||||
struct Args {
|
||||
std::shared_ptr<TrackInfo>* track;
|
||||
@@ -57,10 +57,10 @@ class SampleConverter {
|
||||
std::unique_ptr<Resampler> resampler_;
|
||||
|
||||
StreamBufferHandle_t source_;
|
||||
cpp::span<sample::Sample> input_buffer_;
|
||||
cpp::span<std::byte> input_buffer_as_bytes_;
|
||||
std::span<sample::Sample> input_buffer_;
|
||||
std::span<std::byte> input_buffer_as_bytes_;
|
||||
|
||||
cpp::span<sample::Sample> resampled_buffer_;
|
||||
std::span<sample::Sample> resampled_buffer_;
|
||||
|
||||
std::shared_ptr<IAudioOutput> sink_;
|
||||
IAudioOutput::Format source_format_;
|
||||
|
||||
@@ -50,7 +50,7 @@ class Decoder {
|
||||
std::optional<codecs::ICodec::OutputFormat> current_format_;
|
||||
std::optional<IAudioOutput::Format> current_sink_format_;
|
||||
|
||||
cpp::span<sample::Sample> codec_buffer_;
|
||||
std::span<sample::Sample> codec_buffer_;
|
||||
};
|
||||
|
||||
} // namespace audio
|
||||
|
||||
@@ -23,7 +23,7 @@ class TaggedStream : public codecs::IStream {
|
||||
|
||||
auto tags() -> std::shared_ptr<database::TrackTags>;
|
||||
|
||||
auto Read(cpp::span<std::byte> dest) -> ssize_t override;
|
||||
auto Read(std::span<std::byte> dest) -> ssize_t override;
|
||||
|
||||
auto CanSeek() -> bool override;
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ class FatfsSource : public codecs::IStream {
|
||||
FatfsSource(codecs::StreamType, std::unique_ptr<FIL> file);
|
||||
~FatfsSource();
|
||||
|
||||
auto Read(cpp::span<std::byte> dest) -> ssize_t override;
|
||||
auto Read(std::span<std::byte> dest) -> ssize_t override;
|
||||
|
||||
auto CanSeek() -> bool override;
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ class ReadaheadSource : public codecs::IStream {
|
||||
ReadaheadSource(tasks::WorkerPool&, std::unique_ptr<codecs::IStream>);
|
||||
~ReadaheadSource();
|
||||
|
||||
auto Read(cpp::span<std::byte> dest) -> ssize_t override;
|
||||
auto Read(std::span<std::byte> dest) -> ssize_t override;
|
||||
|
||||
auto CanSeek() -> bool override;
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
|
||||
#include "span.hpp"
|
||||
#include "speex/speex_resampler.h"
|
||||
|
||||
#include "sample.hpp"
|
||||
@@ -24,8 +24,8 @@ class Resampler {
|
||||
|
||||
~Resampler();
|
||||
|
||||
auto Process(cpp::span<sample::Sample> input,
|
||||
cpp::span<sample::Sample> output,
|
||||
auto Process(std::span<sample::Sample> input,
|
||||
std::span<sample::Sample> output,
|
||||
bool end_of_data) -> std::pair<size_t, size_t>;
|
||||
|
||||
private:
|
||||
@@ -34,4 +34,4 @@ class Resampler {
|
||||
uint8_t num_channels_;
|
||||
};
|
||||
|
||||
} // namespace audio
|
||||
} // namespace audio
|
||||
|
||||
@@ -41,7 +41,7 @@ ReadaheadSource::~ReadaheadSource() {
|
||||
vStreamBufferDeleteWithCaps(buffer_);
|
||||
}
|
||||
|
||||
auto ReadaheadSource::Read(cpp::span<std::byte> dest) -> ssize_t {
|
||||
auto ReadaheadSource::Read(std::span<std::byte> dest) -> ssize_t {
|
||||
size_t bytes_written = 0;
|
||||
// Fill the destination from our buffer, until either the buffer is drained
|
||||
// or the destination is full.
|
||||
|
||||
@@ -38,8 +38,8 @@ Resampler::~Resampler() {
|
||||
speex_resampler_destroy(resampler_);
|
||||
}
|
||||
|
||||
auto Resampler::Process(cpp::span<sample::Sample> input,
|
||||
cpp::span<sample::Sample> output,
|
||||
auto Resampler::Process(std::span<sample::Sample> input,
|
||||
std::span<sample::Sample> output,
|
||||
bool end_of_data) -> std::pair<size_t, size_t> {
|
||||
uint32_t samples_used = input.size() / num_channels_;
|
||||
uint32_t samples_produced = output.size() / num_channels_;
|
||||
|
||||
@@ -6,7 +6,7 @@ idf_component_register(
|
||||
SRCS "dr_flac.cpp" "codec.cpp" "mad.cpp" "opus.cpp" "vorbis.cpp"
|
||||
"source_buffer.cpp" "sample.cpp" "wav.cpp"
|
||||
INCLUDE_DIRS "include"
|
||||
REQUIRES "result" "span" "libmad" "drflac" "tremor" "opusfile" "memory" "util"
|
||||
REQUIRES "result" "libmad" "drflac" "tremor" "opusfile" "memory" "util"
|
||||
"komihash")
|
||||
|
||||
target_compile_options("${COMPONENT_LIB}" PRIVATE ${EXTRA_WARNINGS})
|
||||
|
||||
@@ -100,7 +100,7 @@ auto DrFlacDecoder::OpenStream(std::shared_ptr<IStream> input, uint32_t offset)
|
||||
return format;
|
||||
}
|
||||
|
||||
auto DrFlacDecoder::DecodeTo(cpp::span<sample::Sample> output)
|
||||
auto DrFlacDecoder::DecodeTo(std::span<sample::Sample> output)
|
||||
-> cpp::result<OutputInfo, Error> {
|
||||
size_t frames_to_read = output.size() / flac_->channels / 2;
|
||||
|
||||
|
||||
@@ -6,19 +6,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/_stdint.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "result.hpp"
|
||||
#include "sample.hpp"
|
||||
#include "span.hpp"
|
||||
#include "types.hpp"
|
||||
|
||||
#include "memory_resource.hpp"
|
||||
@@ -35,7 +32,7 @@ class IStream {
|
||||
|
||||
auto type() -> StreamType { return t_; }
|
||||
|
||||
virtual auto Read(cpp::span<std::byte> dest) -> ssize_t = 0;
|
||||
virtual auto Read(std::span<std::byte> dest) -> ssize_t = 0;
|
||||
|
||||
virtual auto CanSeek() -> bool = 0;
|
||||
|
||||
@@ -54,7 +51,7 @@ class IStream {
|
||||
/*
|
||||
* Called by codecs to indicate that they've finished parsing any header data
|
||||
* within this stream, and are about to begin decoding.
|
||||
*
|
||||
*
|
||||
* Currently used as a hint to the readahead stream to begin prefetching file
|
||||
* data.
|
||||
*/
|
||||
@@ -117,7 +114,7 @@ class ICodec {
|
||||
* Decodes metadata or headers from the given input stream, and returns the
|
||||
* format for the samples that will be decoded from it.
|
||||
*/
|
||||
virtual auto OpenStream(std::shared_ptr<IStream> input,uint32_t offset)
|
||||
virtual auto OpenStream(std::shared_ptr<IStream> input, uint32_t offset)
|
||||
-> cpp::result<OutputFormat, Error> = 0;
|
||||
|
||||
struct OutputInfo {
|
||||
@@ -128,7 +125,7 @@ class ICodec {
|
||||
/*
|
||||
* Writes PCM samples to the given output buffer.
|
||||
*/
|
||||
virtual auto DecodeTo(cpp::span<sample::Sample> destination)
|
||||
virtual auto DecodeTo(std::span<sample::Sample> destination)
|
||||
-> cpp::result<OutputInfo, Error> = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "dr_flac.h"
|
||||
#include "sample.hpp"
|
||||
#include "source_buffer.hpp"
|
||||
#include "span.hpp"
|
||||
|
||||
#include "codec.hpp"
|
||||
|
||||
@@ -27,10 +27,10 @@ class DrFlacDecoder : public ICodec {
|
||||
DrFlacDecoder();
|
||||
~DrFlacDecoder();
|
||||
|
||||
auto OpenStream(std::shared_ptr<IStream> input,uint32_t offset)
|
||||
auto OpenStream(std::shared_ptr<IStream> input, uint32_t offset)
|
||||
-> cpp::result<OutputFormat, Error> override;
|
||||
|
||||
auto DecodeTo(cpp::span<sample::Sample> destination)
|
||||
auto DecodeTo(std::span<sample::Sample> destination)
|
||||
-> cpp::result<OutputInfo, Error> override;
|
||||
|
||||
DrFlacDecoder(const DrFlacDecoder&) = delete;
|
||||
@@ -38,7 +38,7 @@ class DrFlacDecoder : public ICodec {
|
||||
|
||||
private:
|
||||
std::shared_ptr<IStream> input_;
|
||||
drflac *flac_;
|
||||
drflac* flac_;
|
||||
};
|
||||
|
||||
} // namespace codecs
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <span>
|
||||
|
||||
#include "mad.h"
|
||||
#include "sample.hpp"
|
||||
#include "source_buffer.hpp"
|
||||
#include "span.hpp"
|
||||
|
||||
#include "codec.hpp"
|
||||
|
||||
@@ -29,7 +29,7 @@ class MadMp3Decoder : public ICodec {
|
||||
auto OpenStream(std::shared_ptr<IStream> input,uint32_t offset)
|
||||
-> cpp::result<OutputFormat, Error> override;
|
||||
|
||||
auto DecodeTo(cpp::span<sample::Sample> destination)
|
||||
auto DecodeTo(std::span<sample::Sample> destination)
|
||||
-> cpp::result<OutputInfo, Error> override;
|
||||
|
||||
MadMp3Decoder(const MadMp3Decoder&) = delete;
|
||||
|
||||
@@ -10,12 +10,12 @@
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "opusfile.h"
|
||||
#include "sample.hpp"
|
||||
#include "span.hpp"
|
||||
|
||||
#include "codec.hpp"
|
||||
|
||||
@@ -26,10 +26,10 @@ class XiphOpusDecoder : public ICodec {
|
||||
XiphOpusDecoder();
|
||||
~XiphOpusDecoder();
|
||||
|
||||
auto OpenStream(std::shared_ptr<IStream> input,uint32_t offset)
|
||||
auto OpenStream(std::shared_ptr<IStream> input, uint32_t offset)
|
||||
-> cpp::result<OutputFormat, Error> override;
|
||||
|
||||
auto DecodeTo(cpp::span<sample::Sample> destination)
|
||||
auto DecodeTo(std::span<sample::Sample> destination)
|
||||
-> cpp::result<OutputInfo, Error> override;
|
||||
|
||||
XiphOpusDecoder(const XiphOpusDecoder&) = delete;
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
|
||||
#include "span.hpp"
|
||||
#include <span>
|
||||
|
||||
#include "codec.hpp"
|
||||
|
||||
@@ -22,15 +21,15 @@ class SourceBuffer {
|
||||
~SourceBuffer();
|
||||
|
||||
auto Refill(IStream* src) -> bool;
|
||||
auto AddBytes(std::function<size_t(cpp::span<std::byte>)> writer) -> void;
|
||||
auto ConsumeBytes(std::function<size_t(cpp::span<std::byte>)> reader) -> void;
|
||||
auto AddBytes(std::function<size_t(std::span<std::byte>)> writer) -> void;
|
||||
auto ConsumeBytes(std::function<size_t(std::span<std::byte>)> reader) -> void;
|
||||
auto Empty() -> void;
|
||||
|
||||
SourceBuffer(const SourceBuffer&) = delete;
|
||||
SourceBuffer& operator=(const SourceBuffer&) = delete;
|
||||
|
||||
private:
|
||||
const cpp::span<std::byte> buffer_;
|
||||
const std::span<std::byte> buffer_;
|
||||
size_t bytes_in_buffer_;
|
||||
size_t offset_of_bytes_;
|
||||
};
|
||||
|
||||
@@ -10,12 +10,12 @@
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "ivorbisfile.h"
|
||||
#include "sample.hpp"
|
||||
#include "span.hpp"
|
||||
|
||||
#include "codec.hpp"
|
||||
|
||||
@@ -26,10 +26,10 @@ class TremorVorbisDecoder : public ICodec {
|
||||
TremorVorbisDecoder();
|
||||
~TremorVorbisDecoder();
|
||||
|
||||
auto OpenStream(std::shared_ptr<IStream> input,uint32_t offset)
|
||||
auto OpenStream(std::shared_ptr<IStream> input, uint32_t offset)
|
||||
-> cpp::result<OutputFormat, Error> override;
|
||||
|
||||
auto DecodeTo(cpp::span<sample::Sample> destination)
|
||||
auto DecodeTo(std::span<sample::Sample> destination)
|
||||
-> cpp::result<OutputInfo, Error> override;
|
||||
|
||||
TremorVorbisDecoder(const TremorVorbisDecoder&) = delete;
|
||||
|
||||
@@ -34,7 +34,7 @@ class WavDecoder : public ICodec {
|
||||
auto OpenStream(std::shared_ptr<IStream> input,uint32_t offset)
|
||||
-> cpp::result<OutputFormat, Error> override;
|
||||
|
||||
auto DecodeTo(cpp::span<sample::Sample> destination)
|
||||
auto DecodeTo(std::span<sample::Sample> destination)
|
||||
-> cpp::result<OutputInfo, Error> override;
|
||||
|
||||
WavDecoder(const WavDecoder&) = delete;
|
||||
|
||||
+5
-5
@@ -74,7 +74,7 @@ auto MadMp3Decoder::OpenStream(std::shared_ptr<IStream> input, uint32_t offset)
|
||||
while (!eof && !got_header) {
|
||||
eof = buffer_.Refill(input_.get());
|
||||
|
||||
buffer_.ConsumeBytes([&](cpp::span<std::byte> buf) -> size_t {
|
||||
buffer_.ConsumeBytes([&](std::span<std::byte> buf) -> size_t {
|
||||
mad_stream_buffer(stream_.get(),
|
||||
reinterpret_cast<const unsigned char*>(buf.data()),
|
||||
buf.size_bytes());
|
||||
@@ -130,7 +130,7 @@ auto MadMp3Decoder::OpenStream(std::shared_ptr<IStream> input, uint32_t offset)
|
||||
}
|
||||
need_refill = false;
|
||||
|
||||
buffer_.ConsumeBytes([&](cpp::span<std::byte> buf) -> size_t {
|
||||
buffer_.ConsumeBytes([&](std::span<std::byte> buf) -> size_t {
|
||||
mad_stream_buffer(stream_.get(),
|
||||
reinterpret_cast<const unsigned char*>(buf.data()),
|
||||
buf.size());
|
||||
@@ -156,13 +156,13 @@ auto MadMp3Decoder::OpenStream(std::shared_ptr<IStream> input, uint32_t offset)
|
||||
return output;
|
||||
}
|
||||
|
||||
auto MadMp3Decoder::DecodeTo(cpp::span<sample::Sample> output)
|
||||
auto MadMp3Decoder::DecodeTo(std::span<sample::Sample> output)
|
||||
-> cpp::result<OutputInfo, Error> {
|
||||
if (current_sample_ < 0 && !is_eos_) {
|
||||
if (!is_eof_) {
|
||||
is_eof_ = buffer_.Refill(input_.get());
|
||||
if (is_eof_) {
|
||||
buffer_.AddBytes([&](cpp::span<std::byte> buf) -> size_t {
|
||||
buffer_.AddBytes([&](std::span<std::byte> buf) -> size_t {
|
||||
if (buf.size() < MAD_BUFFER_GUARD) {
|
||||
is_eof_ = false;
|
||||
return 0;
|
||||
@@ -174,7 +174,7 @@ auto MadMp3Decoder::DecodeTo(cpp::span<sample::Sample> output)
|
||||
}
|
||||
}
|
||||
|
||||
buffer_.ConsumeBytes([&](cpp::span<std::byte> buf) -> size_t {
|
||||
buffer_.ConsumeBytes([&](std::span<std::byte> buf) -> size_t {
|
||||
mad_stream_buffer(stream_.get(),
|
||||
reinterpret_cast<const unsigned char*>(buf.data()),
|
||||
buf.size());
|
||||
|
||||
+1
-1
@@ -140,7 +140,7 @@ auto XiphOpusDecoder::OpenStream(std::shared_ptr<IStream> input,
|
||||
};
|
||||
}
|
||||
|
||||
auto XiphOpusDecoder::DecodeTo(cpp::span<sample::Sample> output)
|
||||
auto XiphOpusDecoder::DecodeTo(std::span<sample::Sample> output)
|
||||
-> cpp::result<OutputInfo, Error> {
|
||||
int samples_written = op_read_stereo(opus_, output.data(), output.size());
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ auto SourceBuffer::Refill(IStream* src) -> bool {
|
||||
return false;
|
||||
}
|
||||
bool eof = false;
|
||||
AddBytes([&](cpp::span<std::byte> buf) -> size_t {
|
||||
AddBytes([&](std::span<std::byte> buf) -> size_t {
|
||||
ssize_t bytes_read = src->Read(buf);
|
||||
// Treat read errors as EOF.
|
||||
eof = bytes_read <= 0;
|
||||
@@ -48,7 +48,7 @@ auto SourceBuffer::Refill(IStream* src) -> bool {
|
||||
return eof;
|
||||
}
|
||||
|
||||
auto SourceBuffer::AddBytes(std::function<size_t(cpp::span<std::byte>)> writer)
|
||||
auto SourceBuffer::AddBytes(std::function<size_t(std::span<std::byte>)> writer)
|
||||
-> void {
|
||||
if (offset_of_bytes_ > 0) {
|
||||
std::memmove(buffer_.data(), buffer_.data() + offset_of_bytes_,
|
||||
@@ -61,7 +61,7 @@ auto SourceBuffer::AddBytes(std::function<size_t(cpp::span<std::byte>)> writer)
|
||||
}
|
||||
|
||||
auto SourceBuffer::ConsumeBytes(
|
||||
std::function<size_t(cpp::span<std::byte>)> reader) -> void {
|
||||
std::function<size_t(std::span<std::byte>)> reader) -> void {
|
||||
size_t bytes_consumed = std::invoke(
|
||||
reader, buffer_.subspan(offset_of_bytes_, bytes_in_buffer_));
|
||||
assert(bytes_consumed <= bytes_in_buffer_);
|
||||
|
||||
@@ -8,14 +8,14 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <span>
|
||||
|
||||
#include "catch2/catch.hpp"
|
||||
#include "span.hpp"
|
||||
|
||||
#include "test.mp3.hpp"
|
||||
|
||||
void load_mp3(cpp::span<std::byte> dest) {
|
||||
cpp::span<std::byte> src(reinterpret_cast<std::byte*>(test_mp3),
|
||||
void load_mp3(std::span<std::byte> dest) {
|
||||
std::span<std::byte> src(reinterpret_cast<std::byte*>(test_mp3),
|
||||
test_mp3_len);
|
||||
std::copy(src.begin(), src.begin() + dest.size(), dest.begin());
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ auto TremorVorbisDecoder::OpenStream(std::shared_ptr<IStream> input,
|
||||
};
|
||||
}
|
||||
|
||||
auto TremorVorbisDecoder::DecodeTo(cpp::span<sample::Sample> output)
|
||||
auto TremorVorbisDecoder::DecodeTo(std::span<sample::Sample> output)
|
||||
-> cpp::result<OutputInfo, Error> {
|
||||
int unused = 0;
|
||||
long bytes_written =
|
||||
|
||||
+31
-28
@@ -20,24 +20,24 @@ namespace codecs {
|
||||
|
||||
[[maybe_unused]] static const char kTag[] = "wav";
|
||||
|
||||
static inline auto bytes_to_u16(cpp::span<std::byte const, 2> bytes)
|
||||
static inline auto bytes_to_u16(std::span<std::byte const, 2> bytes)
|
||||
-> uint16_t {
|
||||
return (uint16_t)bytes[0] | (uint16_t)bytes[1] << 8;
|
||||
}
|
||||
|
||||
static inline auto bytes_to_u32(cpp::span<std::byte const, 4> bytes)
|
||||
static inline auto bytes_to_u32(std::span<std::byte const, 4> bytes)
|
||||
-> uint32_t {
|
||||
return (uint32_t)bytes[0] | (uint32_t)bytes[1] << 8 |
|
||||
(uint32_t)bytes[2] << 16 | (uint32_t)bytes[3] << 24;
|
||||
}
|
||||
|
||||
static inline auto bytes_to_str(cpp::span<std::byte const> bytes)
|
||||
static inline auto bytes_to_str(std::span<std::byte const> bytes)
|
||||
-> std::string {
|
||||
return std::string(reinterpret_cast<const char*>(bytes.data()),
|
||||
bytes.size_bytes());
|
||||
bytes.size_bytes());
|
||||
}
|
||||
|
||||
static int16_t convert_f32_to_16_bit(cpp::span<const std::byte> bytes) {
|
||||
static int16_t convert_f32_to_16_bit(std::span<const std::byte> bytes) {
|
||||
uint64_t val = 0;
|
||||
val = (uint8_t)bytes[3];
|
||||
val = (val << 8) | (uint8_t)bytes[2];
|
||||
@@ -57,7 +57,7 @@ static int16_t convert_f32_to_16_bit(cpp::span<const std::byte> bytes) {
|
||||
return sample::FromDouble(*fval);
|
||||
}
|
||||
|
||||
static int16_t convert_f64_to_16_bit(cpp::span<const std::byte> bytes) {
|
||||
static int16_t convert_f64_to_16_bit(std::span<const std::byte> bytes) {
|
||||
uint64_t val = 0;
|
||||
val = (uint8_t)bytes[7];
|
||||
val = (val << 8) | (uint8_t)bytes[6];
|
||||
@@ -71,7 +71,7 @@ static int16_t convert_f64_to_16_bit(cpp::span<const std::byte> bytes) {
|
||||
return sample::FromDouble(*fval);
|
||||
}
|
||||
|
||||
static int16_t convert_to_16_bit(cpp::span<const std::byte> bytes) {
|
||||
static int16_t convert_to_16_bit(std::span<const std::byte> bytes) {
|
||||
int depth = bytes.size();
|
||||
int32_t val = 0;
|
||||
// If 8-bit Assume Unsigned
|
||||
@@ -82,10 +82,13 @@ static int16_t convert_to_16_bit(cpp::span<const std::byte> bytes) {
|
||||
switch (depth) {
|
||||
case 4:
|
||||
val = (uint8_t)bytes[3];
|
||||
[[fallthrough]];
|
||||
case 3:
|
||||
val = (val << 8) | (uint8_t)bytes[2];
|
||||
[[fallthrough]];
|
||||
case 2:
|
||||
val = (val << 8) | (uint8_t)bytes[1];
|
||||
[[fallthrough]];
|
||||
case 1:
|
||||
val = (val << 8) | (uint8_t)bytes[0];
|
||||
}
|
||||
@@ -98,7 +101,7 @@ WavDecoder::WavDecoder() : input_(), buffer_() {}
|
||||
|
||||
WavDecoder::~WavDecoder() {}
|
||||
|
||||
auto WavDecoder::OpenStream(std::shared_ptr<IStream> input,uint32_t offset)
|
||||
auto WavDecoder::OpenStream(std::shared_ptr<IStream> input, uint32_t offset)
|
||||
-> cpp::result<OutputFormat, Error> {
|
||||
input_ = input;
|
||||
|
||||
@@ -123,7 +126,7 @@ auto WavDecoder::OpenStream(std::shared_ptr<IStream> input,uint32_t offset)
|
||||
// - end of this part, next header we care about is 'data'
|
||||
// - and then the next 4 bytes = 32 bit int = size of data
|
||||
|
||||
auto buffer_span = cpp::span{buf};
|
||||
auto buffer_span = std::span{buf};
|
||||
|
||||
std::string riff = bytes_to_str(buffer_span.subspan(0, 4));
|
||||
if (riff != "RIFF") {
|
||||
@@ -131,7 +134,7 @@ auto WavDecoder::OpenStream(std::shared_ptr<IStream> input,uint32_t offset)
|
||||
return cpp::fail(Error::kMalformedData);
|
||||
}
|
||||
|
||||
uint32_t file_size = bytes_to_u32(buffer_span.subspan(4, 4)) + 8;
|
||||
// uint32_t file_size = bytes_to_u32(buffer_span.subspan(4, 4)) + 8;
|
||||
|
||||
std::string fmt_header = bytes_to_str(buffer_span.subspan(12, 4));
|
||||
ESP_LOGI(kTag, "fmt header found? %s",
|
||||
@@ -142,9 +145,9 @@ auto WavDecoder::OpenStream(std::shared_ptr<IStream> input,uint32_t offset)
|
||||
}
|
||||
|
||||
// Size of the fmt header, should be 16, 18 or 40
|
||||
uint32_t fmt_header_size = bytes_to_u32(buffer_span.subspan(16, 4));
|
||||
// uint32_t fmt_header_size = bytes_to_u32(buffer_span.subspan(16, 4));
|
||||
|
||||
wave_format_ = bytes_to_u16(buffer_span.subspan(20, 2));
|
||||
wave_format_ = bytes_to_u16(buffer_span.subspan<20, 2>());
|
||||
if (wave_format_ == kWaveFormatPCM) {
|
||||
ESP_LOGD(kTag, "wave format: PCM");
|
||||
} else if (wave_format_ == kWaveFormatExtensible) {
|
||||
@@ -156,17 +159,17 @@ auto WavDecoder::OpenStream(std::shared_ptr<IStream> input,uint32_t offset)
|
||||
return cpp::fail(Error::kUnsupportedFormat);
|
||||
}
|
||||
|
||||
num_channels_ = bytes_to_u16(buffer_span.subspan(22, 2));
|
||||
num_channels_ = bytes_to_u16(buffer_span.subspan<22, 2>());
|
||||
|
||||
uint32_t samples_per_second = bytes_to_u32(buffer_span.subspan(24, 4));
|
||||
uint32_t samples_per_second = bytes_to_u32(buffer_span.subspan<24, 4>());
|
||||
|
||||
uint32_t avg_bytes_per_second = bytes_to_u32(buffer_span.subspan(28, 4));
|
||||
// uint32_t avg_bytes_per_second = bytes_to_u32(buffer_span.subspan(28, 4));
|
||||
|
||||
uint16_t block_align = bytes_to_u16(buffer_span.subspan(32, 2));
|
||||
uint16_t block_align = bytes_to_u16(buffer_span.subspan<32, 2>());
|
||||
|
||||
bytes_per_sample_ = block_align / num_channels_;
|
||||
|
||||
uint16_t bits_per_sample = bytes_to_u16(buffer_span.subspan(34, 2));
|
||||
// uint16_t bits_per_sample = bytes_to_u16(buffer_span.subspan(34, 2));
|
||||
|
||||
// find the start of the data chunk
|
||||
std::array<std::byte, 4> data_tag = {std::byte{0x64}, std::byte{0x61},
|
||||
@@ -180,7 +183,7 @@ auto WavDecoder::OpenStream(std::shared_ptr<IStream> input,uint32_t offset)
|
||||
int data_chunk_index = std::distance(buffer_span.begin(), data_loc.begin());
|
||||
|
||||
uint32_t data_chunk_size =
|
||||
bytes_to_u32(buffer_span.subspan(data_chunk_index + 4, 4));
|
||||
bytes_to_u32(buffer_span.subspan(data_chunk_index + 4, 4).first<4>());
|
||||
|
||||
// calculate number of samples
|
||||
int number_of_samples = data_chunk_size / bytes_per_sample_;
|
||||
@@ -188,20 +191,20 @@ auto WavDecoder::OpenStream(std::shared_ptr<IStream> input,uint32_t offset)
|
||||
// extension to the fmt chunk size (0 or 22)
|
||||
uint16_t extension_size = 0;
|
||||
if (wave_format_ == kWaveFormatExtensible) {
|
||||
extension_size = bytes_to_u16(buffer_span.subspan(36, 2));
|
||||
extension_size = bytes_to_u16(buffer_span.subspan<36, 2>());
|
||||
}
|
||||
|
||||
// Parse extension if applicable
|
||||
if (extension_size == 22) {
|
||||
// Valid bits per sample
|
||||
uint16_t valid_bits_per_sample = bytes_to_u16(buffer_span.subspan(38, 2));
|
||||
// uint16_t valid_bits_per_sample = bytes_to_u16(buffer_span.subspan(38,
|
||||
// 2));
|
||||
|
||||
uint32_t speaker_mask = bytes_to_u32(buffer_span.subspan(40, 4));
|
||||
// uint32_t speaker_mask = bytes_to_u32(buffer_span.subspan(40, 4));
|
||||
|
||||
// Parse subformat
|
||||
subformat_ = bytes_to_u16(buffer_span.subspan(44, 2));
|
||||
if (!(subformat_ == kWaveFormatPCM ||
|
||||
subformat_ == kWaveFormatIEEEFloat)) {
|
||||
subformat_ = bytes_to_u16(buffer_span.subspan<44, 2>());
|
||||
if (!(subformat_ == kWaveFormatPCM || subformat_ == kWaveFormatIEEEFloat)) {
|
||||
ESP_LOGW(kTag, "WAVE extensible subformat_ not supported");
|
||||
return cpp::fail(Error::kUnsupportedFormat);
|
||||
}
|
||||
@@ -210,7 +213,8 @@ auto WavDecoder::OpenStream(std::shared_ptr<IStream> input,uint32_t offset)
|
||||
int64_t data_offset = offset * samples_per_second * bytes_per_sample_;
|
||||
|
||||
// Seek track to start of data
|
||||
input->SeekTo(data_chunk_index + 8 + data_offset, IStream::SeekFrom::kStartOfStream);
|
||||
input->SeekTo(data_chunk_index + 8 + data_offset,
|
||||
IStream::SeekFrom::kStartOfStream);
|
||||
|
||||
output_format_ = {.num_channels = (uint8_t)num_channels_,
|
||||
.sample_rate_hz = samples_per_second,
|
||||
@@ -219,12 +223,12 @@ auto WavDecoder::OpenStream(std::shared_ptr<IStream> input,uint32_t offset)
|
||||
return output_format_;
|
||||
}
|
||||
|
||||
auto WavDecoder::DecodeTo(cpp::span<sample::Sample> output)
|
||||
auto WavDecoder::DecodeTo(std::span<sample::Sample> output)
|
||||
-> cpp::result<OutputInfo, Error> {
|
||||
bool is_eof = buffer_.Refill(input_.get());
|
||||
size_t samples_written = 0;
|
||||
|
||||
buffer_.ConsumeBytes([&](cpp::span<std::byte> buf) -> size_t {
|
||||
buffer_.ConsumeBytes([&](std::span<std::byte> buf) -> size_t {
|
||||
size_t bytes_read = buf.size_bytes();
|
||||
size_t frames_read =
|
||||
bytes_read / bytes_per_sample_ / output_format_.num_channels;
|
||||
@@ -254,7 +258,6 @@ auto WavDecoder::DecodeTo(cpp::span<sample::Sample> output)
|
||||
return samples_written * bytes_per_sample_;
|
||||
});
|
||||
|
||||
|
||||
return OutputInfo{.samples_written = samples_written,
|
||||
.is_stream_finished = samples_written == 0 && is_eof};
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ idf_component_register(
|
||||
SRCS "env_esp.cpp" "database.cpp" "track.cpp" "records.cpp"
|
||||
"file_gatherer.cpp" "tag_parser.cpp" "index.cpp"
|
||||
INCLUDE_DIRS "include"
|
||||
REQUIRES "result" "span" "esp_psram" "fatfs" "libtags" "komihash" "cbor"
|
||||
REQUIRES "result" "esp_psram" "fatfs" "libtags" "komihash" "cbor"
|
||||
"tasks" "memory" "util" "tinyfsm" "events" "opusfile" "libcppbor")
|
||||
|
||||
target_compile_options(${COMPONENT_LIB} PRIVATE ${EXTRA_WARNINGS})
|
||||
|
||||
@@ -80,6 +80,6 @@ auto TrackIdToBytes(TrackId id) -> std::string;
|
||||
* Converts a track id encoded via TrackIdToBytes back into a TrackId. May
|
||||
* return nullopt if parsing fails.
|
||||
*/
|
||||
auto BytesToTrackId(cpp::span<const char> bytes) -> std::optional<TrackId>;
|
||||
auto BytesToTrackId(std::span<const char> bytes) -> std::optional<TrackId>;
|
||||
|
||||
} // namespace database
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/_stdint.h>
|
||||
#include <cstdint>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
#include "leveldb/db.h"
|
||||
#include "memory_resource.hpp"
|
||||
#include "span.hpp"
|
||||
|
||||
namespace database {
|
||||
|
||||
@@ -62,7 +61,7 @@ enum class Tag {
|
||||
using TagValue = std::variant<std::monostate,
|
||||
std::pmr::string,
|
||||
uint32_t,
|
||||
cpp::span<const std::pmr::string>>;
|
||||
std::span<const std::pmr::string>>;
|
||||
|
||||
auto tagName(Tag) -> std::string;
|
||||
auto tagHash(const TagValue&) -> uint64_t;
|
||||
@@ -112,7 +111,7 @@ class TrackTags {
|
||||
|
||||
auto albumOrder() const -> uint32_t;
|
||||
|
||||
auto genres() const -> cpp::span<const std::pmr::string>;
|
||||
auto genres() const -> std::span<const std::pmr::string>;
|
||||
auto genres(const std::string_view) -> void;
|
||||
|
||||
/*
|
||||
|
||||
@@ -61,11 +61,11 @@ class Indexer {
|
||||
|
||||
private:
|
||||
auto handleLevel(const IndexKey::Header& header,
|
||||
cpp::span<const Tag> components) -> void;
|
||||
std::span<const Tag> components) -> void;
|
||||
|
||||
auto handleItem(const IndexKey::Header& header,
|
||||
std::variant<std::pmr::string, uint32_t> item,
|
||||
cpp::span<const Tag> components) -> void;
|
||||
std::span<const Tag> components) -> void;
|
||||
|
||||
auto missing_value(Tag tag) -> TagValue {
|
||||
switch (tag) {
|
||||
@@ -111,7 +111,7 @@ auto Indexer::index() -> std::vector<std::pair<IndexKey, std::string>> {
|
||||
}
|
||||
|
||||
auto Indexer::handleLevel(const IndexKey::Header& header,
|
||||
cpp::span<const Tag> components) -> void {
|
||||
std::span<const Tag> components) -> void {
|
||||
Tag component = components.front();
|
||||
TagValue value = track_.tags().get(component);
|
||||
if (std::holds_alternative<std::monostate>(value)) {
|
||||
@@ -129,7 +129,7 @@ auto Indexer::handleLevel(const IndexKey::Header& header,
|
||||
} else if constexpr (std::is_same_v<T, uint32_t>) {
|
||||
handleItem(header, arg, components);
|
||||
} else if constexpr (std::is_same_v<
|
||||
T, cpp::span<const std::pmr::string>>) {
|
||||
T, std::span<const std::pmr::string>>) {
|
||||
for (const auto& i : arg) {
|
||||
handleItem(header, i, components);
|
||||
}
|
||||
@@ -140,7 +140,7 @@ auto Indexer::handleLevel(const IndexKey::Header& header,
|
||||
|
||||
auto Indexer::handleItem(const IndexKey::Header& header,
|
||||
std::variant<std::pmr::string, uint32_t> item,
|
||||
cpp::span<const Tag> components) -> void {
|
||||
std::span<const Tag> components) -> void {
|
||||
IndexKey key{
|
||||
.header = header,
|
||||
.item = {},
|
||||
|
||||
@@ -248,7 +248,7 @@ auto TrackIdToBytes(TrackId id) -> std::string {
|
||||
return cppbor::Uint{id}.toString();
|
||||
}
|
||||
|
||||
auto BytesToTrackId(cpp::span<const char> bytes) -> std::optional<TrackId> {
|
||||
auto BytesToTrackId(std::span<const char> bytes) -> std::optional<TrackId> {
|
||||
auto [res, unused, err] = cppbor::parse(
|
||||
reinterpret_cast<const uint8_t*>(bytes.data()), bytes.size());
|
||||
if (!res || res->type() != cppbor::UINT) {
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <memory_resource>
|
||||
#include <span>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
@@ -16,7 +17,6 @@
|
||||
#include "komihash.h"
|
||||
|
||||
#include "memory_resource.hpp"
|
||||
#include "span.hpp"
|
||||
|
||||
namespace database {
|
||||
|
||||
@@ -55,7 +55,7 @@ auto tagHash(const TagValue& t) -> uint64_t {
|
||||
} else if constexpr (std::is_same_v<T, uint32_t>) {
|
||||
return komihash(&arg, sizeof(arg), 0);
|
||||
} else if constexpr (std::is_same_v<
|
||||
T, cpp::span<const std::pmr::string>>) {
|
||||
T, std::span<const std::pmr::string>>) {
|
||||
komihash_stream_t hash;
|
||||
komihash_stream_init(&hash, 0);
|
||||
for (const auto& i : arg) {
|
||||
@@ -79,7 +79,7 @@ auto tagToString(const TagValue& val) -> std::string {
|
||||
} else if constexpr (std::is_same_v<T, uint32_t>) {
|
||||
return std::to_string(arg);
|
||||
} else if constexpr (std::is_same_v<
|
||||
T, cpp::span<const std::pmr::string>>) {
|
||||
T, std::span<const std::pmr::string>>) {
|
||||
std::ostringstream builder{};
|
||||
for (const auto& str : arg) {
|
||||
builder << std::string{str.data(), str.size()} << ",";
|
||||
@@ -225,7 +225,7 @@ auto TrackTags::albumOrder() const -> uint32_t {
|
||||
return (disc_.value_or(0) << 16) | track_.value_or(0);
|
||||
}
|
||||
|
||||
auto TrackTags::genres() const -> cpp::span<const std::pmr::string> {
|
||||
auto TrackTags::genres() const -> std::span<const std::pmr::string> {
|
||||
return genres_;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,6 @@ idf_component_register(
|
||||
"i2c.cpp" "bluetooth.cpp" "spi.cpp" "display.cpp" "display_init.cpp"
|
||||
"samd.cpp" "wm8523.cpp" "nvs.cpp" "haptics.cpp" "spiffs.cpp"
|
||||
INCLUDE_DIRS "include"
|
||||
REQUIRES "esp_adc" "fatfs" "result" "lvgl" "span" "tasks" "nvs_flash" "spiffs"
|
||||
REQUIRES "esp_adc" "fatfs" "result" "lvgl" "tasks" "nvs_flash" "spiffs"
|
||||
"bt" "tinyfsm" "util")
|
||||
target_compile_options(${COMPONENT_LIB} PRIVATE ${EXTRA_WARNINGS})
|
||||
|
||||
@@ -207,7 +207,7 @@ auto I2SDac::Reconfigure(Channels ch, BitsPerSample bps, SampleRate rate)
|
||||
}
|
||||
}
|
||||
|
||||
auto I2SDac::WriteData(const cpp::span<const std::byte>& data) -> void {
|
||||
auto I2SDac::WriteData(const std::span<const std::byte>& data) -> void {
|
||||
std::size_t bytes_written = 0;
|
||||
esp_err_t err = i2s_channel_write(i2s_handle_, data.data(), data.size_bytes(),
|
||||
&bytes_written, portMAX_DELAY);
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
#include <span>
|
||||
|
||||
#include "driver/i2s_std.h"
|
||||
#include "driver/i2s_types.h"
|
||||
@@ -20,7 +21,6 @@
|
||||
#include "freertos/portmacro.h"
|
||||
#include "freertos/stream_buffer.h"
|
||||
#include "result.hpp"
|
||||
#include "span.hpp"
|
||||
|
||||
#include "gpios.hpp"
|
||||
#include "sys/_stdint.h"
|
||||
@@ -68,7 +68,7 @@ class I2SDac {
|
||||
|
||||
auto Reconfigure(Channels ch, BitsPerSample bps, SampleRate rate) -> void;
|
||||
|
||||
auto WriteData(const cpp::span<const std::byte>& data) -> void;
|
||||
auto WriteData(const std::span<const std::byte>& data) -> void;
|
||||
auto SetSource(StreamBufferHandle_t buffer) -> void;
|
||||
|
||||
// Not copyable or movable.
|
||||
|
||||
@@ -6,6 +6,6 @@ idf_component_register(
|
||||
SRCS "collation.cpp" "strxfrm_l.c"
|
||||
INCLUDE_DIRS "include"
|
||||
PRIV_INCLUDE_DIRS "priv_include"
|
||||
REQUIRES "span" "esp_partition" "spi_flash")
|
||||
REQUIRES "esp_partition" "spi_flash")
|
||||
|
||||
target_compile_options(${COMPONENT_LIB} PRIVATE ${EXTRA_WARNINGS})
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
#include <string>
|
||||
|
||||
#include "esp_partition.h"
|
||||
#include "span.hpp"
|
||||
|
||||
#include "strxfrm.h"
|
||||
|
||||
|
||||
@@ -247,7 +247,7 @@ static auto pushTagValue(lua_State* L, const database::TagValue& val) -> void {
|
||||
if constexpr (std::is_same_v<T, std::pmr::string>) {
|
||||
lua_pushlstring(L, arg.data(), arg.size());
|
||||
} else if constexpr (std::is_same_v<
|
||||
T, cpp::span<const std::pmr::string>>) {
|
||||
T, std::span<const std::pmr::string>>) {
|
||||
lua_createtable(L, 0, arg.size());
|
||||
for (const auto& i : arg) {
|
||||
lua_pushlstring(L, i.data(), i.size());
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <span>
|
||||
|
||||
#include "esp32/himem.h"
|
||||
#include "span.hpp"
|
||||
|
||||
/*
|
||||
* Wrapper around an ESP-IDF himem allocation, which uses RAII to clean up after
|
||||
@@ -62,14 +62,14 @@ class MappableRegion {
|
||||
}
|
||||
}
|
||||
|
||||
auto Get() -> cpp::span<std::byte> {
|
||||
auto Get() -> std::span<std::byte> {
|
||||
if (bytes_ == nullptr) {
|
||||
return {};
|
||||
}
|
||||
return {bytes_, size};
|
||||
}
|
||||
|
||||
auto Map(const HimemAlloc<size>& alloc) -> cpp::span<std::byte> {
|
||||
auto Map(const HimemAlloc<size>& alloc) -> std::span<std::byte> {
|
||||
assert(bytes_ == nullptr);
|
||||
ESP_ERROR_CHECK(esp_himem_map(alloc.handle, range_handle, 0, 0, size, 0,
|
||||
reinterpret_cast<void**>(&bytes_)));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Copyright 2023 jacqueline <me@jacqueline.id.au>
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
idf_component_register(SRCS "tasks.cpp" INCLUDE_DIRS "." REQUIRES "span" "memory")
|
||||
idf_component_register(SRCS "tasks.cpp" INCLUDE_DIRS "." REQUIRES "memory")
|
||||
target_compile_options(${COMPONENT_LIB} PRIVATE ${EXTRA_WARNINGS})
|
||||
|
||||
+5
-5
@@ -33,12 +33,12 @@ auto Name<Type::kAudioConverter>() -> std::pmr::string {
|
||||
}
|
||||
|
||||
template <Type t>
|
||||
auto AllocateStack() -> cpp::span<StackType_t>;
|
||||
auto AllocateStack() -> std::span<StackType_t>;
|
||||
|
||||
// Decoders often require a very large amount of stack space, since they aren't
|
||||
// usually written with embedded use cases in mind.
|
||||
template <>
|
||||
auto AllocateStack<Type::kAudioDecoder>() -> cpp::span<StackType_t> {
|
||||
auto AllocateStack<Type::kAudioDecoder>() -> std::span<StackType_t> {
|
||||
constexpr std::size_t size = 20 * 1024;
|
||||
static StackType_t sStack[size];
|
||||
return {sStack, size};
|
||||
@@ -46,14 +46,14 @@ auto AllocateStack<Type::kAudioDecoder>() -> cpp::span<StackType_t> {
|
||||
// LVGL requires only a relatively small stack. Lua's stack is allocated
|
||||
// separately.
|
||||
template <>
|
||||
auto AllocateStack<Type::kUi>() -> cpp::span<StackType_t> {
|
||||
auto AllocateStack<Type::kUi>() -> std::span<StackType_t> {
|
||||
constexpr std::size_t size = 14 * 1024;
|
||||
static StackType_t sStack[size];
|
||||
return {sStack, size};
|
||||
}
|
||||
template <>
|
||||
// PCM conversion and resampling uses a very small amount of stack.
|
||||
auto AllocateStack<Type::kAudioConverter>() -> cpp::span<StackType_t> {
|
||||
auto AllocateStack<Type::kAudioConverter>() -> std::span<StackType_t> {
|
||||
constexpr std::size_t size = 4 * 1024;
|
||||
static StackType_t sStack[size];
|
||||
return {sStack, size};
|
||||
@@ -63,7 +63,7 @@ auto AllocateStack<Type::kAudioConverter>() -> cpp::span<StackType_t> {
|
||||
// cases, where large stack usage isn't so much of a concern. It therefore uses
|
||||
// an eye-wateringly large amount of stack.
|
||||
template <>
|
||||
auto AllocateStack<Type::kBackgroundWorker>() -> cpp::span<StackType_t> {
|
||||
auto AllocateStack<Type::kBackgroundWorker>() -> std::span<StackType_t> {
|
||||
std::size_t size = 64 * 1024;
|
||||
return {static_cast<StackType_t*>(heap_caps_malloc(size, MALLOC_CAP_SPIRAM)),
|
||||
size};
|
||||
|
||||
+4
-4
@@ -11,6 +11,7 @@
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <memory_resource>
|
||||
#include <span>
|
||||
#include <string>
|
||||
|
||||
#include "esp_heap_caps.h"
|
||||
@@ -19,7 +20,6 @@
|
||||
#include "freertos/projdefs.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/task.h"
|
||||
#include "span.hpp"
|
||||
|
||||
namespace tasks {
|
||||
|
||||
@@ -46,7 +46,7 @@ enum class Type {
|
||||
template <Type t>
|
||||
auto Name() -> std::pmr::string;
|
||||
template <Type t>
|
||||
auto AllocateStack() -> cpp::span<StackType_t>;
|
||||
auto AllocateStack() -> std::span<StackType_t>;
|
||||
template <Type t>
|
||||
auto Priority() -> UBaseType_t;
|
||||
|
||||
@@ -56,7 +56,7 @@ template <Type t>
|
||||
auto StartPersistent(const std::function<void(void)>& fn) -> void {
|
||||
StaticTask_t* task_buffer = static_cast<StaticTask_t*>(heap_caps_malloc(
|
||||
sizeof(StaticTask_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT));
|
||||
cpp::span<StackType_t> stack = AllocateStack<t>();
|
||||
std::span<StackType_t> stack = AllocateStack<t>();
|
||||
xTaskCreateStatic(&PersistentMain, Name<t>().c_str(), stack.size(),
|
||||
new std::function<void(void)>(fn), Priority<t>(),
|
||||
stack.data(), task_buffer);
|
||||
@@ -67,7 +67,7 @@ auto StartPersistent(BaseType_t core, const std::function<void(void)>& fn)
|
||||
-> void {
|
||||
StaticTask_t* task_buffer = static_cast<StaticTask_t*>(heap_caps_malloc(
|
||||
sizeof(StaticTask_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT));
|
||||
cpp::span<StackType_t> stack = AllocateStack<t>();
|
||||
std::span<StackType_t> stack = AllocateStack<t>();
|
||||
xTaskCreateStaticPinnedToCore(&PersistentMain, Name<t>().c_str(),
|
||||
stack.size(), new std::function<void(void)>(fn),
|
||||
Priority<t>(), stack.data(), task_buffer, core);
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
idf_component_register(SRCS INCLUDE_DIRS "include" REQUIRES "database" "span")
|
||||
idf_component_register(SRCS INCLUDE_DIRS "include" REQUIRES "database")
|
||||
|
||||
@@ -8,13 +8,12 @@
|
||||
|
||||
#include <iomanip>
|
||||
#include <ostream>
|
||||
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include "span.hpp"
|
||||
|
||||
namespace util {
|
||||
|
||||
inline std::string format_hex_string(cpp::span<const std::byte> data) {
|
||||
inline std::string format_hex_string(std::span<const std::byte> data) {
|
||||
std::ostringstream oss;
|
||||
std::ostringstream ascii_values;
|
||||
int count = 0;
|
||||
|
||||
Reference in New Issue
Block a user