15 #if defined(AJA_LINUX) || defined(AJA_BAREMETAL)
19 #define UINT32_C(x) x##U
28 #if defined(AJA_LITTLE_ENDIAN)
29 #define AjaWavLittleEndianHw
31 #define AjaWavBigEndianHw
34 #define AjaWavSwap16(x) ( ((uint16_t(x) & 0xFF00) >> 8) | \
35 ((uint16_t(x) & 0x00FF) << 8) )
37 #define AjaWavSwap32(x) ( ((uint32_t(x) & 0xFF000000) >> 24) | \
38 ((uint32_t(x) & 0x00FF0000) >> 8) | \
39 ((uint32_t(x) & 0x0000FF00) << 8) | \
40 ((uint32_t(x) & 0x000000FF) << 24) )
42 #define AjaWavSwap64(x) ( ((uint64_t(x) & 0xFF00000000000000ULL) >> 56) | \
43 ((uint64_t(x) & 0x00FF000000000000ULL) >> 40) | \
44 ((uint64_t(x) & 0x0000FF0000000000ULL) >> 24) | \
45 ((uint64_t(x) & 0x000000FF00000000ULL) >> 8) | \
46 ((uint64_t(x) & 0x00000000FF000000ULL) << 8) | \
47 ((uint64_t(x) & 0x0000000000FF0000ULL) << 24) | \
48 ((uint64_t(x) & 0x000000000000FF00ULL) << 40) | \
49 ((uint64_t(x) & 0x00000000000000FFULL) << 56) )
51 #ifdef AjaWavBigEndianHw
52 #define AjaWavBigEndian16(x) (x)
53 #define AjaWavLittleEndian16(x) AjaWavSwap16(x)
54 #define AjaWavBigEndian32(x) (x)
55 #define AjaWavLittleEndian32(x) AjaWavSwap32(x)
56 #define AjaWavBigEndian64(x) (x)
57 #define AjaWavLittleEndian64(x) AjaWavSwap64(x)
59 #define AjaWavLittleEndian16(x) (x)
60 #define AjaWavBigEndian16(x) AjaWavSwap16(x)
61 #define AjaWavLittleEndian32(x) (x)
62 #define AjaWavBigEndian32(x) AjaWavSwap32(x)
63 #define AjaWavLittleEndian64(x) (x)
64 #define AjaWavBigEndian64(x) AjaWavSwap64(x)
70 time_t now = time(
NULL);
71 struct tm lcl = *localtime(&now);
72 ::strftime(tmp,16,
"%Y:%m:%d",&lcl);
73 formattedDate.assign(tmp);
75 ::strftime(tmp,16,
"%H:%M:%S",&lcl);
76 formattedTime.assign(tmp);
82 :
AJAFileIO(), mFileName(name), mAudioFormat(audioFormat), mVideoFormat(videoFormat), mStartTimecode(startTimecode), mFlags(flags), mLittleEndian(
true),
83 mUseFloatData(useFloatNotPCM)
120 return writeRawData(data,len);
123 uint32_t AJAWavWriter::writeRawData(
const char* data,uint32_t len)
125 return writeRawData((
char*)data,len);
128 uint32_t AJAWavWriter::writeRawData(
char* data,uint32_t len)
130 return Write((uint8_t*)data,len);
133 uint32_t AJAWavWriter::writeRaw_uint8_t(uint8_t value, uint32_t count)
135 uint32_t bytesWritten = 0;
137 for(uint32_t i=0;i<count;i++)
139 bytesWritten +=
Write(&value,1);
145 uint32_t AJAWavWriter::writeRaw_uint16_t(uint16_t value, uint32_t count)
147 uint32_t bytesWritten = 0;
154 for(uint32_t i=0;i<count;i++)
156 bytesWritten +=
Write((uint8_t*)&value,
sizeof(uint16_t));
162 uint32_t AJAWavWriter::writeRaw_uint32_t(uint32_t value, uint32_t count)
164 uint32_t bytesWritten = 0;
171 for(uint32_t i=0;i<count;i++)
173 bytesWritten +=
Write((uint8_t*)&value,
sizeof(uint32_t));
179 void AJAWavWriter::writeHeader()
181 mLittleEndian =
true;
186 wtn += writeRawData(
"RIFF", 4);
187 wtn += writeRaw_uint32_t(0);
188 wtn += writeRawData(
"WAVE", 4);
201 if(scale == 24000 && duration == 1001)
209 uint64_t frames = tc.QueryFrame();
210 uint64_t numAudioSamplesPerSecond = tb.FramesToSamples(frames);
212 uint32_t startSequenceTcLow = numAudioSamplesPerSecond & 0x00000000FFFFFFFF;
213 uint32_t startSequenceTcHigh = numAudioSamplesPerSecond >> 32;
215 std::string formattedDate;
216 std::string formattedTime;
220 memset(emptyBuf,0,256);
222 wtn += writeRawData(
"bext",4);
223 wtn += writeRaw_uint32_t(602);
224 wtn += writeRawData(emptyBuf,256);
225 wtn += writeRawData(emptyBuf,32);
226 wtn += writeRawData(emptyBuf,32);
227 wtn += writeRawData(formattedDate.c_str(),10);
228 wtn += writeRawData(formattedTime.c_str(),8);
229 wtn += writeRaw_uint32_t(startSequenceTcLow);
230 wtn += writeRaw_uint32_t(startSequenceTcHigh);
231 wtn += writeRaw_uint16_t(1);
232 wtn += writeRaw_uint8_t(0,64);
233 wtn += writeRaw_uint8_t(0,190);
237 wtn += writeRawData(
"fmt ", 4);
238 wtn += writeRaw_uint32_t(16);
244 wtn += writeRaw_uint16_t(audioFormat);
246 wtn += writeRaw_uint32_t(mAudioFormat.
sampleRate);
249 wtn += writeRaw_uint16_t(mAudioFormat.
sampleSize);
252 wtn += writeRawData(
"data", 4);
253 wtn += writeRaw_uint32_t(0);
255 assert(
Tell() == mSizeOfHeader);
261 uint32_t fileSize = (uint32_t)
Tell();
263 mLittleEndian =
true;
271 writeRaw_uint32_t(fileSize - mSizeOfHeader);