SPKT
Dependencies: SDFileSystem_Warning_Fixed
Dependents: DISCO-F746_WAV_PLAYER WAV
SD_WavReader.hpp@18:6631cd0fbbcd, 2019-06-04 (annotated)
- Committer:
- phungductung
- Date:
- Tue Jun 04 21:35:59 2019 +0000
- Revision:
- 18:6631cd0fbbcd
- Parent:
- 16:299cc1052baa
WAV
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
phungductung | 18:6631cd0fbbcd | 1 | |
MikamiUitOpen | 0:d310bb78455d | 2 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:d310bb78455d | 3 | |
MikamiUitOpen | 0:d310bb78455d | 4 | #ifndef SD_WAV_READER_HPP |
MikamiUitOpen | 0:d310bb78455d | 5 | #define SD_WAV_READER_HPP |
MikamiUitOpen | 0:d310bb78455d | 6 | |
MikamiUitOpen | 16:299cc1052baa | 7 | #include "stm32746g_discovery_audio.h" |
MikamiUitOpen | 0:d310bb78455d | 8 | #include "SDFileSystem.h" |
MikamiUitOpen | 0:d310bb78455d | 9 | #include "BlinkLabel.hpp" |
MikamiUitOpen | 0:d310bb78455d | 10 | #include "Array.hpp" |
MikamiUitOpen | 0:d310bb78455d | 11 | #include <string> |
MikamiUitOpen | 0:d310bb78455d | 12 | |
MikamiUitOpen | 0:d310bb78455d | 13 | namespace Mikami |
MikamiUitOpen | 0:d310bb78455d | 14 | { |
MikamiUitOpen | 0:d310bb78455d | 15 | class SD_WavReader |
MikamiUitOpen | 0:d310bb78455d | 16 | { |
MikamiUitOpen | 0:d310bb78455d | 17 | public: |
MikamiUitOpen | 0:d310bb78455d | 18 | SD_WavReader(int32_t bufferSize); |
MikamiUitOpen | 0:d310bb78455d | 19 | virtual ~SD_WavReader(); |
MikamiUitOpen | 0:d310bb78455d | 20 | |
MikamiUitOpen | 0:d310bb78455d | 21 | void Open(const string fileName); |
MikamiUitOpen | 0:d310bb78455d | 22 | |
MikamiUitOpen | 0:d310bb78455d | 23 | void Close() { fclose(fp_); } |
MikamiUitOpen | 0:d310bb78455d | 24 | |
phungductung | 18:6631cd0fbbcd | 25 | // Đọc tiêu đề của tệp |
MikamiUitOpen | 0:d310bb78455d | 26 | bool IsWavFile(); |
MikamiUitOpen | 0:d310bb78455d | 27 | |
phungductung | 18:6631cd0fbbcd | 28 | // Nhận dữ liệu âm thanh nổi từ tệp |
MikamiUitOpen | 0:d310bb78455d | 29 | void ReadStereo(Array<int16_t>& dataL, Array<int16_t>& dataR); |
MikamiUitOpen | 0:d310bb78455d | 30 | |
phungductung | 18:6631cd0fbbcd | 31 | // Chuyển đổi dữ liệu từ tệp thành đơn âm |
MikamiUitOpen | 0:d310bb78455d | 32 | void ReadAndToMono(Array<int16_t>& data); |
MikamiUitOpen | 0:d310bb78455d | 33 | |
phungductung | 18:6631cd0fbbcd | 34 | // Lấy kích thước dữ liệu (số điểm lấy mẫu) |
MikamiUitOpen | 0:d310bb78455d | 35 | int32_t GetSize(); |
MikamiUitOpen | 0:d310bb78455d | 36 | |
MikamiUitOpen | 0:d310bb78455d | 37 | private: |
MikamiUitOpen | 0:d310bb78455d | 38 | const string STR_; |
MikamiUitOpen | 0:d310bb78455d | 39 | |
MikamiUitOpen | 0:d310bb78455d | 40 | struct WaveFormatEx |
MikamiUitOpen | 0:d310bb78455d | 41 | { |
MikamiUitOpen | 0:d310bb78455d | 42 | uint16_t wFormatTag; // 1: PCM |
phungductung | 18:6631cd0fbbcd | 43 | uint16_t nChannels; // 1: 1: đơn âm, 2: âm thanh nổi |
phungductung | 18:6631cd0fbbcd | 44 | uint32_t nSamplesPerSec; // Tần số lấy mẫu (Hz) |
phungductung | 18:6631cd0fbbcd | 45 | uint32_t nAvgBytesPerSec; // Tốc độ truyền (byte / s) |
phungductung | 18:6631cd0fbbcd | 46 | uint16_t nBlockAlign; // 4: Trong trường hợp âm thanh nổi 16 bit |
phungductung | 18:6631cd0fbbcd | 47 | uint16_t wBitsPerSample; // Số bit dữ liệu, 8 hoặc 16 |
phungductung | 18:6631cd0fbbcd | 48 | uint16_t cbSize; // Không được sử dụng cho PCM |
MikamiUitOpen | 0:d310bb78455d | 49 | }; |
MikamiUitOpen | 0:d310bb78455d | 50 | |
MikamiUitOpen | 0:d310bb78455d | 51 | SDFileSystem *sd_; |
MikamiUitOpen | 0:d310bb78455d | 52 | FILE *fp_; |
MikamiUitOpen | 0:d310bb78455d | 53 | |
MikamiUitOpen | 0:d310bb78455d | 54 | bool ok_; |
phungductung | 18:6631cd0fbbcd | 55 | int32_t size_; // Kích thước dữ liệu (số điểm lấy mẫu) |
phungductung | 18:6631cd0fbbcd | 56 | Array<int16_t> buffer; // Khu vực làm việc |
MikamiUitOpen | 0:d310bb78455d | 57 | |
MikamiUitOpen | 0:d310bb78455d | 58 | void ErrorMsg(char msg[]) |
MikamiUitOpen | 0:d310bb78455d | 59 | { BlinkLabel errLabel(240, 100, msg, Label::CENTER); } |
phungductung | 18:6631cd0fbbcd | 60 | // Không sử dụng hàm tạo sao chép và toán tử gán đối tượng |
MikamiUitOpen | 0:d310bb78455d | 61 | SD_WavReader(const SD_WavReader&); |
MikamiUitOpen | 0:d310bb78455d | 62 | SD_WavReader& operator=(const SD_WavReader&); |
MikamiUitOpen | 0:d310bb78455d | 63 | }; |
MikamiUitOpen | 0:d310bb78455d | 64 | } |
MikamiUitOpen | 0:d310bb78455d | 65 | #endif // SD_BINARY_READER_HPP |