Sample is a wrapper around SampleImpl, hiding the reference counting so that the api object can be simple and have standard object semantics.
| 20 | // counting so that the api object can be simple and have standard object |
| 21 | // semantics. |
| 22 | class Sample { |
| 23 | public: |
| 24 | using VectorPCM = fl::vector<fl::i16>; |
| 25 | using const_iterator = VectorPCM::const_iterator; |
| 26 | Sample() FL_NOEXCEPT {} |
| 27 | Sample(const Sample &other) FL_NOEXCEPT : mImpl(other.mImpl) {} |
| 28 | Sample(SampleImplPtr impl) FL_NOEXCEPT : mImpl(impl) {} |
| 29 | ~Sample() FL_NOEXCEPT; |
| 30 | |
| 31 | // Constructor that takes raw audio data and handles pooling internally |
| 32 | Sample(fl::span<const fl::i16> span, fl::u32 timestamp = 0) FL_NOEXCEPT; |
| 33 | |
| 34 | Sample &operator=(const Sample &other) FL_NOEXCEPT; |
| 35 | bool isValid() const FL_NOEXCEPT { return mImpl != nullptr; } |
| 36 | |
| 37 | fl::size size() const FL_NOEXCEPT; |
| 38 | // Raw pcm levels. |
| 39 | const VectorPCM &pcm() const FL_NOEXCEPT; |
| 40 | // Zero crossing factor between 0.0f -> 1.0f, detects "hiss" |
| 41 | // and sounds like cloths rubbing. Useful for sound analysis. |
| 42 | float zcf() const FL_NOEXCEPT; |
| 43 | float rms() const FL_NOEXCEPT; |
| 44 | fl::u32 timestamp() const FL_NOEXCEPT; // Timestamp when sample became valid (millis) |
| 45 | |
| 46 | void fft(fft::Bins *out) const FL_NOEXCEPT; |
| 47 | |
| 48 | const_iterator begin() const FL_NOEXCEPT { return pcm().begin(); } |
| 49 | const_iterator end() const FL_NOEXCEPT { return pcm().end(); } |
| 50 | const fl::i16 &at(fl::size i) const FL_NOEXCEPT; |
| 51 | const fl::i16 &operator[](fl::size i) const FL_NOEXCEPT; |
| 52 | operator bool() const FL_NOEXCEPT { return isValid(); } |
| 53 | bool operator==(const Sample &other) const FL_NOEXCEPT; |
| 54 | bool operator!=(const Sample &other) const FL_NOEXCEPT; |
| 55 | |
| 56 | /// Apply a digital gain multiplier to all PCM samples in-place. |
| 57 | /// Clamps to i16 range to prevent overflow. |
| 58 | void applyGain(float gain) FL_NOEXCEPT; |
| 59 | |
| 60 | private: |
| 61 | static const VectorPCM &empty() FL_NOEXCEPT; |
| 62 | SampleImplPtr mImpl; |
| 63 | }; |
| 64 | |
| 65 | // Sound level meter is a persistant measuring class that will auto-tune the |
| 66 | // microphone to real world SPL levels. It will adapt to the noise floor of the |
no outgoing calls
no test coverage detected