![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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
MyClasses_Functions/SD_WavReader.hpp@10:fc6367c2ffcf, 2016-06-22 (annotated)
- Committer:
- edamame22
- Date:
- Wed Jun 22 03:50:38 2016 +0000
- Revision:
- 10:fc6367c2ffcf
- Parent:
- 0:e953eb392151
auto play is enabled
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:e953eb392151 | 1 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:e953eb392151 | 2 | // SD_WavReader class ---- Header |
MikamiUitOpen | 0:e953eb392151 | 3 | // SD カードの *.wav ファイルの内容を読み出す |
MikamiUitOpen | 0:e953eb392151 | 4 | // 以下のフォーマット以外は扱わない |
MikamiUitOpen | 0:e953eb392151 | 5 | // PCM,16 ビットステレオ,標本化周波数 44.1 kHz |
MikamiUitOpen | 0:e953eb392151 | 6 | // |
MikamiUitOpen | 0:e953eb392151 | 7 | // 2016/04/19, Copyright (c) 2016 MIKAMI, Naoki |
MikamiUitOpen | 0:e953eb392151 | 8 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:e953eb392151 | 9 | |
MikamiUitOpen | 0:e953eb392151 | 10 | #ifndef SD_WAV_READER_HPP |
MikamiUitOpen | 0:e953eb392151 | 11 | #define SD_WAV_READER_HPP |
MikamiUitOpen | 0:e953eb392151 | 12 | |
MikamiUitOpen | 0:e953eb392151 | 13 | #include "SDFileSystem.h" |
MikamiUitOpen | 0:e953eb392151 | 14 | #include "BlinkLabel.hpp" |
MikamiUitOpen | 0:e953eb392151 | 15 | #include <string> |
MikamiUitOpen | 0:e953eb392151 | 16 | |
MikamiUitOpen | 0:e953eb392151 | 17 | namespace Mikami |
MikamiUitOpen | 0:e953eb392151 | 18 | { |
MikamiUitOpen | 0:e953eb392151 | 19 | class SD_WavReader |
MikamiUitOpen | 0:e953eb392151 | 20 | { |
MikamiUitOpen | 0:e953eb392151 | 21 | public: |
MikamiUitOpen | 0:e953eb392151 | 22 | SD_WavReader(int32_t bufferSize); |
MikamiUitOpen | 0:e953eb392151 | 23 | ~SD_WavReader(); |
MikamiUitOpen | 0:e953eb392151 | 24 | |
MikamiUitOpen | 0:e953eb392151 | 25 | void Open(const string fileName); |
MikamiUitOpen | 0:e953eb392151 | 26 | |
MikamiUitOpen | 0:e953eb392151 | 27 | void Close() { fclose(fp_); } |
MikamiUitOpen | 0:e953eb392151 | 28 | |
MikamiUitOpen | 0:e953eb392151 | 29 | // ファイルのヘッダ (RIFFxxxxWAVEfm ) 読み込み |
MikamiUitOpen | 0:e953eb392151 | 30 | // 戻り値: *.wav で,16 ビットステレオ, |
MikamiUitOpen | 0:e953eb392151 | 31 | // 標本化周波数:44.1 kHz の場合 true |
MikamiUitOpen | 0:e953eb392151 | 32 | bool IsWavFile(); |
MikamiUitOpen | 0:e953eb392151 | 33 | |
MikamiUitOpen | 0:e953eb392151 | 34 | // ファイルからデータの取得 |
MikamiUitOpen | 0:e953eb392151 | 35 | void Read(int16_t data[], uint32_t size); |
MikamiUitOpen | 0:e953eb392151 | 36 | |
MikamiUitOpen | 0:e953eb392151 | 37 | // ファイルからデータをモノラルに変換しての取得 |
MikamiUitOpen | 0:e953eb392151 | 38 | void ReadAndToMono(int16_t data[], uint32_t size); |
MikamiUitOpen | 0:e953eb392151 | 39 | |
MikamiUitOpen | 0:e953eb392151 | 40 | // データサイズ(標本化点の数)の取得 |
MikamiUitOpen | 0:e953eb392151 | 41 | int32_t GetSize(); |
edamame22 | 10:fc6367c2ffcf | 42 | |
edamame22 | 10:fc6367c2ffcf | 43 | // ren: show a string |
edamame22 | 10:fc6367c2ffcf | 44 | /* void ren_Msg1(int pos, char msg[]) |
edamame22 | 10:fc6367c2ffcf | 45 | { int lin, str_ln, y_pos[7]= {0,70,130,160,190,220,250}; |
edamame22 | 10:fc6367c2ffcf | 46 | // char msg[501]; |
edamame22 | 10:fc6367c2ffcf | 47 | // strcpy(msg, str_msg.c_str()); |
edamame22 | 10:fc6367c2ffcf | 48 | // str_ln=str_msg.size(); |
edamame22 | 10:fc6367c2ffcf | 49 | // if(str_ln>500) str_ln=500; |
edamame22 | 10:fc6367c2ffcf | 50 | // msg[str_ln]='\0'; |
edamame22 | 10:fc6367c2ffcf | 51 | if(pos<0) lin=0; |
edamame22 | 10:fc6367c2ffcf | 52 | else if (pos>6) lin=6; |
edamame22 | 10:fc6367c2ffcf | 53 | else lin=pos; |
edamame22 | 10:fc6367c2ffcf | 54 | Label renLabel(0, y_pos[lin], msg, Label::LEFT,Font20); |
edamame22 | 10:fc6367c2ffcf | 55 | } |
edamame22 | 10:fc6367c2ffcf | 56 | */ |
MikamiUitOpen | 0:e953eb392151 | 57 | private: |
MikamiUitOpen | 0:e953eb392151 | 58 | const string STR_; |
MikamiUitOpen | 0:e953eb392151 | 59 | |
MikamiUitOpen | 0:e953eb392151 | 60 | struct WaveFormatEx |
MikamiUitOpen | 0:e953eb392151 | 61 | { |
MikamiUitOpen | 0:e953eb392151 | 62 | uint16_t wFormatTag; // 1: PCM |
MikamiUitOpen | 0:e953eb392151 | 63 | uint16_t nChannels; // 1:モノラル,2: ステレオ |
MikamiUitOpen | 0:e953eb392151 | 64 | uint32_t nSamplesPerSec; // 標本化周波数 (Hz) |
MikamiUitOpen | 0:e953eb392151 | 65 | uint32_t nAvgBytesPerSec; // 転送速度 (bytes/s) |
MikamiUitOpen | 0:e953eb392151 | 66 | uint16_t nBlockAlign; // 4: 16ビットステレオの場合 |
MikamiUitOpen | 0:e953eb392151 | 67 | uint16_t wBitsPerSample; // データのビット数,8 または 16 |
MikamiUitOpen | 0:e953eb392151 | 68 | uint16_t cbSize; |
MikamiUitOpen | 0:e953eb392151 | 69 | }; |
MikamiUitOpen | 0:e953eb392151 | 70 | |
MikamiUitOpen | 0:e953eb392151 | 71 | SDFileSystem *sd_; |
MikamiUitOpen | 0:e953eb392151 | 72 | FILE *fp_; |
MikamiUitOpen | 0:e953eb392151 | 73 | |
MikamiUitOpen | 0:e953eb392151 | 74 | bool ok_; |
MikamiUitOpen | 0:e953eb392151 | 75 | int32_t size_; // モノラルデータのサイズ |
MikamiUitOpen | 0:e953eb392151 | 76 | int16_t *buffer; // ステレオをモノラルに変換する際の作業領域 |
MikamiUitOpen | 0:e953eb392151 | 77 | |
MikamiUitOpen | 0:e953eb392151 | 78 | void ErrorMsg(char msg[]) |
MikamiUitOpen | 0:e953eb392151 | 79 | { BlinkLabel errLabel(240, 100, msg, Label::CENTER); } |
MikamiUitOpen | 0:e953eb392151 | 80 | |
MikamiUitOpen | 0:e953eb392151 | 81 | // disallow copy constructor and assignment operator |
MikamiUitOpen | 0:e953eb392151 | 82 | SD_WavReader(const SD_WavReader&); |
MikamiUitOpen | 0:e953eb392151 | 83 | SD_WavReader& operator=(const SD_WavReader&); |
MikamiUitOpen | 0:e953eb392151 | 84 | }; |
MikamiUitOpen | 0:e953eb392151 | 85 | } |
MikamiUitOpen | 0:e953eb392151 | 86 | #endif // SD_BINARY_READER_HPP |