Update mcl-audio-buffer in d/missing-sources
authorDennis Braun <d_braun@kabelmail.de>
Wed, 4 May 2022 15:32:09 +0000 (17:32 +0200)
committerDennis Braun <d_braun@kabelmail.de>
Wed, 4 May 2022 15:32:09 +0000 (17:32 +0200)
debian/missing-sources/mcl-audio-buffer/audioBuffer.cpp
debian/missing-sources/mcl-audio-buffer/audioBuffer.hpp

index 84a7df8d25d8d977f9d53fca3b12b4248769d765..1edc2abfdc304024bb936cbf40c73f269440ea0a 100644 (file)
@@ -268,6 +268,32 @@ void AudioBuffer::copy(const AudioBuffer& o)
 
 /* -------------------------------------------------------------------------- */
 
+void AudioBuffer::forEachFrame(std::function<void(float*, int)> f)
+{
+       for (int i = 0; i < countFrames(); i++)
+               f((*this)[i], i);
+}
+
+/* -------------------------------------------------------------------------- */
+
+void AudioBuffer::forEachChannel(int frame, std::function<void(float&, int)> f)
+{
+       assert(frame < m_size);
+
+       for (int i = 0; i < countChannels(); i++)
+               f((*this)[frame][i], i);
+}
+
+/* -------------------------------------------------------------------------- */
+
+void AudioBuffer::forEachSample(std::function<void(float&, int)> f)
+{
+       for (int i = 0; i < countSamples(); i++)
+               f(m_data[i], i);
+}
+
+/* -------------------------------------------------------------------------- */
+
 template void AudioBuffer::copyData<AudioBuffer::Operation::SUM>(const AudioBuffer&, int, int, int, float, Pan);
 template void AudioBuffer::copyData<AudioBuffer::Operation::SET>(const AudioBuffer&, int, int, int, float, Pan);
-} // namespace mcl
\ No newline at end of file
+} // namespace mcl
index 9b3107fcfd035cd29c158430645ad4aa7830141c..d77cde06c5fdbf8b0d07e596fee8307e8ac141e0 100644 (file)
@@ -28,6 +28,7 @@
 #define MONOCASUAL_AUDIO_BUFFER_H
 
 #include <array>
+#include <functional>
 
 namespace mcl
 {
@@ -136,6 +137,21 @@ public:
 
        void applyGain(float g);
 
+       /* forEachFrame
+       Applies a function to each frame in the audio buffer. */
+
+       void forEachFrame(std::function<void(float* /*channels*/, int /*numFrame*/)>);
+
+       /* forEachChannel
+       Applies a function to each channel in the given frame. */
+
+       void forEachChannel(int frame, std::function<void(float& /*value*/, int /*numChannel*/)>);
+
+       /* forEachSample
+       Applies a function to each sample in the audio buffer. */
+
+       void forEachSample(std::function<void(float& /*value*/, int /*numSample*/)>);
+
 private:
        enum class Operation
        {
@@ -160,4 +176,4 @@ private:
 };
 } // namespace mcl
 
-#endif
\ No newline at end of file
+#endif