EMIPLIB

miprawaudiomessage.h

Go to the documentation of this file.
00001 /*
00002     
00003   This file is a part of EMIPLIB, the EDM Media over IP Library.
00004   
00005   Copyright (C) 2006-2011  Hasselt University - Expertise Centre for
00006                       Digital Media (EDM) (http://www.edm.uhasselt.be)
00007 
00008   This library is free software; you can redistribute it and/or
00009   modify it under the terms of the GNU Lesser General Public
00010   License as published by the Free Software Foundation; either
00011   version 2.1 of the License, or (at your option) any later version.
00012 
00013   This library is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016   Lesser General Public License for more details.
00017 
00018   You should have received a copy of the GNU Lesser General Public
00019   License along with this library; if not, write to the Free Software
00020   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  
00021   USA
00022 
00023 */
00024 
00029 #ifndef MIPRAWAUDIOMESSAGE_H
00030 
00031 #define MIPRAWAUDIOMESSAGE_H
00032 
00033 #include "mipconfig.h"
00034 #include "mipaudiomessage.h"
00035 #include "miptime.h"
00036 #include <string.h>
00037 
00065 #define MIPRAWAUDIOMESSAGE_TYPE_FLOAT                                                           0x00000001
00066 #define MIPRAWAUDIOMESSAGE_TYPE_U8                                                              0x00000002
00067 #define MIPRAWAUDIOMESSAGE_TYPE_U16LE                                                           0x00000004
00068 #define MIPRAWAUDIOMESSAGE_TYPE_U16BE                                                           0x00000008
00069 #define MIPRAWAUDIOMESSAGE_TYPE_S16LE                                                           0x00000010
00070 #define MIPRAWAUDIOMESSAGE_TYPE_S16BE                                                           0x00000020
00071 #define MIPRAWAUDIOMESSAGE_TYPE_S16                                                             0x00000040
00072 #define MIPRAWAUDIOMESSAGE_TYPE_U16                                                             0x00000080
00073 
00075 class EMIPLIB_IMPORTEXPORT MIPRawFloatAudioMessage : public MIPAudioMessage
00076 {
00077 public:
00087         MIPRawFloatAudioMessage(int sampRate, int numChannels, int numFrames, float *pFrames, bool deleteFrames) : MIPAudioMessage(true, MIPRAWAUDIOMESSAGE_TYPE_FLOAT, sampRate, numChannels, numFrames)
00088                                                                                                 { m_pFrames = pFrames; m_deleteFrames = deleteFrames; }
00089         ~MIPRawFloatAudioMessage()                                                              { if (m_deleteFrames) delete [] m_pFrames; }
00090 
00092         const float *getFrames() const                                                          { return m_pFrames; }
00093 
00100         void setFrames(float *pFrames, bool deleteFrames)                                       { if (m_deleteFrames) delete [] m_pFrames; m_pFrames = pFrames; m_deleteFrames = deleteFrames; }
00101 
00103         MIPMediaMessage *createCopy() const
00104         {
00105                 size_t numSamples = getNumberOfFrames()*getNumberOfChannels();
00106                 float *pFrames = new float [numSamples];
00107 
00108                 memcpy(pFrames, m_pFrames, numSamples*sizeof(float));
00109                 MIPMediaMessage *pMsg = new MIPRawFloatAudioMessage(getSamplingRate(), getNumberOfChannels(),
00110                                                                     getNumberOfFrames(), pFrames, true);
00111                 pMsg->copyMediaInfoFrom(*this);
00112                 return pMsg;
00113         }
00114 private:
00115         float *m_pFrames;
00116         bool m_deleteFrames;
00117 };
00118 
00120 class EMIPLIB_IMPORTEXPORT MIPRawU8AudioMessage : public MIPAudioMessage
00121 {
00122 public:
00132         MIPRawU8AudioMessage(int sampRate, int numChannels, int numFrames, uint8_t *pFrames, bool deleteFrames) : MIPAudioMessage(true, MIPRAWAUDIOMESSAGE_TYPE_U8, sampRate, numChannels, numFrames)
00133                                                                                                 { m_pFrames = pFrames; m_deleteFrames = deleteFrames; }
00134         ~MIPRawU8AudioMessage()                                                                 { if (m_deleteFrames) delete [] m_pFrames; }
00135 
00137         uint8_t *getFrames() const                                                              { return m_pFrames; }
00138 
00145         void setFrames(uint8_t *pFrames, bool deleteFrames)                                     { if (m_deleteFrames) delete [] m_pFrames; m_pFrames = pFrames; m_deleteFrames = deleteFrames; }
00146         
00148         MIPMediaMessage *createCopy() const
00149         {
00150                 size_t numSamples = getNumberOfFrames()*getNumberOfChannels();
00151                 uint8_t *pFrames = new uint8_t [numSamples];
00152 
00153                 memcpy(pFrames, m_pFrames, numSamples*sizeof(uint8_t));
00154                 MIPMediaMessage *pMsg = new MIPRawU8AudioMessage(getSamplingRate(), getNumberOfChannels(),
00155                                                                  getNumberOfFrames(), pFrames, true);
00156                 pMsg->copyMediaInfoFrom(*this);
00157                 return pMsg;
00158         }
00159 
00160 private:
00161         uint8_t *m_pFrames;
00162         bool m_deleteFrames;
00163 };
00164 
00166 class EMIPLIB_IMPORTEXPORT MIPRaw16bitAudioMessage : public MIPAudioMessage
00167 {
00168 public:
00170         enum SampleEncoding { LittleEndian, BigEndian, Native };
00171 
00183         MIPRaw16bitAudioMessage(int sampRate, int numChannels, int numFrames, bool isSigned, SampleEncoding sampleEncoding, 
00184                                 uint16_t *pFrames, bool deleteFrames) : MIPAudioMessage(true, calcSubtype(isSigned, sampleEncoding), sampRate, numChannels, numFrames)
00185                                                                                                 { m_pFrames = pFrames; m_deleteFrames = deleteFrames; m_isSigned = isSigned; m_sampleEncoding = sampleEncoding; }
00186         ~MIPRaw16bitAudioMessage()                                                              { if (m_deleteFrames) delete [] m_pFrames; }
00187 
00189         uint16_t *getFrames() const                                                             { return m_pFrames; }
00190 
00199         void setFrames(bool isSigned, SampleEncoding sampleEncoding, uint16_t *pFrames, bool deleteFrames)
00200                                                                                                 { if (m_deleteFrames) delete [] m_pFrames; m_pFrames = pFrames; m_deleteFrames = deleteFrames; setMessageSubtype(calcSubtype(isSigned, sampleEncoding)); m_sampleEncoding = sampleEncoding; m_isSigned = isSigned; }
00201 
00203         bool isSigned() const                                                                   { return m_isSigned; }
00204 
00206         bool isBigEndian() const                                                                { return (m_sampleEncoding == BigEndian)?true:false; }
00207         
00209         bool isLittleEndian() const                                                             { return (m_sampleEncoding == LittleEndian)?true:false; }
00210 
00212         bool isNative() const                                                                   { return (m_sampleEncoding == Native)?true:false; }
00213 
00215         SampleEncoding getSampleEncoding() const                                                { return m_sampleEncoding; } 
00216 
00218         MIPMediaMessage *createCopy() const
00219         {
00220                 size_t numSamples = getNumberOfFrames()*getNumberOfChannels();
00221                 uint16_t *pFrames = new uint16_t [numSamples];
00222 
00223                 memcpy(pFrames, m_pFrames, numSamples*sizeof(uint16_t));
00224                 MIPMediaMessage *pMsg = new MIPRaw16bitAudioMessage(getSamplingRate(), getNumberOfChannels(),
00225                                                                     getNumberOfFrames(), m_isSigned, 
00226                                                                     m_sampleEncoding, pFrames, true);
00227                 pMsg->copyMediaInfoFrom(*this);
00228                 return pMsg;
00229         }
00230 private:
00231         static inline uint32_t calcSubtype(bool isSigned, SampleEncoding sampleEncoding)
00232         {
00233                 if (isSigned)
00234                 {
00235                         if (sampleEncoding == BigEndian)
00236                                 return MIPRAWAUDIOMESSAGE_TYPE_S16BE;
00237                         if (sampleEncoding == LittleEndian)
00238                                 return MIPRAWAUDIOMESSAGE_TYPE_S16LE;
00239                         return MIPRAWAUDIOMESSAGE_TYPE_S16;
00240                 }
00241                 if (sampleEncoding == BigEndian)
00242                         return MIPRAWAUDIOMESSAGE_TYPE_U16BE;
00243                 if (sampleEncoding == LittleEndian)
00244                         return MIPRAWAUDIOMESSAGE_TYPE_U16LE;
00245                 return MIPRAWAUDIOMESSAGE_TYPE_U16;
00246         }
00247         
00248         uint16_t *m_pFrames;
00249         bool m_deleteFrames;
00250         bool m_isSigned;
00251         SampleEncoding m_sampleEncoding;
00252 };
00253 
00254 #endif // MIPRAWAUDIOMESSAGE_H
00255