00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef _waveheader_h_
00031 #define _waveheader_h_
00032
00033
00034
00035 namespace mxflib
00036 {
00037
00038
00039 class fourcc
00040 {
00041 public:
00042 inline fourcc() { memset( data, 0, 4 ); }
00043 inline fourcc& operator= (const fourcc & s) { memcpy( this->data, s.data, 4); return *this; }
00044 inline fourcc( char *const v ) { memcpy( this->data, v, 4 ); }
00045
00046 private:
00047 char data[4];
00048 };
00049
00050 class LEUint32
00051 {
00052 public:
00053 inline LEUint32() { memset( data, 0, 4 ); }
00054 inline LEUint32& operator= (const LEUint32 & s) { memcpy( this->data, s.data, 4); return *this; }
00055 inline LEUint32( const Uint32 v )
00056 {
00057 Uint32 t = v;
00058 data[0] = (t) & 0xff;
00059 data[1] = (t >>= 8) & 0xff;
00060 data[2] = (t >>= 8) & 0xff;
00061 data[3] = (t >>= 8) & 0xff;
00062 }
00063 inline operator Uint32()
00064 {
00065 Uint32 ret = data[3];
00066 ( ret <<= 8 ) |= data[2];
00067 ( ret <<= 8 ) |= data[1];
00068 ( ret <<= 8 ) |= data[0];
00069 return ret;
00070 }
00071
00072 private:
00073 unsigned char data[4];
00074 };
00075
00076 class LEUint16
00077 {
00078 public:
00079 inline LEUint16() { memset( data, 0, 2 ); }
00080 inline LEUint16& operator= (const LEUint16 & s) { memcpy( this->data, s.data, 2); return *this; }
00081 inline LEUint16( const Uint16 v )
00082 {
00083 Uint16 t = v;
00084 data[0] = (t) & 0xff;
00085 data[1] = (t >>= 8) & 0xff;
00086 }
00087 inline operator Uint16()
00088 {
00089 Uint16 ret = data[1];
00090 ( ret <<= 8 ) |= data[0];
00091 return ret;
00092 }
00093
00094 private:
00095 unsigned char data[2];
00096 };
00097
00098 class waveheader_t
00099 {
00100 public:
00101 fourcc fRIFF;
00102 LEUint32 RIFF_len;
00103 fourcc fWAVE;
00104
00105 fourcc ffmt_;
00106 LEUint32 fmt__len;
00107
00108 LEUint16 format;
00109 LEUint16 nchannels;
00110 LEUint32 samplespersec;
00111 LEUint32 avgbps;
00112 LEUint16 blockalign;
00113 LEUint16 bitspersample;
00114 LEUint16 cbsize;
00115
00116 fourcc data;
00117 LEUint32 data_len;
00118
00119 waveheader_t( Uint16 nc =2, Uint32 sa =48000, Uint16 bi =24 )
00120 {
00121 fRIFF = fourcc( "RIFF" );
00122 fWAVE = fourcc( "WAVE" );
00123
00124 ffmt_ = fourcc( "fmt " );
00125 fmt__len = sizeof( format )
00126 + sizeof( nchannels )
00127 + sizeof( samplespersec )
00128 + sizeof( avgbps )
00129 + sizeof( blockalign )
00130 + sizeof( bitspersample )
00131 + sizeof( cbsize );
00132
00133 format = 1;
00134 nchannels = nc;
00135 samplespersec = sa;
00136 avgbps = sa*nc*((bi+7)/8);
00137 blockalign = nc*((bi+7)/8);
00138 bitspersample = bi;
00139 cbsize = 0;
00140
00141 data = fourcc( "data" );
00142 data_len = 0;
00143
00144 RIFF_len = data_len + sizeof( waveheader_t ) - sizeof( fRIFF ) - sizeof( RIFF_len );
00145 }
00146
00147 void SetDataLength( Uint32 len )
00148 {
00149 data_len = len;
00150 RIFF_len = data_len + sizeof( waveheader_t ) - sizeof( fRIFF ) - sizeof( RIFF_len );
00151 }
00152 };
00153 }
00154
00155 #endif // _waveheader_h_