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