22 fl::unique_lock<fl::mutex> lock(
mtx);
34 void put(SampleImplPtr&& impl) {
37 fl::unique_lock<fl::mutex> lock(
mutex);
50 fl::unique_lock<fl::mutex> lock(
mutex);
52 SampleImplPtr impl =
pool.back();
88 return mImpl->pcm().size();
106 if (
mImpl ==
nullptr || other.
mImpl ==
nullptr) {
109 if (
mImpl->pcm().size() != other.
mImpl->pcm().size()) {
112 for (fl::size i = 0; i <
mImpl->pcm().
size(); ++i) {
113 if (
mImpl->pcm()[i] != other.
mImpl->pcm()[i]) {
121 return !(*
this == other);
125 static fl::i16 empty_data[1] = {0};
134 return mImpl->timestamp();
155 for (fl::size i = 0; i < count; ++i) {
156 double s = samples[i] / 32768.0;
159 double p = sum_sq / count;
160 double dbfs = 10.0 *
log10(p + 1e-12);
192 if (!
isValid() || gain == 1.0f)
return;
193 auto& samples =
mImpl->pcm_mutable();
194 for (fl::size i = 0; i < samples.size(); ++i) {
195 fl::i32 val =
static_cast<fl::i32
>(
static_cast<float>(samples[i]) * gain);
196 if (val > 32767) val = 32767;
197 if (val < -32768) val = -32768;
198 samples[i] =
static_cast<fl::i16
>(val);
static T & instance() FL_NOEXCEPT
Sample & operator=(const Sample &other) FL_NOEXCEPT
static const VectorPCM & empty() FL_NOEXCEPT
bool isValid() const FL_NOEXCEPT
void applyGain(float gain) FL_NOEXCEPT
Apply a digital gain multiplier to all PCM samples in-place.
float rms() const FL_NOEXCEPT
fl::u32 timestamp() const FL_NOEXCEPT
float zcf() const FL_NOEXCEPT
const fl::i16 & operator[](fl::size i) const FL_NOEXCEPT
fl::vector< fl::i16 > VectorPCM
void fft(fft::Bins *out) const FL_NOEXCEPT
const_iterator end() const FL_NOEXCEPT
fl::size size() const FL_NOEXCEPT
bool operator==(const Sample &other) const FL_NOEXCEPT
bool operator!=(const Sample &other) const FL_NOEXCEPT
const_iterator begin() const FL_NOEXCEPT
const fl::i16 & at(fl::size i) const FL_NOEXCEPT
const VectorPCM & pcm() const FL_NOEXCEPT
void processBlock(const fl::i16 *samples, fl::size count) FL_NOEXCEPT
Process a block of int16 PCM samples.
SoundLevelMeter(double spl_floor=33.0, double smoothing_alpha=0.0) FL_NOEXCEPT
fl::size bands() const FL_NOEXCEPT
const T * data() const FL_NOEXCEPT
constexpr fl::size size() const FL_NOEXCEPT
#define FL_INFINITY_DOUBLE
Platform-independent mutex interface.
constexpr remove_reference< T >::type && move(T &&t) FL_NOEXCEPT
CRGB sample(const CRGB *grid, const XYMap &xyMap, float x, float y, SampleMode mode)
Sample a pixel from a 2D CRGB grid at floating-point coordinates.
shared_ptr< T > make_shared(Args &&... args) FL_NOEXCEPT
double log10(double value) FL_NOEXCEPT
fl::platforms::mutex mutex
Base definition for an LED controller.
static constexpr fl::size MAX_POOL_SIZE
void put(SampleImplPtr &&impl)
SampleImplPtr getOrCreate()
fl::vector< SampleImplPtr > pool
void run(fl::span< const fl::i16 > sample, fft::Bins *out, const fft::Args &args)
static float DefaultMaxFrequency() FL_NOEXCEPT
static int DefaultSampleRate() FL_NOEXCEPT
static float DefaultMinFrequency() FL_NOEXCEPT