MCPcopy Create free account
hub / github.com/TheForceEngine/TheForceEngine / parseVoc

Function parseVoc

TheForceEngine/TFE_Asset/vocAsset.cpp:222–296  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

220 }
221
222 bool parseVoc(SoundBuffer* voc, u8* buffer)
223 {
224 memset(voc, 0, sizeof(SoundBuffer));
225 voc->type = SOUND_DATA_8BIT;
226
227 // Read the header.
228 u8* readBuffer = buffer;
229 VocHeader* header = (VocHeader*)readBuffer;
230 readBuffer += sizeof(VocHeader);
231
232 // Parse blocks.
233 readBuffer = buffer + header->datablockOffset;
234 while (1)
235 {
236 const BlockType type = BlockType(*readBuffer); readBuffer++;
237 // Break if this is the final block.
238 if (type == VOC_TERMINATOR || type > VOC_END_REPEAT) { break; }
239
240 // All other blocks have a 3 byte size (up to 16MB).
241 const u32 blockLen = readBuffer[0] | (readBuffer[1] << 8u) | (readBuffer[2] << 16u);
242 readBuffer += 3;
243 // Block parsing.
244 switch (type)
245 {
246 case VOC_SOUND_DATA:
247 {
248 const s32 sampleRate = 1000000 / (256 - (s32)readBuffer[0]);
249 const u8 codec = readBuffer[1];
250 const u8* soundData = &readBuffer[2];
251 addSoundData(voc, sampleRate, codec, soundData, blockLen - 2);
252 } break;
253 case VOC_SOUND_CONTINUE:
254 {
255 const u8* soundData = &readBuffer[2];
256 continueSoundData(voc, soundData, blockLen);
257 } break;
258 case VOC_SILENCE:
259 {
260 const u16 silenceLen = *((u16*)readBuffer);
261 const s32 sampleRate = 1000000 / (256 - (s32)readBuffer[2]);
262 addSilence(voc, sampleRate, silenceLen);
263 } break;
264 case VOC_MARKER:
265 {
266 const u16 markerId = *((u16*)readBuffer);
267 addMarker(voc, markerId);
268 } break;
269 case VOC_ASCII:
270 {
271 // The string is ignored.
272 } break;
273 case VOC_REPEAT:
274 {
275 const u16 repeatCount = *((u16*)readBuffer);
276 loopStart(voc, repeatCount);
277 } break;
278 case VOC_END_REPEAT:
279 {

Callers 2

getFunction · 0.85
getIndexFunction · 0.85

Calls 10

BlockTypeEnum · 0.85
addSoundDataFunction · 0.85
continueSoundDataFunction · 0.85
addSilenceFunction · 0.85
addMarkerFunction · 0.85
loopStartFunction · 0.85
loopEndFunction · 0.85
dataMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected