PTLib  Version 2.14.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pwavfiledev.h
Go to the documentation of this file.
1 /*
2  * pwavfiledev.cxx
3  *
4  * Sound file device declaration
5  *
6  * Portable Windows Library
7  *
8  * Copyright (C) 2007 Post Increment
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is
23  * Robert Jongbloed <robertj@postincrement.com>
24  *
25  * All Rights Reserved.
26  *
27  * Contributor(s): ______________________________________.
28  *
29  * $Revision: 30241 $
30  * $Author: rjongbloed $
31  * $Date: 2013-08-06 12:00:10 +1000 (Tue, 06 Aug 2013) $
32  */
33 
34 #ifndef PTLIB_PWAVFILEDEV_H
35 #define PTLIB_PWAVFILEDEV_H
36 
37 #ifdef P_USE_PRAGMA
38 #pragma interface
39 #endif
40 
41 #include <ptlib.h>
42 
43 #include <ptlib/sound.h>
44 #include <ptclib/pwavfile.h>
45 #include <ptclib/delaychan.h>
46 
47 #if defined(P_WAVFILE)
48 
49 
51 //
52 // This class defines a sound channel device that reads audio from a raw WAV file
53 //
54 
55 class PSoundChannel_WAVFile : public PSoundChannel
56 {
57  PCLASSINFO(PSoundChannel_WAVFile, PSoundChannel);
58  public:
59  PSoundChannel_WAVFile();
60  ~PSoundChannel_WAVFile();
61  static PStringArray GetDeviceNames(PSoundChannel::Directions = Player);
62  bool Open(const Params & params);
63  virtual PString GetName() const;
64  PBoolean Close();
65  PBoolean IsOpen() const;
66  PBoolean Write(const void * buf, PINDEX len);
67  PBoolean Read(void * buf, PINDEX len);
68  PBoolean SetFormat(unsigned numChannels,
69  unsigned sampleRate,
70  unsigned bitsPerSample);
71  unsigned GetChannels() const;
72  unsigned GetSampleRate() const;
73  unsigned GetSampleSize() const;
74  PBoolean SetBuffers(PINDEX size, PINDEX count);
75  PBoolean GetBuffers(PINDEX & size, PINDEX & count);
83 
84 protected:
85  bool ReadSamples(void * data, PINDEX size);
86  bool ReadSample(short * data, unsigned channels);
87  void CopyMerge(short * & output, const short * wavSample, unsigned wavChannels);
88 
89  PWAVFile m_WAVFile;
90  PAdaptiveDelay m_Pacing;
91  bool m_autoRepeat;
92  unsigned m_sampleRate;
93  unsigned m_channels;
94  PINDEX m_bufferSize;
95  PShortArray m_sampleBuffer;
96  PINDEX m_samplePosition;
97 };
98 
99 
100 #endif // defined(P_WAVFILE)
101 
102 #endif // PTLIB_PWAVFILEDEV_H
103 
104 
105 // End Of File ///////////////////////////////////////////////////////////////