From a231fd1c8afedbeb14b0bc77d76bad61db986059 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 2 May 2024 17:06:25 +1000 Subject: [PATCH] Replace cpp::span shim with std::span --- .reuse/dep5 | 4 - lib/span/CMakeLists.txt | 5 - lib/span/LICENSE.txt | 23 - lib/span/include/span.hpp | 618 ------------------------- lua/licenses.lua | 13 - src/audio/CMakeLists.txt | 2 +- src/audio/audio_converter.cpp | 8 +- src/audio/audio_decoder.cpp | 3 +- src/audio/audio_source.cpp | 2 +- src/audio/fatfs_audio_input.cpp | 8 +- src/audio/fatfs_source.cpp | 2 +- src/audio/include/audio_converter.hpp | 12 +- src/audio/include/audio_decoder.hpp | 2 +- src/audio/include/audio_source.hpp | 2 +- src/audio/include/fatfs_source.hpp | 2 +- src/audio/include/readahead_source.hpp | 2 +- src/audio/include/resample.hpp | 8 +- src/audio/readahead_source.cpp | 2 +- src/audio/resample.cpp | 4 +- src/codecs/CMakeLists.txt | 2 +- src/codecs/dr_flac.cpp | 2 +- src/codecs/include/codec.hpp | 13 +- src/codecs/include/dr_flac.hpp | 8 +- src/codecs/include/mad.hpp | 4 +- src/codecs/include/opus.hpp | 6 +- src/codecs/include/source_buffer.hpp | 9 +- src/codecs/include/vorbis.hpp | 6 +- src/codecs/include/wav.hpp | 2 +- src/codecs/mad.cpp | 10 +- src/codecs/opus.cpp | 2 +- src/codecs/source_buffer.cpp | 6 +- src/codecs/test/test_mad.cpp | 6 +- src/codecs/vorbis.cpp | 2 +- src/codecs/wav.cpp | 59 +-- src/database/CMakeLists.txt | 2 +- src/database/include/records.hpp | 2 +- src/database/include/track.hpp | 9 +- src/database/index.cpp | 10 +- src/database/records.cpp | 2 +- src/database/track.cpp | 8 +- src/drivers/CMakeLists.txt | 2 +- src/drivers/i2s_dac.cpp | 2 +- src/drivers/include/i2s_dac.hpp | 4 +- src/locale/CMakeLists.txt | 2 +- src/locale/include/collation.hpp | 2 +- src/lua/property.cpp | 2 +- src/memory/include/himem.hpp | 6 +- src/tasks/CMakeLists.txt | 2 +- src/tasks/tasks.cpp | 10 +- src/tasks/tasks.hpp | 8 +- src/util/CMakeLists.txt | 2 +- src/util/include/debug.hpp | 5 +- tools/cmake/common.cmake | 1 - 53 files changed, 137 insertions(+), 803 deletions(-) delete mode 100644 lib/span/CMakeLists.txt delete mode 100644 lib/span/LICENSE.txt delete mode 100644 lib/span/include/span.hpp diff --git a/.reuse/dep5 b/.reuse/dep5 index 71ca581e..615c30c4 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -66,10 +66,6 @@ Files: lib/result/include/* Copyright: 2017-2021 Matthew Rodusek License: MIT -Files: lib/span/include/* -Copyright: 2018 Tristan Brindle -License: BSL-1.0 - Files: lib/speexdsp/* Copyright: 2002-2008 Xiph.org Foundation 2002-2008 Jean-Marc Valin diff --git a/lib/span/CMakeLists.txt b/lib/span/CMakeLists.txt deleted file mode 100644 index 57871f57..00000000 --- a/lib/span/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -# Copyright 2023 jacqueline -# -# SPDX-License-Identifier: GPL-3.0-only - -idf_component_register(INCLUDE_DIRS "include") diff --git a/lib/span/LICENSE.txt b/lib/span/LICENSE.txt deleted file mode 100644 index 36b7cd93..00000000 --- a/lib/span/LICENSE.txt +++ /dev/null @@ -1,23 +0,0 @@ -Boost Software License - Version 1.0 - August 17th, 2003 - -Permission is hereby granted, free of charge, to any person or organization -obtaining a copy of the software and accompanying documentation covered by -this license (the "Software") to use, reproduce, display, distribute, -execute, and transmit the Software, and to prepare derivative works of the -Software, and to permit third-parties to whom the Software is furnished to -do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including -the above license grant, this restriction and the following disclaimer, -must be included in all copies of the Software, in whole or in part, and -all derivative works of the Software, unless such copies or derivative -works are solely in the form of machine-executable object code generated by -a source language processor. - -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, TITLE AND NON-INFRINGEMENT. IN NO EVENT -SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/lib/span/include/span.hpp b/lib/span/include/span.hpp deleted file mode 100644 index fdc3a988..00000000 --- a/lib/span/include/span.hpp +++ /dev/null @@ -1,618 +0,0 @@ - -/* -This is an implementation of C++20's std::span -http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/n4820.pdf -*/ - -// Copyright Tristan Brindle 2018. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file ../../LICENSE_1_0.txt or copy at -// https://www.boost.org/LICENSE_1_0.txt) - -#ifndef TCB_SPAN_HPP_INCLUDED -#define TCB_SPAN_HPP_INCLUDED - -#include -#include -#include -#include - -#ifndef TCB_SPAN_NO_EXCEPTIONS -// Attempt to discover whether we're being compiled with exception support -#if !(defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) -#define TCB_SPAN_NO_EXCEPTIONS -#endif -#endif - -#ifndef TCB_SPAN_NO_EXCEPTIONS -#include -#include -#endif - -// Various feature test macros - -#ifndef TCB_SPAN_NAMESPACE_NAME -#define TCB_SPAN_NAMESPACE_NAME tcb -#endif - -#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) -#define TCB_SPAN_HAVE_CPP17 -#endif - -#if __cplusplus >= 201402L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) -#define TCB_SPAN_HAVE_CPP14 -#endif - -namespace TCB_SPAN_NAMESPACE_NAME { - -// Establish default contract checking behavior -#if !defined(TCB_SPAN_THROW_ON_CONTRACT_VIOLATION) && \ - !defined(TCB_SPAN_TERMINATE_ON_CONTRACT_VIOLATION) && \ - !defined(TCB_SPAN_NO_CONTRACT_CHECKING) -#if defined(NDEBUG) || !defined(TCB_SPAN_HAVE_CPP14) -#define TCB_SPAN_NO_CONTRACT_CHECKING -#else -#define TCB_SPAN_TERMINATE_ON_CONTRACT_VIOLATION -#endif -#endif - -#if defined(TCB_SPAN_THROW_ON_CONTRACT_VIOLATION) -struct contract_violation_error : std::logic_error { - explicit contract_violation_error(const char* msg) : std::logic_error(msg) - {} -}; - -inline void contract_violation(const char* msg) -{ - throw contract_violation_error(msg); -} - -#elif defined(TCB_SPAN_TERMINATE_ON_CONTRACT_VIOLATION) -[[noreturn]] inline void contract_violation(const char* /*unused*/) -{ - std::terminate(); -} -#endif - -#if !defined(TCB_SPAN_NO_CONTRACT_CHECKING) -#define TCB_SPAN_STRINGIFY(cond) #cond -#define TCB_SPAN_EXPECT(cond) \ - cond ? (void) 0 : contract_violation("Expected " TCB_SPAN_STRINGIFY(cond)) -#else -#define TCB_SPAN_EXPECT(cond) -#endif - -#if defined(TCB_SPAN_HAVE_CPP17) || defined(__cpp_inline_variables) -#define TCB_SPAN_INLINE_VAR inline -#else -#define TCB_SPAN_INLINE_VAR -#endif - -#if defined(TCB_SPAN_HAVE_CPP14) || \ - (defined(__cpp_constexpr) && __cpp_constexpr >= 201304) -#define TCB_SPAN_HAVE_CPP14_CONSTEXPR -#endif - -#if defined(TCB_SPAN_HAVE_CPP14_CONSTEXPR) -#define TCB_SPAN_CONSTEXPR14 constexpr -#else -#define TCB_SPAN_CONSTEXPR14 -#endif - -#if defined(TCB_SPAN_HAVE_CPP14_CONSTEXPR) && \ - (!defined(_MSC_VER) || _MSC_VER > 1900) -#define TCB_SPAN_CONSTEXPR_ASSIGN constexpr -#else -#define TCB_SPAN_CONSTEXPR_ASSIGN -#endif - -#if defined(TCB_SPAN_NO_CONTRACT_CHECKING) -#define TCB_SPAN_CONSTEXPR11 constexpr -#else -#define TCB_SPAN_CONSTEXPR11 TCB_SPAN_CONSTEXPR14 -#endif - -#if defined(TCB_SPAN_HAVE_CPP17) || defined(__cpp_deduction_guides) -#define TCB_SPAN_HAVE_DEDUCTION_GUIDES -#endif - -#if defined(TCB_SPAN_HAVE_CPP17) || defined(__cpp_lib_byte) -#define TCB_SPAN_HAVE_STD_BYTE -#endif - -#if defined(TCB_SPAN_HAVE_CPP17) || defined(__cpp_lib_array_constexpr) -#define TCB_SPAN_HAVE_CONSTEXPR_STD_ARRAY_ETC -#endif - -#if defined(TCB_SPAN_HAVE_CONSTEXPR_STD_ARRAY_ETC) -#define TCB_SPAN_ARRAY_CONSTEXPR constexpr -#else -#define TCB_SPAN_ARRAY_CONSTEXPR -#endif - -#ifdef TCB_SPAN_HAVE_STD_BYTE -using byte = std::byte; -#else -using byte = unsigned char; -#endif - -#if defined(TCB_SPAN_HAVE_CPP17) -#define TCB_SPAN_NODISCARD [[nodiscard]] -#else -#define TCB_SPAN_NODISCARD -#endif - -TCB_SPAN_INLINE_VAR constexpr std::size_t dynamic_extent = SIZE_MAX; - -template -class span; - -namespace detail { - -template -struct span_storage { - constexpr span_storage() noexcept = default; - - constexpr span_storage(E* p_ptr, std::size_t /*unused*/) noexcept - : ptr(p_ptr) - {} - - E* ptr = nullptr; - static constexpr std::size_t size = S; -}; - -template -struct span_storage { - constexpr span_storage() noexcept = default; - - constexpr span_storage(E* p_ptr, std::size_t p_size) noexcept - : ptr(p_ptr), size(p_size) - {} - - E* ptr = nullptr; - std::size_t size = 0; -}; - -// Reimplementation of C++17 std::size() and std::data() -#if defined(TCB_SPAN_HAVE_CPP17) || \ - defined(__cpp_lib_nonmember_container_access) -using std::data; -using std::size; -#else -template -constexpr auto size(const C& c) -> decltype(c.size()) -{ - return c.size(); -} - -template -constexpr std::size_t size(const T (&)[N]) noexcept -{ - return N; -} - -template -constexpr auto data(C& c) -> decltype(c.data()) -{ - return c.data(); -} - -template -constexpr auto data(const C& c) -> decltype(c.data()) -{ - return c.data(); -} - -template -constexpr T* data(T (&array)[N]) noexcept -{ - return array; -} - -template -constexpr const E* data(std::initializer_list il) noexcept -{ - return il.begin(); -} -#endif // TCB_SPAN_HAVE_CPP17 - -#if defined(TCB_SPAN_HAVE_CPP17) || defined(__cpp_lib_void_t) -using std::void_t; -#else -template -using void_t = void; -#endif - -template -using uncvref_t = - typename std::remove_cv::type>::type; - -template -struct is_span : std::false_type {}; - -template -struct is_span> : std::true_type {}; - -template -struct is_std_array : std::false_type {}; - -template -struct is_std_array> : std::true_type {}; - -template -struct has_size_and_data : std::false_type {}; - -template -struct has_size_and_data())), - decltype(detail::data(std::declval()))>> - : std::true_type {}; - -template > -struct is_container { - static constexpr bool value = - !is_span::value && !is_std_array::value && - !std::is_array::value && has_size_and_data::value; -}; - -template -using remove_pointer_t = typename std::remove_pointer::type; - -template -struct is_container_element_type_compatible : std::false_type {}; - -template -struct is_container_element_type_compatible< - T, E, - typename std::enable_if< - !std::is_same< - typename std::remove_cv()))>::type, - void>::value && - std::is_convertible< - remove_pointer_t()))> (*)[], - E (*)[]>::value - >::type> - : std::true_type {}; - -template -struct is_complete : std::false_type {}; - -template -struct is_complete : std::true_type {}; - -} // namespace detail - -template -class span { - static_assert(std::is_object::value, - "A span's ElementType must be an object type (not a " - "reference type or void)"); - static_assert(detail::is_complete::value, - "A span's ElementType must be a complete type (not a forward " - "declaration)"); - static_assert(!std::is_abstract::value, - "A span's ElementType cannot be an abstract class type"); - - using storage_type = detail::span_storage; - -public: - // constants and types - using element_type = ElementType; - using value_type = typename std::remove_cv::type; - using size_type = std::size_t; - using difference_type = std::ptrdiff_t; - using pointer = element_type*; - using const_pointer = const element_type*; - using reference = element_type&; - using const_reference = const element_type&; - using iterator = pointer; - using reverse_iterator = std::reverse_iterator; - - static constexpr size_type extent = Extent; - - // [span.cons], span constructors, copy, assignment, and destructor - template < - std::size_t E = Extent, - typename std::enable_if<(E == dynamic_extent || E <= 0), int>::type = 0> - constexpr span() noexcept - {} - - TCB_SPAN_CONSTEXPR11 span(pointer ptr, size_type count) - : storage_(ptr, count) - { - TCB_SPAN_EXPECT(extent == dynamic_extent || count == extent); - } - - TCB_SPAN_CONSTEXPR11 span(pointer first_elem, pointer last_elem) - : storage_(first_elem, last_elem - first_elem) - { - TCB_SPAN_EXPECT(extent == dynamic_extent || - last_elem - first_elem == - static_cast(extent)); - } - - template ::value, - int>::type = 0> - constexpr span(element_type (&arr)[N]) noexcept : storage_(arr, N) - {} - - template &, ElementType>::value, - int>::type = 0> - TCB_SPAN_ARRAY_CONSTEXPR span(std::array& arr) noexcept - : storage_(arr.data(), N) - {} - - template &, ElementType>::value, - int>::type = 0> - TCB_SPAN_ARRAY_CONSTEXPR span(const std::array& arr) noexcept - : storage_(arr.data(), N) - {} - - template < - typename Container, std::size_t E = Extent, - typename std::enable_if< - E == dynamic_extent && detail::is_container::value && - detail::is_container_element_type_compatible< - Container&, ElementType>::value, - int>::type = 0> - constexpr span(Container& cont) - : storage_(detail::data(cont), detail::size(cont)) - {} - - template < - typename Container, std::size_t E = Extent, - typename std::enable_if< - E == dynamic_extent && detail::is_container::value && - detail::is_container_element_type_compatible< - const Container&, ElementType>::value, - int>::type = 0> - constexpr span(const Container& cont) - : storage_(detail::data(cont), detail::size(cont)) - {} - - constexpr span(const span& other) noexcept = default; - - template ::value, - int>::type = 0> - constexpr span(const span& other) noexcept - : storage_(other.data(), other.size()) - {} - - ~span() noexcept = default; - - TCB_SPAN_CONSTEXPR_ASSIGN span& - operator=(const span& other) noexcept = default; - - // [span.sub], span subviews - template - TCB_SPAN_CONSTEXPR11 span first() const - { - TCB_SPAN_EXPECT(Count <= size()); - return {data(), Count}; - } - - template - TCB_SPAN_CONSTEXPR11 span last() const - { - TCB_SPAN_EXPECT(Count <= size()); - return {data() + (size() - Count), Count}; - } - - template - using subspan_return_t = - span; - - template - TCB_SPAN_CONSTEXPR11 subspan_return_t subspan() const - { - TCB_SPAN_EXPECT(Offset <= size() && - (Count == dynamic_extent || Offset + Count <= size())); - return {data() + Offset, - Count != dynamic_extent ? Count : size() - Offset}; - } - - TCB_SPAN_CONSTEXPR11 span - first(size_type count) const - { - TCB_SPAN_EXPECT(count <= size()); - return {data(), count}; - } - - TCB_SPAN_CONSTEXPR11 span - last(size_type count) const - { - TCB_SPAN_EXPECT(count <= size()); - return {data() + (size() - count), count}; - } - - TCB_SPAN_CONSTEXPR11 span - subspan(size_type offset, size_type count = dynamic_extent) const - { - TCB_SPAN_EXPECT(offset <= size() && - (count == dynamic_extent || offset + count <= size())); - return {data() + offset, - count == dynamic_extent ? size() - offset : count}; - } - - // [span.obs], span observers - constexpr size_type size() const noexcept { return storage_.size; } - - constexpr size_type size_bytes() const noexcept - { - return size() * sizeof(element_type); - } - - TCB_SPAN_NODISCARD constexpr bool empty() const noexcept - { - return size() == 0; - } - - // [span.elem], span element access - TCB_SPAN_CONSTEXPR11 reference operator[](size_type idx) const - { - TCB_SPAN_EXPECT(idx < size()); - return *(data() + idx); - } - - TCB_SPAN_CONSTEXPR11 reference front() const - { - TCB_SPAN_EXPECT(!empty()); - return *data(); - } - - TCB_SPAN_CONSTEXPR11 reference back() const - { - TCB_SPAN_EXPECT(!empty()); - return *(data() + (size() - 1)); - } - - constexpr pointer data() const noexcept { return storage_.ptr; } - - // [span.iterators], span iterator support - constexpr iterator begin() const noexcept { return data(); } - - constexpr iterator end() const noexcept { return data() + size(); } - - TCB_SPAN_ARRAY_CONSTEXPR reverse_iterator rbegin() const noexcept - { - return reverse_iterator(end()); - } - - TCB_SPAN_ARRAY_CONSTEXPR reverse_iterator rend() const noexcept - { - return reverse_iterator(begin()); - } - -private: - storage_type storage_{}; -}; - -#ifdef TCB_SPAN_HAVE_DEDUCTION_GUIDES - -/* Deduction Guides */ -template -span(T (&)[N])->span; - -template -span(std::array&)->span; - -template -span(const std::array&)->span; - -template -span(Container&)->span()))>::type>; - -template -span(const Container&)->span; - -#endif // TCB_HAVE_DEDUCTION_GUIDES - -template -constexpr span -make_span(span s) noexcept -{ - return s; -} - -template -constexpr span make_span(T (&arr)[N]) noexcept -{ - return {arr}; -} - -template -TCB_SPAN_ARRAY_CONSTEXPR span make_span(std::array& arr) noexcept -{ - return {arr}; -} - -template -TCB_SPAN_ARRAY_CONSTEXPR span -make_span(const std::array& arr) noexcept -{ - return {arr}; -} - -template -constexpr span()))>::type> -make_span(Container& cont) -{ - return {cont}; -} - -template -constexpr span -make_span(const Container& cont) -{ - return {cont}; -} - -template -span -as_bytes(span s) noexcept -{ - return {reinterpret_cast(s.data()), s.size_bytes()}; -} - -template < - class ElementType, size_t Extent, - typename std::enable_if::value, int>::type = 0> -span -as_writable_bytes(span s) noexcept -{ - return {reinterpret_cast(s.data()), s.size_bytes()}; -} - -template -constexpr auto get(span s) -> decltype(s[N]) -{ - return s[N]; -} - -} // namespace TCB_SPAN_NAMESPACE_NAME - -namespace std { - -template -class tuple_size> - : public integral_constant {}; - -template -class tuple_size>; // not defined - -template -class tuple_element> { -public: - static_assert(Extent != TCB_SPAN_NAMESPACE_NAME::dynamic_extent && - I < Extent, - ""); - using type = ElementType; -}; - -} // end namespace std - -#endif // TCB_SPAN_HPP_INCLUDED diff --git a/lua/licenses.lua b/lua/licenses.lua index 8d5813c4..b8c71f36 100644 --- a/lua/licenses.lua +++ b/lua/licenses.lua @@ -63,16 +63,6 @@ The above copyright notice and this permission notice shall be included in all c 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.]]) end -local function boost(copyright) - show_license(copyright .. [[ - -Boost Software License - Version 1.0 - August 17th, 2003 -Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following: -The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor. -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, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.]]) -end - - return function(self) local container = self.root:Object { flex = { @@ -159,9 +149,6 @@ return function(self) library("result", "MIT", function() mit("Copyright (c) 2017-2021 Matthew Rodusek") end) - library("span", "Boost", function() - boost("Copyright Tristan Brindle 2018") - end) library("speexdsp", "bsd", function() xiphbsd( "Copyright 2002-2008 Xiph.org Foundation, Copyright 2002-2008 Jean-Marc Valin, Copyright 2005-2007 Analog Devices Inc., Copyright 2005-2008 Commonwealth Scientific and Industrial Research, Organisation (CSIRO), Copyright 1993, 2002, 2006 David Rowe, Copyright 2003 EpicGames, Copyright 1992-1994 Jutta Degener, Carsten Bormann") diff --git a/src/audio/CMakeLists.txt b/src/audio/CMakeLists.txt index 8ed5efbb..635320f4 100644 --- a/src/audio/CMakeLists.txt +++ b/src/audio/CMakeLists.txt @@ -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}) diff --git a/src/audio/audio_converter.cpp b/src/audio/audio_converter.cpp index eb1cde80..d2edb0b3 100644 --- a/src/audio/audio_converter.cpp +++ b/src/audio/audio_converter.cpp @@ -76,7 +76,7 @@ auto SampleConverter::beginStream(std::shared_ptr track) -> void { xQueueSend(commands_, &args, portMAX_DELAY); } -auto SampleConverter::continueStream(cpp::span input) -> void { +auto SampleConverter::continueStream(std::span 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 input) -> size_t { +auto SampleConverter::handleSamples(std::span 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 input) -> size_t { size_t samples_used = 0; while (samples_used < input.size()) { - cpp::span output_source; + std::span 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 samples) -> void { +auto SampleConverter::sendToSink(std::span 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(); diff --git a/src/audio/audio_decoder.cpp b/src/audio/audio_decoder.cpp index 90c69c16..baf17e7a 100644 --- a/src/audio/audio_decoder.cpp +++ b/src/audio/audio_decoder.cpp @@ -5,7 +5,6 @@ */ #include "audio_decoder.hpp" -#include #include #include @@ -17,6 +16,7 @@ #include #include #include +#include #include #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" diff --git a/src/audio/audio_source.cpp b/src/audio/audio_source.cpp index d9e8e04a..ee2f617f 100644 --- a/src/audio/audio_source.cpp +++ b/src/audio/audio_source.cpp @@ -20,7 +20,7 @@ auto TaggedStream::tags() -> std::shared_ptr { return tags_; } -auto TaggedStream::Read(cpp::span dest) -> ssize_t { +auto TaggedStream::Read(std::span dest) -> ssize_t { return wrapped_->Read(dest); } diff --git a/src/audio/fatfs_audio_input.cpp b/src/audio/fatfs_audio_input.cpp index 29d32390..e5fb3b21 100644 --- a/src/audio/fatfs_audio_input.cpp +++ b/src/audio/fatfs_audio_input.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -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 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 guard{new_stream_mutex_}; if (OpenFile(path, offset)) { has_new_stream_ = true; @@ -102,7 +103,8 @@ auto FatfsAudioInput::NextStream() -> std::shared_ptr { } } -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); diff --git a/src/audio/fatfs_source.cpp b/src/audio/fatfs_source.cpp index 72c3940d..dccdd581 100644 --- a/src/audio/fatfs_source.cpp +++ b/src/audio/fatfs_source.cpp @@ -33,7 +33,7 @@ FatfsSource::~FatfsSource() { f_close(file_.get()); } -auto FatfsSource::Read(cpp::span dest) -> ssize_t { +auto FatfsSource::Read(std::span dest) -> ssize_t { auto lock = drivers::acquire_spi(); if (f_eof(file_.get())) { return 0; diff --git a/src/audio/include/audio_converter.hpp b/src/audio/include/audio_converter.hpp index 232b5d8e..163c6836 100644 --- a/src/audio/include/audio_converter.hpp +++ b/src/audio/include/audio_converter.hpp @@ -33,7 +33,7 @@ class SampleConverter { auto SetOutput(std::shared_ptr) -> void; auto beginStream(std::shared_ptr) -> void; - auto continueStream(cpp::span) -> void; + auto continueStream(std::span) -> 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) -> size_t; + auto handleSamples(std::span) -> size_t; - auto sendToSink(cpp::span) -> void; + auto sendToSink(std::span) -> void; struct Args { std::shared_ptr* track; @@ -57,10 +57,10 @@ class SampleConverter { std::unique_ptr resampler_; StreamBufferHandle_t source_; - cpp::span input_buffer_; - cpp::span input_buffer_as_bytes_; + std::span input_buffer_; + std::span input_buffer_as_bytes_; - cpp::span resampled_buffer_; + std::span resampled_buffer_; std::shared_ptr sink_; IAudioOutput::Format source_format_; diff --git a/src/audio/include/audio_decoder.hpp b/src/audio/include/audio_decoder.hpp index 89f0f43c..8e955f74 100644 --- a/src/audio/include/audio_decoder.hpp +++ b/src/audio/include/audio_decoder.hpp @@ -50,7 +50,7 @@ class Decoder { std::optional current_format_; std::optional current_sink_format_; - cpp::span codec_buffer_; + std::span codec_buffer_; }; } // namespace audio diff --git a/src/audio/include/audio_source.hpp b/src/audio/include/audio_source.hpp index b38acd7a..f6a34300 100644 --- a/src/audio/include/audio_source.hpp +++ b/src/audio/include/audio_source.hpp @@ -23,7 +23,7 @@ class TaggedStream : public codecs::IStream { auto tags() -> std::shared_ptr; - auto Read(cpp::span dest) -> ssize_t override; + auto Read(std::span dest) -> ssize_t override; auto CanSeek() -> bool override; diff --git a/src/audio/include/fatfs_source.hpp b/src/audio/include/fatfs_source.hpp index 45ab34c6..ce9b4db8 100644 --- a/src/audio/include/fatfs_source.hpp +++ b/src/audio/include/fatfs_source.hpp @@ -26,7 +26,7 @@ class FatfsSource : public codecs::IStream { FatfsSource(codecs::StreamType, std::unique_ptr file); ~FatfsSource(); - auto Read(cpp::span dest) -> ssize_t override; + auto Read(std::span dest) -> ssize_t override; auto CanSeek() -> bool override; diff --git a/src/audio/include/readahead_source.hpp b/src/audio/include/readahead_source.hpp index 3e18a989..74a30e1b 100644 --- a/src/audio/include/readahead_source.hpp +++ b/src/audio/include/readahead_source.hpp @@ -30,7 +30,7 @@ class ReadaheadSource : public codecs::IStream { ReadaheadSource(tasks::WorkerPool&, std::unique_ptr); ~ReadaheadSource(); - auto Read(cpp::span dest) -> ssize_t override; + auto Read(std::span dest) -> ssize_t override; auto CanSeek() -> bool override; diff --git a/src/audio/include/resample.hpp b/src/audio/include/resample.hpp index a9464cb1..4d48d47f 100644 --- a/src/audio/include/resample.hpp +++ b/src/audio/include/resample.hpp @@ -7,9 +7,9 @@ #pragma once #include +#include #include -#include "span.hpp" #include "speex/speex_resampler.h" #include "sample.hpp" @@ -24,8 +24,8 @@ class Resampler { ~Resampler(); - auto Process(cpp::span input, - cpp::span output, + auto Process(std::span input, + std::span output, bool end_of_data) -> std::pair; private: @@ -34,4 +34,4 @@ class Resampler { uint8_t num_channels_; }; -} // namespace audio \ No newline at end of file +} // namespace audio diff --git a/src/audio/readahead_source.cpp b/src/audio/readahead_source.cpp index fe7ac3bd..6276907a 100644 --- a/src/audio/readahead_source.cpp +++ b/src/audio/readahead_source.cpp @@ -41,7 +41,7 @@ ReadaheadSource::~ReadaheadSource() { vStreamBufferDeleteWithCaps(buffer_); } -auto ReadaheadSource::Read(cpp::span dest) -> ssize_t { +auto ReadaheadSource::Read(std::span 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. diff --git a/src/audio/resample.cpp b/src/audio/resample.cpp index a3a34ee7..1e20392b 100644 --- a/src/audio/resample.cpp +++ b/src/audio/resample.cpp @@ -38,8 +38,8 @@ Resampler::~Resampler() { speex_resampler_destroy(resampler_); } -auto Resampler::Process(cpp::span input, - cpp::span output, +auto Resampler::Process(std::span input, + std::span output, bool end_of_data) -> std::pair { uint32_t samples_used = input.size() / num_channels_; uint32_t samples_produced = output.size() / num_channels_; diff --git a/src/codecs/CMakeLists.txt b/src/codecs/CMakeLists.txt index b6481bd1..a1221adf 100644 --- a/src/codecs/CMakeLists.txt +++ b/src/codecs/CMakeLists.txt @@ -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}) diff --git a/src/codecs/dr_flac.cpp b/src/codecs/dr_flac.cpp index 2f9acf8c..9341e938 100644 --- a/src/codecs/dr_flac.cpp +++ b/src/codecs/dr_flac.cpp @@ -100,7 +100,7 @@ auto DrFlacDecoder::OpenStream(std::shared_ptr input, uint32_t offset) return format; } -auto DrFlacDecoder::DecodeTo(cpp::span output) +auto DrFlacDecoder::DecodeTo(std::span output) -> cpp::result { size_t frames_to_read = output.size() / flac_->channels / 2; diff --git a/src/codecs/include/codec.hpp b/src/codecs/include/codec.hpp index e48e3c58..4d588a98 100644 --- a/src/codecs/include/codec.hpp +++ b/src/codecs/include/codec.hpp @@ -6,19 +6,16 @@ #pragma once -#include -#include - #include #include #include #include +#include #include #include #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 dest) -> ssize_t = 0; + virtual auto Read(std::span 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 input,uint32_t offset) + virtual auto OpenStream(std::shared_ptr input, uint32_t offset) -> cpp::result = 0; struct OutputInfo { @@ -128,7 +125,7 @@ class ICodec { /* * Writes PCM samples to the given output buffer. */ - virtual auto DecodeTo(cpp::span destination) + virtual auto DecodeTo(std::span destination) -> cpp::result = 0; }; diff --git a/src/codecs/include/dr_flac.hpp b/src/codecs/include/dr_flac.hpp index 547876f4..ac46e92f 100644 --- a/src/codecs/include/dr_flac.hpp +++ b/src/codecs/include/dr_flac.hpp @@ -10,13 +10,13 @@ #include #include #include +#include #include #include #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 input,uint32_t offset) + auto OpenStream(std::shared_ptr input, uint32_t offset) -> cpp::result override; - auto DecodeTo(cpp::span destination) + auto DecodeTo(std::span destination) -> cpp::result override; DrFlacDecoder(const DrFlacDecoder&) = delete; @@ -38,7 +38,7 @@ class DrFlacDecoder : public ICodec { private: std::shared_ptr input_; - drflac *flac_; + drflac* flac_; }; } // namespace codecs diff --git a/src/codecs/include/mad.hpp b/src/codecs/include/mad.hpp index ead0b2a2..d1d0aac5 100644 --- a/src/codecs/include/mad.hpp +++ b/src/codecs/include/mad.hpp @@ -11,11 +11,11 @@ #include #include #include +#include #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 input,uint32_t offset) -> cpp::result override; - auto DecodeTo(cpp::span destination) + auto DecodeTo(std::span destination) -> cpp::result override; MadMp3Decoder(const MadMp3Decoder&) = delete; diff --git a/src/codecs/include/opus.hpp b/src/codecs/include/opus.hpp index de2f7131..200b2d44 100644 --- a/src/codecs/include/opus.hpp +++ b/src/codecs/include/opus.hpp @@ -10,12 +10,12 @@ #include #include #include +#include #include #include #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 input,uint32_t offset) + auto OpenStream(std::shared_ptr input, uint32_t offset) -> cpp::result override; - auto DecodeTo(cpp::span destination) + auto DecodeTo(std::span destination) -> cpp::result override; XiphOpusDecoder(const XiphOpusDecoder&) = delete; diff --git a/src/codecs/include/source_buffer.hpp b/src/codecs/include/source_buffer.hpp index 7834834d..6444dd2c 100644 --- a/src/codecs/include/source_buffer.hpp +++ b/src/codecs/include/source_buffer.hpp @@ -9,8 +9,7 @@ #include #include #include - -#include "span.hpp" +#include #include "codec.hpp" @@ -22,15 +21,15 @@ class SourceBuffer { ~SourceBuffer(); auto Refill(IStream* src) -> bool; - auto AddBytes(std::function)> writer) -> void; - auto ConsumeBytes(std::function)> reader) -> void; + auto AddBytes(std::function)> writer) -> void; + auto ConsumeBytes(std::function)> reader) -> void; auto Empty() -> void; SourceBuffer(const SourceBuffer&) = delete; SourceBuffer& operator=(const SourceBuffer&) = delete; private: - const cpp::span buffer_; + const std::span buffer_; size_t bytes_in_buffer_; size_t offset_of_bytes_; }; diff --git a/src/codecs/include/vorbis.hpp b/src/codecs/include/vorbis.hpp index 3cf0f9ce..e6f393dc 100644 --- a/src/codecs/include/vorbis.hpp +++ b/src/codecs/include/vorbis.hpp @@ -10,12 +10,12 @@ #include #include #include +#include #include #include #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 input,uint32_t offset) + auto OpenStream(std::shared_ptr input, uint32_t offset) -> cpp::result override; - auto DecodeTo(cpp::span destination) + auto DecodeTo(std::span destination) -> cpp::result override; TremorVorbisDecoder(const TremorVorbisDecoder&) = delete; diff --git a/src/codecs/include/wav.hpp b/src/codecs/include/wav.hpp index 40138968..c09a3bb3 100644 --- a/src/codecs/include/wav.hpp +++ b/src/codecs/include/wav.hpp @@ -34,7 +34,7 @@ class WavDecoder : public ICodec { auto OpenStream(std::shared_ptr input,uint32_t offset) -> cpp::result override; - auto DecodeTo(cpp::span destination) + auto DecodeTo(std::span destination) -> cpp::result override; WavDecoder(const WavDecoder&) = delete; diff --git a/src/codecs/mad.cpp b/src/codecs/mad.cpp index e44e9922..01b2f721 100644 --- a/src/codecs/mad.cpp +++ b/src/codecs/mad.cpp @@ -74,7 +74,7 @@ auto MadMp3Decoder::OpenStream(std::shared_ptr input, uint32_t offset) while (!eof && !got_header) { eof = buffer_.Refill(input_.get()); - buffer_.ConsumeBytes([&](cpp::span buf) -> size_t { + buffer_.ConsumeBytes([&](std::span buf) -> size_t { mad_stream_buffer(stream_.get(), reinterpret_cast(buf.data()), buf.size_bytes()); @@ -130,7 +130,7 @@ auto MadMp3Decoder::OpenStream(std::shared_ptr input, uint32_t offset) } need_refill = false; - buffer_.ConsumeBytes([&](cpp::span buf) -> size_t { + buffer_.ConsumeBytes([&](std::span buf) -> size_t { mad_stream_buffer(stream_.get(), reinterpret_cast(buf.data()), buf.size()); @@ -156,13 +156,13 @@ auto MadMp3Decoder::OpenStream(std::shared_ptr input, uint32_t offset) return output; } -auto MadMp3Decoder::DecodeTo(cpp::span output) +auto MadMp3Decoder::DecodeTo(std::span output) -> cpp::result { if (current_sample_ < 0 && !is_eos_) { if (!is_eof_) { is_eof_ = buffer_.Refill(input_.get()); if (is_eof_) { - buffer_.AddBytes([&](cpp::span buf) -> size_t { + buffer_.AddBytes([&](std::span buf) -> size_t { if (buf.size() < MAD_BUFFER_GUARD) { is_eof_ = false; return 0; @@ -174,7 +174,7 @@ auto MadMp3Decoder::DecodeTo(cpp::span output) } } - buffer_.ConsumeBytes([&](cpp::span buf) -> size_t { + buffer_.ConsumeBytes([&](std::span buf) -> size_t { mad_stream_buffer(stream_.get(), reinterpret_cast(buf.data()), buf.size()); diff --git a/src/codecs/opus.cpp b/src/codecs/opus.cpp index a5220c4b..b5e7c3fc 100644 --- a/src/codecs/opus.cpp +++ b/src/codecs/opus.cpp @@ -140,7 +140,7 @@ auto XiphOpusDecoder::OpenStream(std::shared_ptr input, }; } -auto XiphOpusDecoder::DecodeTo(cpp::span output) +auto XiphOpusDecoder::DecodeTo(std::span output) -> cpp::result { int samples_written = op_read_stereo(opus_, output.data(), output.size()); diff --git a/src/codecs/source_buffer.cpp b/src/codecs/source_buffer.cpp index 0a986bc3..538d7f47 100644 --- a/src/codecs/source_buffer.cpp +++ b/src/codecs/source_buffer.cpp @@ -39,7 +39,7 @@ auto SourceBuffer::Refill(IStream* src) -> bool { return false; } bool eof = false; - AddBytes([&](cpp::span buf) -> size_t { + AddBytes([&](std::span 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)> writer) +auto SourceBuffer::AddBytes(std::function)> 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)> writer) } auto SourceBuffer::ConsumeBytes( - std::function)> reader) -> void { + std::function)> reader) -> void { size_t bytes_consumed = std::invoke( reader, buffer_.subspan(offset_of_bytes_, bytes_in_buffer_)); assert(bytes_consumed <= bytes_in_buffer_); diff --git a/src/codecs/test/test_mad.cpp b/src/codecs/test/test_mad.cpp index e8c714e7..15c96eae 100644 --- a/src/codecs/test/test_mad.cpp +++ b/src/codecs/test/test_mad.cpp @@ -8,14 +8,14 @@ #include #include +#include #include "catch2/catch.hpp" -#include "span.hpp" #include "test.mp3.hpp" -void load_mp3(cpp::span dest) { - cpp::span src(reinterpret_cast(test_mp3), +void load_mp3(std::span dest) { + std::span src(reinterpret_cast(test_mp3), test_mp3_len); std::copy(src.begin(), src.begin() + dest.size(), dest.begin()); } diff --git a/src/codecs/vorbis.cpp b/src/codecs/vorbis.cpp index 9131451b..0b2af691 100644 --- a/src/codecs/vorbis.cpp +++ b/src/codecs/vorbis.cpp @@ -129,7 +129,7 @@ auto TremorVorbisDecoder::OpenStream(std::shared_ptr input, }; } -auto TremorVorbisDecoder::DecodeTo(cpp::span output) +auto TremorVorbisDecoder::DecodeTo(std::span output) -> cpp::result { int unused = 0; long bytes_written = diff --git a/src/codecs/wav.cpp b/src/codecs/wav.cpp index 714ec237..f5b9d789 100644 --- a/src/codecs/wav.cpp +++ b/src/codecs/wav.cpp @@ -20,24 +20,24 @@ namespace codecs { [[maybe_unused]] static const char kTag[] = "wav"; -static inline auto bytes_to_u16(cpp::span bytes) +static inline auto bytes_to_u16(std::span bytes) -> uint16_t { return (uint16_t)bytes[0] | (uint16_t)bytes[1] << 8; } -static inline auto bytes_to_u32(cpp::span bytes) +static inline auto bytes_to_u32(std::span 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 bytes) +static inline auto bytes_to_str(std::span bytes) -> std::string { return std::string(reinterpret_cast(bytes.data()), - bytes.size_bytes()); + bytes.size_bytes()); } -static int16_t convert_f32_to_16_bit(cpp::span bytes) { +static int16_t convert_f32_to_16_bit(std::span 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 bytes) { return sample::FromDouble(*fval); } -static int16_t convert_f64_to_16_bit(cpp::span bytes) { +static int16_t convert_f64_to_16_bit(std::span 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 bytes) { return sample::FromDouble(*fval); } -static int16_t convert_to_16_bit(cpp::span bytes) { +static int16_t convert_to_16_bit(std::span 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 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 input,uint32_t offset) +auto WavDecoder::OpenStream(std::shared_ptr input, uint32_t offset) -> cpp::result { input_ = input; @@ -123,7 +126,7 @@ auto WavDecoder::OpenStream(std::shared_ptr 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 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 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 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 data_tag = {std::byte{0x64}, std::byte{0x61}, @@ -180,7 +183,7 @@ auto WavDecoder::OpenStream(std::shared_ptr 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 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 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 input,uint32_t offset) return output_format_; } -auto WavDecoder::DecodeTo(cpp::span output) +auto WavDecoder::DecodeTo(std::span output) -> cpp::result { bool is_eof = buffer_.Refill(input_.get()); size_t samples_written = 0; - buffer_.ConsumeBytes([&](cpp::span buf) -> size_t { + buffer_.ConsumeBytes([&](std::span 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 output) return samples_written * bytes_per_sample_; }); - return OutputInfo{.samples_written = samples_written, .is_stream_finished = samples_written == 0 && is_eof}; } diff --git a/src/database/CMakeLists.txt b/src/database/CMakeLists.txt index 26c14815..248ca3d7 100644 --- a/src/database/CMakeLists.txt +++ b/src/database/CMakeLists.txt @@ -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}) diff --git a/src/database/include/records.hpp b/src/database/include/records.hpp index 87034059..3ca68fea 100644 --- a/src/database/include/records.hpp +++ b/src/database/include/records.hpp @@ -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 bytes) -> std::optional; +auto BytesToTrackId(std::span bytes) -> std::optional; } // namespace database diff --git a/src/database/include/track.hpp b/src/database/include/track.hpp index 76b1c56e..b097ab52 100644 --- a/src/database/include/track.hpp +++ b/src/database/include/track.hpp @@ -6,12 +6,12 @@ #pragma once -#include -#include +#include #include #include #include +#include #include #include #include @@ -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::span>; 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; + auto genres() const -> std::span; auto genres(const std::string_view) -> void; /* diff --git a/src/database/index.cpp b/src/database/index.cpp index 857fbcc5..328c3b43 100644 --- a/src/database/index.cpp +++ b/src/database/index.cpp @@ -61,11 +61,11 @@ class Indexer { private: auto handleLevel(const IndexKey::Header& header, - cpp::span components) -> void; + std::span components) -> void; auto handleItem(const IndexKey::Header& header, std::variant item, - cpp::span components) -> void; + std::span components) -> void; auto missing_value(Tag tag) -> TagValue { switch (tag) { @@ -111,7 +111,7 @@ auto Indexer::index() -> std::vector> { } auto Indexer::handleLevel(const IndexKey::Header& header, - cpp::span components) -> void { + std::span components) -> void { Tag component = components.front(); TagValue value = track_.tags().get(component); if (std::holds_alternative(value)) { @@ -129,7 +129,7 @@ auto Indexer::handleLevel(const IndexKey::Header& header, } else if constexpr (std::is_same_v) { handleItem(header, arg, components); } else if constexpr (std::is_same_v< - T, cpp::span>) { + T, std::span>) { 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 item, - cpp::span components) -> void { + std::span components) -> void { IndexKey key{ .header = header, .item = {}, diff --git a/src/database/records.cpp b/src/database/records.cpp index a1efb568..b086be3b 100644 --- a/src/database/records.cpp +++ b/src/database/records.cpp @@ -248,7 +248,7 @@ auto TrackIdToBytes(TrackId id) -> std::string { return cppbor::Uint{id}.toString(); } -auto BytesToTrackId(cpp::span bytes) -> std::optional { +auto BytesToTrackId(std::span bytes) -> std::optional { auto [res, unused, err] = cppbor::parse( reinterpret_cast(bytes.data()), bytes.size()); if (!res || res->type() != cppbor::UINT) { diff --git a/src/database/track.cpp b/src/database/track.cpp index a2bd05d3..1b1442a1 100644 --- a/src/database/track.cpp +++ b/src/database/track.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -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) { return komihash(&arg, sizeof(arg), 0); } else if constexpr (std::is_same_v< - T, cpp::span>) { + T, std::span>) { 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) { return std::to_string(arg); } else if constexpr (std::is_same_v< - T, cpp::span>) { + T, std::span>) { 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 { +auto TrackTags::genres() const -> std::span { return genres_; } diff --git a/src/drivers/CMakeLists.txt b/src/drivers/CMakeLists.txt index 891115d4..c2018d3f 100644 --- a/src/drivers/CMakeLists.txt +++ b/src/drivers/CMakeLists.txt @@ -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}) diff --git a/src/drivers/i2s_dac.cpp b/src/drivers/i2s_dac.cpp index aef466c2..7fe5547d 100644 --- a/src/drivers/i2s_dac.cpp +++ b/src/drivers/i2s_dac.cpp @@ -207,7 +207,7 @@ auto I2SDac::Reconfigure(Channels ch, BitsPerSample bps, SampleRate rate) } } -auto I2SDac::WriteData(const cpp::span& data) -> void { +auto I2SDac::WriteData(const std::span& 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); diff --git a/src/drivers/include/i2s_dac.hpp b/src/drivers/include/i2s_dac.hpp index bd837ca0..569f0a9a 100644 --- a/src/drivers/include/i2s_dac.hpp +++ b/src/drivers/include/i2s_dac.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #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& data) -> void; + auto WriteData(const std::span& data) -> void; auto SetSource(StreamBufferHandle_t buffer) -> void; // Not copyable or movable. diff --git a/src/locale/CMakeLists.txt b/src/locale/CMakeLists.txt index 627ca314..9c1c2619 100644 --- a/src/locale/CMakeLists.txt +++ b/src/locale/CMakeLists.txt @@ -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}) diff --git a/src/locale/include/collation.hpp b/src/locale/include/collation.hpp index b666860d..88f499c4 100644 --- a/src/locale/include/collation.hpp +++ b/src/locale/include/collation.hpp @@ -9,10 +9,10 @@ #include #include #include +#include #include #include "esp_partition.h" -#include "span.hpp" #include "strxfrm.h" diff --git a/src/lua/property.cpp b/src/lua/property.cpp index 634a6a26..9f4a1908 100644 --- a/src/lua/property.cpp +++ b/src/lua/property.cpp @@ -247,7 +247,7 @@ static auto pushTagValue(lua_State* L, const database::TagValue& val) -> void { if constexpr (std::is_same_v) { lua_pushlstring(L, arg.data(), arg.size()); } else if constexpr (std::is_same_v< - T, cpp::span>) { + T, std::span>) { lua_createtable(L, 0, arg.size()); for (const auto& i : arg) { lua_pushlstring(L, i.data(), i.size()); diff --git a/src/memory/include/himem.hpp b/src/memory/include/himem.hpp index 81166e0d..f70648a9 100644 --- a/src/memory/include/himem.hpp +++ b/src/memory/include/himem.hpp @@ -8,9 +8,9 @@ #include #include +#include #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 { + auto Get() -> std::span { if (bytes_ == nullptr) { return {}; } return {bytes_, size}; } - auto Map(const HimemAlloc& alloc) -> cpp::span { + auto Map(const HimemAlloc& alloc) -> std::span { assert(bytes_ == nullptr); ESP_ERROR_CHECK(esp_himem_map(alloc.handle, range_handle, 0, 0, size, 0, reinterpret_cast(&bytes_))); diff --git a/src/tasks/CMakeLists.txt b/src/tasks/CMakeLists.txt index 0fdacf78..814c9943 100644 --- a/src/tasks/CMakeLists.txt +++ b/src/tasks/CMakeLists.txt @@ -1,5 +1,5 @@ # Copyright 2023 jacqueline # # 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}) diff --git a/src/tasks/tasks.cpp b/src/tasks/tasks.cpp index aa382655..d3937c68 100644 --- a/src/tasks/tasks.cpp +++ b/src/tasks/tasks.cpp @@ -33,12 +33,12 @@ auto Name() -> std::pmr::string { } template -auto AllocateStack() -> cpp::span; +auto AllocateStack() -> std::span; // 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() -> cpp::span { +auto AllocateStack() -> std::span { constexpr std::size_t size = 20 * 1024; static StackType_t sStack[size]; return {sStack, size}; @@ -46,14 +46,14 @@ auto AllocateStack() -> cpp::span { // LVGL requires only a relatively small stack. Lua's stack is allocated // separately. template <> -auto AllocateStack() -> cpp::span { +auto AllocateStack() -> std::span { 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() -> cpp::span { +auto AllocateStack() -> std::span { constexpr std::size_t size = 4 * 1024; static StackType_t sStack[size]; return {sStack, size}; @@ -63,7 +63,7 @@ auto AllocateStack() -> cpp::span { // 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() -> cpp::span { +auto AllocateStack() -> std::span { std::size_t size = 64 * 1024; return {static_cast(heap_caps_malloc(size, MALLOC_CAP_SPIRAM)), size}; diff --git a/src/tasks/tasks.hpp b/src/tasks/tasks.hpp index 47f26837..566b5706 100644 --- a/src/tasks/tasks.hpp +++ b/src/tasks/tasks.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #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 auto Name() -> std::pmr::string; template -auto AllocateStack() -> cpp::span; +auto AllocateStack() -> std::span; template auto Priority() -> UBaseType_t; @@ -56,7 +56,7 @@ template auto StartPersistent(const std::function& fn) -> void { StaticTask_t* task_buffer = static_cast(heap_caps_malloc( sizeof(StaticTask_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT)); - cpp::span stack = AllocateStack(); + std::span stack = AllocateStack(); xTaskCreateStatic(&PersistentMain, Name().c_str(), stack.size(), new std::function(fn), Priority(), stack.data(), task_buffer); @@ -67,7 +67,7 @@ auto StartPersistent(BaseType_t core, const std::function& fn) -> void { StaticTask_t* task_buffer = static_cast(heap_caps_malloc( sizeof(StaticTask_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT)); - cpp::span stack = AllocateStack(); + std::span stack = AllocateStack(); xTaskCreateStaticPinnedToCore(&PersistentMain, Name().c_str(), stack.size(), new std::function(fn), Priority(), stack.data(), task_buffer, core); diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index bb4ce320..e1913920 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -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") diff --git a/src/util/include/debug.hpp b/src/util/include/debug.hpp index 620b0974..27fb2999 100644 --- a/src/util/include/debug.hpp +++ b/src/util/include/debug.hpp @@ -8,13 +8,12 @@ #include #include - +#include #include -#include "span.hpp" namespace util { -inline std::string format_hex_string(cpp::span data) { +inline std::string format_hex_string(std::span data) { std::ostringstream oss; std::ostringstream ascii_values; int count = 0; diff --git a/tools/cmake/common.cmake b/tools/cmake/common.cmake index c7137694..7087e896 100644 --- a/tools/cmake/common.cmake +++ b/tools/cmake/common.cmake @@ -33,7 +33,6 @@ list(APPEND EXTRA_COMPONENT_DIRS "$ENV{PROJ_PATH}/lib/drflac") list(APPEND EXTRA_COMPONENT_DIRS "$ENV{PROJ_PATH}/lib/ogg") list(APPEND EXTRA_COMPONENT_DIRS "$ENV{PROJ_PATH}/lib/opusfile") list(APPEND EXTRA_COMPONENT_DIRS "$ENV{PROJ_PATH}/lib/result") -list(APPEND EXTRA_COMPONENT_DIRS "$ENV{PROJ_PATH}/lib/span") list(APPEND EXTRA_COMPONENT_DIRS "$ENV{PROJ_PATH}/lib/speexdsp") list(APPEND EXTRA_COMPONENT_DIRS "$ENV{PROJ_PATH}/lib/tinyfsm") list(APPEND EXTRA_COMPONENT_DIRS "$ENV{PROJ_PATH}/lib/tremor")