![](/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@11:769d986c10fa, 2016-07-04 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Mon Jul 04 05:59:44 2016 +0000
- Revision:
- 11:769d986c10fa
- Parent:
- 0:04b43b777fae
12
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 | 11:769d986c10fa | 7 | // 2016/06/17, 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 | 11:769d986c10fa | 15 | #define DEBUG_ARRAY_CHECK |
MikamiUitOpen | 11:769d986c10fa | 16 | #include "Array.hpp" |
MikamiUitOpen | 0:04b43b777fae | 17 | #include <string> |
MikamiUitOpen | 0:04b43b777fae | 18 | |
MikamiUitOpen | 0:04b43b777fae | 19 | namespace Mikami |
MikamiUitOpen | 0:04b43b777fae | 20 | { |
MikamiUitOpen | 0:04b43b777fae | 21 | class SD_WavReader |
MikamiUitOpen | 0:04b43b777fae | 22 | { |
MikamiUitOpen | 0:04b43b777fae | 23 | public: |
MikamiUitOpen | 0:04b43b777fae | 24 | SD_WavReader(int32_t bufferSize); |
MikamiUitOpen | 0:04b43b777fae | 25 | ~SD_WavReader(); |
MikamiUitOpen | 0:04b43b777fae | 26 | |
MikamiUitOpen | 0:04b43b777fae | 27 | void Open(const string fileName); |
MikamiUitOpen | 0:04b43b777fae | 28 | |
MikamiUitOpen | 0:04b43b777fae | 29 | void Close() { fclose(fp_); } |
MikamiUitOpen | 0:04b43b777fae | 30 | |
MikamiUitOpen | 11:769d986c10fa | 31 | // ファイルのヘッダ読み込み |
MikamiUitOpen | 0:04b43b777fae | 32 | // 戻り値: *.wav で,16 ビットステレオ, |
MikamiUitOpen | 0:04b43b777fae | 33 | // 標本化周波数:44.1 kHz の場合 true |
MikamiUitOpen | 0:04b43b777fae | 34 | bool IsWavFile(); |
MikamiUitOpen | 0:04b43b777fae | 35 | |
MikamiUitOpen | 11:769d986c10fa | 36 | // ファイルからステレオデータの取得 |
MikamiUitOpen | 11:769d986c10fa | 37 | void ReadStereo(Array<int16_t>& dataL, Array<int16_t>& dataR); |
MikamiUitOpen | 0:04b43b777fae | 38 | |
MikamiUitOpen | 0:04b43b777fae | 39 | // ファイルからデータをモノラルに変換しての取得 |
MikamiUitOpen | 11:769d986c10fa | 40 | void ReadAndToMono(Array<int16_t>& data); |
MikamiUitOpen | 0:04b43b777fae | 41 | |
MikamiUitOpen | 0:04b43b777fae | 42 | // データサイズ(標本化点の数)の取得 |
MikamiUitOpen | 0:04b43b777fae | 43 | int32_t GetSize(); |
MikamiUitOpen | 0:04b43b777fae | 44 | |
MikamiUitOpen | 0:04b43b777fae | 45 | private: |
MikamiUitOpen | 0:04b43b777fae | 46 | const string STR_; |
MikamiUitOpen | 0:04b43b777fae | 47 | |
MikamiUitOpen | 0:04b43b777fae | 48 | struct WaveFormatEx |
MikamiUitOpen | 0:04b43b777fae | 49 | { |
MikamiUitOpen | 0:04b43b777fae | 50 | uint16_t wFormatTag; // 1: PCM |
MikamiUitOpen | 0:04b43b777fae | 51 | uint16_t nChannels; // 1:モノラル,2: ステレオ |
MikamiUitOpen | 0:04b43b777fae | 52 | uint32_t nSamplesPerSec; // 標本化周波数 (Hz) |
MikamiUitOpen | 0:04b43b777fae | 53 | uint32_t nAvgBytesPerSec; // 転送速度 (bytes/s) |
MikamiUitOpen | 0:04b43b777fae | 54 | uint16_t nBlockAlign; // 4: 16ビットステレオの場合 |
MikamiUitOpen | 0:04b43b777fae | 55 | uint16_t wBitsPerSample; // データのビット数,8 または 16 |
MikamiUitOpen | 11:769d986c10fa | 56 | uint16_t cbSize; // PCM の場合使わない |
MikamiUitOpen | 0:04b43b777fae | 57 | }; |
MikamiUitOpen | 0:04b43b777fae | 58 | |
MikamiUitOpen | 0:04b43b777fae | 59 | SDFileSystem *sd_; |
MikamiUitOpen | 0:04b43b777fae | 60 | FILE *fp_; |
MikamiUitOpen | 0:04b43b777fae | 61 | |
MikamiUitOpen | 0:04b43b777fae | 62 | bool ok_; |
MikamiUitOpen | 11:769d986c10fa | 63 | int32_t size_; // データサイズ(標本化点の数) |
MikamiUitOpen | 11:769d986c10fa | 64 | Array<int16_t> buffer; // ステレオをモノラルに変換する際の作業領域 |
MikamiUitOpen | 0:04b43b777fae | 65 | |
MikamiUitOpen | 0:04b43b777fae | 66 | void ErrorMsg(char msg[]) |
MikamiUitOpen | 0:04b43b777fae | 67 | { BlinkLabel errLabel(240, 100, msg, Label::CENTER); } |
MikamiUitOpen | 0:04b43b777fae | 68 | |
MikamiUitOpen | 0:04b43b777fae | 69 | // disallow copy constructor and assignment operator |
MikamiUitOpen | 0:04b43b777fae | 70 | SD_WavReader(const SD_WavReader&); |
MikamiUitOpen | 0:04b43b777fae | 71 | SD_WavReader& operator=(const SD_WavReader&); |
MikamiUitOpen | 0:04b43b777fae | 72 | }; |
MikamiUitOpen | 0:04b43b777fae | 73 | } |
MikamiUitOpen | 0:04b43b777fae | 74 | #endif // SD_BINARY_READER_HPP |