diff options
author | Henri Herscher <henri@oreka.org> | 2006-01-20 22:47:56 +0000 |
---|---|---|
committer | Henri Herscher <henri@oreka.org> | 2006-01-20 22:47:56 +0000 |
commit | e918c412e63769d1db155e1314bb384e092216ec (patch) | |
tree | 7597fcbe70de51963f03fd50668420a2069030f0 /orkbasecxx/AudioCapture.h | |
parent | e07f34274b8912f773993ed96624242115440a3b (diff) |
AudioChunks now contain a "details" class that can be easily serializable.
git-svn-id: https://oreka.svn.sourceforge.net/svnroot/oreka/trunk@121 09dcff7a-b715-0410-9601-b79a96267cd0
Diffstat (limited to 'orkbasecxx/AudioCapture.h')
-rw-r--r-- | orkbasecxx/AudioCapture.h | 64 |
1 files changed, 47 insertions, 17 deletions
diff --git a/orkbasecxx/AudioCapture.h b/orkbasecxx/AudioCapture.h index 41b6130..4e6a53c 100644 --- a/orkbasecxx/AudioCapture.h +++ b/orkbasecxx/AudioCapture.h @@ -20,25 +20,52 @@ #include "boost/shared_ptr.hpp" -/** This class represents a piece of audio. -*/ + +typedef enum +{ + UnknownAudio = 0, + PcmAudio = 1, + AlawAudio = 2, + UlawAudio = 3, + InvalidAudio = 4 +} AudioEncodingEnum; + +/** + * Serialization friendly details struct + */ +#define MEDIA_CHUNK_MARKER 0x2A2A2A2A // corresponds to "****" + +class DLL_IMPORT_EXPORT AudioChunkDetails +{ +public: + AudioChunkDetails(); + void Clear(); + + int m_marker; + AudioEncodingEnum m_encoding; + unsigned int m_numBytes; + unsigned int m_timestamp; // usually relative timestamp measured in samples + unsigned int m_arrivalTimestamp; // usually unix timestamp of arrival + unsigned int m_sequenceNumber; + unsigned int m_sampleRate; + char m_rtpPayloadType; // -1 if none + unsigned char m_channel; // 0 if mono, 1 or 2 if stereo +}; + +/** + * This class represents a piece of audio. + */ class DLL_IMPORT_EXPORT AudioChunk { public: - typedef enum - { - UnknownAudio = 0, - PcmAudio = 1, - AlawAudio = 2, - UlawAudio = 3, - InvalidAudio = 4 - } AudioEncodingEnum; - AudioChunk(); ~AudioChunk(); + /** Allocate a new empty buffer */ + void* CreateBuffer(size_t numBytes, AudioChunkDetails& details); + /** Copy external buffer to internal buffer. Create internal buffer if necessary */ - void SetBuffer(void* pBuffer, size_t numBytes, AudioEncodingEnum, unsigned int timestamp = 0, unsigned int sequenceNumber = 0, unsigned int sampleRate = 8000); + void SetBuffer(void* pBuffer, size_t numBytes, AudioChunkDetails& details); /** Computes the Root-Mean-Square power value of the buffer */ double ComputeRms(); @@ -46,14 +73,17 @@ public: double ComputeRmsDb(); int GetNumSamples(); + int GetNumBytes(); + int GetSampleRate(); double GetDurationSec(); + AudioEncodingEnum GetEncoding(); + AudioChunkDetails* GetDetails(); + void SetDetails(AudioChunkDetails* details); - AudioEncodingEnum m_encoding; - unsigned int m_numBytes; void * m_pBuffer; - unsigned int m_timestamp; // usually: relative timestamp measured in samples - unsigned int m_sequenceNumber; - unsigned int m_sampleRate; + +private: + AudioChunkDetails m_details; }; typedef boost::shared_ptr<AudioChunk> AudioChunkRef; |