WAVAudioFileSource.hh 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**********
  2. This library is free software; you can redistribute it and/or modify it under
  3. the terms of the GNU Lesser General Public License as published by the
  4. Free Software Foundation; either version 3 of the License, or (at your
  5. option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
  6. This library is distributed in the hope that it will be useful, but WITHOUT
  7. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
  9. more details.
  10. You should have received a copy of the GNU Lesser General Public License
  11. along with this library; if not, write to the Free Software Foundation, Inc.,
  12. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  13. **********/
  14. // "liveMedia"
  15. // Copyright (c) 1996-2019 Live Networks, Inc. All rights reserved.
  16. // A WAV audio file source
  17. // NOTE: Samples are returned in little-endian order (the same order in which
  18. // they were stored in the file).
  19. // C++ header
  20. #ifndef _WAV_AUDIO_FILE_SOURCE_HH
  21. #define _WAV_AUDIO_FILE_SOURCE_HH
  22. #ifndef _AUDIO_INPUT_DEVICE_HH
  23. #include "AudioInputDevice.hh"
  24. #endif
  25. typedef enum {
  26. WA_PCM = 0x01,
  27. WA_PCMA = 0x06,
  28. WA_PCMU = 0x07,
  29. WA_IMA_ADPCM = 0x11,
  30. WA_UNKNOWN
  31. } WAV_AUDIO_FORMAT;
  32. class WAVAudioFileSource: public AudioInputDevice {
  33. public:
  34. static WAVAudioFileSource* createNew(UsageEnvironment& env,
  35. char const* fileName);
  36. unsigned numPCMBytes() const;
  37. void setScaleFactor(int scale);
  38. void seekToPCMByte(unsigned byteNumber);
  39. void limitNumBytesToStream(unsigned numBytesToStream);
  40. // if "numBytesToStream" is >0, then we limit the stream to that number of bytes, before treating it as EOF
  41. unsigned char getAudioFormat();
  42. protected:
  43. WAVAudioFileSource(UsageEnvironment& env, FILE* fid);
  44. // called only by createNew()
  45. virtual ~WAVAudioFileSource();
  46. static void fileReadableHandler(WAVAudioFileSource* source, int mask);
  47. void doReadFromFile();
  48. private:
  49. // redefined virtual functions:
  50. virtual void doGetNextFrame();
  51. virtual void doStopGettingFrames();
  52. virtual Boolean setInputPort(int portIndex);
  53. virtual double getAverageLevel() const;
  54. protected:
  55. unsigned fPreferredFrameSize;
  56. private:
  57. FILE* fFid;
  58. double fPlayTimePerSample; // useconds
  59. Boolean fFidIsSeekable;
  60. unsigned fLastPlayTime; // useconds
  61. Boolean fHaveStartedReading;
  62. unsigned fWAVHeaderSize;
  63. unsigned fFileSize;
  64. int fScaleFactor;
  65. Boolean fLimitNumBytesToStream;
  66. unsigned fNumBytesToStream; // used iff "fLimitNumBytesToStream" is True
  67. unsigned char fAudioFormat;
  68. };
  69. #endif