2012-12-27 16:02:19 +00:00
|
|
|
#include "wave.h"
|
|
|
|
|
|
|
|
int wave_ischunk(const unsigned char *start, const unsigned char *end, size_t *lengthptr)
|
|
|
|
{
|
2012-12-28 20:07:42 +00:00
|
|
|
size_t input_len = (size_t)(end - start);
|
2012-12-27 16:02:19 +00:00
|
|
|
size_t length;
|
|
|
|
|
2012-12-28 20:07:42 +00:00
|
|
|
if (input_len < WAVE_HEADER_SIZE)
|
2012-12-27 16:02:19 +00:00
|
|
|
return 0;
|
2012-12-28 00:53:06 +00:00
|
|
|
|
2012-12-28 20:07:42 +00:00
|
|
|
if (MAGIC(start) != RIFF_MAGIC)
|
2012-12-27 16:02:19 +00:00
|
|
|
return 0;
|
2012-12-28 00:53:06 +00:00
|
|
|
|
|
|
|
length = le32toh(*(const uint32_t *)(start + 4)) + 8;
|
2012-12-27 16:02:19 +00:00
|
|
|
|
2012-12-28 20:07:42 +00:00
|
|
|
if (input_len < length)
|
2012-12-27 16:02:19 +00:00
|
|
|
return 0;
|
2012-12-28 00:53:06 +00:00
|
|
|
|
2012-12-28 20:07:42 +00:00
|
|
|
if (MAGIC(start + 8) != WAVE_MAGIC)
|
2012-12-27 16:02:19 +00:00
|
|
|
return 0;
|
2012-12-28 00:53:06 +00:00
|
|
|
|
2012-12-27 16:02:19 +00:00
|
|
|
if (lengthptr)
|
|
|
|
*lengthptr = length;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int aiff_ischunk(const unsigned char *start, const unsigned char *end, size_t *lengthptr)
|
|
|
|
{
|
2012-12-28 20:07:42 +00:00
|
|
|
size_t input_len = (size_t)(end - start);
|
2012-12-27 16:02:19 +00:00
|
|
|
size_t length;
|
|
|
|
int16_t format;
|
|
|
|
|
2012-12-28 20:07:42 +00:00
|
|
|
if (input_len < WAVE_HEADER_SIZE)
|
2012-12-27 16:02:19 +00:00
|
|
|
return 0;
|
2012-12-28 00:53:06 +00:00
|
|
|
|
2012-12-28 20:07:42 +00:00
|
|
|
if (MAGIC(start) != FORM_MAGIC)
|
2012-12-27 16:02:19 +00:00
|
|
|
return 0;
|
2012-12-28 00:53:06 +00:00
|
|
|
|
|
|
|
length = be32toh(*(const uint32_t *)(start + 4)) + 8;
|
2012-12-27 16:02:19 +00:00
|
|
|
|
2012-12-28 20:07:42 +00:00
|
|
|
if (input_len < length)
|
2012-12-27 16:02:19 +00:00
|
|
|
return 0;
|
2012-12-28 00:53:06 +00:00
|
|
|
|
2012-12-28 20:07:42 +00:00
|
|
|
format = MAGIC(start + 8);
|
2012-12-27 16:02:19 +00:00
|
|
|
if (format != AIFF_MAGIC && format != AIFC_MAGIC)
|
|
|
|
return 0;
|
2012-12-28 00:53:06 +00:00
|
|
|
|
2012-12-27 16:02:19 +00:00
|
|
|
if (lengthptr)
|
|
|
|
*lengthptr = length;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|