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

Dependencies:   Array_Matrix mbed SerialTxRxIntr DSP_ADDA UIT_FFT_Real Window

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DoubleBuffer.hpp Source File

DoubleBuffer.hpp

00001 //--------------------------------------------------------
00002 //  ダブル・バッファの template クラス
00003 //      バッファに2次元配列(Matrix クラス)を使用
00004 //
00005 //  2021/10/22, Copyright (c) 2021 MIKAMI, Naoki
00006 //--------------------------------------------------------
00007 
00008 #ifndef DOUBLE_BUFFER_HPP
00009 #define DOUBLE_BUFFER_HPP
00010 
00011 #include "Matrix.hpp"
00012 using namespace Mikami;
00013 
00014 class DoubleBuffer
00015 {
00016 public:
00017     // コンストラクタ
00018     explicit DoubleBuffer(int size, float initialValue = 0)
00019         : N_(size), buf_(2, size, initialValue), ping_(0), pong_(1),
00020           index_(0), full_(false) {}
00021     
00022     // データを格納
00023     void Store(float data)  { buf_[ping_][index_++] = data; }
00024     
00025     // 出力バッファからデータの取り出し
00026     float Get(int n) const { return buf_[pong_][n]; }
00027 
00028     // バッファが満杯でバッファを切り替える
00029     void IsFullSwitch()
00030     {
00031         if (index_ < N_) return;
00032 
00033         ping_ ^= 0x1;   // バッファ切換えのため
00034         pong_ ^= 0x1;   // バッファ切換えのため
00035         index_ = 0;
00036         full_ = true;
00037     }
00038 
00039     // バッファが満杯で,true を返す
00040     bool IsFull()
00041     {
00042         bool temp = full_;
00043         if (full_) full_ = false;
00044         return temp;
00045     }
00046 
00047 private:
00048     const int N_;       // バッファのサイズ
00049     Matrix<float> buf_; // バッファ
00050     int ping_, pong_;   // バッファ切替用
00051     int index_;         // 入力データのカウンタ
00052     bool full_;         // 満杯の場合 true
00053 
00054     // コピー・コンストラクタおよび代入演算子の禁止のため
00055     DoubleBuffer(const DoubleBuffer&);
00056     DoubleBuffer& operator=(const DoubleBuffer&);
00057 };
00058 #endif  // DOUBLE_BUFFER_HPP