PTLib  Version 2.10.11
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: 27468 $
30  * $Author: rjongbloed $
31  * $Date: 2012-04-18 14:31:01 -0500 (Wed, 18 Apr 2012) $
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(const PString &device,
62  unsigned numChannels,
63  unsigned sampleRate,
64  unsigned bitsPerSample);
65  ~PSoundChannel_WAVFile();
67  PBoolean Open(
68  const PString & device,
69  Directions dir,
70  unsigned numChannels,
71  unsigned sampleRate,
72  unsigned bitsPerSample
73  );
74  virtual PString GetName() const;
75  PBoolean Close();
76  PBoolean IsOpen() const;
77  PBoolean Write(const void * buf, PINDEX len);
78  PBoolean Read(void * buf, PINDEX len);
79  PBoolean SetFormat(unsigned numChannels,
80  unsigned sampleRate,
81  unsigned bitsPerSample);
82  unsigned GetChannels() const;
83  unsigned GetSampleRate() const;
84  unsigned GetSampleSize() const;
85  PBoolean SetBuffers(PINDEX size, PINDEX count);
86  PBoolean GetBuffers(PINDEX & size, PINDEX & count);
94 
95 protected:
96  bool ReadSamples(void * data, PINDEX size);
97  bool ReadSample(short & data);
98 
99  PWAVFile m_WAVFile;
100  PAdaptiveDelay m_Pacing;
101  bool m_autoRepeat;
102  unsigned m_sampleRate;
103  PINDEX m_bufferSize;
104  PShortArray m_sampleBuffer;
105  PINDEX m_samplePosition;
106 };
107 
108 
109 #endif // defined(P_WAVFILE)
110 
111 #endif // PTLIB_PWAVFILEDEV_H
112 
113 
114 // End Of File ///////////////////////////////////////////////////////////////
virtual PBoolean Close()
Close the channel, shutting down the link to the data source.
Abstract class for a generalised sound channel, and an implementation of PSoundChannel for old code t...
Definition: sound.h:251
Directions
Definition: sound.h:258
virtual PBoolean WaitForPlayCompletion()
Block calling thread until the sound play begun with PlaySound() or PlayFile() has completed...
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:1049
virtual PBoolean IsOpen() const
Test if this instance of PSoundChannel is open.
A class representing a WAV audio file.
Definition: pwavfile.h:172
virtual PBoolean HasPlayCompleted()
Indicate if the sound play begun with PlayBuffer() or PlayFile() has completed.
virtual PBoolean Read(void *buf, PINDEX len)
Low level read from the channel.
virtual PBoolean SetFormat(unsigned numChannels=1, unsigned sampleRate=8000, unsigned bitsPerSample=16)
Set the format for play/record.
virtual unsigned GetSampleSize() const
Get the sample size in bits per sample.
This is an array collection class of PString objects.
Definition: pstring.h:2024
virtual PBoolean StartRecording()
Start filling record buffers.
virtual PBoolean AreAllRecordBuffersFull()
Determine if all of the record buffer allocated has been filled.
BOOL PBoolean
Definition: object.h:102
virtual PBoolean IsRecordBufferFull()
Determine if a record buffer has been filled, so that the next Read() call will not block...
virtual PBoolean WaitForRecordBufferFull()
Block the thread until a record buffer has been filled, so that the next Read() call will not block...
virtual PBoolean WaitForAllRecordBuffersFull()
Block the thread until all of the record buffer allocated has been filled.
virtual PBoolean Write(const void *buf, PINDEX len)
Low level write (or play) to the channel.
virtual unsigned GetSampleRate() const
Get the sample rate in samples per second.
The character string class.
Definition: pstring.h:108
virtual PBoolean GetBuffers(PINDEX &size, PINDEX &count)
Get the internal buffers for the sound channel I/O.
Class for implementing an "adaptive" delay.
Definition: delaychan.h:52
Array of short integers.
Definition: array.h:589
virtual PString GetName() const
Get the name of the open channel.
static PStringArray GetDeviceNames(const PString &driverName, Directions direction, PPluginManager *pluginMgr=NULL)
Definition: sound.h:302
virtual PBoolean Open(const PString &device, Directions dir, unsigned numChannels=1, unsigned sampleRate=8000, unsigned bitsPerSample=16)
Open the specified device for playing or recording.
virtual PBoolean SetBuffers(PINDEX size, PINDEX count=2)
Set the internal buffers for the sound channel I/O.
virtual unsigned GetChannels() const
Get the number of channels (mono/stereo) in the sound.