![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Realtime sound spectrogram using FFT or linear prediction. Spectrogram is displayed on the display of PC. リアルタイム・スペクトログラム.解析の手法:FFT,線形予測法.スペクトログラムは PC のディスプレー装置に表示される.PC 側のプログラム:F446_Spectrogram.
Dependencies: Array_Matrix mbed SerialTxRxIntr F446_AD_DA UIT_FFT_Real
Xfer.hpp@7:5ba884060d3b, 2019-11-24 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Sun Nov 24 11:14:01 2019 +0000
- Revision:
- 7:5ba884060d3b
8
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 7:5ba884060d3b | 1 | //--------------------------------------------------------------------- |
MikamiUitOpen | 7:5ba884060d3b | 2 | // スペクトル解析の結果を PC へ転送するためのクラス |
MikamiUitOpen | 7:5ba884060d3b | 3 | // |
MikamiUitOpen | 7:5ba884060d3b | 4 | // 2019/11/24, Copyright (c) 2019 MIKAMI, Naoki |
MikamiUitOpen | 7:5ba884060d3b | 5 | //--------------------------------------------------------------------- |
MikamiUitOpen | 7:5ba884060d3b | 6 | |
MikamiUitOpen | 7:5ba884060d3b | 7 | #include <string> |
MikamiUitOpen | 7:5ba884060d3b | 8 | #include "Array.hpp" |
MikamiUitOpen | 7:5ba884060d3b | 9 | #include "SerialRxTxIntr.hpp" |
MikamiUitOpen | 7:5ba884060d3b | 10 | using namespace Mikami; |
MikamiUitOpen | 7:5ba884060d3b | 11 | |
MikamiUitOpen | 7:5ba884060d3b | 12 | #ifndef XFER_CONVERT_TOPC_HPP |
MikamiUitOpen | 7:5ba884060d3b | 13 | #define XFER_CONVERT_TOPC_HPP |
MikamiUitOpen | 7:5ba884060d3b | 14 | |
MikamiUitOpen | 7:5ba884060d3b | 15 | class Xfer |
MikamiUitOpen | 7:5ba884060d3b | 16 | { |
MikamiUitOpen | 7:5ba884060d3b | 17 | public: |
MikamiUitOpen | 7:5ba884060d3b | 18 | // コンストラクタ |
MikamiUitOpen | 7:5ba884060d3b | 19 | Xfer(SerialRxTxIntr& rxTx, int size) |
MikamiUitOpen | 7:5ba884060d3b | 20 | : SIZE_(size), xn_(size), rxTx_(rxTx) {} |
MikamiUitOpen | 7:5ba884060d3b | 21 | |
MikamiUitOpen | 7:5ba884060d3b | 22 | // スペクトル解析の結果を転送する形式に変換 |
MikamiUitOpen | 7:5ba884060d3b | 23 | void Convert(const float db[], float levelShift) |
MikamiUitOpen | 7:5ba884060d3b | 24 | { |
MikamiUitOpen | 7:5ba884060d3b | 25 | static const float FACTOR = 10000.0f/80.0f; // 表示範囲: 0 ~ 80 dB |
MikamiUitOpen | 7:5ba884060d3b | 26 | for (int n=0; n<SIZE_; n++) |
MikamiUitOpen | 7:5ba884060d3b | 27 | { |
MikamiUitOpen | 7:5ba884060d3b | 28 | float xDb = FACTOR*(db[n] + 30.0f + levelShift); |
MikamiUitOpen | 7:5ba884060d3b | 29 | if (xDb > 10000) xDb = 10000; |
MikamiUitOpen | 7:5ba884060d3b | 30 | if (xDb < 0) xDb = 0; |
MikamiUitOpen | 7:5ba884060d3b | 31 | xn_[n] = (uint16_t)xDb; |
MikamiUitOpen | 7:5ba884060d3b | 32 | } |
MikamiUitOpen | 7:5ba884060d3b | 33 | } |
MikamiUitOpen | 7:5ba884060d3b | 34 | |
MikamiUitOpen | 7:5ba884060d3b | 35 | // データを PC へ転送(0 ~ 10,000 の範囲の値を 2 文字で表すコード化を利用) |
MikamiUitOpen | 7:5ba884060d3b | 36 | void ToPC() |
MikamiUitOpen | 7:5ba884060d3b | 37 | { |
MikamiUitOpen | 7:5ba884060d3b | 38 | string str = ""; |
MikamiUitOpen | 7:5ba884060d3b | 39 | for (int n=0; n<SIZE_; n++) |
MikamiUitOpen | 7:5ba884060d3b | 40 | { |
MikamiUitOpen | 7:5ba884060d3b | 41 | div_t a = div(xn_[n], 100); |
MikamiUitOpen | 7:5ba884060d3b | 42 | str += a.quot + 0x10; |
MikamiUitOpen | 7:5ba884060d3b | 43 | str += a.rem + 0x10; |
MikamiUitOpen | 7:5ba884060d3b | 44 | } |
MikamiUitOpen | 7:5ba884060d3b | 45 | rxTx_.Tx(str+"\n"); |
MikamiUitOpen | 7:5ba884060d3b | 46 | rxTx_.Tx("EOT\n"); |
MikamiUitOpen | 7:5ba884060d3b | 47 | } |
MikamiUitOpen | 7:5ba884060d3b | 48 | |
MikamiUitOpen | 7:5ba884060d3b | 49 | private: |
MikamiUitOpen | 7:5ba884060d3b | 50 | const int SIZE_; // PC に送るデータ数 |
MikamiUitOpen | 7:5ba884060d3b | 51 | Array<uint16_t> xn_; // PC に送るデータ |
MikamiUitOpen | 7:5ba884060d3b | 52 | SerialRxTxIntr& rxTx_; |
MikamiUitOpen | 7:5ba884060d3b | 53 | |
MikamiUitOpen | 7:5ba884060d3b | 54 | // コピー・コンストラクタおよび代入演算子の禁止のため |
MikamiUitOpen | 7:5ba884060d3b | 55 | Xfer(const Xfer&); |
MikamiUitOpen | 7:5ba884060d3b | 56 | Xfer& operator=(const Xfer&); |
MikamiUitOpen | 7:5ba884060d3b | 57 | }; |
MikamiUitOpen | 7:5ba884060d3b | 58 | #endif // XFER_CONVERT_TOPC_HPP |