![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Output the audio signal with filtering by IIR filter in the *.wav file on the SD card using onboard CODEC. SD カードの *.wav ファイルのオーディオ信号を遮断周波数可変の IIR フィルタを通して,ボードに搭載されているCODEC で出力する.
Dependencies: BSP_DISCO_F746NG F746_GUI LCD_DISCO_F746NG SDFileSystem_Warning_Fixed TS_DISCO_F746NG mbed FrequencyResponseDrawer F746_SAI_IO Array_Matrix
MyClasses_Functions/SD_WavReader.hpp@0:04b43b777fae, 2016-04-19 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Tue Apr 19 09:46:11 2016 +0000
- Revision:
- 0:04b43b777fae
- Child:
- 11:769d986c10fa
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:04b43b777fae | 1 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:04b43b777fae | 2 | // SD_WavReader class ---- Header |
MikamiUitOpen | 0:04b43b777fae | 3 | // SD カードの *.wav ファイルの内容を読み出す |
MikamiUitOpen | 0:04b43b777fae | 4 | // 以下のフォーマット以外は扱わない |
MikamiUitOpen | 0:04b43b777fae | 5 | // PCM,16 ビットステレオ,標本化周波数 44.1 kHz |
MikamiUitOpen | 0:04b43b777fae | 6 | // |
MikamiUitOpen | 0:04b43b777fae | 7 | // 2016/04/19, Copyright (c) 2016 MIKAMI, Naoki |
MikamiUitOpen | 0:04b43b777fae | 8 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:04b43b777fae | 9 | |
MikamiUitOpen | 0:04b43b777fae | 10 | #ifndef SD_WAV_READER_HPP |
MikamiUitOpen | 0:04b43b777fae | 11 | #define SD_WAV_READER_HPP |
MikamiUitOpen | 0:04b43b777fae | 12 | |
MikamiUitOpen | 0:04b43b777fae | 13 | #include "SDFileSystem.h" |
MikamiUitOpen | 0:04b43b777fae | 14 | #include "BlinkLabel.hpp" |
MikamiUitOpen | 0:04b43b777fae | 15 | #include <string> |
MikamiUitOpen | 0:04b43b777fae | 16 | |
MikamiUitOpen | 0:04b43b777fae | 17 | namespace Mikami |
MikamiUitOpen | 0:04b43b777fae | 18 | { |
MikamiUitOpen | 0:04b43b777fae | 19 | class SD_WavReader |
MikamiUitOpen | 0:04b43b777fae | 20 | { |
MikamiUitOpen | 0:04b43b777fae | 21 | public: |
MikamiUitOpen | 0:04b43b777fae | 22 | SD_WavReader(int32_t bufferSize); |
MikamiUitOpen | 0:04b43b777fae | 23 | ~SD_WavReader(); |
MikamiUitOpen | 0:04b43b777fae | 24 | |
MikamiUitOpen | 0:04b43b777fae | 25 | void Open(const string fileName); |
MikamiUitOpen | 0:04b43b777fae | 26 | |
MikamiUitOpen | 0:04b43b777fae | 27 | void Close() { fclose(fp_); } |
MikamiUitOpen | 0:04b43b777fae | 28 | |
MikamiUitOpen | 0:04b43b777fae | 29 | // ファイルのヘッダ (RIFFxxxxWAVEfm ) 読み込み |
MikamiUitOpen | 0:04b43b777fae | 30 | // 戻り値: *.wav で,16 ビットステレオ, |
MikamiUitOpen | 0:04b43b777fae | 31 | // 標本化周波数:44.1 kHz の場合 true |
MikamiUitOpen | 0:04b43b777fae | 32 | bool IsWavFile(); |
MikamiUitOpen | 0:04b43b777fae | 33 | |
MikamiUitOpen | 0:04b43b777fae | 34 | // ファイルからデータの取得 |
MikamiUitOpen | 0:04b43b777fae | 35 | void Read(int16_t data[], uint32_t size); |
MikamiUitOpen | 0:04b43b777fae | 36 | |
MikamiUitOpen | 0:04b43b777fae | 37 | // ファイルからデータをモノラルに変換しての取得 |
MikamiUitOpen | 0:04b43b777fae | 38 | void ReadAndToMono(int16_t data[], uint32_t size); |
MikamiUitOpen | 0:04b43b777fae | 39 | |
MikamiUitOpen | 0:04b43b777fae | 40 | // データサイズ(標本化点の数)の取得 |
MikamiUitOpen | 0:04b43b777fae | 41 | int32_t GetSize(); |
MikamiUitOpen | 0:04b43b777fae | 42 | |
MikamiUitOpen | 0:04b43b777fae | 43 | private: |
MikamiUitOpen | 0:04b43b777fae | 44 | const string STR_; |
MikamiUitOpen | 0:04b43b777fae | 45 | |
MikamiUitOpen | 0:04b43b777fae | 46 | struct WaveFormatEx |
MikamiUitOpen | 0:04b43b777fae | 47 | { |
MikamiUitOpen | 0:04b43b777fae | 48 | uint16_t wFormatTag; // 1: PCM |
MikamiUitOpen | 0:04b43b777fae | 49 | uint16_t nChannels; // 1:モノラル,2: ステレオ |
MikamiUitOpen | 0:04b43b777fae | 50 | uint32_t nSamplesPerSec; // 標本化周波数 (Hz) |
MikamiUitOpen | 0:04b43b777fae | 51 | uint32_t nAvgBytesPerSec; // 転送速度 (bytes/s) |
MikamiUitOpen | 0:04b43b777fae | 52 | uint16_t nBlockAlign; // 4: 16ビットステレオの場合 |
MikamiUitOpen | 0:04b43b777fae | 53 | uint16_t wBitsPerSample; // データのビット数,8 または 16 |
MikamiUitOpen | 0:04b43b777fae | 54 | uint16_t cbSize; |
MikamiUitOpen | 0:04b43b777fae | 55 | }; |
MikamiUitOpen | 0:04b43b777fae | 56 | |
MikamiUitOpen | 0:04b43b777fae | 57 | SDFileSystem *sd_; |
MikamiUitOpen | 0:04b43b777fae | 58 | FILE *fp_; |
MikamiUitOpen | 0:04b43b777fae | 59 | |
MikamiUitOpen | 0:04b43b777fae | 60 | bool ok_; |
MikamiUitOpen | 0:04b43b777fae | 61 | int32_t size_; // モノラルデータのサイズ |
MikamiUitOpen | 0:04b43b777fae | 62 | int16_t *buffer; // ステレオをモノラルに変換する際の作業領域 |
MikamiUitOpen | 0:04b43b777fae | 63 | |
MikamiUitOpen | 0:04b43b777fae | 64 | void ErrorMsg(char msg[]) |
MikamiUitOpen | 0:04b43b777fae | 65 | { BlinkLabel errLabel(240, 100, msg, Label::CENTER); } |
MikamiUitOpen | 0:04b43b777fae | 66 | |
MikamiUitOpen | 0:04b43b777fae | 67 | // disallow copy constructor and assignment operator |
MikamiUitOpen | 0:04b43b777fae | 68 | SD_WavReader(const SD_WavReader&); |
MikamiUitOpen | 0:04b43b777fae | 69 | SD_WavReader& operator=(const SD_WavReader&); |
MikamiUitOpen | 0:04b43b777fae | 70 | }; |
MikamiUitOpen | 0:04b43b777fae | 71 | } |
MikamiUitOpen | 0:04b43b777fae | 72 | #endif // SD_BINARY_READER_HPP |