Aud.hpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef AUD_HPP
  2. #define AUD_HPP
  3. #include <exception>
  4. #include <string>
  5. #include <io.h>
  6. namespace Aud
  7. {
  8. class FileError : public exception
  9. {
  10. public:
  11. explicit FileError(const char* message);
  12. const char* what() const;
  13. private:
  14. const std::string message;
  15. };
  16. enum { samplesPerSec = 48000 };
  17. enum { sampleSizeInBits = 16, sampleSizeInBytes = 2 };
  18. enum { numberOfChannels = 2 };
  19. enum { blockAlign = numberOfChannels * sampleSizeInBytes };
  20. class File
  21. {
  22. public:
  23. enum mode_t { in, out };
  24. File();
  25. File(const char* name, mode_t mode);
  26. ~File();
  27. void open(const char* name, mode_t mode);
  28. void close();
  29. bool isOpen() const;
  30. bool eof() const;
  31. mode_t mode() const;
  32. const char* name() const;
  33. int sampleCount() const;
  34. void seekSample(int sampleNum) const;
  35. size_t read(void* buffer, size_t size) const;
  36. void write(const void* buffer, size_t size);
  37. typedef __int64 offset_t;
  38. offset_t offset() const;
  39. void seekOffset(offset_t) const;
  40. private:
  41. File(const File&);
  42. File& operator=(const File&);
  43. void init();
  44. int handle_;
  45. char name_[_MAX_PATH];
  46. mode_t mode_;
  47. int m_sampleCount;
  48. };
  49. } //end namespace Aud
  50. #endif