Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
SD_WavReader.hpp
00001 //-------------------------------------------------------------- 00002 // SD_WavReader class ---- Header 00003 // SD カードの *.wav ファイルの内容を読み出す 00004 // 以下のフォーマット以外は扱わない 00005 // PCM,16 ビットステレオ,標本化周波数 44.1 kHz 00006 // 00007 // 2016/06/17, Copyright (c) 2016 MIKAMI, Naoki 00008 //-------------------------------------------------------------- 00009 00010 #ifndef SD_WAV_READER_HPP 00011 #define SD_WAV_READER_HPP 00012 00013 #include "SDFileSystem.h" 00014 #include "BlinkLabel.hpp" 00015 #define DEBUG_ARRAY_CHECK 00016 #include "Array.hpp" 00017 #include <string> 00018 00019 namespace Mikami 00020 { 00021 class SD_WavReader 00022 { 00023 public: 00024 SD_WavReader(int32_t bufferSize); 00025 ~SD_WavReader(); 00026 00027 void Open(const string fileName); 00028 00029 void Close() { fclose(fp_); } 00030 00031 // ファイルのヘッダ読み込み 00032 // 戻り値: *.wav で,16 ビットステレオ, 00033 // 標本化周波数:44.1 kHz の場合 true 00034 bool IsWavFile(); 00035 00036 // ファイルからステレオデータの取得 00037 void ReadStereo(Array<int16_t>& dataL, Array<int16_t>& dataR); 00038 00039 // ファイルからデータをモノラルに変換しての取得 00040 void ReadAndToMono(Array<int16_t>& data); 00041 00042 // データサイズ(標本化点の数)の取得 00043 int32_t GetSize(); 00044 00045 private: 00046 const string STR_; 00047 00048 struct WaveFormatEx 00049 { 00050 uint16_t wFormatTag; // 1: PCM 00051 uint16_t nChannels; // 1:モノラル,2: ステレオ 00052 uint32_t nSamplesPerSec; // 標本化周波数 (Hz) 00053 uint32_t nAvgBytesPerSec; // 転送速度 (bytes/s) 00054 uint16_t nBlockAlign; // 4: 16ビットステレオの場合 00055 uint16_t wBitsPerSample; // データのビット数,8 または 16 00056 uint16_t cbSize; // PCM の場合使わない 00057 }; 00058 00059 SDFileSystem *sd_; 00060 FILE *fp_; 00061 00062 bool ok_; 00063 int32_t size_; // データサイズ(標本化点の数) 00064 Array<int16_t> buffer; // ステレオをモノラルに変換する際の作業領域 00065 00066 void ErrorMsg(char msg[]) 00067 { BlinkLabel errLabel(240, 100, msg, Label::CENTER); } 00068 00069 // disallow copy constructor and assignment operator 00070 SD_WavReader(const SD_WavReader&); 00071 SD_WavReader& operator=(const SD_WavReader&); 00072 }; 00073 } 00074 #endif // SD_BINARY_READER_HPP
Generated on Fri Aug 5 2022 02:03:47 by
