1
0

AC3.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #ifndef AC3_HPP
  2. #define AC3_HPP
  3. //______________________________________________________________________________
  4. //
  5. // AC3.hpp
  6. //
  7. //______________________________________________________________________________
  8. //
  9. #pragma warning(disable:4786)
  10. #include <windows.h>
  11. #include <string>
  12. #include <vector>
  13. #include <exception>
  14. #include <iosfwd>
  15. #include <cstdio>
  16. extern "C"
  17. {
  18. #include "ac3.h"
  19. #include "bitstream.h"
  20. }
  21. namespace AC3
  22. {
  23. //______________________________________________________________________________
  24. //
  25. typedef __int64 offset_t;
  26. //--------------------------------------
  27. enum
  28. {
  29. SamplesPerBlock = 256 * 6
  30. };
  31. //--------------------------------------
  32. class FileError : public std::exception
  33. {
  34. public:
  35. FileError(DWORD messageId);
  36. FileError(const char* message);
  37. const char* what() const;
  38. private:
  39. std::string m_strMessage;
  40. };
  41. //--------------------------------------
  42. struct Header
  43. {
  44. unsigned long m_nBlocks;
  45. unsigned long m_ulSamplesPerSecond;
  46. unsigned long m_ulSamplesPerBlock;
  47. unsigned long m_ulBytesPerBlock; // blockAlign
  48. };
  49. std::ostream& operator<<(std::ostream& os, const Header& h);
  50. //--------------------------------------
  51. struct SyncFrame
  52. {
  53. syncinfo_t m_si;
  54. bsi_t m_bsi;
  55. };
  56. std::ostream& operator<<(std::ostream& os, const SyncFrame& sf);
  57. //--------------------------------------
  58. class File
  59. {
  60. public:
  61. enum mode_t {in, out, inout};
  62. typedef std::vector<SyncFrame> VectorSyncFrame;
  63. File();
  64. File(const char* szName, mode_t mode);
  65. ~File();
  66. void open(const char* szName, mode_t mode);
  67. void close();
  68. bool isOpen() const;
  69. bool eof() const;
  70. const char* name() const;
  71. mode_t mode() const;
  72. unsigned long blockCount() const;
  73. unsigned long samplesPerSecond() const;
  74. unsigned long samplesPerBlock() const;
  75. int samplesPerSec() const;
  76. const Header& header() const;
  77. // const SyncFrame& syncFrame(int nSyncFrame) const;
  78. // SyncFrame& syncFrame(int nSyncFrame);
  79. private:
  80. File(const File& rhs); // Not implemented
  81. File& operator=(const File& rhs); // Not implemented
  82. int readHeader();
  83. void readSyncFrame(SyncFrame& sf);
  84. void writeSyncFrame(const SyncFrame& sf);
  85. void read(void* buffer, size_t size) const;
  86. void write(const void* data, size_t size);
  87. offset_t size() const;
  88. void seekCurrent(__int64) const;
  89. void seek(offset_t) const;
  90. offset_t tell() const;
  91. FILE* m_pFile;
  92. int m_hFile;
  93. bitstream_t* m_pbs;
  94. std::string m_strName;
  95. mode_t m_mode;
  96. Header m_header;
  97. VectorSyncFrame m_vSyncFrame;
  98. __int64 m_fileSize;
  99. __int64 m_fileOffset;
  100. };
  101. } // namespace AC3
  102. #endif // AC3_HPP