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
Diff: MyClasses_Functions/SD_WavReader.hpp
- Revision:
- 0:04b43b777fae
- Child:
- 11:769d986c10fa
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MyClasses_Functions/SD_WavReader.hpp Tue Apr 19 09:46:11 2016 +0000 @@ -0,0 +1,72 @@ +//-------------------------------------------------------------- +// SD_WavReader class ---- Header +// SD カードの *.wav ファイルの内容を読み出す +// 以下のフォーマット以外は扱わない +// PCM,16 ビットステレオ,標本化周波数 44.1 kHz +// +// 2016/04/19, Copyright (c) 2016 MIKAMI, Naoki +//-------------------------------------------------------------- + +#ifndef SD_WAV_READER_HPP +#define SD_WAV_READER_HPP + +#include "SDFileSystem.h" +#include "BlinkLabel.hpp" +#include <string> + +namespace Mikami +{ + class SD_WavReader + { + public: + SD_WavReader(int32_t bufferSize); + ~SD_WavReader(); + + void Open(const string fileName); + + void Close() { fclose(fp_); } + + // ファイルのヘッダ (RIFFxxxxWAVEfm ) 読み込み + // 戻り値: *.wav で,16 ビットステレオ, + // 標本化周波数:44.1 kHz の場合 true + bool IsWavFile(); + + // ファイルからデータの取得 + void Read(int16_t data[], uint32_t size); + + // ファイルからデータをモノラルに変換しての取得 + void ReadAndToMono(int16_t data[], uint32_t size); + + // データサイズ(標本化点の数)の取得 + int32_t GetSize(); + + private: + const string STR_; + + struct WaveFormatEx + { + uint16_t wFormatTag; // 1: PCM + uint16_t nChannels; // 1:モノラル,2: ステレオ + uint32_t nSamplesPerSec; // 標本化周波数 (Hz) + uint32_t nAvgBytesPerSec; // 転送速度 (bytes/s) + uint16_t nBlockAlign; // 4: 16ビットステレオの場合 + uint16_t wBitsPerSample; // データのビット数,8 または 16 + uint16_t cbSize; + }; + + SDFileSystem *sd_; + FILE *fp_; + + bool ok_; + int32_t size_; // モノラルデータのサイズ + int16_t *buffer; // ステレオをモノラルに変換する際の作業領域 + + void ErrorMsg(char msg[]) + { BlinkLabel errLabel(240, 100, msg, Label::CENTER); } + + // disallow copy constructor and assignment operator + SD_WavReader(const SD_WavReader&); + SD_WavReader& operator=(const SD_WavReader&); + }; +} +#endif // SD_BINARY_READER_HPP