FastLED 3.9.15
Loading...
Searching...
No Matches
fft.cpp
Go to the documentation of this file.
1
2#include "fl/fft.h"
4#include "fl/fft_impl.h"
5#include "fl/hash_map_lru.h"
6#include "fl/int.h"
7#include "fl/memory.h"
8
9namespace fl {
10
11template <> struct Hash<FFT_Args> {
12 fl::u32 operator()(const FFT_Args &key) const noexcept {
13 return MurmurHash3_x86_32(&key, sizeof(FFT_Args));
14 }
15};
16
17struct FFT::HashMap : public HashMapLru<FFT_Args, fl::shared_ptr<FFTImpl>> {
20};
21
22FFT::FFT() { mMap.reset(new HashMap(8)); };
23
24FFT::~FFT() = default;
25
26FFT::FFT(const FFT &other) {
27 // copy the map
28 mMap.reset();
29 mMap.reset(new HashMap(*other.mMap));
30}
31
32FFT &FFT::operator=(const FFT &other) {
33 mMap.reset();
34 mMap.reset(new HashMap(*other.mMap));
35 return *this;
36}
37
38void FFT::run(const span<const fl::i16> &sample, FFTBins *out,
39 const FFT_Args &args) {
40 FFT_Args args2 = args;
41 args2.samples = sample.size();
42 get_or_create(args2).run(sample, out);
43}
44
45void FFT::clear() { mMap->clear(); }
46
47fl::size FFT::size() const { return mMap->size(); }
48
49void FFT::setFFTCacheSize(fl::size size) { mMap->setMaxSize(size); }
50
52 fl::shared_ptr<FFTImpl> *val = mMap->find_value(args);
53 if (val) {
54 // we have it.
55 return **val;
56 }
57 // else we have to make a new one.
59 (*mMap)[args] = fft;
60 return *fft;
61}
62
63bool FFT_Args::operator==(const FFT_Args &other) const {
66
67 return samples == other.samples && bands == other.bands &&
68 fmin == other.fmin && fmax == other.fmax &&
69 sample_rate == other.sample_rate;
70
72}
73
74} // namespace fl
AudioAnalyzeFFT1024 fft
void clear()
Definition fft.cpp:45
FFTImpl & get_or_create(const FFT_Args &args)
Definition fft.cpp:51
scoped_ptr< HashMap > mMap
Definition fft.h:122
fl::size size() const
Definition fft.cpp:47
FFT()
Definition fft.cpp:22
void setFFTCacheSize(fl::size size)
Definition fft.cpp:49
void run(const span< const i16 > &sample, FFTBins *out, const FFT_Args &args=FFT_Args())
FFT & operator=(FFT &&)=default
Result run(const AudioSample &sample, FFTBins *out)
Definition fft_impl.cpp:153
fl::size size() const
Definition slice.h:142
#define FL_DISABLE_WARNING(warning)
#define FL_DISABLE_WARNING_PUSH
#define FL_DISABLE_WARNING_POP
Slice< T > span
Definition span.h:8
shared_ptr< T > make_shared(Args &&... args)
Definition shared_ptr.h:348
static u32 MurmurHash3_x86_32(const void *key, fl::size len, u32 seed=0)
Definition hash.h:23
bool equal(Iterator1 first1, Iterator1 last1, Iterator2 first2)
Definition algorithm.h:95
IMPORTANT!
Definition crgb.h:20
corkscrew_args args
Definition old.h:150
HashMap(fl::size max_size)
Definition fft.cpp:18
bool operator==(const FFT_Args &other) const
Definition fft.cpp:63
FFT_Args(int samples=DefaultSamples(), int bands=DefaultBands(), float fmin=DefaultMinFrequency(), float fmax=DefaultMaxFrequency(), int sample_rate=DefaultSampleRate())
Definition fft.h:74
float fmax
Definition fft.h:71
int samples
Definition fft.h:68
float fmin
Definition fft.h:70
int sample_rate
Definition fft.h:72
int bands
Definition fft.h:69
fl::u32 operator()(const FFT_Args &key) const noexcept
Definition fft.cpp:12