340 |
340 |
return true;
|
341 |
341 |
}
|
342 |
342 |
|
|
343 |
/* Function to see if WAV file contains embedded DTS format (contains a DTS header):
|
|
344 |
(Borrowed & modified from: https://hydrogenaud.io/index.php?PHPSESSID=0r361d02rgjc1uo2evsr91acue&action=dlattach;topic=94988.0;attach=10766)
|
|
345 |
(See Reply# 19 in: https://hydrogenaud.io/index.php?topic=94988.0)
|
|
346 |
Function returns FALSE if DTS header found (DTS-WAV file which libsndfile accepts but can't play).
|
|
347 |
*/
|
|
348 |
bool SearchForDTSHeader (VFSFile & file) {
|
|
349 |
unsigned int i;
|
|
350 |
unsigned char next6bytes[7];
|
|
351 |
unsigned long ScanSize = file.fsize () - 12;
|
|
352 |
|
|
353 |
if (ScanSize > 99999)
|
|
354 |
ScanSize = 99999; /* Limit search to first 99999 bytes, per original program. */
|
|
355 |
|
|
356 |
for (i=0; i<ScanSize; i++) {
|
|
357 |
if (file.fseek ((long)i, VFS_SEEK_SET) < 0)
|
|
358 |
return true; /* Couldn't seek, so assume NOT DTS. */
|
|
359 |
|
|
360 |
if (file.fread (next6bytes, 6, 1))
|
|
361 |
{
|
|
362 |
if (next6bytes[0] == 0xFF && next6bytes[1] == 0x1F
|
|
363 |
&& next6bytes[2] == 0x00
|
|
364 |
&& next6bytes[3] == 0xE8
|
|
365 |
&& (next6bytes[4] & 0xF0) == 0xF0
|
|
366 |
&& next6bytes[5] == 0x07)
|
|
367 |
return false; /* Header found (we're DTS format embedded in a WAV file), let ffaudio handle! */
|
|
368 |
}
|
|
369 |
else
|
|
370 |
return true; /* Couldn't read enough, so assume NOT DTS. */
|
|
371 |
}
|
|
372 |
return true; /* We're a standard WAV file, so handle ourselves. */
|
|
373 |
}
|
|
374 |
|
343 |
375 |
bool SndfilePlugin::is_our_file (const char * filename, VFSFile & file)
|
344 |
376 |
{
|
|
377 |
bool ok = true;
|
345 |
378 |
SF_INFO tmp_sfinfo {}; // must be zeroed before sf_open()
|
346 |
379 |
|
347 |
|
/* Have to open the file to see if libsndfile can handle it. */
|
|
380 |
/* Have to open the file virtually as a sndfile to see if libsndfile can handle it. */
|
348 |
381 |
bool stream = (file.fsize () < 0);
|
349 |
382 |
SNDFILE * tmp_sndfile = sf_open_virtual (stream ? & sf_virtual_io_stream :
|
350 |
383 |
& sf_virtual_io, SFM_READ, & tmp_sfinfo, & file);
|
351 |
384 |
|
352 |
|
if (!tmp_sndfile)
|
|
385 |
if (! tmp_sndfile)
|
353 |
386 |
return false;
|
354 |
387 |
|
355 |
|
/* It can so close file and return true. */
|
|
388 |
if (file.fsize () > 12) /* We're not a stream, so check if DTS, if so, punt to ffaudio!: */
|
|
389 |
ok = SearchForDTSHeader (file);
|
|
390 |
|
|
391 |
/* It can so close file and return true (unless embedded DTS). */
|
356 |
392 |
sf_close (tmp_sndfile);
|
357 |
393 |
tmp_sndfile = nullptr;
|
358 |
394 |
|
359 |
|
return true;
|
|
395 |
return ok;
|
360 |
396 |
}
|
361 |
397 |
|
362 |
398 |
const char SndfilePlugin::about[] =
|