revised version of F746_SD_GraphicEqualizer
Dependencies: BSP_DISCO_F746NG F746_GUI F746_SAI_IO FrequencyResponseDrawer LCD_DISCO_F746NG SDFileSystem_Warning_Fixed TS_DISCO_F746NG mbed
Fork of F746_SD_GraphicEqualizer by
Diff: MyClasses_Functions/SD_WavReader.hpp
- Revision:
- 0:e953eb392151
- Child:
- 10:fc6367c2ffcf
diff -r 000000000000 -r e953eb392151 MyClasses_Functions/SD_WavReader.hpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MyClasses_Functions/SD_WavReader.hpp Wed Apr 27 13:56:39 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