pwavfiledev.h
Go to the documentation of this file.
/*
* pwavfiledev.cxx
*
* Sound file device declaration
*
* Portable Windows Library
*
* Copyright (C) 2007 Post Increment
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Portable Windows Library.
*
* The Initial Developer of the Original Code is
* Robert Jongbloed <robertj@postincrement.com>
*
* All Rights Reserved.
*
* Contributor(s): ______________________________________.
*
* $Revision: 27468 $
* $Author: rjongbloed $
* $Date: 2012-04-18 14:31:01 -0500 (Wed, 18 Apr 2012) $
*/
#ifndef PTLIB_PWAVFILEDEV_H
#define PTLIB_PWAVFILEDEV_H
#ifdef P_USE_PRAGMA
#pragma interface
#endif
#include <ptlib.h>
#include <ptlib/sound.h>
#include <ptclib/pwavfile.h>
#include <ptclib/delaychan.h>
#if defined(P_WAVFILE)
//
// This class defines a sound channel device that reads audio from a raw WAV file
//
class PSoundChannel_WAVFile : public PSoundChannel
{
PCLASSINFO(PSoundChannel_WAVFile, PSoundChannel);
public:
PSoundChannel_WAVFile();
PSoundChannel_WAVFile(const PString &device,
PSoundChannel::Directions dir,
unsigned numChannels,
unsigned sampleRate,
unsigned bitsPerSample);
~PSoundChannel_WAVFile();
static PStringArray GetDeviceNames(PSoundChannel::Directions = Player);
PBoolean Open(
const PString & device,
Directions dir,
unsigned numChannels,
unsigned sampleRate,
unsigned bitsPerSample
);
virtual PString GetName() const;
PBoolean Close();
PBoolean IsOpen() const;
PBoolean Write(const void * buf, PINDEX len);
PBoolean Read(void * buf, PINDEX len);
PBoolean SetFormat(unsigned numChannels,
unsigned sampleRate,
unsigned bitsPerSample);
unsigned GetChannels() const;
unsigned GetSampleRate() const;
unsigned GetSampleSize() const;
PBoolean SetBuffers(PINDEX size, PINDEX count);
PBoolean GetBuffers(PINDEX & size, PINDEX & count);
PBoolean HasPlayCompleted();
PBoolean WaitForPlayCompletion();
PBoolean StartRecording();
PBoolean IsRecordBufferFull();
PBoolean AreAllRecordBuffersFull();
PBoolean WaitForRecordBufferFull();
PBoolean WaitForAllRecordBuffersFull();
protected:
bool ReadSamples(void * data, PINDEX size);
bool ReadSample(short & data);
PWAVFile m_WAVFile;
PAdaptiveDelay m_Pacing;
bool m_autoRepeat;
unsigned m_sampleRate;
PINDEX m_bufferSize;
PShortArray m_sampleBuffer;
PINDEX m_samplePosition;
};
#endif // defined(P_WAVFILE)
#endif // PTLIB_PWAVFILEDEV_H
// End Of File ///////////////////////////////////////////////////////////////
PSoundChannel::Close
virtual PBoolean Close()
Close the channel, shutting down the link to the data source.
PSoundChannel
Abstract class for a generalised sound channel, and an implementation of PSoundChannel for old code t...
Definition: sound.h:251
PSoundChannel::Directions
Directions
Definition: sound.h:258
PSoundChannel::GetName
virtual PString GetName() const
Get the name of the open channel.
sound.h
PSoundChannel::WaitForPlayCompletion
virtual PBoolean WaitForPlayCompletion()
Block calling thread until the sound play begun with PlaySound() or PlayFile() has completed...
PCLASSINFO
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:1049
PWAVFile
A class representing a WAV audio file.
Definition: pwavfile.h:172
PSoundChannel::GetSampleSize
virtual unsigned GetSampleSize() const
Get the sample size in bits per sample.
PSoundChannel::HasPlayCompleted
virtual PBoolean HasPlayCompleted()
Indicate if the sound play begun with PlayBuffer() or PlayFile() has completed.
PSoundChannel::Read
virtual PBoolean Read(void *buf, PINDEX len)
Low level read from the channel.
PSoundChannel::SetFormat
virtual PBoolean SetFormat(unsigned numChannels=1, unsigned sampleRate=8000, unsigned bitsPerSample=16)
Set the format for play/record.
PStringArray
This is an array collection class of PString objects.
Definition: pstring.h:2024
PSoundChannel::StartRecording
virtual PBoolean StartRecording()
Start filling record buffers.
PSoundChannel::AreAllRecordBuffersFull
virtual PBoolean AreAllRecordBuffersFull()
Determine if all of the record buffer allocated has been filled.
PBoolean
BOOL PBoolean
Definition: object.h:102
PSoundChannel::IsRecordBufferFull
virtual PBoolean IsRecordBufferFull()
Determine if a record buffer has been filled, so that the next Read() call will not block...
PSoundChannel::WaitForRecordBufferFull
virtual PBoolean WaitForRecordBufferFull()
Block the thread until a record buffer has been filled, so that the next Read() call will not block...
pwavfile.h
PSoundChannel::WaitForAllRecordBuffersFull
virtual PBoolean WaitForAllRecordBuffersFull()
Block the thread until all of the record buffer allocated has been filled.
PSoundChannel::Write
virtual PBoolean Write(const void *buf, PINDEX len)
Low level write (or play) to the channel.
PSoundChannel::GetSampleRate
virtual unsigned GetSampleRate() const
Get the sample rate in samples per second.
PString
The character string class.
Definition: pstring.h:108
PSoundChannel::GetBuffers
virtual PBoolean GetBuffers(PINDEX &size, PINDEX &count)
Get the internal buffers for the sound channel I/O.
PAdaptiveDelay
Class for implementing an "adaptive" delay.
Definition: delaychan.h:52
PShortArray
Array of short integers.
Definition: array.h:589
PSoundChannel::GetChannels
virtual unsigned GetChannels() const
Get the number of channels (mono/stereo) in the sound.
PSoundChannel::GetDeviceNames
static PStringArray GetDeviceNames(const PString &driverName, Directions direction, PPluginManager *pluginMgr=NULL)
Definition: sound.h:302
PSoundChannel::Open
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.
PSoundChannel::IsOpen
virtual PBoolean IsOpen() const
Test if this instance of PSoundChannel is open.
delaychan.h
PSoundChannel::SetBuffers
virtual PBoolean SetBuffers(PINDEX size, PINDEX count=2)
Set the internal buffers for the sound channel I/O.