Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #pragma once
00024
00025 #include "cinder/Cinder.h"
00026 #include "cinder/Exception.h"
00027 #include <vector>
00028 #include <boost/preprocessor/seq.hpp>
00029
00030 namespace cinder { namespace audio {
00031
00032 typedef enum ChannelIdentifier {
00033 CHANNEL_FRONT_LEFT = 0,
00034 CHANNEL_FRONT_RIGHT = 1
00035 } ChannelIdentifier;
00036
00037 template<typename T>
00038 struct BufferT {
00039 uint32_t mNumberChannels;
00040 uint32_t mDataByteSize;
00041 uint32_t mSampleCount;
00042 T * mData;
00043 };
00044
00045 typedef BufferT<void> BufferGeneric;
00046 typedef BufferT<uint8_t> Buffer8u;
00047 typedef BufferT<int8_t> Buffer8i;
00048 typedef BufferT<uint16_t> Buffer16u;
00049 typedef BufferT<int16_t> Buffer16i;
00050 typedef BufferT<int32_t> Buffer32i;
00051 typedef BufferT<uint32_t> Buffer32u;
00052 typedef BufferT<float> Buffer32f;
00053
00054 typedef std::shared_ptr<BufferT<float> > Buffer32fRef;
00055
00056 template<typename T>
00057 struct BufferListT {
00058 uint32_t mNumberBuffers;
00059 BufferT<T> * mBuffers;
00060 };
00061
00062 typedef BufferListT<void> BufferList;
00063 typedef BufferListT<float> BufferList32f;
00064
00065 typedef std::shared_ptr<BufferList32f> BufferList32fRef;
00066
00067 template<typename T>
00068 class PcmBufferT {
00069 public:
00070 PcmBufferT( uint32_t aMaxSampleCount, uint16_t aChannelCount, bool isInterleaved );
00071 ~PcmBufferT();
00072
00073 uint32_t getSampleCount( ChannelIdentifier channelId = CHANNEL_FRONT_LEFT ) const { return mBufferSampleCounts[channelId]; }
00074 uint32_t getMaxSampleCount() const { return mMaxSampleCount; }
00075 uint16_t getChannelCount() const { return mChannelCount; }
00076 bool isInterleaved() const { return mIsInterleaved; }
00077
00078 std::shared_ptr<BufferT<T> > getChannelData( ChannelIdentifier channelId ) const;
00079 std::shared_ptr<BufferT<T> > getInterleavedData() const;
00080
00081
00082
00083 void appendInterleavedData( T * aData, uint32_t aSampleCount );
00084 void appendChannelData( T * aData, uint32_t aSampleCount, ChannelIdentifier channelId );
00085 private:
00086 std::vector<std::shared_ptr<BufferT<T> > > mBuffers;
00087
00088 uint16_t mBufferCount;
00089 uint32_t * mBufferSampleCounts;
00090 uint32_t mMaxSampleCount;
00091 uint16_t mChannelCount;
00092 bool mIsInterleaved;
00093 };
00094
00095 typedef PcmBufferT<float> PcmBuffer32f;
00096
00097 typedef std::shared_ptr<PcmBuffer32f> PcmBuffer32fRef;
00098
00099 class PcmBufferException : public Exception {
00100 };
00101
00102 class InvalidChannelPcmBufferException : public PcmBufferException {
00103 };
00104
00105 class OutOfRangePcmBufferException : public PcmBufferException {
00106 };
00107
00108 inline void silenceBuffers( BufferList * aBufferList )
00109 {
00110 for( uint32_t i = 0; i < aBufferList->mNumberBuffers; i++ ) {
00111 memset( aBufferList->mBuffers[i].mData, 0, aBufferList->mBuffers[i].mDataByteSize );
00112 }
00113 }
00114
00115 template<typename T>
00116 void deleteBuffer( BufferT<T> * aBuffer );
00117
00118 template<typename T>
00119 std::shared_ptr<BufferListT<T> > createBufferList( uint32_t sampleCount, uint16_t channelCount, bool isInterleaved );
00120
00121 template<typename T>
00122 void deleteBufferList( BufferListT<T> * aBufferList );
00123
00124 #define AUDIO_DATA_TYPES (uint8_t)(int16_t)(int32_t)(float)
00125
00126 }}