Fixes for ArduinJson (to work with Arduino-2.0).

Fixes for SynthDexed.
dev
Holger Wirtz 2 years ago
parent 7b21d94c77
commit 9ed4126e10
  1. 20
      third-party/ArduinoJson/extras/ci/arduino.sh
  2. 35
      third-party/ArduinoJson/extras/tests/JsonArray/undefined.cpp
  3. 96
      third-party/ArduinoJson/extras/tests/JsonVariant/undefined.cpp
  4. 32
      third-party/ArduinoJson/src/ArduinoJson/Polyfills/safe_strcmp.hpp
  5. 28
      third-party/ArduinoJson/src/ArduinoJson/Polyfills/utility.hpp
  6. 51
      third-party/ArduinoJson/src/ArduinoJson/Strings/Adapters/ArduinoStringAdapter.hpp
  7. 51
      third-party/ArduinoJson/src/ArduinoJson/Strings/Adapters/ConstRamStringAdapter.hpp
  8. 48
      third-party/ArduinoJson/src/ArduinoJson/Strings/Adapters/FlashStringAdapter.hpp
  9. 27
      third-party/ArduinoJson/src/ArduinoJson/Strings/Adapters/JsonStringAdapter.hpp
  10. 29
      third-party/ArduinoJson/src/ArduinoJson/Strings/Adapters/RamStringAdapter.hpp
  11. 48
      third-party/ArduinoJson/src/ArduinoJson/Strings/Adapters/SizedFlashStringAdapter.hpp
  12. 43
      third-party/ArduinoJson/src/ArduinoJson/Strings/Adapters/SizedRamStringAdapter.hpp
  13. 46
      third-party/ArduinoJson/src/ArduinoJson/Strings/Adapters/StdStringAdapter.hpp
  14. 44
      third-party/ArduinoJson/src/ArduinoJson/Strings/Adapters/StringViewAdapter.hpp
  15. 58
      third-party/ArduinoJson/src/ArduinoJson/Strings/ArduinoStringAdapter.hpp
  16. 58
      third-party/ArduinoJson/src/ArduinoJson/Strings/ConstRamStringAdapter.hpp
  17. 57
      third-party/ArduinoJson/src/ArduinoJson/Strings/FlashStringAdapter.hpp
  18. 37
      third-party/ArduinoJson/src/ArduinoJson/Strings/IsWriteableString.hpp
  19. 43
      third-party/ArduinoJson/src/ArduinoJson/Strings/RamStringAdapter.hpp
  20. 55
      third-party/ArduinoJson/src/ArduinoJson/Strings/SizedFlashStringAdapter.hpp
  21. 51
      third-party/ArduinoJson/src/ArduinoJson/Strings/SizedRamStringAdapter.hpp
  22. 61
      third-party/ArduinoJson/src/ArduinoJson/Strings/StdStringAdapter.hpp
  23. 32
      third-party/ArduinoJson/src/ArduinoJson/Strings/StringAdapter.hpp
  24. 56
      third-party/ArduinoJson/src/ArduinoJson/Strings/StringViewAdapter.hpp
  25. 18
      third-party/Synth_Dexed/src/compressor.h

