1
0

MP3.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #ifndef MP3_HPP
  2. #define MP3_HPP
  3. //______________________________________________________________________________
  4. //
  5. // MP3.hpp
  6. //
  7. //______________________________________________________________________________
  8. //
  9. #pragma warning(disable:4786)
  10. #include "mp3header.hpp"
  11. #include <windows.h>
  12. #include <string>
  13. #include <exception>
  14. #include <iosfwd>
  15. namespace MP3
  16. {
  17. //______________________________________________________________________________
  18. //
  19. typedef __int64 offset_t;
  20. //--------------------------------------
  21. class Exception : public std::exception
  22. {
  23. public:
  24. Exception(DWORD dwMessage);
  25. Exception(const char* szMessage);
  26. const char* what() const;
  27. private:
  28. std::string m_strMessage;
  29. };
  30. //--------------------------------------
  31. struct Header
  32. {
  33. unsigned long m_ulChannels;
  34. unsigned long m_ulSamplesPerSecond;
  35. unsigned long m_ulSamplesPerBlock;
  36. unsigned long m_ulBytesPerBlock;
  37. unsigned long m_ulBlocks;
  38. void clear();
  39. };
  40. std::ostream& operator<<(std::ostream& os, const Header& h);
  41. //--------------------------------------
  42. class File
  43. {
  44. public:
  45. enum mode_t {in, out, inout};
  46. File();
  47. File(const char* szName, mode_t mode);
  48. ~File();
  49. void open(const char* szName, mode_t mode, DWORD dwFlags = 0);
  50. void close();
  51. bool isOpen() const;
  52. bool eof() const;
  53. const char* name() const;
  54. mode_t mode() const;
  55. unsigned long channels() const;
  56. unsigned long samplesPerSecond() const;
  57. unsigned long samplesPerBlock() const;
  58. unsigned long bytesPerBlock() const;
  59. unsigned long blocks() const;
  60. const Header& header() const;
  61. void read(void* pBuffer, size_t size) const;
  62. void write(const void* pBuffer, size_t size);
  63. void seek(offset_t) const;
  64. private:
  65. File(const File& f); // Not implemented
  66. File& operator=(const File& f); // Not implemented
  67. int readHeader();
  68. offset_t size() const;
  69. offset_t tell() const;
  70. HANDLE m_handle;
  71. std::string m_strName;
  72. mode_t m_mode;
  73. Header m_header;
  74. offset_t m_fileSize;
  75. offset_t m_fileOffset;
  76. };
  77. } // namespace MP3
  78. #endif // MP3_HPP