FFT アナライザ このプログラムの説明は,CQ出版社「トランジスタ技術」の2021年10月号から開始された連載記事「STM32マイコンではじめるPC計測」の中にあります.このプログラムといっしょに使うPC側のプログラムについても同誌を参照してください.

Dependencies:   Array_Matrix mbed SerialTxRxIntr DSP_ADDA UIT_FFT_Real Window

Revision:
0:e5fc70976c00
Child:
1:d9dbfbe95c8d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DoubleBuffer.hpp	Thu Sep 09 08:52:33 2021 +0000
@@ -0,0 +1,58 @@
+//--------------------------------------------------------
+//  ダブル・バッファの template クラス
+//      バッファに2次元配列(Matrix クラス)を使用
+//
+//  2021/05/22, Copyright (c) 2021 MIKAMI, Naoki
+//--------------------------------------------------------
+
+#ifndef DOUBLE_BUFFER_HPP
+#define DOUBLE_BUFFER_HPP
+
+#include "Matrix.hpp"
+using namespace Mikami;
+
+template<class T> class DoubleBuffer
+{
+public:
+    // コンストラクタ
+    explicit DoubleBuffer(int size, T initialValue = 0)
+        : N_(size), buf_(2, size, initialValue), ping_(0), pong_(1),
+          index_(0), full_(false) {}
+    
+    // データを格納
+    void Store(T data)  { buf_[ping_][index_++] = data; }
+    
+    // 出力バッファからデータの取り出し
+    T Get(int n) const { return buf_[pong_][n]; }
+
+    // バッファが満杯でバッファを切り替える
+    void IsFullSwitch()
+    {
+        if (index_ < N_) return;
+
+        ping_ ^= 0x1;   // バッファ切換えのため
+        pong_ ^= 0x1;   // バッファ切換えのため
+        index_ = 0;
+        full_ = true;
+    }
+
+    // バッファが満杯で,true を返す
+    bool IsFull()
+    {
+        bool temp = full_;
+        if (full_) full_ = false;
+        return temp;
+    }
+
+private:
+    const int N_;       // バッファのサイズ
+    Matrix<T> buf_;     // バッファ
+    int ping_, pong_;   // バッファ切替用
+    int index_;         // 入力データのカウンタ
+    bool full_;         // 満杯の場合 true
+
+    // コピー・コンストラクタおよび代入演算子の禁止のため
+    DoubleBuffer(const DoubleBuffer&);
+    DoubleBuffer& operator=(const DoubleBuffer&);
+};
+#endif  // DOUBLE_BUFFER_HPP
\ No newline at end of file