1
0

WAV.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #ifndef WAV_HPP
  2. #define WAV_HPP
  3. #include "FourCC.hpp"
  4. #include <io.h>
  5. #include <exception>
  6. #include <string>
  7. #include <iosfwd>
  8. #include <vector>
  9. namespace WAV
  10. {
  11. class FileError : public exception
  12. {
  13. public:
  14. explicit FileError(const char* message);
  15. const char* what() const;
  16. private:
  17. const std::string message;
  18. };
  19. struct Format
  20. {
  21. unsigned short formatTag;
  22. unsigned short nChannels;
  23. unsigned long samplesPerSec;
  24. unsigned long avgBytesPerSec;
  25. unsigned short blockAlign;
  26. unsigned short bitsPerSample;
  27. typedef std::vector<unsigned char> ByteArray;
  28. ByteArray extra;
  29. };
  30. std::ostream& operator<<(std::ostream&, const Format&);
  31. typedef __int64 offset_t;
  32. class File
  33. {
  34. public:
  35. enum mode_t { in, out, inout };
  36. File();
  37. File(const char* name, mode_t mode);
  38. ~File();
  39. void open(const char* name, mode_t mode);
  40. void close();
  41. bool isOpen() const;
  42. bool eof() const;
  43. //size_t sampleNum() const;
  44. //size_t sampleCount() const;
  45. //void seekSample(size_t sampleNum) const;
  46. offset_t offset() const;
  47. void seekOffset(offset_t) const;
  48. size_t read(void* buffer, size_t size) const;
  49. void write(const void* buffer, size_t size);
  50. mode_t mode() const;
  51. const char* name() const;
  52. const Format& format() const;
  53. Format& format();
  54. void seekFormat() const;
  55. //void readFormat() const;
  56. void readFormatChunk() const;
  57. void readFactChunk() const;
  58. void setFactSize(size_t);
  59. size_t factSize() const;
  60. void seekFact() const;
  61. void writeFact(const void*, size_t);
  62. void readFact(void* buffer, size_t size) const;
  63. void writeFormat();
  64. void writeFormatChunk();
  65. size_t dataSize() const;
  66. private:
  67. File(const File&);
  68. File& operator=(const File&);
  69. void init();
  70. void seek(__int64, int) const;
  71. const FourCC queryId() const;
  72. const FourCC readId() const;
  73. void writeId(const char* id);
  74. void writeSize(size_t size);
  75. size_t readSize() const;
  76. int handle_;
  77. __int64 dataPosn;
  78. size_t m_dataSize;
  79. //size_t m_sampleCount;
  80. char name_[_MAX_PATH];
  81. mode_t mode_;
  82. mutable Format format_;
  83. mutable size_t m_factSize;
  84. };
  85. }
  86. #endif