@ -1,20 +0,0 @@
#!/bin/bash -eux
/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16
sleep 3
export DISPLAY=:1.0
mkdir -p /tmp/arduino
curl -sS http://downloads.arduino.cc/arduino-$VERSION-linux64.tar.xz | tar xJ -C /tmp/arduino --strip 1 ||
curl -sS http://downloads.arduino.cc/arduino-$VERSION-linux64.tgz | tar xz -C /tmp/arduino --strip 1
export PATH=$PATH:/tmp/arduino/
if [[ "$BOARD" =~ "arduino:samd:" ]]; then
arduino --install-boards arduino:samd
fi
ln -s $PWD /tmp/arduino/libraries/ArduinoJson
for EXAMPLE in $PWD/examples/*/*.ino; do
arduino --verify --board $BOARD $EXAMPLE
done

@ -1,35 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
using namespace Catch::Matchers;
TEST_CASE("Undefined JsonArray") {
JsonArray array;
SECTION("SubscriptFails") {
REQUIRE(array[0].isNull());
}
SECTION("AddFails") {
array.add(1);
REQUIRE(0 == array.size());
}
SECTION("CreateNestedArrayFails") {
REQUIRE(array.createNestedArray().isNull());
}
SECTION("CreateNestedObjectFails") {
REQUIRE(array.createNestedObject().isNull());
}
SECTION("PrintToWritesBrackets") {
char buffer[32];
serializeJson(array, buffer, sizeof(buffer));
REQUIRE_THAT(buffer, Equals("null"));
}
}

@ -1,96 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#include <ArduinoJson.h>
#include <catch.hpp>
TEST_CASE("JsonVariant undefined") {
JsonVariant variant;
SECTION("as<T>()") {
SECTION("long") {
REQUIRE(variant.as<long>() == 0);
}
SECTION("unsigned") {
REQUIRE(variant.as<unsigned>() == 0);
}
SECTION("const char*") {
REQUIRE(variant.as<const char*>() == 0);
}
SECTION("double") {
REQUIRE(variant.as<double>() == 0);
}
SECTION("bool") {
REQUIRE(variant.as<bool>() == false);
}
SECTION("JsonArray") {
REQUIRE(variant.as<JsonArray>().isNull());
}
SECTION("JsonObject") {
REQUIRE(variant.as<JsonObject>().isNull());
}
}
SECTION("is<T>()") {
SECTION("long") {
REQUIRE(variant.is<long>() == false);
}
SECTION("unsigned") {
REQUIRE(variant.is<unsigned>() == false);
}
SECTION("const char*") {
REQUIRE(variant.is<const char*>() == false);
}
SECTION("double") {
REQUIRE(variant.is<double>() == false);
}
SECTION("bool") {
REQUIRE(variant.is<bool>() == false);
}
SECTION("JsonArray") {
REQUIRE(variant.is<JsonArray>() == false);
}
SECTION("JsonObject") {
REQUIRE(variant.is<JsonObject>() == false);
}
}
SECTION("set<T>()") {
SECTION("long") {
REQUIRE(variant.set(42L) == false);
}
SECTION("unsigned") {
REQUIRE(variant.set(42U) == false);
}
SECTION("const char*") {
REQUIRE(variant.set("42") == false);
}
SECTION("Serialized<const char*>") {
REQUIRE(variant.set(serialized("42")) == false);
}
SECTION("double") {
REQUIRE(variant.set(42.0) == false);
}
SECTION("bool") {
REQUIRE(variant.set(true) == false);
}
}
}

@ -1,32 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <ArduinoJson/Namespace.hpp>
#include <stdint.h> // int8_t
namespace ARDUINOJSON_NAMESPACE {
inline int safe_strcmp(const char* a, const char* b) {
if (a == b)
return 0;
if (!a)
return -1;
if (!b)
return 1;
return strcmp(a, b);
}
inline int safe_strncmp(const char* a, const char* b, size_t n) {
if (a == b)
return 0;
if (!a)
return -1;
if (!b)
return 1;
return strncmp(a, b, n);
}
} // namespace ARDUINOJSON_NAMESPACE

@ -1,28 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include "type_traits.hpp"
namespace ARDUINOJSON_NAMESPACE {
template <typename T>
inline void swap(T& a, T& b) {
T t(a);
a = b;
b = t;
}
#if ARDUINOJSON_HAS_RVALUE_REFERENCES
template <typename T>
typename remove_reference<T>::type&& move(T&& t) {
return static_cast<typename remove_reference<T>::type&&>(t);
}
#else
template <typename T>
T& move(T& t) {
return t;
}
#endif
} // namespace ARDUINOJSON_NAMESPACE

@ -1,51 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <Arduino.h>
#include <ArduinoJson/Polyfills/safe_strcmp.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
#include <ArduinoJson/Strings/StringAdapter.hpp>
namespace ARDUINOJSON_NAMESPACE {
template <>
class StringAdapter< ::String> {
public:
StringAdapter(const ::String& str) : _str(&str) {}
void copyTo(char* p, size_t n) const {
memcpy(p, _str->c_str(), n);
}
bool isNull() const {
// Arduino's String::c_str() can return NULL
return !_str->c_str();
}
int compare(const char* other) const {
// Arduino's String::c_str() can return NULL
const char* me = _str->c_str();
return safe_strcmp(me, other);
}
size_t size() const {
return _str->length();
}
typedef storage_policies::store_by_copy storage_policy;
private:
const ::String* _str;
};
template <>
class StringAdapter< ::StringSumHelper> : public StringAdapter< ::String> {
public:
StringAdapter(const ::String& s) : StringAdapter< ::String>(s) {}
};
} // namespace ARDUINOJSON_NAMESPACE

@ -1,51 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <stddef.h> // size_t
#include <string.h> // strcmp
#include <ArduinoJson/Polyfills/safe_strcmp.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
#include <ArduinoJson/Strings/StringAdapter.hpp>
namespace ARDUINOJSON_NAMESPACE {
template <>
class StringAdapter<const char*> {
public:
StringAdapter(const char* str = 0) : _str(str) {}
int compare(const char* other) const {
return safe_strcmp(_str, other);
}
bool isNull() const {
return !_str;
}
size_t size() const {
if (!_str)
return 0;
return strlen(_str);
}
const char* data() const {
return _str;
}
typedef storage_policies::store_by_address storage_policy;
protected:
const char* _str;
};
template <int N>
class StringAdapter<const char[N]> : public StringAdapter<const char*> {
public:
StringAdapter(const char* s) : StringAdapter<const char*>(s) {}
};
} // namespace ARDUINOJSON_NAMESPACE

@ -1,48 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <ArduinoJson/Polyfills/pgmspace.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
#include <ArduinoJson/Strings/StringAdapter.hpp>
namespace ARDUINOJSON_NAMESPACE {
template <>
class StringAdapter<const __FlashStringHelper*> {
public:
StringAdapter(const __FlashStringHelper* str) : _str(str) {}
int compare(const char* other) const {
if (!other && !_str)
return 0;
if (!_str)
return -1;
if (!other)
return 1;
return -strcmp_P(other, reinterpret_cast<const char*>(_str));
}
bool isNull() const {
return !_str;
}
void copyTo(char* p, size_t n) const {
memcpy_P(p, reinterpret_cast<const char*>(_str), n);
}
size_t size() const {
if (!_str)
return 0;
return strlen_P(reinterpret_cast<const char*>(_str));
}
typedef storage_policies::store_by_copy storage_policy;
private:
const __FlashStringHelper* _str;
};
} // namespace ARDUINOJSON_NAMESPACE

@ -1,27 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <ArduinoJson/Strings/Adapters/RamStringAdapter.hpp>
#include <ArduinoJson/Strings/String.hpp>
namespace ARDUINOJSON_NAMESPACE {
template <>
class StringAdapter<String> : public StringAdapter<char*> {
public:
StringAdapter(const String& str)
: StringAdapter<char*>(str.c_str()), _isStatic(str.isStatic()) {}
bool isStatic() const {
return _isStatic;
}
typedef storage_policies::decide_at_runtime storage_policy;
private:
bool _isStatic;
};
} // namespace ARDUINOJSON_NAMESPACE

@ -1,29 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <ArduinoJson/Polyfills/type_traits.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
#include <ArduinoJson/Strings/StringAdapter.hpp>
namespace ARDUINOJSON_NAMESPACE {
template <typename TChar>
class StringAdapter<TChar*, false,
typename enable_if<sizeof(TChar) == 1 &&
!is_same<TChar, void>::value>::type>
: public StringAdapter<const char*> {
public:
StringAdapter(const TChar* str)
: StringAdapter<const char*>(reinterpret_cast<const char*>(str)) {}
void copyTo(char* p, size_t n) const {
memcpy(p, _str, n);
}
typedef ARDUINOJSON_NAMESPACE::storage_policies::store_by_copy storage_policy;
};
} // namespace ARDUINOJSON_NAMESPACE

@ -1,48 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <ArduinoJson/Namespace.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
#include <ArduinoJson/Strings/StringAdapter.hpp>
namespace ARDUINOJSON_NAMESPACE {
template <>
class StringAdapter<const __FlashStringHelper*, true> {
public:
StringAdapter(const __FlashStringHelper* str, size_t sz)
: _str(str), _size(sz) {}
int compare(const char* other) const {
if (!other && !_str)
return 0;
if (!_str)
return -1;
if (!other)
return 1;
return -strncmp_P(other, reinterpret_cast<const char*>(_str), _size);
}
bool isNull() const {
return !_str;
}
void copyTo(char* p, size_t n) const {
memcpy_P(p, reinterpret_cast<const char*>(_str), n);
}
size_t size() const {
return _size;
}
typedef storage_policies::store_by_copy storage_policy;
private:
const __FlashStringHelper* _str;
size_t _size;
};
} // namespace ARDUINOJSON_NAMESPACE

@ -1,43 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <ArduinoJson/Namespace.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
#include <ArduinoJson/Strings/StringAdapter.hpp>
#include <string.h> // strcmp
namespace ARDUINOJSON_NAMESPACE {
template <typename TChar>
class StringAdapter<TChar*, true> {
public:
StringAdapter(const char* str, size_t n) : _str(str), _size(n) {}
int compare(const char* other) const {
return safe_strncmp(_str, other, _size);
}
bool isNull() const {
return !_str;
}
void copyTo(char* p, size_t n) const {
memcpy(p, _str, n);
}
size_t size() const {
return _size;
}
typedef storage_policies::store_by_copy storage_policy;
private:
const char* _str;
size_t _size;
};
} // namespace ARDUINOJSON_NAMESPACE

@ -1,46 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <ArduinoJson/Namespace.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
#include <ArduinoJson/Strings/StringAdapter.hpp>
#include <string>
namespace ARDUINOJSON_NAMESPACE {
template <typename TCharTraits, typename TAllocator>
class StringAdapter<std::basic_string<char, TCharTraits, TAllocator> > {
public:
typedef std::basic_string<char, TCharTraits, TAllocator> string_type;
StringAdapter(const string_type& str) : _str(&str) {}
void copyTo(char* p, size_t n) const {
memcpy(p, _str->c_str(), n);
}
bool isNull() const {
return false;
}
int compare(const char* other) const {
if (!other)
return 1;
return _str->compare(other);
}
size_t size() const {
return _str->size();
}
typedef storage_policies::store_by_copy storage_policy;
private:
const string_type* _str;
};
} // namespace ARDUINOJSON_NAMESPACE

@ -1,44 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <ArduinoJson/Namespace.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
#include <ArduinoJson/Strings/StringAdapter.hpp>
#include <string_view>
namespace ARDUINOJSON_NAMESPACE {
template <>
class StringAdapter<std::string_view> {
public:
StringAdapter(std::string_view str) : _str(str) {}
void copyTo(char* p, size_t n) const {
memcpy(p, _str.data(), n);
}
bool isNull() const {
return false;
}
int compare(const char* other) const {
if (!other)
return 1;
return _str.compare(other);
}
size_t size() const {
return _str.size();
}
typedef storage_policies::store_by_copy storage_policy;
private:
std::string_view _str;
};
} // namespace ARDUINOJSON_NAMESPACE

@ -1,58 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <Arduino.h>
#include <ArduinoJson/Polyfills/safe_strcmp.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
namespace ARDUINOJSON_NAMESPACE {
class ArduinoStringAdapter {
public:
ArduinoStringAdapter(const ::String& str) : _str(&str) {}
void copyTo(char* p, size_t n) const {
memcpy(p, _str->c_str(), n);
}
bool isNull() const {
// Arduino's String::c_str() can return NULL
return !_str->c_str();
}
int compare(const char* other) const {
// Arduino's String::c_str() can return NULL
const char* me = _str->c_str();
return safe_strcmp(me, other);
}
bool equals(const char* expected) const {
return compare(expected) == 0;
}
size_t size() const {
return _str->length();
}
typedef storage_policies::store_by_copy storage_policy;
private:
const ::String* _str;
};
template <>
struct IsString< ::String> : true_type {};
template <>
struct IsString< ::StringSumHelper> : true_type {};
inline ArduinoStringAdapter adaptString(const ::String& str) {
return ArduinoStringAdapter(str);
}
} // namespace ARDUINOJSON_NAMESPACE

@ -1,58 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <stddef.h> // size_t
#include <string.h> // strcmp
#include <ArduinoJson/Polyfills/safe_strcmp.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
namespace ARDUINOJSON_NAMESPACE {
class ConstRamStringAdapter {
public:
ConstRamStringAdapter(const char* str = 0) : _str(str) {}
int compare(const char* other) const {
return safe_strcmp(_str, other);
}
bool equals(const char* expected) const {
return compare(expected) == 0;
}
bool isNull() const {
return !_str;
}
size_t size() const {
if (!_str)
return 0;
return strlen(_str);
}
const char* data() const {
return _str;
}
typedef storage_policies::store_by_address storage_policy;
protected:
const char* _str;
};
template <>
struct IsString<const char*> : true_type {};
template <int N>
struct IsString<const char[N]> : true_type {};
inline ConstRamStringAdapter adaptString(const char* str) {
return ConstRamStringAdapter(str);
}
} // namespace ARDUINOJSON_NAMESPACE

@ -1,57 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <ArduinoJson/Polyfills/pgmspace.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
namespace ARDUINOJSON_NAMESPACE {
class FlashStringAdapter {
public:
FlashStringAdapter(const __FlashStringHelper* str) : _str(str) {}
int compare(const char* other) const {
if (!other && !_str)
return 0;
if (!_str)
return -1;
if (!other)
return 1;
return -strcmp_P(other, reinterpret_cast<const char*>(_str));
}
bool equals(const char* expected) const {
return compare(expected) == 0;
}
bool isNull() const {
return !_str;
}
void copyTo(char* p, size_t n) const {
memcpy_P(p, reinterpret_cast<const char*>(_str), n);
}
size_t size() const {
if (!_str)
return 0;
return strlen_P(reinterpret_cast<const char*>(_str));
}
typedef storage_policies::store_by_copy storage_policy;
private:
const __FlashStringHelper* _str;
};
inline FlashStringAdapter adaptString(const __FlashStringHelper* str) {
return FlashStringAdapter(str);
}
template <>
struct IsString<const __FlashStringHelper*> : true_type {};
} // namespace ARDUINOJSON_NAMESPACE

@ -1,37 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <ArduinoJson/Configuration.hpp>
#include <ArduinoJson/Polyfills/type_traits.hpp>
#if ARDUINOJSON_ENABLE_ARDUINO_STRING
# include <Arduino.h>
#endif
#if ARDUINOJSON_ENABLE_STD_STRING
# include <string>
#endif
namespace ARDUINOJSON_NAMESPACE {
template <typename>
struct IsWriteableString : false_type {};
#if ARDUINOJSON_ENABLE_ARDUINO_STRING
template <>
struct IsWriteableString< ::String> : true_type {};
#endif
#if ARDUINOJSON_ENABLE_STD_STRING
template <typename TCharTraits, typename TAllocator>
struct IsWriteableString<std::basic_string<char, TCharTraits, TAllocator> >
: true_type {};
#endif
} // namespace ARDUINOJSON_NAMESPACE

@ -1,43 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <ArduinoJson/Strings/ConstRamStringAdapter.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
namespace ARDUINOJSON_NAMESPACE {
class RamStringAdapter : public ConstRamStringAdapter {
public:
RamStringAdapter(const char* str) : ConstRamStringAdapter(str) {}
void copyTo(char* p, size_t n) const {
memcpy(p, _str, n);
}
typedef ARDUINOJSON_NAMESPACE::storage_policies::store_by_copy storage_policy;
};
template <typename TChar>
inline RamStringAdapter adaptString(const TChar* str) {
return RamStringAdapter(reinterpret_cast<const char*>(str));
}
inline RamStringAdapter adaptString(char* str) {
return RamStringAdapter(str);
}
template <typename TChar>
struct IsString<TChar*> {
static const bool value = sizeof(TChar) == 1;
};
template <>
struct IsString<void*> {
static const bool value = false;
};
} // namespace ARDUINOJSON_NAMESPACE

@ -1,55 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <ArduinoJson/Namespace.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
namespace ARDUINOJSON_NAMESPACE {
class SizedFlashStringAdapter {
public:
SizedFlashStringAdapter(const __FlashStringHelper* str, size_t sz)
: _str(str), _size(sz) {}
int compare(const char* other) const {
if (!other && !_str)
return 0;
if (!_str)
return -1;
if (!other)
return 1;
return -strncmp_P(other, reinterpret_cast<const char*>(_str), _size);
}
bool equals(const char* expected) const {
return compare(expected) == 0;
}
bool isNull() const {
return !_str;
}
void copyTo(char* p, size_t n) const {
memcpy_P(p, reinterpret_cast<const char*>(_str), n);
}
size_t size() const {
return _size;
}
typedef storage_policies::store_by_copy storage_policy;
private:
const __FlashStringHelper* _str;
size_t _size;
};
inline SizedFlashStringAdapter adaptString(const __FlashStringHelper* str,
size_t sz) {
return SizedFlashStringAdapter(str, sz);
}
} // namespace ARDUINOJSON_NAMESPACE

@ -1,51 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <ArduinoJson/Namespace.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
#include <string.h> // strcmp
namespace ARDUINOJSON_NAMESPACE {
class SizedRamStringAdapter {
public:
SizedRamStringAdapter(const char* str, size_t n) : _str(str), _size(n) {}
int compare(const char* other) const {
return safe_strncmp(_str, other, _size);
}
bool equals(const char* expected) const {
return compare(expected) == 0;
}
bool isNull() const {
return !_str;
}
void copyTo(char* p, size_t n) const {
memcpy(p, _str, n);
}
size_t size() const {
return _size;
}
typedef storage_policies::store_by_copy storage_policy;
private:
const char* _str;
size_t _size;
};
template <typename TChar>
inline SizedRamStringAdapter adaptString(const TChar* str, size_t size) {
return SizedRamStringAdapter(reinterpret_cast<const char*>(str), size);
}
} // namespace ARDUINOJSON_NAMESPACE

@ -1,61 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <ArduinoJson/Namespace.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
#include <string>
namespace ARDUINOJSON_NAMESPACE {
template <typename TString>
class StdStringAdapter {
public:
StdStringAdapter(const TString& str) : _str(&str) {}
void copyTo(char* p, size_t n) const {
memcpy(p, _str->c_str(), n);
}
bool isNull() const {
return false;
}
int compare(const char* other) const {
if (!other)
return 1;
return _str->compare(other);
}
bool equals(const char* expected) const {
if (!expected)
return false;
return *_str == expected;
}
size_t size() const {
return _str->size();
}
typedef storage_policies::store_by_copy storage_policy;
private:
const TString* _str;
};
template <typename TCharTraits, typename TAllocator>
struct IsString<std::basic_string<char, TCharTraits, TAllocator> > : true_type {
};
template <typename TCharTraits, typename TAllocator>
inline StdStringAdapter<std::basic_string<char, TCharTraits, TAllocator> >
adaptString(const std::basic_string<char, TCharTraits, TAllocator>& str) {
return StdStringAdapter<std::basic_string<char, TCharTraits, TAllocator> >(
str);
}
} // namespace ARDUINOJSON_NAMESPACE

@ -1,32 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <ArduinoJson/Polyfills/type_traits.hpp>
namespace ARDUINOJSON_NAMESPACE {
template <typename T, bool bounded = false, typename Enable = void>
class StringAdapter;
template <typename T>
inline StringAdapter<T, false> adaptString(const T& str) {
return StringAdapter<T, false>(str);
}
template <typename T>
inline StringAdapter<T, true> adaptString(const T& str, size_t sz) {
return StringAdapter<T, true>(str, sz);
}
template <typename T, typename Enable = void>
struct IsString : false_type {};
template <typename T>
struct IsString<
T, typename make_void<typename StringAdapter<T>::storage_policy>::type>
: true_type {};
} // namespace ARDUINOJSON_NAMESPACE

@ -1,56 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <ArduinoJson/Namespace.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
#include <string_view>
namespace ARDUINOJSON_NAMESPACE {
class StringViewAdapter {
public:
StringViewAdapter(std::string_view str) : _str(str) {}
void copyTo(char* p, size_t n) const {
memcpy(p, _str.data(), n);
}
bool isNull() const {
return false;
}
int compare(const char* other) const {
if (!other)
return 1;
return _str.compare(other);
}
bool equals(const char* expected) const {
if (!expected)
return false;
return _str == expected;
}
size_t size() const {
return _str.size();
}
typedef storage_policies::store_by_copy storage_policy;
private:
std::string_view _str;
};
template <>
struct IsString<std::string_view> : true_type {};
inline StringViewAdapter adaptString(const std::string_view& str) {
return StringViewAdapter(str);
}
} // namespace ARDUINOJSON_NAMESPACE

@ -87,7 +87,8 @@ class Compressor
arm_scale_f32(audio_block, pre_gain, audio_block, len); //use ARM DSP for speed! arm_scale_f32(audio_block, pre_gain, audio_block, len); //use ARM DSP for speed!
//calculate the level of the audio (ie, calculate a smoothed version of the signal power) //calculate the level of the audio (ie, calculate a smoothed version of the signal power)
float32_t* audio_level_dB_block = (float32_t*)malloc(sizeof(float32_t)*len); //float32_t* audio_level_dB_block = (float32_t*)malloc(sizeof(float32_t)*len);
float32_t* audio_level_dB_block = new float32_t[len];
if(!audio_level_dB_block) if(!audio_level_dB_block)
{ {
printf("Cannot allocate memory for \"audio_level_dB_block\" - stopping\n"); printf("Cannot allocate memory for \"audio_level_dB_block\" - stopping\n");
@ -100,7 +101,8 @@ class Compressor
calcAudioLevel_dB(audio_block, audio_level_dB_block, len); //returns through audio_level_dB_block calcAudioLevel_dB(audio_block, audio_level_dB_block, len); //returns through audio_level_dB_block
//compute the desired gain based on the observed audio level //compute the desired gain based on the observed audio level
float32_t* gain_block=(float32_t*)malloc(sizeof(float32_t)*len); //float32_t* gain_block=(float32_t*)malloc(sizeof(float32_t)*len);
float32_t* gain_block=new float32_t[len];
if(!gain_block) if(!gain_block)
{ {
printf("Cannot allocate memory for \"gain_block\" - stopping\n"); printf("Cannot allocate memory for \"gain_block\" - stopping\n");
@ -130,7 +132,8 @@ class Compressor
void calcAudioLevel_dB(float32_t *wav_block, float32_t *level_dB_block, uint16_t len) { void calcAudioLevel_dB(float32_t *wav_block, float32_t *level_dB_block, uint16_t len) {
// calculate the instantaneous signal power (square the signal) // calculate the instantaneous signal power (square the signal)
float32_t* wav_pow_block=(float32_t*)malloc(sizeof(float32_t)*len); //float32_t* wav_pow_block=(float32_t*)malloc(sizeof(float32_t)*len);
float32_t* wav_pow_block=new float32_t[len];
if(!wav_pow_block) if(!wav_pow_block)
{ {
printf("Cannot allocate memory for \"wav_pow_block\" - stopping\n"); printf("Cannot allocate memory for \"wav_pow_block\" - stopping\n");
@ -172,7 +175,8 @@ class Compressor
void calcGain(float32_t *audio_level_dB_block, float32_t *gain_block,uint16_t len) { void calcGain(float32_t *audio_level_dB_block, float32_t *gain_block,uint16_t len) {
//first, calculate the instantaneous target gain based on the compression ratio //first, calculate the instantaneous target gain based on the compression ratio
float32_t* inst_targ_gain_dB_block=(float32_t*)malloc(sizeof(float32_t)*len); //float32_t* inst_targ_gain_dB_block=(float32_t*)malloc(sizeof(float32_t)*len);
float32_t* inst_targ_gain_dB_block=new float32_t[len];
if(!inst_targ_gain_dB_block) if(!inst_targ_gain_dB_block)
{ {
printf("Cannot allocate memory for \"inst_targ_gain_dB_block\" - stopping\n"); printf("Cannot allocate memory for \"inst_targ_gain_dB_block\" - stopping\n");
@ -183,7 +187,8 @@ class Compressor
calcInstantaneousTargetGain(audio_level_dB_block, inst_targ_gain_dB_block,len); calcInstantaneousTargetGain(audio_level_dB_block, inst_targ_gain_dB_block,len);
//second, smooth in time (attack and release) by stepping through each sample //second, smooth in time (attack and release) by stepping through each sample
float32_t *gain_dB_block = (float32_t*)malloc(sizeof(float32_t)*len); //float32_t *gain_dB_block = (float32_t*)malloc(sizeof(float32_t)*len);
float32_t *gain_dB_block = new float32_t[len];
if(!gain_dB_block) if(!gain_dB_block)
{ {
printf("Cannot allocate memory for \"gain_dB_block\" - stopping\n"); printf("Cannot allocate memory for \"gain_dB_block\" - stopping\n");
@ -212,7 +217,8 @@ class Compressor
void calcInstantaneousTargetGain(float32_t *audio_level_dB_block, float32_t *inst_targ_gain_dB_block, uint16_t len) { void calcInstantaneousTargetGain(float32_t *audio_level_dB_block, float32_t *inst_targ_gain_dB_block, uint16_t len) {
// how much are we above the compression threshold? // how much are we above the compression threshold?
float32_t* above_thresh_dB_block=(float32_t*)malloc(sizeof(float32_t)*len); //float32_t* above_thresh_dB_block=(float32_t*)malloc(sizeof(float32_t)*len);
float32_t* above_thresh_dB_block=new float32_t[len];
if(!above_thresh_dB_block) if(!above_thresh_dB_block)
{ {
printf("Cannot allocate memory for \"above_thresh_dB_block\" - stopping\n"); printf("Cannot allocate memory for \"above_thresh_dB_block\" - stopping\n");

Loading…
Cancel
Save