123#define DRWAV_STRINGIFY(x) #x
124#define DRWAV_XSTRINGIFY(x) DRWAV_STRINGIFY(x)
126#define DRWAV_VERSION_MAJOR 0
127#define DRWAV_VERSION_MINOR 13
128#define DRWAV_VERSION_REVISION 4
129#define DRWAV_VERSION_STRING DRWAV_XSTRINGIFY(DRWAV_VERSION_MAJOR) "." DRWAV_XSTRINGIFY(DRWAV_VERSION_MINOR) "." DRWAV_XSTRINGIFY(DRWAV_VERSION_REVISION)
140#if defined(_MSC_VER) && !defined(__clang__)
144 #if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)))
145 #pragma GCC diagnostic push
146 #pragma GCC diagnostic ignored "-Wlong-long"
147 #if defined(__clang__)
148 #pragma GCC diagnostic ignored "-Wc++11-long-long"
153 #if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)))
154 #pragma GCC diagnostic pop
157#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(_M_ARM64) || defined(__powerpc64__)
167#if !defined(DRWAV_API)
168 #if defined(DRWAV_DLL)
170 #define DRWAV_DLL_IMPORT __declspec(dllimport)
171 #define DRWAV_DLL_EXPORT __declspec(dllexport)
172 #define DRWAV_DLL_PRIVATE static
174 #if defined(__GNUC__) && __GNUC__ >= 4
175 #define DRWAV_DLL_IMPORT __attribute__((visibility("default")))
176 #define DRWAV_DLL_EXPORT __attribute__((visibility("default")))
177 #define DRWAV_DLL_PRIVATE __attribute__((visibility("hidden")))
179 #define DRWAV_DLL_IMPORT
180 #define DRWAV_DLL_EXPORT
181 #define DRWAV_DLL_PRIVATE static
185 #if defined(DR_WAV_IMPLEMENTATION) || defined(DRWAV_IMPLEMENTATION)
186 #define DRWAV_API DRWAV_DLL_EXPORT
188 #define DRWAV_API DRWAV_DLL_IMPORT
190 #define DRWAV_PRIVATE DRWAV_DLL_PRIVATE
192 #define DRWAV_API extern
193 #define DRWAV_PRIVATE static
198#define DRWAV_SUCCESS 0
199#define DRWAV_ERROR -1
200#define DRWAV_INVALID_ARGS -2
201#define DRWAV_INVALID_OPERATION -3
202#define DRWAV_OUT_OF_MEMORY -4
203#define DRWAV_OUT_OF_RANGE -5
204#define DRWAV_ACCESS_DENIED -6
205#define DRWAV_DOES_NOT_EXIST -7
206#define DRWAV_ALREADY_EXISTS -8
207#define DRWAV_TOO_MANY_OPEN_FILES -9
208#define DRWAV_INVALID_FILE -10
209#define DRWAV_TOO_BIG -11
210#define DRWAV_PATH_TOO_LONG -12
211#define DRWAV_NAME_TOO_LONG -13
212#define DRWAV_NOT_DIRECTORY -14
213#define DRWAV_IS_DIRECTORY -15
214#define DRWAV_DIRECTORY_NOT_EMPTY -16
215#define DRWAV_END_OF_FILE -17
216#define DRWAV_NO_SPACE -18
217#define DRWAV_BUSY -19
218#define DRWAV_IO_ERROR -20
219#define DRWAV_INTERRUPT -21
220#define DRWAV_UNAVAILABLE -22
221#define DRWAV_ALREADY_IN_USE -23
222#define DRWAV_BAD_ADDRESS -24
223#define DRWAV_BAD_SEEK -25
224#define DRWAV_BAD_PIPE -26
225#define DRWAV_DEADLOCK -27
226#define DRWAV_TOO_MANY_LINKS -28
227#define DRWAV_NOT_IMPLEMENTED -29
228#define DRWAV_NO_MESSAGE -30
229#define DRWAV_BAD_MESSAGE -31
230#define DRWAV_NO_DATA_AVAILABLE -32
231#define DRWAV_INVALID_DATA -33
232#define DRWAV_TIMEOUT -34
233#define DRWAV_NO_NETWORK -35
234#define DRWAV_NOT_UNIQUE -36
235#define DRWAV_NOT_SOCKET -37
236#define DRWAV_NO_ADDRESS -38
237#define DRWAV_BAD_PROTOCOL -39
238#define DRWAV_PROTOCOL_UNAVAILABLE -40
239#define DRWAV_PROTOCOL_NOT_SUPPORTED -41
240#define DRWAV_PROTOCOL_FAMILY_NOT_SUPPORTED -42
241#define DRWAV_ADDRESS_FAMILY_NOT_SUPPORTED -43
242#define DRWAV_SOCKET_NOT_SUPPORTED -44
243#define DRWAV_CONNECTION_RESET -45
244#define DRWAV_ALREADY_CONNECTED -46
245#define DRWAV_NOT_CONNECTED -47
246#define DRWAV_CONNECTION_REFUSED -48
247#define DRWAV_NO_HOST -49
248#define DRWAV_IN_PROGRESS -50
249#define DRWAV_CANCELLED -51
250#define DRWAV_MEMORY_ALREADY_MAPPED -52
251#define DRWAV_AT_END -53
254#define DR_WAVE_FORMAT_PCM 0x1
255#define DR_WAVE_FORMAT_ADPCM 0x2
256#define DR_WAVE_FORMAT_IEEE_FLOAT 0x3
257#define DR_WAVE_FORMAT_ALAW 0x6
258#define DR_WAVE_FORMAT_MULAW 0x7
259#define DR_WAVE_FORMAT_DVI_ADPCM 0x11
260#define DR_WAVE_FORMAT_EXTENSIBLE 0xFFFE
263#define DRWAV_SEQUENTIAL 0x00000001
354typedef size_t (*
drwav_read_proc)(
void* pUserData,
void* pBufferOut,
size_t bytesToRead);
367typedef size_t (*
drwav_write_proc)(
void* pUserData,
const void* pData,
size_t bytesToWrite);
412 void* (* onMalloc)(
size_t sz,
void* pUserData);
413 void* (* onRealloc)(
void* p,
size_t sz,
void* pUserData);
414 void (* onFree)(
void* p,
void* pUserData);
689 char pOriginationDate[10];
690 char pOriginationTime[8];
1066#ifndef DR_WAV_NO_CONVERSION_API
1177#ifndef DR_WAV_NO_STDIO
1233#ifndef DR_WAV_NO_CONVERSION_API
1242#ifndef DR_WAV_NO_STDIO
1296#if defined(DR_WAV_IMPLEMENTATION) || defined(DRWAV_IMPLEMENTATION)
1304#ifndef DR_WAV_NO_STDIO
1312#define DRWAV_ASSERT(expression) assert(expression)
1315#define DRWAV_MALLOC(sz) malloc((sz))
1317#ifndef DRWAV_REALLOC
1318#define DRWAV_REALLOC(p, sz) realloc((p), (sz))
1321#define DRWAV_FREE(p) free((p))
1323#ifndef DRWAV_COPY_MEMORY
1324#define DRWAV_COPY_MEMORY(dst, src, sz) memcpy((dst), (src), (sz))
1326#ifndef DRWAV_ZERO_MEMORY
1327#define DRWAV_ZERO_MEMORY(p, sz) memset((p), 0, (sz))
1329#ifndef DRWAV_ZERO_OBJECT
1330#define DRWAV_ZERO_OBJECT(p) DRWAV_ZERO_MEMORY((p), sizeof(*p))
1333#define drwav_countof(x) (sizeof(x) / sizeof(x[0]))
1334#define drwav_align(x, a) ((((x) + (a) - 1) / (a)) * (a))
1335#define drwav_min(a, b) (((a) < (b)) ? (a) : (b))
1336#define drwav_max(a, b) (((a) > (b)) ? (a) : (b))
1337#define drwav_clamp(x, lo, hi) (drwav_max((lo), drwav_min((hi), (x))))
1338#define drwav_offset_ptr(p, offset) (((drwav_uint8*)(p)) + (offset))
1340#define DRWAV_MAX_SIMD_VECTOR_SIZE 64
1343#if defined(__x86_64__) || defined(_M_X64)
1345#elif defined(__i386) || defined(_M_IX86)
1347#elif defined(__arm__) || defined(_M_ARM)
1352 #define DRWAV_INLINE __forceinline
1353#elif defined(__GNUC__)
1361 #if defined(__STRICT_ANSI__)
1362 #define DRWAV_INLINE __inline__ __attribute__((always_inline))
1364 #define DRWAV_INLINE inline __attribute__((always_inline))
1366#elif defined(__WATCOMC__)
1367 #define DRWAV_INLINE __inline
1369 #define DRWAV_INLINE
1372#if defined(SIZE_MAX)
1373 #define DRWAV_SIZE_MAX SIZE_MAX
1375 #if defined(_WIN64) || defined(_LP64) || defined(__LP64__)
1376 #define DRWAV_SIZE_MAX ((drwav_uint64)0xFFFFFFFFFFFFFFFF)
1378 #define DRWAV_SIZE_MAX 0xFFFFFFFF
1382#if defined(_MSC_VER) && _MSC_VER >= 1400
1383 #define DRWAV_HAS_BYTESWAP16_INTRINSIC
1384 #define DRWAV_HAS_BYTESWAP32_INTRINSIC
1385 #define DRWAV_HAS_BYTESWAP64_INTRINSIC
1386#elif defined(__clang__)
1387 #if defined(__has_builtin)
1388 #if __has_builtin(__builtin_bswap16)
1389 #define DRWAV_HAS_BYTESWAP16_INTRINSIC
1391 #if __has_builtin(__builtin_bswap32)
1392 #define DRWAV_HAS_BYTESWAP32_INTRINSIC
1394 #if __has_builtin(__builtin_bswap64)
1395 #define DRWAV_HAS_BYTESWAP64_INTRINSIC
1398#elif defined(__GNUC__)
1399 #if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
1400 #define DRWAV_HAS_BYTESWAP32_INTRINSIC
1401 #define DRWAV_HAS_BYTESWAP64_INTRINSIC
1403 #if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))
1404 #define DRWAV_HAS_BYTESWAP16_INTRINSIC
1432#ifndef DRWAV_MAX_SAMPLE_RATE
1433#define DRWAV_MAX_SAMPLE_RATE 384000
1435#ifndef DRWAV_MAX_CHANNELS
1436#define DRWAV_MAX_CHANNELS 256
1438#ifndef DRWAV_MAX_BITS_PER_SAMPLE
1439#define DRWAV_MAX_BITS_PER_SAMPLE 64
1442static const drwav_uint8 drwavGUID_W64_RIFF[16] = {0x72,0x69,0x66,0x66, 0x2E,0x91, 0xCF,0x11, 0xA5,0xD6, 0x28,0xDB,0x04,0xC1,0x00,0x00};
1443static const drwav_uint8 drwavGUID_W64_WAVE[16] = {0x77,0x61,0x76,0x65, 0xF3,0xAC, 0xD3,0x11, 0x8C,0xD1, 0x00,0xC0,0x4F,0x8E,0xDB,0x8A};
1445static const drwav_uint8 drwavGUID_W64_FMT [16] = {0x66,0x6D,0x74,0x20, 0xF3,0xAC, 0xD3,0x11, 0x8C,0xD1, 0x00,0xC0,0x4F,0x8E,0xDB,0x8A};
1446static const drwav_uint8 drwavGUID_W64_FACT[16] = {0x66,0x61,0x63,0x74, 0xF3,0xAC, 0xD3,0x11, 0x8C,0xD1, 0x00,0xC0,0x4F,0x8E,0xDB,0x8A};
1447static const drwav_uint8 drwavGUID_W64_DATA[16] = {0x64,0x61,0x74,0x61, 0xF3,0xAC, 0xD3,0x11, 0x8C,0xD1, 0x00,0xC0,0x4F,0x8E,0xDB,0x8A};
1451static DRWAV_INLINE
int drwav__is_little_endian(
void)
1453#if defined(DRWAV_X86) || defined(DRWAV_X64)
1455#elif defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN
1459 return (*(
char*)&n) == 1;
1467 for (i = 0; i < 16; ++i) {
1475#ifdef DRWAV_HAS_BYTESWAP16_INTRINSIC
1476 #if defined(_MSC_VER)
1477 return _byteswap_ushort(n);
1478 #elif defined(__GNUC__) || defined(__clang__)
1479 return __builtin_bswap16(n);
1481 #error "This compiler does not support the byte swap intrinsic."
1484 return ((n & 0xFF00) >> 8) |
1485 ((n & 0x00FF) << 8);
1491#ifdef DRWAV_HAS_BYTESWAP32_INTRINSIC
1492 #if defined(_MSC_VER)
1493 return _byteswap_ulong(n);
1494 #elif defined(__GNUC__) || defined(__clang__)
1495 #if defined(DRWAV_ARM) && (defined(__ARM_ARCH) && __ARM_ARCH >= 6) && !defined(DRWAV_64BIT)
1498 __asm__ __volatile__ (
1499 #
if defined(DRWAV_64BIT)
1500 "rev %w[out], %w[in]" : [out]
"=r"(r) : [in]
"r"(n)
1502 "rev %[out], %[in]" : [out]
"=r"(r) : [in]
"r"(n)
1507 return __builtin_bswap32(n);
1510 #error "This compiler does not support the byte swap intrinsic."
1513 return ((n & 0xFF000000) >> 24) |
1514 ((n & 0x00FF0000) >> 8) |
1515 ((n & 0x0000FF00) << 8) |
1516 ((n & 0x000000FF) << 24);
1522#ifdef DRWAV_HAS_BYTESWAP64_INTRINSIC
1523 #if defined(_MSC_VER)
1524 return _byteswap_uint64(n);
1525 #elif defined(__GNUC__) || defined(__clang__)
1526 return __builtin_bswap64(n);
1528 #error "This compiler does not support the byte swap intrinsic."
1532 return ((n & ((
drwav_uint64)0xFF000000 << 32)) >> 56) |
1552 for (iSample = 0; iSample < sampleCount; iSample += 1) {
1553 pSamples[iSample] = drwav__bswap_s16(pSamples[iSample]);
1558static DRWAV_INLINE
void drwav__bswap_s24(
drwav_uint8* p)
1569 for (iSample = 0; iSample < sampleCount; iSample += 1) {
1571 drwav__bswap_s24(pSample);
1584 for (iSample = 0; iSample < sampleCount; iSample += 1) {
1585 pSamples[iSample] = drwav__bswap_s32(pSamples[iSample]);
1590static DRWAV_INLINE
float drwav__bswap_f32(
float n)
1597 x.i = drwav__bswap32(x.i);
1602static DRWAV_INLINE
void drwav__bswap_samples_f32(
float* pSamples,
drwav_uint64 sampleCount)
1605 for (iSample = 0; iSample < sampleCount; iSample += 1) {
1606 pSamples[iSample] = drwav__bswap_f32(pSamples[iSample]);
1611static DRWAV_INLINE
double drwav__bswap_f64(
double n)
1618 x.i = drwav__bswap64(x.i);
1623static DRWAV_INLINE
void drwav__bswap_samples_f64(
double* pSamples,
drwav_uint64 sampleCount)
1626 for (iSample = 0; iSample < sampleCount; iSample += 1) {
1627 pSamples[iSample] = drwav__bswap_f64(pSamples[iSample]);
1632static DRWAV_INLINE
void drwav__bswap_samples_pcm(
void* pSamples,
drwav_uint64 sampleCount,
drwav_uint32 bytesPerSample)
1635 switch (bytesPerSample)
1643 drwav__bswap_samples_s16((
drwav_int16*)pSamples, sampleCount);
1647 drwav__bswap_samples_s24((
drwav_uint8*)pSamples, sampleCount);
1651 drwav__bswap_samples_s32((
drwav_int32*)pSamples, sampleCount);
1661static DRWAV_INLINE
void drwav__bswap_samples_ieee(
void* pSamples,
drwav_uint64 sampleCount,
drwav_uint32 bytesPerSample)
1663 switch (bytesPerSample)
1668 drwav__bswap_samples_f16((drwav_float16*)pSamples, sampleCount);
1673 drwav__bswap_samples_f32((
float*)pSamples, sampleCount);
1677 drwav__bswap_samples_f64((
double*)pSamples, sampleCount);
1693 drwav__bswap_samples_pcm(pSamples, sampleCount, bytesPerSample);
1698 drwav__bswap_samples_ieee(pSamples, sampleCount, bytesPerSample);
1704 drwav__bswap_samples_s16((
drwav_int16*)pSamples, sampleCount);
1718DRWAV_PRIVATE void* drwav__malloc_default(
size_t sz,
void* pUserData)
1724DRWAV_PRIVATE void* drwav__realloc_default(
void* p,
size_t sz,
void* pUserData)
1730DRWAV_PRIVATE void drwav__free_default(
void* p,
void* pUserData)
1739 if (pAllocationCallbacks ==
NULL) {
1757 if (pAllocationCallbacks ==
NULL) {
1775 DRWAV_COPY_MEMORY(p2, p, szOld);
1787 if (p ==
NULL || pAllocationCallbacks ==
NULL) {
1799 if (pAllocationCallbacks !=
NULL) {
1801 return *pAllocationCallbacks;
1806 allocationCallbacks.
onMalloc = drwav__malloc_default;
1807 allocationCallbacks.
onRealloc = drwav__realloc_default;
1808 allocationCallbacks.
onFree = drwav__free_default;
1809 return allocationCallbacks;
1823 return (
unsigned int)(chunkSize % 2);
1828 return (
unsigned int)(chunkSize % 8);
1840 if (onRead(pUserData, pHeaderOut->
id.
fourcc, 4) != 4) {
1844 if (onRead(pUserData, sizeInBytes, 4) != 4) {
1850 *pRunningBytesReadOut += 8;
1854 if (onRead(pUserData, pHeaderOut->
id.
guid, 16) != 16) {
1858 if (onRead(pUserData, sizeInBytes, 8) != 8) {
1864 *pRunningBytesReadOut += 24;
1873 while (bytesRemainingToSeek > 0) {
1874 if (bytesRemainingToSeek > 0x7FFFFFFF) {
1878 bytesRemainingToSeek -= 0x7FFFFFFF;
1883 bytesRemainingToSeek = 0;
1892 if (offset <= 0x7FFFFFFF) {
1900 offset -= 0x7FFFFFFF;
1903 if (offset <= 0x7FFFFFFF) {
1910 offset -= 0x7FFFFFFF;
1923 if (drwav__read_chunk_header(onRead, pUserData, container, pRunningBytesReadOut, &header) !=
DRWAV_SUCCESS) {
1936 if (drwav__read_chunk_header(onRead, pUserData, container, pRunningBytesReadOut, &header) !=
DRWAV_SUCCESS) {
1954 if (onRead(pUserData, fmt,
sizeof(fmt)) !=
sizeof(fmt)) {
1957 *pRunningBytesReadOut +=
sizeof(fmt);
1973 int bytesReadSoFar = 0;
1975 if (onRead(pUserData, fmt_cbSize,
sizeof(fmt_cbSize)) !=
sizeof(fmt_cbSize)) {
1978 *pRunningBytesReadOut +=
sizeof(fmt_cbSize);
1980 bytesReadSoFar = 18;
1999 drwav_bytes_to_guid(fmtext + 6, fmtOut->
subFormat);
2014 *pRunningBytesReadOut += (header.
sizeInBytes - bytesReadSoFar);
2032 DRWAV_ASSERT(onRead !=
NULL);
2033 DRWAV_ASSERT(pCursor !=
NULL);
2035 bytesRead = onRead(pUserData, pBufferOut, bytesToRead);
2036 *pCursor += bytesRead;
2043 DRWAV_ASSERT(onSeek !=
NULL);
2044 DRWAV_ASSERT(pCursor !=
NULL);
2046 if (!onSeek(pUserData, offset, origin)) {
2061#define DRWAV_SMPL_BYTES 36
2062#define DRWAV_SMPL_LOOP_BYTES 24
2063#define DRWAV_INST_BYTES 7
2064#define DRWAV_ACID_BYTES 24
2065#define DRWAV_CUE_BYTES 4
2066#define DRWAV_BEXT_BYTES 602
2067#define DRWAV_BEXT_DESCRIPTION_BYTES 256
2068#define DRWAV_BEXT_ORIGINATOR_NAME_BYTES 32
2069#define DRWAV_BEXT_ORIGINATOR_REF_BYTES 32
2070#define DRWAV_BEXT_RESERVED_BYTES 180
2071#define DRWAV_BEXT_UMID_BYTES 64
2072#define DRWAV_CUE_POINT_BYTES 24
2073#define DRWAV_LIST_LABEL_OR_NOTE_BYTES 4
2074#define DRWAV_LIST_LABELLED_TEXT_BYTES 20
2076#define DRWAV_METADATA_ALIGNMENT 8
2080 drwav__metadata_parser_stage_count,
2081 drwav__metadata_parser_stage_read
2082} drwav__metadata_parser_stage;
2088 void *pReadSeekUserData;
2089 drwav__metadata_parser_stage stage;
2096} drwav__metadata_parser;
2098DRWAV_PRIVATE size_t drwav__metadata_memory_capacity(drwav__metadata_parser* pParser)
2101 if (cap > DRWAV_SIZE_MAX) {
2115 pParser->pDataCursor += align - modulo;
2119 pResult = pParser->pDataCursor;
2125 DRWAV_ASSERT((pResult + size) <= (pParser->pData + drwav__metadata_memory_capacity(pParser)));
2127 pParser->pDataCursor += size;
2131DRWAV_PRIVATE void drwav__metadata_request_extra_memory_for_stage_2(drwav__metadata_parser* pParser,
size_t bytes,
size_t align)
2133 size_t extra = bytes + (align ? (align - 1) : 0);
2134 pParser->extraCapacity += extra;
2139 if (pParser->extraCapacity != 0 || pParser->metadataCount != 0) {
2140 free(pParser->pData);
2142 pParser->pData = (
drwav_uint8*)pAllocationCallbacks->
onMalloc(drwav__metadata_memory_capacity(pParser), pAllocationCallbacks->
pUserData);
2143 pParser->pDataCursor = pParser->pData;
2145 if (pParser->pData ==
NULL) {
2155 pParser->metadataCursor = 0;
2161DRWAV_PRIVATE size_t drwav__metadata_parser_read(drwav__metadata_parser* pParser,
void* pBufferOut,
size_t bytesToRead,
drwav_uint64* pCursor)
2163 if (pCursor !=
NULL) {
2164 return drwav__on_read(pParser->onRead, pParser->pReadSeekUserData, pBufferOut, bytesToRead, pCursor);
2166 return pParser->onRead(pParser->pReadSeekUserData, pBufferOut, bytesToRead);
2174 size_t bytesJustRead = drwav__metadata_parser_read(pParser, smplHeaderData,
sizeof(smplHeaderData), &totalBytesRead);
2176 DRWAV_ASSERT(pParser->stage == drwav__metadata_parser_stage_read);
2177 DRWAV_ASSERT(pChunkHeader !=
NULL);
2179 if (bytesJustRead ==
sizeof(smplHeaderData)) {
2202 bytesJustRead = drwav__metadata_parser_read(pParser, smplLoopData,
sizeof(smplLoopData), &totalBytesRead);
2204 if (bytesJustRead ==
sizeof(smplLoopData)) {
2225 return totalBytesRead;
2230 drwav_uint8 cueHeaderSectionData[DRWAV_CUE_BYTES];
2232 size_t bytesJustRead = drwav__metadata_parser_read(pParser, cueHeaderSectionData,
sizeof(cueHeaderSectionData), &totalBytesRead);
2234 DRWAV_ASSERT(pParser->stage == drwav__metadata_parser_stage_read);
2236 if (bytesJustRead ==
sizeof(cueHeaderSectionData)) {
2253 bytesJustRead = drwav__metadata_parser_read(pParser, cuePointData,
sizeof(cuePointData), &totalBytesRead);
2255 if (bytesJustRead ==
sizeof(cuePointData)) {
2273 return totalBytesRead;
2279 drwav_uint64 bytesRead = drwav__metadata_parser_read(pParser, instData,
sizeof(instData),
NULL);
2281 DRWAV_ASSERT(pParser->stage == drwav__metadata_parser_stage_read);
2283 if (bytesRead ==
sizeof(instData)) {
2300 drwav_uint64 bytesRead = drwav__metadata_parser_read(pParser, acidData,
sizeof(acidData),
NULL);
2302 DRWAV_ASSERT(pParser->stage == drwav__metadata_parser_stage_read);
2304 if (bytesRead ==
sizeof(acidData)) {
2319DRWAV_PRIVATE size_t drwav__strlen_clamped(
const char* str,
size_t maxToRead)
2323 while (*str++ && result < maxToRead) {
2330DRWAV_PRIVATE char* drwav__metadata_copy_string(drwav__metadata_parser* pParser,
const char* str,
size_t maxToRead)
2332 size_t len = drwav__strlen_clamped(str, maxToRead);
2335 char* result = (
char*)drwav__metadata_get_memory(pParser, len + 1, 1);
2336 DRWAV_ASSERT(result !=
NULL);
2338 memcpy(result, str, len);
2349 const void* pBuffer;
2352} drwav_buffer_reader;
2354DRWAV_PRIVATE drwav_result drwav_buffer_reader_init(
const void* pBuffer,
size_t sizeInBytes, drwav_buffer_reader* pReader)
2356 DRWAV_ASSERT(pBuffer !=
NULL);
2357 DRWAV_ASSERT(pReader !=
NULL);
2359 DRWAV_ZERO_OBJECT(pReader);
2361 pReader->pBuffer = pBuffer;
2362 pReader->sizeInBytes = sizeInBytes;
2363 pReader->cursor = 0;
2368DRWAV_PRIVATE const void* drwav_buffer_reader_ptr(
const drwav_buffer_reader* pReader)
2370 DRWAV_ASSERT(pReader !=
NULL);
2372 return drwav_offset_ptr(pReader->pBuffer, pReader->cursor);
2377 DRWAV_ASSERT(pReader !=
NULL);
2379 if (pReader->cursor + bytesToSeek > pReader->sizeInBytes) {
2383 pReader->cursor += bytesToSeek;
2388DRWAV_PRIVATE drwav_result drwav_buffer_reader_read(drwav_buffer_reader* pReader,
void* pDst,
size_t bytesToRead,
size_t* pBytesRead)
2391 size_t bytesRemaining;
2393 DRWAV_ASSERT(pReader !=
NULL);
2395 if (pBytesRead !=
NULL) {
2399 bytesRemaining = (pReader->sizeInBytes - pReader->cursor);
2400 if (bytesToRead > bytesRemaining) {
2401 bytesToRead = bytesRemaining;
2406 result = drwav_buffer_reader_seek(pReader, bytesToRead);
2409 DRWAV_COPY_MEMORY(pDst, drwav_buffer_reader_ptr(pReader), bytesToRead);
2410 pReader->cursor += bytesToRead;
2413 DRWAV_ASSERT(pReader->cursor <= pReader->sizeInBytes);
2416 if (pBytesRead !=
NULL) {
2417 *pBytesRead = bytesToRead;
2430 DRWAV_ASSERT(pReader !=
NULL);
2431 DRWAV_ASSERT(pDst !=
NULL);
2435 result = drwav_buffer_reader_read(pReader, data,
sizeof(*pDst), &bytesRead);
2436 if (result !=
DRWAV_SUCCESS || bytesRead !=
sizeof(*pDst)) {
2451 DRWAV_ASSERT(pReader !=
NULL);
2452 DRWAV_ASSERT(pDst !=
NULL);
2456 result = drwav_buffer_reader_read(pReader, data,
sizeof(*pDst), &bytesRead);
2457 if (result !=
DRWAV_SUCCESS || bytesRead !=
sizeof(*pDst)) {
2471 size_t bytesRead = drwav__metadata_parser_read(pParser, bextData,
sizeof(bextData),
NULL);
2473 DRWAV_ASSERT(pParser->stage == drwav__metadata_parser_stage_read);
2475 if (bytesRead ==
sizeof(bextData)) {
2476 drwav_buffer_reader reader;
2483 if (drwav_buffer_reader_init(bextData, bytesRead, &reader) ==
DRWAV_SUCCESS) {
2484 pMetadata->
data.
bext.
pDescription = drwav__metadata_copy_string(pParser, (
const char*)drwav_buffer_reader_ptr(&reader), DRWAV_BEXT_DESCRIPTION_BYTES);
2485 drwav_buffer_reader_seek(&reader, DRWAV_BEXT_DESCRIPTION_BYTES);
2487 pMetadata->
data.
bext.
pOriginatorName = drwav__metadata_copy_string(pParser, (
const char*)drwav_buffer_reader_ptr(&reader), DRWAV_BEXT_ORIGINATOR_NAME_BYTES);
2488 drwav_buffer_reader_seek(&reader, DRWAV_BEXT_ORIGINATOR_NAME_BYTES);
2490 pMetadata->
data.
bext.
pOriginatorReference = drwav__metadata_copy_string(pParser, (
const char*)drwav_buffer_reader_ptr(&reader), DRWAV_BEXT_ORIGINATOR_REF_BYTES);
2491 drwav_buffer_reader_seek(&reader, DRWAV_BEXT_ORIGINATOR_REF_BYTES);
2496 drwav_buffer_reader_read_u32(&reader, &timeReferenceLow);
2497 drwav_buffer_reader_read_u32(&reader, &timeReferenceHigh);
2502 pMetadata->
data.
bext.
pUMID = drwav__metadata_get_memory(pParser, DRWAV_BEXT_UMID_BYTES, 1);
2503 drwav_buffer_reader_read(&reader, pMetadata->
data.
bext.
pUMID, DRWAV_BEXT_UMID_BYTES,
NULL);
2511 DRWAV_ASSERT((drwav_offset_ptr(drwav_buffer_reader_ptr(&reader), DRWAV_BEXT_RESERVED_BYTES)) == (bextData + DRWAV_BEXT_BYTES));
2513 extraBytes = (size_t)(chunkSize - DRWAV_BEXT_BYTES);
2514 if (extraBytes > 0) {
2532 drwav_uint8 cueIDBuffer[DRWAV_LIST_LABEL_OR_NOTE_BYTES];
2534 size_t bytesJustRead = drwav__metadata_parser_read(pParser, cueIDBuffer,
sizeof(cueIDBuffer), &totalBytesRead);
2536 DRWAV_ASSERT(pParser->stage == drwav__metadata_parser_stage_read);
2538 if (bytesJustRead ==
sizeof(cueIDBuffer)) {
2541 pMetadata->
type = type;
2544 sizeIncludingNullTerminator = (
drwav_uint32)chunkSize - DRWAV_LIST_LABEL_OR_NOTE_BYTES;
2545 if (sizeIncludingNullTerminator > 0) {
2547 pMetadata->
data.
labelOrNote.
pString = (
char*)drwav__metadata_get_memory(pParser, sizeIncludingNullTerminator, 1);
2550 drwav__metadata_parser_read(pParser, pMetadata->
data.
labelOrNote.
pString, sizeIncludingNullTerminator, &totalBytesRead);
2557 return totalBytesRead;
2562 drwav_uint8 buffer[DRWAV_LIST_LABELLED_TEXT_BYTES];
2564 size_t bytesJustRead = drwav__metadata_parser_read(pParser, buffer,
sizeof(buffer), &totalBytesRead);
2566 DRWAV_ASSERT(pParser->stage == drwav__metadata_parser_stage_read);
2568 if (bytesJustRead ==
sizeof(buffer)) {
2583 sizeIncludingNullTerminator = (
drwav_uint32)chunkSize - DRWAV_LIST_LABELLED_TEXT_BYTES;
2584 if (sizeIncludingNullTerminator > 0) {
2596 return totalBytesRead;
2604 if (pParser->stage == drwav__metadata_parser_stage_count) {
2605 pParser->metadataCount += 1;
2606 drwav__metadata_request_extra_memory_for_stage_2(pParser, stringSizeWithNullTerminator, 1);
2608 drwav_metadata* pMetadata = &pParser->pMetadata[pParser->metadataCursor];
2609 pMetadata->
type = type;
2610 if (stringSizeWithNullTerminator > 0) {
2612 pMetadata->
data.
infoText.
pString = (
char*)drwav__metadata_get_memory(pParser, stringSizeWithNullTerminator, 1);
2615 bytesRead = drwav__metadata_parser_read(pParser, pMetadata->
data.
infoText.
pString, (
size_t)stringSizeWithNullTerminator,
NULL);
2616 if (bytesRead == chunkSize) {
2617 pParser->metadataCursor += 1;
2624 pParser->metadataCursor += 1;
2643 if (pParser->stage == drwav__metadata_parser_stage_count) {
2644 pParser->metadataCount += 1;
2645 drwav__metadata_request_extra_memory_for_stage_2(pParser, (
size_t)chunkSize, 1);
2647 drwav_metadata* pMetadata = &pParser->pMetadata[pParser->metadataCursor];
2660 pParser->metadataCursor += 1;
2680 if (pChunkHeader->
sizeInBytes >= DRWAV_SMPL_BYTES) {
2681 if (pParser->stage == drwav__metadata_parser_stage_count) {
2683 size_t bytesJustRead;
2690 bytesJustRead = drwav__metadata_parser_read(pParser, buffer,
sizeof(buffer), &bytesRead);
2691 if (bytesJustRead ==
sizeof(buffer)) {
2696 calculatedLoopCount = (pChunkHeader->
sizeInBytes - DRWAV_SMPL_BYTES) / DRWAV_SMPL_LOOP_BYTES;
2697 if (calculatedLoopCount == loopCount) {
2698 bytesJustRead = drwav__metadata_parser_read(pParser, buffer,
sizeof(buffer), &bytesRead);
2699 if (bytesJustRead ==
sizeof(buffer)) {
2702 pParser->metadataCount += 1;
2703 drwav__metadata_request_extra_memory_for_stage_2(pParser,
sizeof(
drwav_smpl_loop) * loopCount, DRWAV_METADATA_ALIGNMENT);
2704 drwav__metadata_request_extra_memory_for_stage_2(pParser, samplerSpecificDataSizeInBytes, 1);
2711 bytesRead = drwav__read_smpl_to_metadata_obj(pParser, pChunkHeader, &pParser->pMetadata[pParser->metadataCursor]);
2713 pParser->metadataCursor += 1;
2722 if (pChunkHeader->
sizeInBytes == DRWAV_INST_BYTES) {
2723 if (pParser->stage == drwav__metadata_parser_stage_count) {
2724 pParser->metadataCount += 1;
2726 bytesRead = drwav__read_inst_to_metadata_obj(pParser, &pParser->pMetadata[pParser->metadataCursor]);
2728 pParser->metadataCursor += 1;
2737 if (pChunkHeader->
sizeInBytes == DRWAV_ACID_BYTES) {
2738 if (pParser->stage == drwav__metadata_parser_stage_count) {
2739 pParser->metadataCount += 1;
2741 bytesRead = drwav__read_acid_to_metadata_obj(pParser, &pParser->pMetadata[pParser->metadataCursor]);
2743 pParser->metadataCursor += 1;
2752 if (pChunkHeader->
sizeInBytes >= DRWAV_CUE_BYTES) {
2753 if (pParser->stage == drwav__metadata_parser_stage_count) {
2756 pParser->metadataCount += 1;
2757 cueCount = (size_t)(pChunkHeader->
sizeInBytes - DRWAV_CUE_BYTES) / DRWAV_CUE_POINT_BYTES;
2758 drwav__metadata_request_extra_memory_for_stage_2(pParser,
sizeof(
drwav_cue_point) * cueCount, DRWAV_METADATA_ALIGNMENT);
2760 bytesRead = drwav__read_cue_to_metadata_obj(pParser, pChunkHeader, &pParser->pMetadata[pParser->metadataCursor]);
2762 pParser->metadataCursor += 1;
2771 if (pChunkHeader->
sizeInBytes >= DRWAV_BEXT_BYTES) {
2772 if (pParser->stage == drwav__metadata_parser_stage_count) {
2774 char buffer[DRWAV_BEXT_DESCRIPTION_BYTES + 1];
2775 size_t allocSizeNeeded = DRWAV_BEXT_UMID_BYTES;
2776 size_t bytesJustRead;
2778 buffer[DRWAV_BEXT_DESCRIPTION_BYTES] =
'\0';
2779 bytesJustRead = drwav__metadata_parser_read(pParser, buffer, DRWAV_BEXT_DESCRIPTION_BYTES, &bytesRead);
2780 if (bytesJustRead != DRWAV_BEXT_DESCRIPTION_BYTES) {
2783 allocSizeNeeded += strlen(buffer) + 1;
2785 buffer[DRWAV_BEXT_ORIGINATOR_NAME_BYTES] =
'\0';
2786 bytesJustRead = drwav__metadata_parser_read(pParser, buffer, DRWAV_BEXT_ORIGINATOR_NAME_BYTES, &bytesRead);
2787 if (bytesJustRead != DRWAV_BEXT_ORIGINATOR_NAME_BYTES) {
2790 allocSizeNeeded += strlen(buffer) + 1;
2792 buffer[DRWAV_BEXT_ORIGINATOR_REF_BYTES] =
'\0';
2793 bytesJustRead = drwav__metadata_parser_read(pParser, buffer, DRWAV_BEXT_ORIGINATOR_REF_BYTES, &bytesRead);
2794 if (bytesJustRead != DRWAV_BEXT_ORIGINATOR_REF_BYTES) {
2797 allocSizeNeeded += strlen(buffer) + 1;
2798 allocSizeNeeded += (size_t)pChunkHeader->
sizeInBytes - DRWAV_BEXT_BYTES;
2800 drwav__metadata_request_extra_memory_for_stage_2(pParser, allocSizeNeeded, 1);
2802 pParser->metadataCount += 1;
2804 bytesRead = drwav__read_bext_to_metadata_obj(pParser, &pParser->pMetadata[pParser->metadataCursor], pChunkHeader->
sizeInBytes);
2806 pParser->metadataCursor += 1;
2816 while (bytesRead < pChunkHeader->sizeInBytes) {
2821 drwav_uint64 bytesJustRead = drwav__metadata_parser_read(pParser, subchunkId,
sizeof(subchunkId), &bytesRead);
2822 if (bytesJustRead !=
sizeof(subchunkId)) {
2845 bytesJustRead = drwav__metadata_parser_read(pParser, subchunkSizeBuffer,
sizeof(subchunkSizeBuffer), &bytesRead);
2846 if (bytesJustRead !=
sizeof(subchunkSizeBuffer)) {
2852 if (subchunkDataSize >= DRWAV_LIST_LABEL_OR_NOTE_BYTES) {
2853 drwav_uint64 stringSizeWithNullTerm = subchunkDataSize - DRWAV_LIST_LABEL_OR_NOTE_BYTES;
2854 if (pParser->stage == drwav__metadata_parser_stage_count) {
2855 pParser->metadataCount += 1;
2856 drwav__metadata_request_extra_memory_for_stage_2(pParser, (
size_t)stringSizeWithNullTerm, 1);
2859 if (subchunkBytesRead == subchunkDataSize) {
2860 pParser->metadataCursor += 1;
2869 if (subchunkDataSize >= DRWAV_LIST_LABELLED_TEXT_BYTES) {
2870 drwav_uint64 stringSizeWithNullTerminator = subchunkDataSize - DRWAV_LIST_LABELLED_TEXT_BYTES;
2871 if (pParser->stage == drwav__metadata_parser_stage_count) {
2872 pParser->metadataCount += 1;
2873 drwav__metadata_request_extra_memory_for_stage_2(pParser, (
size_t)stringSizeWithNullTerminator, 1);
2875 subchunkBytesRead = drwav__read_list_labelled_cue_region_to_metadata_obj(pParser, &pParser->pMetadata[pParser->metadataCursor], subchunkDataSize);
2876 if (subchunkBytesRead == subchunkDataSize) {
2877 pParser->metadataCursor += 1;
2904 subchunkBytesRead = drwav__metadata_process_unknown_chunk(pParser, subchunkId, subchunkDataSize, listType);
2907 bytesRead += subchunkBytesRead;
2908 DRWAV_ASSERT(subchunkBytesRead <= subchunkDataSize);
2910 if (subchunkBytesRead < subchunkDataSize) {
2911 drwav_uint64 bytesToSeek = subchunkDataSize - subchunkBytesRead;
2916 bytesRead += bytesToSeek;
2919 if ((subchunkDataSize % 2) == 1) {
2956 return bytesPerFrame;
2974 if (pWav ==
NULL || onRead ==
NULL || onSeek ==
NULL) {
2978 DRWAV_ZERO_MEMORY(pWav,
sizeof(*pWav));
2982 pWav->
allocationCallbacks = drwav_copy_allocation_callbacks_or_defaults(pAllocationCallbacks);
2999 unsigned short translatedFormatTag;
3004 drwav__metadata_parser metadataParser;
3010 if (drwav__on_read(pWav->
onRead, pWav->
pUserData, riff,
sizeof(riff), &cursor) !=
sizeof(riff)) {
3027 if (drwav__on_read(pWav->
onRead, pWav->
pUserData, riff2,
sizeof(riff2), &cursor) !=
sizeof(riff2)) {
3031 for (i = 0; i < 12; ++i) {
3032 if (riff2[i] != drwavGUID_W64_RIFF[i+4]) {
3048 if (drwav__on_read(pWav->
onRead, pWav->
pUserData, chunkSizeBytes,
sizeof(chunkSizeBytes), &cursor) !=
sizeof(chunkSizeBytes)) {
3062 if (drwav__on_read(pWav->
onRead, pWav->
pUserData, wave,
sizeof(wave), &cursor) !=
sizeof(wave)) {
3074 if (drwav__on_read(pWav->
onRead, pWav->
pUserData, chunkSizeBytes,
sizeof(chunkSizeBytes), &cursor) !=
sizeof(chunkSizeBytes)) {
3082 if (drwav__on_read(pWav->
onRead, pWav->
pUserData, wave,
sizeof(wave), &cursor) !=
sizeof(wave)) {
3112 bytesRemainingInChunk -= 8;
3117 if (drwav__on_read(pWav->
onRead, pWav->
pUserData, sizeBytes,
sizeof(sizeBytes), &cursor) !=
sizeof(sizeBytes)) {
3120 bytesRemainingInChunk -= 8;
3125 if (drwav__on_read(pWav->
onRead, pWav->
pUserData, sizeBytes,
sizeof(sizeBytes), &cursor) !=
sizeof(sizeBytes)) {
3128 bytesRemainingInChunk -= 8;
3133 if (!drwav__seek_forward(pWav->
onSeek, bytesRemainingInChunk, pWav->
pUserData)) {
3136 cursor += bytesRemainingInChunk;
3160 memset(&metadataParser, 0,
sizeof(metadataParser));
3166 metadataParser.onRead = pWav->
onRead;
3167 metadataParser.onSeek = pWav->
onSeek;
3168 metadataParser.pReadSeekUserData = pWav->
pUserData;
3169 metadataParser.stage = drwav__metadata_parser_stage_count;
3182 bytesRead = drwav__metadata_process_chunk(&metadataParser, &header, pWav->
allowedMetadataTypes);
3186 if (!drwav__seek_forward(pWav->
onSeek, remainingBytes, pWav->
pUserData)) {
3189 cursorForMetadata += remainingBytes;
3197 metadataParser.stage = drwav__metadata_parser_stage_read;
3214 if (!foundDataChunk) {
3222 if (!sequential && onChunk !=
NULL) {
3229 if (callbackBytesRead > 0) {
3239 if (bytesRead > 0) {
3247 if (!foundDataChunk) {
3256 dataChunkSize = chunkSize;
3262 dataChunkSize = chunkSize;
3270 if (foundDataChunk && sequential) {
3278 if (drwav__on_read(pWav->
onRead, pWav->
pUserData, &sampleCount, 4, &cursor) != 4) {
3283 if (!foundDataChunk) {
3292 sampleCountFromFactChunk = sampleCount;
3294 sampleCountFromFactChunk = 0;
3299 if (drwav__on_read(pWav->
onRead, pWav->
pUserData, &sampleCountFromFactChunk, 8, &cursor) != 8) {
3304 if (!foundDataChunk) {
3317 cursor += chunkSize;
3319 if (!foundDataChunk) {
3324 pWav->
pMetadata = metadataParser.pMetadata;
3328 if (!foundDataChunk) {
3351 if (sampleCountFromFactChunk != 0) {
3354 drwav_uint32 bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
3355 if (bytesPerFrame == 0) {
3366 if ((blockCount * fmt.
blockAlign) < dataChunkSize) {
3371 totalBlockHeaderSizeInBytes = blockCount * (6*fmt.
channels);
3379 if ((blockCount * fmt.
blockAlign) < dataChunkSize) {
3384 totalBlockHeaderSizeInBytes = blockCount * (4*fmt.
channels);
3400 if (drwav_get_bytes_per_pcm_frame(pWav) == 0) {
3404#ifdef DR_WAV_LIBSNDFILE_COMPAT
3433 if (!drwav_preinit(pWav, onRead, onSeek, pReadSeekUserData, pAllocationCallbacks)) {
3437 return drwav_init__internal(pWav, onChunk, pChunkUserData, flags);
3442 if (!drwav_preinit(pWav, onRead, onSeek, pUserData, pAllocationCallbacks)) {
3447 return drwav_init__internal(pWav,
NULL,
NULL, flags);
3463 DRWAV_ASSERT(pWav !=
NULL);
3472 DRWAV_ASSERT(pWav !=
NULL);
3480 DRWAV_ASSERT(pWav !=
NULL);
3483 if (!drwav__is_little_endian()) {
3484 value = drwav__bswap16(value);
3487 return drwav__write(pWav, &value, 2);
3492 DRWAV_ASSERT(pWav !=
NULL);
3495 if (!drwav__is_little_endian()) {
3496 value = drwav__bswap32(value);
3499 return drwav__write(pWav, &value, 4);
3504 DRWAV_ASSERT(pWav !=
NULL);
3507 if (!drwav__is_little_endian()) {
3508 value = drwav__bswap64(value);
3511 return drwav__write(pWav, &value, 8);
3521 DRWAV_ASSERT(pWav !=
NULL);
3526 if (!drwav__is_little_endian()) {
3527 u.u32 = drwav__bswap32(u.u32);
3530 return drwav__write(pWav, &u.u32, 4);
3533DRWAV_PRIVATE size_t drwav__write_or_count(
drwav* pWav,
const void* pData,
size_t dataSize)
3539 return drwav__write(pWav, pData, dataSize);
3548 return drwav__write_byte(pWav,
byte);
3557 return drwav__write_u16ne_to_le(pWav, value);
3566 return drwav__write_u32ne_to_le(pWav, value);
3576 return drwav__write_u64ne_to_le(pWav, value);
3586 return drwav__write_f32ne_to_le(pWav, value);
3589DRWAV_PRIVATE size_t drwav__write_or_count_string_to_fixed_size_buf(
drwav* pWav,
char* str,
size_t bufFixedSize)
3594 return bufFixedSize;
3597 len = drwav__strlen_clamped(str, bufFixedSize);
3598 drwav__write_or_count(pWav, str, len);
3600 if (len < bufFixedSize) {
3602 for (i = 0; i < bufFixedSize - len; ++i) {
3603 drwav__write_byte(pWav, 0);
3607 return bufFixedSize;
3614 size_t bytesWritten = 0;
3619 if (pMetadatas ==
NULL || metadataCount == 0) {
3623 for (iMetadata = 0; iMetadata < metadataCount; ++iMetadata) {
3635 switch (pMetadata->
type) {
3642 bytesWritten += drwav__write_or_count(pWav,
"smpl", 4);
3643 bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, chunkSize);
3646 bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->
data.
smpl.
productId);
3650 bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->
data.
smpl.
smpteFormat);
3651 bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->
data.
smpl.
smpteOffset);
3657 bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->
data.
smpl.
pLoops[iLoop].
type);
3671 chunkSize = DRWAV_INST_BYTES;
3673 bytesWritten += drwav__write_or_count(pWav,
"inst", 4);
3674 bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, chunkSize);
3678 bytesWritten += drwav__write_or_count(pWav, &pMetadata->
data.
inst.
lowNote, 1);
3679 bytesWritten += drwav__write_or_count(pWav, &pMetadata->
data.
inst.
highNote, 1);
3690 bytesWritten += drwav__write_or_count(pWav,
"cue ", 4);
3691 bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, chunkSize);
3694 bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->
data.
cue.
pCuePoints[iCuePoint].
id);
3705 chunkSize = DRWAV_ACID_BYTES;
3707 bytesWritten += drwav__write_or_count(pWav,
"acid", 4);
3708 bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, chunkSize);
3709 bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->
data.
acid.
flags);
3711 bytesWritten += drwav__write_or_count_u16ne_to_le(pWav, pMetadata->
data.
acid.
reserved1);
3712 bytesWritten += drwav__write_or_count_f32ne_to_le(pWav, pMetadata->
data.
acid.
reserved2);
3713 bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, pMetadata->
data.
acid.
numBeats);
3716 bytesWritten += drwav__write_or_count_f32ne_to_le(pWav, pMetadata->
data.
acid.
tempo);
3721 char reservedBuf[DRWAV_BEXT_RESERVED_BYTES];
3727 bytesWritten += drwav__write_or_count(pWav,
"bext", 4);
3728 bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, chunkSize);
3730 bytesWritten += drwav__write_or_count_string_to_fixed_size_buf(pWav, pMetadata->
data.
bext.
pDescription, DRWAV_BEXT_DESCRIPTION_BYTES);
3731 bytesWritten += drwav__write_or_count_string_to_fixed_size_buf(pWav, pMetadata->
data.
bext.
pOriginatorName, DRWAV_BEXT_ORIGINATOR_NAME_BYTES);
3732 bytesWritten += drwav__write_or_count_string_to_fixed_size_buf(pWav, pMetadata->
data.
bext.
pOriginatorReference, DRWAV_BEXT_ORIGINATOR_REF_BYTES);
3738 bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, timeReferenceLow);
3739 bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, timeReferenceHigh);
3741 bytesWritten += drwav__write_or_count_u16ne_to_le(pWav, pMetadata->
data.
bext.
version);
3742 bytesWritten += drwav__write_or_count(pWav, pMetadata->
data.
bext.
pUMID, DRWAV_BEXT_UMID_BYTES);
3749 memset(reservedBuf, 0,
sizeof(reservedBuf));
3750 bytesWritten += drwav__write_or_count(pWav, reservedBuf,
sizeof(reservedBuf));
3762 bytesWritten += drwav__write_or_count(pWav, pMetadata->
data.
unknown.
id, 4);
3763 bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, chunkSize);
3770 if ((chunkSize % 2) != 0) {
3771 bytesWritten += drwav__write_or_count_byte(pWav, 0);
3777 for (iMetadata = 0; iMetadata < metadataCount; ++iMetadata) {
3788 if ((chunkSize % 2) != 0) {
3793 bytesWritten += drwav__write_or_count(pWav,
"LIST", 4);
3794 bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, chunkSize);
3795 bytesWritten += drwav__write_or_count(pWav,
"INFO", 4);
3797 for (iMetadata = 0; iMetadata < metadataCount; ++iMetadata) {
3802 const char* pID =
NULL;
3804 switch (pMetadata->
type) {
3817 DRWAV_ASSERT(pID !=
NULL);
3821 bytesWritten += drwav__write_or_count(pWav, pID, 4);
3822 bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, subchunkSize);
3824 bytesWritten += drwav__write_or_count_byte(pWav,
'\0');
3830 bytesWritten += drwav__write_or_count(pWav, pMetadata->
data.
unknown.
id, 4);
3832 bytesWritten += drwav__write_or_count(pWav, pMetadata->
data.
unknown.
pData, subchunkSize);
3836 if ((subchunkSize % 2) != 0) {
3837 bytesWritten += drwav__write_or_count_byte(pWav, 0);
3845 for (iMetadata = 0; iMetadata < metadataCount; ++iMetadata) {
3848 switch (pMetadata->
type)
3854 chunkSize += DRWAV_LIST_LABEL_OR_NOTE_BYTES;
3864 chunkSize += DRWAV_LIST_LABELLED_TEXT_BYTES;
3882 if ((chunkSize % 2) != 0) {
3887 bytesWritten += drwav__write_or_count(pWav,
"LIST", 4);
3888 bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, chunkSize);
3889 bytesWritten += drwav__write_or_count(pWav,
"adtl", 4);
3891 for (iMetadata = 0; iMetadata < metadataCount; ++iMetadata) {
3895 switch (pMetadata->
type)
3901 const char *pID =
NULL;
3910 DRWAV_ASSERT(pID !=
NULL);
3913 subchunkSize = DRWAV_LIST_LABEL_OR_NOTE_BYTES;
3915 bytesWritten += drwav__write_or_count(pWav, pID, 4);
3917 bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, subchunkSize);
3921 bytesWritten += drwav__write_or_count_byte(pWav,
'\0');
3927 subchunkSize = DRWAV_LIST_LABELLED_TEXT_BYTES;
3929 bytesWritten += drwav__write_or_count(pWav,
"ltxt", 4);
3933 bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, subchunkSize);
3946 bytesWritten += drwav__write_or_count_byte(pWav,
'\0');
3956 bytesWritten += drwav__write_or_count(pWav, pMetadata->
data.
unknown.
id, 4);
3957 bytesWritten += drwav__write_or_count_u32ne_to_le(pWav, subchunkSize);
3958 bytesWritten += drwav__write_or_count(pWav, pMetadata->
data.
unknown.
pData, subchunkSize);
3965 if ((subchunkSize % 2) != 0) {
3966 bytesWritten += drwav__write_or_count_byte(pWav, 0);
3971 DRWAV_ASSERT((bytesWritten % 2) == 0);
3973 return bytesWritten;
3978 drwav_uint64 chunkSize = 4 + 24 + (
drwav_uint64)drwav__write_or_count_metadata(
NULL, pMetadata, metadataCount) + 8 + dataChunkSize + drwav__chunk_padding_size_riff(dataChunkSize);
3979 if (chunkSize > 0xFFFFFFFFUL) {
3980 chunkSize = 0xFFFFFFFFUL;
3988 if (dataChunkSize <= 0xFFFFFFFFUL) {
3991 return 0xFFFFFFFFUL;
3997 drwav_uint64 dataSubchunkPaddingSize = drwav__chunk_padding_size_w64(dataChunkSize);
3999 return 80 + 24 + dataChunkSize + dataSubchunkPaddingSize;
4004 return 24 + dataChunkSize;
4009 drwav_uint64 chunkSize = 4 + 36 + 24 + (
drwav_uint64)drwav__write_or_count_metadata(
NULL, metadata, numMetadata) + 8 + dataChunkSize + drwav__chunk_padding_size_riff(dataChunkSize);
4010 if (chunkSize > 0xFFFFFFFFUL) {
4011 chunkSize = 0xFFFFFFFFUL;
4019 return dataChunkSize;
4026 if (pWav ==
NULL || onWrite ==
NULL) {
4030 if (!isSequential && onSeek ==
NULL) {
4042 DRWAV_ZERO_MEMORY(pWav,
sizeof(*pWav));
4046 pWav->
allocationCallbacks = drwav_copy_allocation_callbacks_or_defaults(pAllocationCallbacks);
4069 size_t runningPos = 0;
4086 if (initialDataChunkSize > (0xFFFFFFFFUL - 36)) {
4098 runningPos += drwav__write(pWav,
"RIFF", 4);
4099 runningPos += drwav__write_u32ne_to_le(pWav, chunkSizeRIFF);
4100 runningPos += drwav__write(pWav,
"WAVE", 4);
4102 drwav_uint64 chunkSizeRIFF = 80 + 24 + initialDataChunkSize;
4103 runningPos += drwav__write(pWav, drwavGUID_W64_RIFF, 16);
4104 runningPos += drwav__write_u64ne_to_le(pWav, chunkSizeRIFF);
4105 runningPos += drwav__write(pWav, drwavGUID_W64_WAVE, 16);
4107 runningPos += drwav__write(pWav,
"RF64", 4);
4108 runningPos += drwav__write_u32ne_to_le(pWav, 0xFFFFFFFF);
4109 runningPos += drwav__write(pWav,
"WAVE", 4);
4116 drwav_uint64 initialRiffChunkSize = 8 + initialds64ChunkSize + initialDataChunkSize;
4118 runningPos += drwav__write(pWav,
"ds64", 4);
4119 runningPos += drwav__write_u32ne_to_le(pWav, initialds64ChunkSize);
4120 runningPos += drwav__write_u64ne_to_le(pWav, initialRiffChunkSize);
4121 runningPos += drwav__write_u64ne_to_le(pWav, initialDataChunkSize);
4122 runningPos += drwav__write_u64ne_to_le(pWav, totalSampleCount);
4123 runningPos += drwav__write_u32ne_to_le(pWav, 0);
4130 runningPos += drwav__write(pWav,
"fmt ", 4);
4131 runningPos += drwav__write_u32ne_to_le(pWav, (
drwav_uint32)chunkSizeFMT);
4134 runningPos += drwav__write(pWav, drwavGUID_W64_FMT, 16);
4135 runningPos += drwav__write_u64ne_to_le(pWav, chunkSizeFMT);
4138 runningPos += drwav__write_u16ne_to_le(pWav, pWav->
fmt.
formatTag);
4139 runningPos += drwav__write_u16ne_to_le(pWav, pWav->
fmt.
channels);
4140 runningPos += drwav__write_u32ne_to_le(pWav, pWav->
fmt.
sampleRate);
4142 runningPos += drwav__write_u16ne_to_le(pWav, pWav->
fmt.
blockAlign);
4156 runningPos += drwav__write(pWav,
"data", 4);
4157 runningPos += drwav__write_u32ne_to_le(pWav, chunkSizeDATA);
4159 drwav_uint64 chunkSizeDATA = 24 + initialDataChunkSize;
4160 runningPos += drwav__write(pWav, drwavGUID_W64_DATA, 16);
4161 runningPos += drwav__write_u64ne_to_le(pWav, chunkSizeDATA);
4163 runningPos += drwav__write(pWav,
"data", 4);
4164 runningPos += drwav__write_u32ne_to_le(pWav, 0xFFFFFFFF);
4181 if (!drwav_preinit_write(pWav, pFormat,
DRWAV_FALSE, onWrite, onSeek, pUserData, pAllocationCallbacks)) {
4185 return drwav_init_write__internal(pWav, pFormat, 0);
4190 if (!drwav_preinit_write(pWav, pFormat,
DRWAV_TRUE, onWrite,
NULL, pUserData, pAllocationCallbacks)) {
4194 return drwav_init_write__internal(pWav, pFormat, totalSampleCount);
4199 if (pFormat ==
NULL) {
4208 if (!drwav_preinit_write(pWav, pFormat,
DRWAV_FALSE, onWrite, onSeek, pUserData, pAllocationCallbacks)) {
4215 return drwav_init_write__internal(pWav, pFormat, 0);
4227 riffChunkSizeBytes = drwav__riff_chunk_size_riff(targetDataSizeBytes, pMetadata, metadataCount);
4228 fileSizeBytes = (8 + riffChunkSizeBytes);
4230 riffChunkSizeBytes = drwav__riff_chunk_size_w64(targetDataSizeBytes);
4231 fileSizeBytes = riffChunkSizeBytes;
4233 riffChunkSizeBytes = drwav__riff_chunk_size_rf64(targetDataSizeBytes, pMetadata, metadataCount);
4234 fileSizeBytes = (8 + riffChunkSizeBytes);
4237 return fileSizeBytes;
4241#ifndef DR_WAV_NO_STDIO
4520 #ifdef EPROTONOSUPPORT
4523 #ifdef ESOCKTNOSUPPORT
4538 #ifdef EADDRNOTAVAIL
4634 #ifdef ENOTRECOVERABLE
4649#if defined(_MSC_VER) && _MSC_VER >= 1400
4653 if (ppFile !=
NULL) {
4657 if (pFilePath ==
NULL || pOpenMode ==
NULL || ppFile ==
NULL) {
4661#if defined(_MSC_VER) && _MSC_VER >= 1400
4662 err = fopen_s(ppFile, pFilePath, pOpenMode);
4664 return drwav_result_from_errno(err);
4667#if defined(_WIN32) || defined(__APPLE__)
4668 *ppFile = fopen(pFilePath, pOpenMode);
4670 #if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 && defined(_LARGEFILE64_SOURCE)
4671 *ppFile = fopen64(pFilePath, pOpenMode);
4673 *ppFile = fopen(pFilePath, pOpenMode);
4676 if (*ppFile ==
NULL) {
4702 #if defined(_MSC_VER) || defined(__MINGW64__) || (!defined(__STRICT_ANSI__) && !defined(_NO_EXT_KEYS))
4703 #define DRWAV_HAS_WFOPEN
4709 if (ppFile !=
NULL) {
4713 if (pFilePath ==
NULL || pOpenMode ==
NULL || ppFile ==
NULL) {
4717#if defined(DRWAV_HAS_WFOPEN)
4720 #if defined(_MSC_VER) && _MSC_VER >= 1400
4721 errno_t err = _wfopen_s(ppFile, pFilePath, pOpenMode);
4723 return drwav_result_from_errno(err);
4726 *ppFile = _wfopen(pFilePath, pOpenMode);
4727 if (*ppFile ==
NULL) {
4728 return drwav_result_from_errno(errno);
4731 (void)pAllocationCallbacks;
4742 const wchar_t* pFilePathTemp = pFilePath;
4743 char* pFilePathMB =
NULL;
4744 char pOpenModeMB[32] = {0};
4747 DRWAV_ZERO_OBJECT(&mbs);
4748 lenMB = wcsrtombs(
NULL, &pFilePathTemp, 0, &mbs);
4749 if (lenMB == (
size_t)-1) {
4750 return drwav_result_from_errno(errno);
4753 pFilePathMB = (
char*)drwav__malloc_from_callbacks(lenMB + 1, pAllocationCallbacks);
4754 if (pFilePathMB ==
NULL) {
4758 pFilePathTemp = pFilePath;
4759 DRWAV_ZERO_OBJECT(&mbs);
4760 wcsrtombs(pFilePathMB, &pFilePathTemp, lenMB + 1, &mbs);
4766 if (pOpenMode[i] == 0) {
4767 pOpenModeMB[i] =
'\0';
4771 pOpenModeMB[i] = (char)pOpenMode[i];
4776 *ppFile = fopen(pFilePathMB, pOpenModeMB);
4778 drwav__free_from_callbacks(pFilePathMB, pAllocationCallbacks);
4781 if (*ppFile ==
NULL) {
4790DRWAV_PRIVATE size_t drwav__on_read_stdio(
void* pUserData,
void* pBufferOut,
size_t bytesToRead)
4792 return fread(pBufferOut, 1, bytesToRead, (FILE*)pUserData);
4795DRWAV_PRIVATE size_t drwav__on_write_stdio(
void* pUserData,
const void* pData,
size_t bytesToWrite)
4797 return fwrite(pData, 1, bytesToWrite, (FILE*)pUserData);
4815 result = drwav_preinit(pWav, drwav__on_read_stdio, drwav__on_seek_stdio, (
void*)pFile, pAllocationCallbacks);
4823 result = drwav_init__internal(pWav, onChunk, pChunkUserData, flags);
4840 return drwav_init_file__internal_FILE(pWav, pFile, onChunk, pChunkUserData, flags,
drwav_metadata_type_none, pAllocationCallbacks);
4851 if (drwav_wfopen(&pFile, filename, L
"rb", pAllocationCallbacks) !=
DRWAV_SUCCESS) {
4856 return drwav_init_file__internal_FILE(pWav, pFile, onChunk, pChunkUserData, flags,
drwav_metadata_type_none, pAllocationCallbacks);
4873 if (drwav_wfopen(&pFile, filename, L
"rb", pAllocationCallbacks) !=
DRWAV_SUCCESS) {
4886 result = drwav_preinit_write(pWav, pFormat, isSequential, drwav__on_write_stdio, drwav__on_seek_stdio, (
void*)pFile, pAllocationCallbacks);
4892 result = drwav_init_write__internal(pWav, pFormat, totalSampleCount);
4909 return drwav_init_file_write__internal_FILE(pWav, pFile, pFormat, totalSampleCount, isSequential, pAllocationCallbacks);
4915 if (drwav_wfopen(&pFile, filename, L
"wb", pAllocationCallbacks) !=
DRWAV_SUCCESS) {
4920 return drwav_init_file_write__internal_FILE(pWav, pFile, pFormat, totalSampleCount, isSequential, pAllocationCallbacks);
4925 return drwav_init_file_write__internal(pWav, filename, pFormat, 0,
DRWAV_FALSE, pAllocationCallbacks);
4930 return drwav_init_file_write__internal(pWav, filename, pFormat, totalSampleCount,
DRWAV_TRUE, pAllocationCallbacks);
4935 if (pFormat ==
NULL) {
4944 return drwav_init_file_write_w__internal(pWav, filename, pFormat, 0,
DRWAV_FALSE, pAllocationCallbacks);
4949 return drwav_init_file_write_w__internal(pWav, filename, pFormat, totalSampleCount,
DRWAV_TRUE, pAllocationCallbacks);
4954 if (pFormat ==
NULL) {
4963DRWAV_PRIVATE size_t drwav__on_read_memory(
void* pUserData,
void* pBufferOut,
size_t bytesToRead)
4966 size_t bytesRemaining;
4968 DRWAV_ASSERT(pWav !=
NULL);
4972 if (bytesToRead > bytesRemaining) {
4973 bytesToRead = bytesRemaining;
4976 if (bytesToRead > 0) {
4987 DRWAV_ASSERT(pWav !=
NULL);
5003 if ((
drwav_uint32)offset <= pWav->memoryStream.dataSize) {
5013DRWAV_PRIVATE size_t drwav__on_write_memory(
void* pUserData,
const void* pDataIn,
size_t bytesToWrite)
5016 size_t bytesRemaining;
5018 DRWAV_ASSERT(pWav !=
NULL);
5022 if (bytesRemaining < bytesToWrite) {
5033 if (pNewData ==
NULL) {
5050 return bytesToWrite;
5056 DRWAV_ASSERT(pWav !=
NULL);
5089 if (data ==
NULL || dataSize == 0) {
5093 if (!drwav_preinit(pWav, drwav__on_read_memory, drwav__on_seek_memory, pWav, pAllocationCallbacks)) {
5101 return drwav_init__internal(pWav, onChunk, pChunkUserData, flags);
5106 if (data ==
NULL || dataSize == 0) {
5110 if (!drwav_preinit(pWav, drwav__on_read_memory, drwav__on_seek_memory, pWav, pAllocationCallbacks)) {
5120 return drwav_init__internal(pWav,
NULL,
NULL, flags);
5126 if (ppData ==
NULL || pDataSize ==
NULL) {
5133 if (!drwav_preinit_write(pWav, pFormat, isSequential, drwav__on_write_memory, drwav__on_seek_memory_write, pWav, pAllocationCallbacks)) {
5143 return drwav_init_write__internal(pWav, pFormat, totalSampleCount);
5148 return drwav_init_memory_write__internal(pWav, ppData, pDataSize, pFormat, 0,
DRWAV_FALSE, pAllocationCallbacks);
5153 return drwav_init_memory_write__internal(pWav, ppData, pDataSize, pFormat, totalSampleCount,
DRWAV_TRUE, pAllocationCallbacks);
5158 if (pFormat ==
NULL) {
5190 if (paddingSize > 0) {
5192 drwav__write(pWav, &paddingData, paddingSize);
5204 drwav__write_u32ne_to_le(pWav, riffChunkSize);
5210 drwav__write_u32ne_to_le(pWav, dataChunkSize);
5216 drwav__write_u64ne_to_le(pWav, riffChunkSize);
5222 drwav__write_u64ne_to_le(pWav, dataChunkSize);
5226 int ds64BodyPos = 12 + 8;
5231 drwav__write_u64ne_to_le(pWav, riffChunkSize);
5237 drwav__write_u64ne_to_le(pWav, dataChunkSize);
5254#ifndef DR_WAV_NO_STDIO
5259 if (pWav->
onRead == drwav__on_read_stdio || pWav->
onWrite == drwav__on_write_stdio) {
5274 if (pWav ==
NULL || bytesToRead == 0) {
5282 if (bytesToRead == 0) {
5286 bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
5287 if (bytesPerFrame == 0) {
5291 if (pBufferOut !=
NULL) {
5296 while (bytesRead < bytesToRead) {
5297 size_t bytesToSeek = (bytesToRead - bytesRead);
5298 if (bytesToSeek > 0x7FFFFFFF) {
5299 bytesToSeek = 0x7FFFFFFF;
5306 bytesRead += bytesToSeek;
5310 while (bytesRead < bytesToRead) {
5313 size_t bytesToSeek = (bytesToRead - bytesRead);
5314 if (bytesToSeek >
sizeof(buffer)) {
5315 bytesToSeek =
sizeof(buffer);
5319 bytesRead += bytesSeeked;
5321 if (bytesSeeked < bytesToSeek) {
5340 if (pWav ==
NULL || framesToRead == 0) {
5349 bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
5350 if (bytesPerFrame == 0) {
5355 bytesToRead = framesToRead * bytesPerFrame;
5356 if (bytesToRead > DRWAV_SIZE_MAX) {
5357 bytesToRead = (DRWAV_SIZE_MAX / bytesPerFrame) * bytesPerFrame;
5364 if (bytesToRead == 0) {
5368 return drwav_read_raw(pWav, (
size_t)bytesToRead, pBufferOut) / bytesPerFrame;
5375 if (pBufferOut !=
NULL) {
5376 drwav_uint32 bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
5377 if (bytesPerFrame == 0) {
5389 if (drwav__is_little_endian()) {
5411 DRWAV_ZERO_OBJECT(&pWav->
msadpcm);
5413 DRWAV_ZERO_OBJECT(&pWav->
ima);
5459 if (targetFrameIndex < pWav->readCursorInPCMFrames) {
5460 if (!drwav_seek_to_first_pcm_frame(pWav)) {
5469 while (offsetInFrames > 0) {
5472 if (framesToRead > drwav_countof(devnull)/pWav->
channels) {
5473 framesToRead = drwav_countof(devnull)/pWav->
channels;
5477 framesRead = drwav_read_pcm_frames_s16__msadpcm(pWav, framesToRead, devnull);
5479 framesRead = drwav_read_pcm_frames_s16__ima(pWav, framesToRead, devnull);
5484 if (framesRead != framesToRead) {
5488 offsetInFrames -= framesRead;
5498 bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
5499 if (bytesPerFrame == 0) {
5507 targetBytePos = targetFrameIndex * bytesPerFrame;
5509 if (currentBytePos < targetBytePos) {
5511 offset = (targetBytePos - currentBytePos);
5514 if (!drwav_seek_to_first_pcm_frame(pWav)) {
5517 offset = targetBytePos;
5520 while (offset > 0) {
5521 int offset32 = ((offset > INT_MAX) ? INT_MAX : (
int)offset);
5537 if (pCursor ==
NULL) {
5554 if (pLength ==
NULL) {
5572 size_t bytesWritten;
5574 if (pWav ==
NULL || bytesToWrite == 0 || pData ==
NULL) {
5581 return bytesWritten;
5590 if (pWav ==
NULL || framesToWrite == 0 || pData ==
NULL) {
5595 if (bytesToWrite > DRWAV_SIZE_MAX) {
5602 while (bytesToWrite > 0) {
5603 size_t bytesJustWritten;
5606 bytesToWriteThisIteration = bytesToWrite;
5607 DRWAV_ASSERT(bytesToWriteThisIteration <= DRWAV_SIZE_MAX);
5609 bytesJustWritten =
drwav_write_raw(pWav, (
size_t)bytesToWriteThisIteration, pRunningData);
5610 if (bytesJustWritten == 0) {
5614 bytesToWrite -= bytesJustWritten;
5615 bytesWritten += bytesJustWritten;
5616 pRunningData += bytesJustWritten;
5629 if (pWav ==
NULL || framesToWrite == 0 || pData ==
NULL) {
5634 if (bytesToWrite > DRWAV_SIZE_MAX) {
5641 bytesPerSample = drwav_get_bytes_per_pcm_frame(pWav) / pWav->
channels;
5642 if (bytesPerSample == 0) {
5646 while (bytesToWrite > 0) {
5649 size_t bytesJustWritten;
5652 bytesToWriteThisIteration = bytesToWrite;
5653 DRWAV_ASSERT(bytesToWriteThisIteration <= DRWAV_SIZE_MAX);
5659 sampleCount =
sizeof(temp)/bytesPerSample;
5661 if (bytesToWriteThisIteration > ((
drwav_uint64)sampleCount)*bytesPerSample) {
5662 bytesToWriteThisIteration = ((
drwav_uint64)sampleCount)*bytesPerSample;
5665 DRWAV_COPY_MEMORY(temp, pRunningData, (
size_t)bytesToWriteThisIteration);
5668 bytesJustWritten =
drwav_write_raw(pWav, (
size_t)bytesToWriteThisIteration, temp);
5669 if (bytesJustWritten == 0) {
5673 bytesToWrite -= bytesJustWritten;
5674 bytesWritten += bytesJustWritten;
5675 pRunningData += bytesJustWritten;
5683 if (drwav__is_little_endian()) {
5695 DRWAV_ASSERT(pWav !=
NULL);
5696 DRWAV_ASSERT(framesToRead > 0);
5701 DRWAV_ASSERT(framesToRead > 0);
5708 if (pWav->
onRead(pWav->
pUserData, header,
sizeof(header)) !=
sizeof(header)) {
5709 return totalFramesRead;
5723 if (pWav->
onRead(pWav->
pUserData, header,
sizeof(header)) !=
sizeof(header)) {
5724 return totalFramesRead;
5747 if (pBufferOut !=
NULL) {
5749 for (iSample = 0; iSample < pWav->
channels; iSample += 1) {
5757 totalFramesRead += 1;
5762 if (framesToRead == 0) {
5776 230, 230, 230, 230, 307, 409, 512, 614,
5777 768, 614, 512, 409, 307, 230, 230, 230
5779 static drwav_int32 coeff1Table[] = { 256, 512, 0, 192, 240, 460, 392 };
5780 static drwav_int32 coeff2Table[] = { 0, -256, 0, 64, 0, -208, -232 };
5787 return totalFramesRead;
5792 nibble0 = ((nibbles & 0xF0) >> 4);
if ((nibbles & 0x80)) { nibble0 |= 0xFFFFFFF0UL; }
5793 nibble1 = ((nibbles & 0x0F) >> 0);
if ((nibbles & 0x08)) { nibble1 |= 0xFFFFFFF0UL; }
5802 newSample0 = drwav_clamp(newSample0, -32768, 32767);
5815 newSample1 = drwav_clamp(newSample1, -32768, 32767);
5837 newSample0 = drwav_clamp(newSample0, -32768, 32767);
5851 newSample1 = drwav_clamp(newSample1, -32768, 32767);
5869 return totalFramesRead;
5879 -1, -1, -1, -1, 2, 4, 6, 8,
5880 -1, -1, -1, -1, 2, 4, 6, 8
5884 7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
5885 19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
5886 50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
5887 130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
5888 337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
5889 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
5890 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
5891 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
5892 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
5895 DRWAV_ASSERT(pWav !=
NULL);
5896 DRWAV_ASSERT(framesToRead > 0);
5901 DRWAV_ASSERT(framesToRead > 0);
5908 if (pWav->
onRead(pWav->
pUserData, header,
sizeof(header)) !=
sizeof(header)) {
5909 return totalFramesRead;
5913 if (header[2] >= drwav_countof(stepTable)) {
5916 return totalFramesRead;
5926 if (pWav->
onRead(pWav->
pUserData, header,
sizeof(header)) !=
sizeof(header)) {
5927 return totalFramesRead;
5931 if (header[2] >= drwav_countof(stepTable) || header[6] >= drwav_countof(stepTable)) {
5934 return totalFramesRead;
5950 if (pBufferOut !=
NULL) {
5952 for (iSample = 0; iSample < pWav->
channels; iSample += 1) {
5959 totalFramesRead += 1;
5964 if (framesToRead == 0) {
5981 for (iChannel = 0; iChannel < pWav->
channels; ++iChannel) {
5986 return totalFramesRead;
5990 for (iByte = 0; iByte < 4; ++iByte) {
5991 drwav_uint8 nibble0 = ((nibbles[iByte] & 0x0F) >> 0);
5992 drwav_uint8 nibble1 = ((nibbles[iByte] & 0xF0) >> 4);
5998 if (nibble0 & 1) diff += step >> 2;
5999 if (nibble0 & 2) diff += step >> 1;
6000 if (nibble0 & 4) diff += step;
6001 if (nibble0 & 8) diff = -diff;
6003 predictor = drwav_clamp(predictor + diff, -32768, 32767);
6013 if (nibble1 & 1) diff += step >> 2;
6014 if (nibble1 & 2) diff += step >> 1;
6015 if (nibble1 & 4) diff += step;
6016 if (nibble1 & 8) diff = -diff;
6018 predictor = drwav_clamp(predictor + diff, -32768, 32767);
6028 return totalFramesRead;
6032#ifndef DR_WAV_NO_CONVERSION_API
6033static unsigned short g_drwavAlawTable[256] = {
6034 0xEA80, 0xEB80, 0xE880, 0xE980, 0xEE80, 0xEF80, 0xEC80, 0xED80, 0xE280, 0xE380, 0xE080, 0xE180, 0xE680, 0xE780, 0xE480, 0xE580,
6035 0xF540, 0xF5C0, 0xF440, 0xF4C0, 0xF740, 0xF7C0, 0xF640, 0xF6C0, 0xF140, 0xF1C0, 0xF040, 0xF0C0, 0xF340, 0xF3C0, 0xF240, 0xF2C0,
6036 0xAA00, 0xAE00, 0xA200, 0xA600, 0xBA00, 0xBE00, 0xB200, 0xB600, 0x8A00, 0x8E00, 0x8200, 0x8600, 0x9A00, 0x9E00, 0x9200, 0x9600,
6037 0xD500, 0xD700, 0xD100, 0xD300, 0xDD00, 0xDF00, 0xD900, 0xDB00, 0xC500, 0xC700, 0xC100, 0xC300, 0xCD00, 0xCF00, 0xC900, 0xCB00,
6038 0xFEA8, 0xFEB8, 0xFE88, 0xFE98, 0xFEE8, 0xFEF8, 0xFEC8, 0xFED8, 0xFE28, 0xFE38, 0xFE08, 0xFE18, 0xFE68, 0xFE78, 0xFE48, 0xFE58,
6039 0xFFA8, 0xFFB8, 0xFF88, 0xFF98, 0xFFE8, 0xFFF8, 0xFFC8, 0xFFD8, 0xFF28, 0xFF38, 0xFF08, 0xFF18, 0xFF68, 0xFF78, 0xFF48, 0xFF58,
6040 0xFAA0, 0xFAE0, 0xFA20, 0xFA60, 0xFBA0, 0xFBE0, 0xFB20, 0xFB60, 0xF8A0, 0xF8E0, 0xF820, 0xF860, 0xF9A0, 0xF9E0, 0xF920, 0xF960,
6041 0xFD50, 0xFD70, 0xFD10, 0xFD30, 0xFDD0, 0xFDF0, 0xFD90, 0xFDB0, 0xFC50, 0xFC70, 0xFC10, 0xFC30, 0xFCD0, 0xFCF0, 0xFC90, 0xFCB0,
6042 0x1580, 0x1480, 0x1780, 0x1680, 0x1180, 0x1080, 0x1380, 0x1280, 0x1D80, 0x1C80, 0x1F80, 0x1E80, 0x1980, 0x1880, 0x1B80, 0x1A80,
6043 0x0AC0, 0x0A40, 0x0BC0, 0x0B40, 0x08C0, 0x0840, 0x09C0, 0x0940, 0x0EC0, 0x0E40, 0x0FC0, 0x0F40, 0x0CC0, 0x0C40, 0x0DC0, 0x0D40,
6044 0x5600, 0x5200, 0x5E00, 0x5A00, 0x4600, 0x4200, 0x4E00, 0x4A00, 0x7600, 0x7200, 0x7E00, 0x7A00, 0x6600, 0x6200, 0x6E00, 0x6A00,
6045 0x2B00, 0x2900, 0x2F00, 0x2D00, 0x2300, 0x2100, 0x2700, 0x2500, 0x3B00, 0x3900, 0x3F00, 0x3D00, 0x3300, 0x3100, 0x3700, 0x3500,
6046 0x0158, 0x0148, 0x0178, 0x0168, 0x0118, 0x0108, 0x0138, 0x0128, 0x01D8, 0x01C8, 0x01F8, 0x01E8, 0x0198, 0x0188, 0x01B8, 0x01A8,
6047 0x0058, 0x0048, 0x0078, 0x0068, 0x0018, 0x0008, 0x0038, 0x0028, 0x00D8, 0x00C8, 0x00F8, 0x00E8, 0x0098, 0x0088, 0x00B8, 0x00A8,
6048 0x0560, 0x0520, 0x05E0, 0x05A0, 0x0460, 0x0420, 0x04E0, 0x04A0, 0x0760, 0x0720, 0x07E0, 0x07A0, 0x0660, 0x0620, 0x06E0, 0x06A0,
6049 0x02B0, 0x0290, 0x02F0, 0x02D0, 0x0230, 0x0210, 0x0270, 0x0250, 0x03B0, 0x0390, 0x03F0, 0x03D0, 0x0330, 0x0310, 0x0370, 0x0350
6052static unsigned short g_drwavMulawTable[256] = {
6053 0x8284, 0x8684, 0x8A84, 0x8E84, 0x9284, 0x9684, 0x9A84, 0x9E84, 0xA284, 0xA684, 0xAA84, 0xAE84, 0xB284, 0xB684, 0xBA84, 0xBE84,
6054 0xC184, 0xC384, 0xC584, 0xC784, 0xC984, 0xCB84, 0xCD84, 0xCF84, 0xD184, 0xD384, 0xD584, 0xD784, 0xD984, 0xDB84, 0xDD84, 0xDF84,
6055 0xE104, 0xE204, 0xE304, 0xE404, 0xE504, 0xE604, 0xE704, 0xE804, 0xE904, 0xEA04, 0xEB04, 0xEC04, 0xED04, 0xEE04, 0xEF04, 0xF004,
6056 0xF0C4, 0xF144, 0xF1C4, 0xF244, 0xF2C4, 0xF344, 0xF3C4, 0xF444, 0xF4C4, 0xF544, 0xF5C4, 0xF644, 0xF6C4, 0xF744, 0xF7C4, 0xF844,
6057 0xF8A4, 0xF8E4, 0xF924, 0xF964, 0xF9A4, 0xF9E4, 0xFA24, 0xFA64, 0xFAA4, 0xFAE4, 0xFB24, 0xFB64, 0xFBA4, 0xFBE4, 0xFC24, 0xFC64,
6058 0xFC94, 0xFCB4, 0xFCD4, 0xFCF4, 0xFD14, 0xFD34, 0xFD54, 0xFD74, 0xFD94, 0xFDB4, 0xFDD4, 0xFDF4, 0xFE14, 0xFE34, 0xFE54, 0xFE74,
6059 0xFE8C, 0xFE9C, 0xFEAC, 0xFEBC, 0xFECC, 0xFEDC, 0xFEEC, 0xFEFC, 0xFF0C, 0xFF1C, 0xFF2C, 0xFF3C, 0xFF4C, 0xFF5C, 0xFF6C, 0xFF7C,
6060 0xFF88, 0xFF90, 0xFF98, 0xFFA0, 0xFFA8, 0xFFB0, 0xFFB8, 0xFFC0, 0xFFC8, 0xFFD0, 0xFFD8, 0xFFE0, 0xFFE8, 0xFFF0, 0xFFF8, 0x0000,
6061 0x7D7C, 0x797C, 0x757C, 0x717C, 0x6D7C, 0x697C, 0x657C, 0x617C, 0x5D7C, 0x597C, 0x557C, 0x517C, 0x4D7C, 0x497C, 0x457C, 0x417C,
6062 0x3E7C, 0x3C7C, 0x3A7C, 0x387C, 0x367C, 0x347C, 0x327C, 0x307C, 0x2E7C, 0x2C7C, 0x2A7C, 0x287C, 0x267C, 0x247C, 0x227C, 0x207C,
6063 0x1EFC, 0x1DFC, 0x1CFC, 0x1BFC, 0x1AFC, 0x19FC, 0x18FC, 0x17FC, 0x16FC, 0x15FC, 0x14FC, 0x13FC, 0x12FC, 0x11FC, 0x10FC, 0x0FFC,
6064 0x0F3C, 0x0EBC, 0x0E3C, 0x0DBC, 0x0D3C, 0x0CBC, 0x0C3C, 0x0BBC, 0x0B3C, 0x0ABC, 0x0A3C, 0x09BC, 0x093C, 0x08BC, 0x083C, 0x07BC,
6065 0x075C, 0x071C, 0x06DC, 0x069C, 0x065C, 0x061C, 0x05DC, 0x059C, 0x055C, 0x051C, 0x04DC, 0x049C, 0x045C, 0x041C, 0x03DC, 0x039C,
6066 0x036C, 0x034C, 0x032C, 0x030C, 0x02EC, 0x02CC, 0x02AC, 0x028C, 0x026C, 0x024C, 0x022C, 0x020C, 0x01EC, 0x01CC, 0x01AC, 0x018C,
6067 0x0174, 0x0164, 0x0154, 0x0144, 0x0134, 0x0124, 0x0114, 0x0104, 0x00F4, 0x00E4, 0x00D4, 0x00C4, 0x00B4, 0x00A4, 0x0094, 0x0084,
6068 0x0078, 0x0070, 0x0068, 0x0060, 0x0058, 0x0050, 0x0048, 0x0040, 0x0038, 0x0030, 0x0028, 0x0020, 0x0018, 0x0010, 0x0008, 0x0000
6073 return (
short)g_drwavAlawTable[sampleIn];
6078 return (
short)g_drwavMulawTable[sampleIn];
6088 if (bytesPerSample == 1) {
6095 if (bytesPerSample == 2) {
6096 for (i = 0; i < totalSampleCount; ++i) {
6101 if (bytesPerSample == 3) {
6105 if (bytesPerSample == 4) {
6112 if (bytesPerSample > 8) {
6113 DRWAV_ZERO_MEMORY(pOut, totalSampleCount *
sizeof(*pOut));
6119 for (i = 0; i < totalSampleCount; ++i) {
6121 unsigned int shift = (8 - bytesPerSample) * 8;
6124 for (j = 0; j < bytesPerSample; j += 1) {
6125 DRWAV_ASSERT(j < 8);
6137 if (bytesPerSample == 4) {
6140 }
else if (bytesPerSample == 8) {
6145 DRWAV_ZERO_MEMORY(pOut, totalSampleCount *
sizeof(*pOut));
6163 bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
6164 if (bytesPerFrame == 0) {
6168 bytesPerSample = bytesPerFrame / pWav->
channels;
6169 if (bytesPerSample == 0 || (bytesPerFrame % pWav->
channels) != 0) {
6173 totalFramesRead = 0;
6175 while (framesToRead > 0) {
6176 drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead,
sizeof(sampleData)/bytesPerFrame);
6178 if (framesRead == 0) {
6182 DRWAV_ASSERT(framesRead <= framesToReadThisIteration);
6185 samplesRead = framesRead * pWav->
channels;
6186 if ((samplesRead * bytesPerSample) >
sizeof(sampleData)) {
6191 drwav__pcm_to_s16(pBufferOut, sampleData, (
size_t)samplesRead, bytesPerSample);
6193 pBufferOut += samplesRead;
6194 framesToRead -= framesRead;
6195 totalFramesRead += framesRead;
6198 return totalFramesRead;
6209 if (pBufferOut ==
NULL) {
6213 bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
6214 if (bytesPerFrame == 0) {
6218 bytesPerSample = bytesPerFrame / pWav->
channels;
6219 if (bytesPerSample == 0 || (bytesPerFrame % pWav->
channels) != 0) {
6223 totalFramesRead = 0;
6225 while (framesToRead > 0) {
6226 drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead,
sizeof(sampleData)/bytesPerFrame);
6228 if (framesRead == 0) {
6232 DRWAV_ASSERT(framesRead <= framesToReadThisIteration);
6235 samplesRead = framesRead * pWav->
channels;
6236 if ((samplesRead * bytesPerSample) >
sizeof(sampleData)) {
6241 drwav__ieee_to_s16(pBufferOut, sampleData, (
size_t)samplesRead, bytesPerSample);
6243 pBufferOut += samplesRead;
6244 framesToRead -= framesRead;
6245 totalFramesRead += framesRead;
6248 return totalFramesRead;
6259 if (pBufferOut ==
NULL) {
6263 bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
6264 if (bytesPerFrame == 0) {
6268 bytesPerSample = bytesPerFrame / pWav->
channels;
6269 if (bytesPerSample == 0 || (bytesPerFrame % pWav->
channels) != 0) {
6273 totalFramesRead = 0;
6275 while (framesToRead > 0) {
6276 drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead,
sizeof(sampleData)/bytesPerFrame);
6278 if (framesRead == 0) {
6282 DRWAV_ASSERT(framesRead <= framesToReadThisIteration);
6285 samplesRead = framesRead * pWav->
channels;
6286 if ((samplesRead * bytesPerSample) >
sizeof(sampleData)) {
6293 pBufferOut += samplesRead;
6294 framesToRead -= framesRead;
6295 totalFramesRead += framesRead;
6298 return totalFramesRead;
6309 if (pBufferOut ==
NULL) {
6313 bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
6314 if (bytesPerFrame == 0) {
6318 bytesPerSample = bytesPerFrame / pWav->
channels;
6319 if (bytesPerSample == 0 || (bytesPerFrame % pWav->
channels) != 0) {
6323 totalFramesRead = 0;
6325 while (framesToRead > 0) {
6326 drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead,
sizeof(sampleData)/bytesPerFrame);
6328 if (framesRead == 0) {
6332 DRWAV_ASSERT(framesRead <= framesToReadThisIteration);
6335 samplesRead = framesRead * pWav->
channels;
6336 if ((samplesRead * bytesPerSample) >
sizeof(sampleData)) {
6343 pBufferOut += samplesRead;
6344 framesToRead -= framesRead;
6345 totalFramesRead += framesRead;
6348 return totalFramesRead;
6353 if (pWav ==
NULL || framesToRead == 0) {
6357 if (pBufferOut ==
NULL) {
6367 return drwav_read_pcm_frames_s16__pcm(pWav, framesToRead, pBufferOut);
6371 return drwav_read_pcm_frames_s16__ieee(pWav, framesToRead, pBufferOut);
6375 return drwav_read_pcm_frames_s16__alaw(pWav, framesToRead, pBufferOut);
6379 return drwav_read_pcm_frames_s16__mulaw(pWav, framesToRead, pBufferOut);
6383 return drwav_read_pcm_frames_s16__msadpcm(pWav, framesToRead, pBufferOut);
6387 return drwav_read_pcm_frames_s16__ima(pWav, framesToRead, pBufferOut);
6397 drwav__bswap_samples_s16(pBufferOut, framesRead*pWav->
channels);
6406 if (pBufferOut !=
NULL && drwav__is_little_endian() ==
DRWAV_TRUE) {
6407 drwav__bswap_samples_s16(pBufferOut, framesRead*pWav->
channels);
6418 for (i = 0; i < sampleCount; ++i) {
6430 for (i = 0; i < sampleCount; ++i) {
6431 int x = ((int)(((
unsigned int)(((
const drwav_uint8*)pIn)[i*3+0]) << 8) | ((
unsigned int)(((
const drwav_uint8*)pIn)[i*3+1]) << 16) | ((
unsigned int)(((
const drwav_uint8*)pIn)[i*3+2])) << 24)) >> 8;
6441 for (i = 0; i < sampleCount; ++i) {
6452 for (i = 0; i < sampleCount; ++i) {
6455 c = ((x < -1) ? -1 : ((x > 1) ? 1 : x));
6457 r = (int)(c * 32767.5f);
6467 for (i = 0; i < sampleCount; ++i) {
6470 c = ((x < -1) ? -1 : ((x > 1) ? 1 : x));
6472 r = (int)(c * 32767.5);
6481 for (i = 0; i < sampleCount; ++i) {
6482 pOut[i] = drwav__alaw_to_s16(pIn[i]);
6489 for (i = 0; i < sampleCount; ++i) {
6490 pOut[i] = drwav__mulaw_to_s16(pIn[i]);
6496DRWAV_PRIVATE void drwav__pcm_to_f32(
float* pOut,
const drwav_uint8* pIn,
size_t sampleCount,
unsigned int bytesPerSample)
6501 if (bytesPerSample == 1) {
6507 if (bytesPerSample == 2) {
6511 if (bytesPerSample == 3) {
6515 if (bytesPerSample == 4) {
6522 if (bytesPerSample > 8) {
6523 DRWAV_ZERO_MEMORY(pOut, sampleCount *
sizeof(*pOut));
6529 for (i = 0; i < sampleCount; ++i) {
6531 unsigned int shift = (8 - bytesPerSample) * 8;
6534 for (j = 0; j < bytesPerSample; j += 1) {
6535 DRWAV_ASSERT(j < 8);
6545DRWAV_PRIVATE void drwav__ieee_to_f32(
float* pOut,
const drwav_uint8* pIn,
size_t sampleCount,
unsigned int bytesPerSample)
6547 if (bytesPerSample == 4) {
6549 for (i = 0; i < sampleCount; ++i) {
6550 *pOut++ = ((
const float*)pIn)[i];
6553 }
else if (bytesPerSample == 8) {
6558 DRWAV_ZERO_MEMORY(pOut, sampleCount *
sizeof(*pOut));
6572 bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
6573 if (bytesPerFrame == 0) {
6577 bytesPerSample = bytesPerFrame / pWav->
channels;
6578 if (bytesPerSample == 0 || (bytesPerFrame % pWav->
channels) != 0) {
6582 totalFramesRead = 0;
6584 while (framesToRead > 0) {
6585 drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead,
sizeof(sampleData)/bytesPerFrame);
6587 if (framesRead == 0) {
6591 DRWAV_ASSERT(framesRead <= framesToReadThisIteration);
6594 samplesRead = framesRead * pWav->
channels;
6595 if ((samplesRead * bytesPerSample) >
sizeof(sampleData)) {
6600 drwav__pcm_to_f32(pBufferOut, sampleData, (
size_t)samplesRead, bytesPerSample);
6602 pBufferOut += samplesRead;
6603 framesToRead -= framesRead;
6604 totalFramesRead += framesRead;
6607 return totalFramesRead;
6619 totalFramesRead = 0;
6621 while (framesToRead > 0) {
6622 drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead, drwav_countof(samples16)/pWav->
channels);
6624 if (framesRead == 0) {
6628 DRWAV_ASSERT(framesRead <= framesToReadThisIteration);
6632 pBufferOut += framesRead*pWav->
channels;
6633 framesToRead -= framesRead;
6634 totalFramesRead += framesRead;
6637 return totalFramesRead;
6653 bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
6654 if (bytesPerFrame == 0) {
6658 bytesPerSample = bytesPerFrame / pWav->
channels;
6659 if (bytesPerSample == 0 || (bytesPerFrame % pWav->
channels) != 0) {
6663 totalFramesRead = 0;
6665 while (framesToRead > 0) {
6666 drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead,
sizeof(sampleData)/bytesPerFrame);
6668 if (framesRead == 0) {
6672 DRWAV_ASSERT(framesRead <= framesToReadThisIteration);
6675 samplesRead = framesRead * pWav->
channels;
6676 if ((samplesRead * bytesPerSample) >
sizeof(sampleData)) {
6681 drwav__ieee_to_f32(pBufferOut, sampleData, (
size_t)samplesRead, bytesPerSample);
6683 pBufferOut += samplesRead;
6684 framesToRead -= framesRead;
6685 totalFramesRead += framesRead;
6688 return totalFramesRead;
6699 bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
6700 if (bytesPerFrame == 0) {
6704 bytesPerSample = bytesPerFrame / pWav->
channels;
6705 if (bytesPerSample == 0 || (bytesPerFrame % pWav->
channels) != 0) {
6709 totalFramesRead = 0;
6711 while (framesToRead > 0) {
6712 drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead,
sizeof(sampleData)/bytesPerFrame);
6714 if (framesRead == 0) {
6718 DRWAV_ASSERT(framesRead <= framesToReadThisIteration);
6721 samplesRead = framesRead * pWav->
channels;
6722 if ((samplesRead * bytesPerSample) >
sizeof(sampleData)) {
6729 pBufferOut += samplesRead;
6730 framesToRead -= framesRead;
6731 totalFramesRead += framesRead;
6734 return totalFramesRead;
6745 bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
6746 if (bytesPerFrame == 0) {
6750 bytesPerSample = bytesPerFrame / pWav->
channels;
6751 if (bytesPerSample == 0 || (bytesPerFrame % pWav->
channels) != 0) {
6755 totalFramesRead = 0;
6757 while (framesToRead > 0) {
6758 drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead,
sizeof(sampleData)/bytesPerFrame);
6760 if (framesRead == 0) {
6764 DRWAV_ASSERT(framesRead <= framesToReadThisIteration);
6767 samplesRead = framesRead * pWav->
channels;
6768 if ((samplesRead * bytesPerSample) >
sizeof(sampleData)) {
6775 pBufferOut += samplesRead;
6776 framesToRead -= framesRead;
6777 totalFramesRead += framesRead;
6780 return totalFramesRead;
6785 if (pWav ==
NULL || framesToRead == 0) {
6789 if (pBufferOut ==
NULL) {
6794 if (framesToRead * pWav->
channels *
sizeof(
float) > DRWAV_SIZE_MAX) {
6795 framesToRead = DRWAV_SIZE_MAX /
sizeof(float) / pWav->
channels;
6799 return drwav_read_pcm_frames_f32__pcm(pWav, framesToRead, pBufferOut);
6803 return drwav_read_pcm_frames_f32__msadpcm_ima(pWav, framesToRead, pBufferOut);
6807 return drwav_read_pcm_frames_f32__ieee(pWav, framesToRead, pBufferOut);
6811 return drwav_read_pcm_frames_f32__alaw(pWav, framesToRead, pBufferOut);
6815 return drwav_read_pcm_frames_f32__mulaw(pWav, framesToRead, pBufferOut);
6825 drwav__bswap_samples_f32(pBufferOut, framesRead*pWav->
channels);
6834 if (pBufferOut !=
NULL && drwav__is_little_endian() ==
DRWAV_TRUE) {
6835 drwav__bswap_samples_f32(pBufferOut, framesRead*pWav->
channels);
6850#ifdef DR_WAV_LIBSNDFILE_COMPAT
6857 for (i = 0; i < sampleCount; ++i) {
6858 *pOut++ = (pIn[i] / 256.0f) * 2 - 1;
6861 for (i = 0; i < sampleCount; ++i) {
6863 x = x * 0.00784313725490196078f;
6879 for (i = 0; i < sampleCount; ++i) {
6880 *pOut++ = pIn[i] * 0.000030517578125f;
6892 for (i = 0; i < sampleCount; ++i) {
6899 *pOut++ = (float)(x * 0.00000011920928955078125);
6910 for (i = 0; i < sampleCount; ++i) {
6911 *pOut++ = (float)(pIn[i] / 2147483648.0);
6923 for (i = 0; i < sampleCount; ++i) {
6924 *pOut++ = (float)pIn[i];
6936 for (i = 0; i < sampleCount; ++i) {
6937 *pOut++ = drwav__alaw_to_s16(pIn[i]) / 32768.0f;
6949 for (i = 0; i < sampleCount; ++i) {
6950 *pOut++ = drwav__mulaw_to_s16(pIn[i]) / 32768.0f;
6961 if (bytesPerSample == 1) {
6967 if (bytesPerSample == 2) {
6971 if (bytesPerSample == 3) {
6975 if (bytesPerSample == 4) {
6976 for (i = 0; i < totalSampleCount; ++i) {
6984 if (bytesPerSample > 8) {
6985 DRWAV_ZERO_MEMORY(pOut, totalSampleCount *
sizeof(*pOut));
6991 for (i = 0; i < totalSampleCount; ++i) {
6993 unsigned int shift = (8 - bytesPerSample) * 8;
6996 for (j = 0; j < bytesPerSample; j += 1) {
6997 DRWAV_ASSERT(j < 8);
7009 if (bytesPerSample == 4) {
7012 }
else if (bytesPerSample == 8) {
7017 DRWAV_ZERO_MEMORY(pOut, totalSampleCount *
sizeof(*pOut));
7036 bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
7037 if (bytesPerFrame == 0) {
7041 bytesPerSample = bytesPerFrame / pWav->
channels;
7042 if (bytesPerSample == 0 || (bytesPerFrame % pWav->
channels) != 0) {
7046 totalFramesRead = 0;
7048 while (framesToRead > 0) {
7049 drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead,
sizeof(sampleData)/bytesPerFrame);
7051 if (framesRead == 0) {
7055 DRWAV_ASSERT(framesRead <= framesToReadThisIteration);
7058 samplesRead = framesRead * pWav->
channels;
7059 if ((samplesRead * bytesPerSample) >
sizeof(sampleData)) {
7064 drwav__pcm_to_s32(pBufferOut, sampleData, (
size_t)samplesRead, bytesPerSample);
7066 pBufferOut += samplesRead;
7067 framesToRead -= framesRead;
7068 totalFramesRead += framesRead;
7071 return totalFramesRead;
7083 while (framesToRead > 0) {
7084 drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead, drwav_countof(samples16)/pWav->
channels);
7086 if (framesRead == 0) {
7090 DRWAV_ASSERT(framesRead <= framesToReadThisIteration);
7094 pBufferOut += framesRead*pWav->
channels;
7095 framesToRead -= framesRead;
7096 totalFramesRead += framesRead;
7099 return totalFramesRead;
7110 bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
7111 if (bytesPerFrame == 0) {
7115 bytesPerSample = bytesPerFrame / pWav->
channels;
7116 if (bytesPerSample == 0 || (bytesPerFrame % pWav->
channels) != 0) {
7120 totalFramesRead = 0;
7122 while (framesToRead > 0) {
7123 drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead,
sizeof(sampleData)/bytesPerFrame);
7125 if (framesRead == 0) {
7129 DRWAV_ASSERT(framesRead <= framesToReadThisIteration);
7132 samplesRead = framesRead * pWav->
channels;
7133 if ((samplesRead * bytesPerSample) >
sizeof(sampleData)) {
7138 drwav__ieee_to_s32(pBufferOut, sampleData, (
size_t)samplesRead, bytesPerSample);
7140 pBufferOut += samplesRead;
7141 framesToRead -= framesRead;
7142 totalFramesRead += framesRead;
7145 return totalFramesRead;
7156 bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
7157 if (bytesPerFrame == 0) {
7161 bytesPerSample = bytesPerFrame / pWav->
channels;
7162 if (bytesPerSample == 0 || (bytesPerFrame % pWav->
channels) != 0) {
7166 totalFramesRead = 0;
7168 while (framesToRead > 0) {
7169 drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead,
sizeof(sampleData)/bytesPerFrame);
7171 if (framesRead == 0) {
7175 DRWAV_ASSERT(framesRead <= framesToReadThisIteration);
7178 samplesRead = framesRead * pWav->
channels;
7179 if ((samplesRead * bytesPerSample) >
sizeof(sampleData)) {
7186 pBufferOut += samplesRead;
7187 framesToRead -= framesRead;
7188 totalFramesRead += framesRead;
7191 return totalFramesRead;
7202 bytesPerFrame = drwav_get_bytes_per_pcm_frame(pWav);
7203 if (bytesPerFrame == 0) {
7207 bytesPerSample = bytesPerFrame / pWav->
channels;
7208 if (bytesPerSample == 0 || (bytesPerFrame % pWav->
channels) != 0) {
7212 totalFramesRead = 0;
7214 while (framesToRead > 0) {
7215 drwav_uint64 framesToReadThisIteration = drwav_min(framesToRead,
sizeof(sampleData)/bytesPerFrame);
7217 if (framesRead == 0) {
7221 DRWAV_ASSERT(framesRead <= framesToReadThisIteration);
7224 samplesRead = framesRead * pWav->
channels;
7225 if ((samplesRead * bytesPerSample) >
sizeof(sampleData)) {
7232 pBufferOut += samplesRead;
7233 framesToRead -= framesRead;
7234 totalFramesRead += framesRead;
7237 return totalFramesRead;
7242 if (pWav ==
NULL || framesToRead == 0) {
7246 if (pBufferOut ==
NULL) {
7256 return drwav_read_pcm_frames_s32__pcm(pWav, framesToRead, pBufferOut);
7260 return drwav_read_pcm_frames_s32__msadpcm_ima(pWav, framesToRead, pBufferOut);
7264 return drwav_read_pcm_frames_s32__ieee(pWav, framesToRead, pBufferOut);
7268 return drwav_read_pcm_frames_s32__alaw(pWav, framesToRead, pBufferOut);
7272 return drwav_read_pcm_frames_s32__mulaw(pWav, framesToRead, pBufferOut);
7282 drwav__bswap_samples_s32(pBufferOut, framesRead*pWav->
channels);
7291 if (pBufferOut !=
NULL && drwav__is_little_endian() ==
DRWAV_TRUE) {
7292 drwav__bswap_samples_s32(pBufferOut, framesRead*pWav->
channels);
7307 for (i = 0; i < sampleCount; ++i) {
7308 *pOut++ = ((int)pIn[i] - 128) << 24;
7320 for (i = 0; i < sampleCount; ++i) {
7321 *pOut++ = pIn[i] << 16;
7333 for (i = 0; i < sampleCount; ++i) {
7334 unsigned int s0 = pIn[i*3 + 0];
7335 unsigned int s1 = pIn[i*3 + 1];
7336 unsigned int s2 = pIn[i*3 + 2];
7351 for (i = 0; i < sampleCount; ++i) {
7364 for (i = 0; i < sampleCount; ++i) {
7377 for (i = 0; i < sampleCount; ++i) {
7378 *pOut++ = ((
drwav_int32)drwav__alaw_to_s16(pIn[i])) << 16;
7390 for (i= 0; i < sampleCount; ++i) {
7391 *pOut++ = ((
drwav_int32)drwav__mulaw_to_s16(pIn[i])) << 16;
7403 DRWAV_ASSERT(pWav !=
NULL);
7406 if (sampleDataSize > DRWAV_SIZE_MAX) {
7412 if (pSampleData ==
NULL) {
7432 if (totalFrameCount) {
7439DRWAV_PRIVATE float* drwav__read_pcm_frames_and_close_f32(
drwav* pWav,
unsigned int* channels,
unsigned int* sampleRate,
drwav_uint64* totalFrameCount)
7445 DRWAV_ASSERT(pWav !=
NULL);
7448 if (sampleDataSize > DRWAV_SIZE_MAX) {
7453 pSampleData = (
float*)drwav__malloc_from_callbacks((
size_t)sampleDataSize, &pWav->
allocationCallbacks);
7454 if (pSampleData ==
NULL) {
7474 if (totalFrameCount) {
7487 DRWAV_ASSERT(pWav !=
NULL);
7490 if (sampleDataSize > DRWAV_SIZE_MAX) {
7496 if (pSampleData ==
NULL) {
7516 if (totalFrameCount) {
7532 if (sampleRateOut) {
7535 if (totalFrameCountOut) {
7536 *totalFrameCountOut = 0;
7539 if (!
drwav_init(&wav, onRead, onSeek, pUserData, pAllocationCallbacks)) {
7543 return drwav__read_pcm_frames_and_close_s16(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
7553 if (sampleRateOut) {
7556 if (totalFrameCountOut) {
7557 *totalFrameCountOut = 0;
7560 if (!
drwav_init(&wav, onRead, onSeek, pUserData, pAllocationCallbacks)) {
7564 return drwav__read_pcm_frames_and_close_f32(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
7574 if (sampleRateOut) {
7577 if (totalFrameCountOut) {
7578 *totalFrameCountOut = 0;
7581 if (!
drwav_init(&wav, onRead, onSeek, pUserData, pAllocationCallbacks)) {
7585 return drwav__read_pcm_frames_and_close_s32(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
7588#ifndef DR_WAV_NO_STDIO
7596 if (sampleRateOut) {
7599 if (totalFrameCountOut) {
7600 *totalFrameCountOut = 0;
7607 return drwav__read_pcm_frames_and_close_s16(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
7617 if (sampleRateOut) {
7620 if (totalFrameCountOut) {
7621 *totalFrameCountOut = 0;
7628 return drwav__read_pcm_frames_and_close_f32(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
7638 if (sampleRateOut) {
7641 if (totalFrameCountOut) {
7642 *totalFrameCountOut = 0;
7649 return drwav__read_pcm_frames_and_close_s32(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
7657 if (sampleRateOut) {
7663 if (totalFrameCountOut) {
7664 *totalFrameCountOut = 0;
7671 return drwav__read_pcm_frames_and_close_s16(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
7678 if (sampleRateOut) {
7684 if (totalFrameCountOut) {
7685 *totalFrameCountOut = 0;
7692 return drwav__read_pcm_frames_and_close_f32(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
7699 if (sampleRateOut) {
7705 if (totalFrameCountOut) {
7706 *totalFrameCountOut = 0;
7713 return drwav__read_pcm_frames_and_close_s32(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
7724 if (sampleRateOut) {
7727 if (totalFrameCountOut) {
7728 *totalFrameCountOut = 0;
7735 return drwav__read_pcm_frames_and_close_s16(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
7745 if (sampleRateOut) {
7748 if (totalFrameCountOut) {
7749 *totalFrameCountOut = 0;
7756 return drwav__read_pcm_frames_and_close_f32(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
7766 if (sampleRateOut) {
7769 if (totalFrameCountOut) {
7770 *totalFrameCountOut = 0;
7777 return drwav__read_pcm_frames_and_close_s32(&wav, channelsOut, sampleRateOut, totalFrameCountOut);
7784 if (pAllocationCallbacks !=
NULL) {
7785 drwav__free_from_callbacks(p, pAllocationCallbacks);
7787 drwav__free_default(p,
NULL);
7838 for (i = 0; i < 16; i += 1) {
DRWAV_API void drwav_s32_to_s16(drwav_int16 *pOut, const drwav_int32 *pIn, size_t sampleCount)
DRWAV_API drwav_bool32 drwav_init_with_metadata(drwav *pWav, drwav_read_proc onRead, drwav_seek_proc onSeek, void *pUserData, drwav_uint32 flags, const drwav_allocation_callbacks *pAllocationCallbacks)
@ drwav_metadata_location_invalid
@ drwav_metadata_location_inside_info_list
@ drwav_metadata_location_inside_adtl_list
@ drwav_metadata_location_top_level
DRWAV_API drwav_bool32 drwav_init_file_ex_w(drwav *pWav, const wchar_t *filename, drwav_chunk_proc onChunk, void *pChunkUserData, drwav_uint32 flags, const drwav_allocation_callbacks *pAllocationCallbacks)
DRWAV_API void drwav_f32_to_s16(drwav_int16 *pOut, const float *pIn, size_t sampleCount)
#define DRWAV_OUT_OF_RANGE
#define DRWAV_VERSION_MINOR
DRWAV_API drwav_bool32 drwav_init_file_with_metadata(drwav *pWav, const char *filename, drwav_uint32 flags, const drwav_allocation_callbacks *pAllocationCallbacks)
#define DRWAV_SOCKET_NOT_SUPPORTED
#define DRWAV_ACCESS_DENIED
DRWAV_API drwav_bool32 drwav_init_file_write_sequential_pcm_frames_w(drwav *pWav, const wchar_t *filename, const drwav_data_format *pFormat, drwav_uint64 totalPCMFrameCount, const drwav_allocation_callbacks *pAllocationCallbacks)
DRWAV_API void drwav_s24_to_f32(float *pOut, const drwav_uint8 *pIn, size_t sampleCount)
DRWAV_API void drwav_s32_to_f32(float *pOut, const drwav_int32 *pIn, size_t sampleCount)
#define DRWAV_TOO_MANY_LINKS
@ drwav_smpl_loop_type_backward
@ drwav_smpl_loop_type_pingpong
@ drwav_smpl_loop_type_forward
#define DRWAV_INVALID_DATA
DRWAV_API drwav_uint64 drwav_write_pcm_frames_be(drwav *pWav, drwav_uint64 framesToWrite, const void *pData)
DRWAV_API drwav_int32 * drwav_open_memory_and_read_pcm_frames_s32(const void *data, size_t dataSize, unsigned int *channelsOut, unsigned int *sampleRateOut, drwav_uint64 *totalFrameCountOut, const drwav_allocation_callbacks *pAllocationCallbacks)
DRWAV_API const char * drwav_version_string(void)
DRWAV_API drwav_uint64 drwav_read_pcm_frames_be(drwav *pWav, drwav_uint64 framesToRead, void *pBufferOut)
DRWAV_API drwav_uint64 drwav_bytes_to_u64(const drwav_uint8 *data)
#define DRWAV_UNAVAILABLE
DRWAV_API void drwav_free(void *p, const drwav_allocation_callbacks *pAllocationCallbacks)
DRWAV_API void drwav_alaw_to_s32(drwav_int32 *pOut, const drwav_uint8 *pIn, size_t sampleCount)
DRWAV_API drwav_bool32 drwav_init_write_sequential_pcm_frames(drwav *pWav, const drwav_data_format *pFormat, drwav_uint64 totalPCMFrameCount, drwav_write_proc onWrite, void *pUserData, const drwav_allocation_callbacks *pAllocationCallbacks)
DRWAV_API void drwav_f64_to_s16(drwav_int16 *pOut, const double *pIn, size_t sampleCount)
DRWAV_API drwav_bool32 drwav_init_file_write_sequential_pcm_frames(drwav *pWav, const char *filename, const drwav_data_format *pFormat, drwav_uint64 totalPCMFrameCount, const drwav_allocation_callbacks *pAllocationCallbacks)
DRWAV_API drwav_uint64 drwav_read_pcm_frames_le(drwav *pWav, drwav_uint64 framesToRead, void *pBufferOut)
drwav_bool32(* drwav_seek_proc)(void *pUserData, int offset, drwav_seek_origin origin)
DRWAV_API void drwav_s24_to_s32(drwav_int32 *pOut, const drwav_uint8 *pIn, size_t sampleCount)
#define DRWAV_ADDRESS_FAMILY_NOT_SUPPORTED
drwav_uint32 drwav_bool32
#define DRWAV_NOT_DIRECTORY
DRWAV_API drwav_uint64 drwav_read_pcm_frames_f32be(drwav *pWav, drwav_uint64 framesToRead, float *pBufferOut)
#define DR_WAVE_FORMAT_DVI_ADPCM
#define DRWAV_VERSION_STRING
DRWAV_API void drwav_f64_to_f32(float *pOut, const double *pIn, size_t sampleCount)
#define DRWAV_INVALID_ARGS
#define DRWAV_PROTOCOL_UNAVAILABLE
DRWAV_API drwav_int16 * drwav_open_file_and_read_pcm_frames_s16_w(const wchar_t *filename, unsigned int *channelsOut, unsigned int *sampleRateOut, drwav_uint64 *totalFrameCountOut, const drwav_allocation_callbacks *pAllocationCallbacks)
#define DR_WAVE_FORMAT_EXTENSIBLE
DRWAV_API drwav_bool32 drwav_init_file_w(drwav *pWav, const wchar_t *filename, const drwav_allocation_callbacks *pAllocationCallbacks)
DRWAV_API drwav_int32 * drwav_open_file_and_read_pcm_frames_s32_w(const wchar_t *filename, unsigned int *channelsOut, unsigned int *sampleRateOut, drwav_uint64 *totalFrameCountOut, const drwav_allocation_callbacks *pAllocationCallbacks)
DRWAV_API size_t drwav_write_raw(drwav *pWav, size_t bytesToWrite, const void *pData)
DRWAV_API void drwav_u8_to_s32(drwav_int32 *pOut, const drwav_uint8 *pIn, size_t sampleCount)
DRWAV_API drwav_uint64 drwav_read_pcm_frames_s16le(drwav *pWav, drwav_uint64 framesToRead, drwav_int16 *pBufferOut)
DRWAV_API float * drwav_open_file_and_read_pcm_frames_f32_w(const wchar_t *filename, unsigned int *channelsOut, unsigned int *sampleRateOut, drwav_uint64 *totalFrameCountOut, const drwav_allocation_callbacks *pAllocationCallbacks)
DRWAV_API drwav_uint64 drwav_read_pcm_frames_f32(drwav *pWav, drwav_uint64 framesToRead, float *pBufferOut)
drwav_uint32 drwav_uintptr
DRWAV_API drwav_metadata * drwav_take_ownership_of_metadata(drwav *pWav)
#define DRWAV_ALREADY_IN_USE
#define DRWAV_PROTOCOL_FAMILY_NOT_SUPPORTED
DRWAV_API drwav_bool32 drwav_init_file_ex(drwav *pWav, const char *filename, drwav_chunk_proc onChunk, void *pChunkUserData, drwav_uint32 flags, const drwav_allocation_callbacks *pAllocationCallbacks)
DRWAV_API drwav_bool32 drwav_init_write_sequential(drwav *pWav, const drwav_data_format *pFormat, drwav_uint64 totalSampleCount, drwav_write_proc onWrite, void *pUserData, const drwav_allocation_callbacks *pAllocationCallbacks)
DRWAV_API float drwav_bytes_to_f32(const drwav_uint8 *data)
#define DR_WAVE_FORMAT_MULAW
DRWAV_API drwav_bool32 drwav_guid_equal(const drwav_uint8 a[16], const drwav_uint8 b[16])
DRWAV_API drwav_int32 * drwav_open_file_and_read_pcm_frames_s32(const char *filename, unsigned int *channelsOut, unsigned int *sampleRateOut, drwav_uint64 *totalFrameCountOut, const drwav_allocation_callbacks *pAllocationCallbacks)
DRWAV_API drwav_int16 * drwav_open_file_and_read_pcm_frames_s16(const char *filename, unsigned int *channelsOut, unsigned int *sampleRateOut, drwav_uint64 *totalFrameCountOut, const drwav_allocation_callbacks *pAllocationCallbacks)
DRWAV_API void drwav_s16_to_f32(float *pOut, const drwav_int16 *pIn, size_t sampleCount)
#define DRWAV_OUT_OF_MEMORY
drwav_uint64(* drwav_chunk_proc)(void *pChunkUserData, drwav_read_proc onRead, drwav_seek_proc onSeek, void *pReadSeekUserData, const drwav_chunk_header *pChunkHeader, drwav_container container, const drwav_fmt *pFMT)
DRWAV_API drwav_bool32 drwav_init_memory_write(drwav *pWav, void **ppData, size_t *pDataSize, const drwav_data_format *pFormat, const drwav_allocation_callbacks *pAllocationCallbacks)
DRWAV_API drwav_bool32 drwav_init_memory_write_sequential_pcm_frames(drwav *pWav, void **ppData, size_t *pDataSize, const drwav_data_format *pFormat, drwav_uint64 totalPCMFrameCount, const drwav_allocation_callbacks *pAllocationCallbacks)
DRWAV_API drwav_uint32 drwav_bytes_to_u32(const drwav_uint8 *data)
#define DRWAV_BAD_MESSAGE
#define DRWAV_PATH_TOO_LONG
DRWAV_API drwav_uint64 drwav_read_pcm_frames_s32be(drwav *pWav, drwav_uint64 framesToRead, drwav_int32 *pBufferOut)
DRWAV_API drwav_uint64 drwav_read_pcm_frames_f32le(drwav *pWav, drwav_uint64 framesToRead, float *pBufferOut)
DRWAV_API size_t drwav_read_raw(drwav *pWav, size_t bytesToRead, void *pBufferOut)
DRWAV_API void drwav_f64_to_s32(drwav_int32 *pOut, const double *pIn, size_t sampleCount)
DRWAV_API drwav_bool32 drwav_init_write_with_metadata(drwav *pWav, const drwav_data_format *pFormat, drwav_write_proc onWrite, drwav_seek_proc onSeek, void *pUserData, const drwav_allocation_callbacks *pAllocationCallbacks, drwav_metadata *pMetadata, drwav_uint32 metadataCount)
DRWAV_API void drwav_alaw_to_f32(float *pOut, const drwav_uint8 *pIn, size_t sampleCount)
DRWAV_API drwav_uint16 drwav_fmt_get_format(const drwav_fmt *pFMT)
DRWAV_API float * drwav_open_memory_and_read_pcm_frames_f32(const void *data, size_t dataSize, unsigned int *channelsOut, unsigned int *sampleRateOut, drwav_uint64 *totalFrameCountOut, const drwav_allocation_callbacks *pAllocationCallbacks)
DRWAV_API drwav_bool32 drwav_init_file_write_w(drwav *pWav, const wchar_t *filename, const drwav_data_format *pFormat, const drwav_allocation_callbacks *pAllocationCallbacks)
DRWAV_API drwav_bool32 drwav_init_memory(drwav *pWav, const void *data, size_t dataSize, const drwav_allocation_callbacks *pAllocationCallbacks)
DRWAV_API drwav_bool32 drwav_init_memory_write_sequential(drwav *pWav, void **ppData, size_t *pDataSize, const drwav_data_format *pFormat, drwav_uint64 totalSampleCount, const drwav_allocation_callbacks *pAllocationCallbacks)
#define DR_WAVE_FORMAT_PCM
#define DRWAV_NO_DATA_AVAILABLE
unsigned int drwav_uint32
#define DRWAV_INVALID_FILE
DRWAV_API void drwav_f32_to_s32(drwav_int32 *pOut, const float *pIn, size_t sampleCount)
#define DRWAV_NOT_CONNECTED
DRWAV_API drwav_int64 drwav_bytes_to_s64(const drwav_uint8 *data)
DRWAV_API drwav_bool32 drwav_init_file_with_metadata_w(drwav *pWav, const wchar_t *filename, drwav_uint32 flags, const drwav_allocation_callbacks *pAllocationCallbacks)
#define DRWAV_BAD_PROTOCOL
#define DRWAV_DOES_NOT_EXIST
DRWAV_API drwav_uint64 drwav_read_pcm_frames_s32(drwav *pWav, drwav_uint64 framesToRead, drwav_int32 *pBufferOut)
DRWAV_API drwav_uint64 drwav_write_pcm_frames_le(drwav *pWav, drwav_uint64 framesToWrite, const void *pData)
#define DRWAV_IS_DIRECTORY
#define DRWAV_BAD_ADDRESS
DRWAV_API drwav_int32 drwav_bytes_to_s32(const drwav_uint8 *data)
DRWAV_API drwav_bool32 drwav_init_file(drwav *pWav, const char *filename, const drwav_allocation_callbacks *pAllocationCallbacks)
@ drwav_seek_origin_current
@ drwav_seek_origin_start
#define DRWAV_ALREADY_EXISTS
DRWAV_API drwav_bool32 drwav_init_file_write(drwav *pWav, const char *filename, const drwav_data_format *pFormat, const drwav_allocation_callbacks *pAllocationCallbacks)
DRWAV_API drwav_bool32 drwav_seek_to_pcm_frame(drwav *pWav, drwav_uint64 targetFrameIndex)
DRWAV_API void drwav_mulaw_to_s16(drwav_int16 *pOut, const drwav_uint8 *pIn, size_t sampleCount)
#define DR_WAVE_FORMAT_ALAW
DRWAV_API drwav_bool32 drwav_fourcc_equal(const drwav_uint8 *a, const char *b)
DRWAV_API drwav_bool32 drwav_init_memory_ex(drwav *pWav, const void *data, size_t dataSize, drwav_chunk_proc onChunk, void *pChunkUserData, drwav_uint32 flags, const drwav_allocation_callbacks *pAllocationCallbacks)
DRWAV_API void drwav_s16_to_s32(drwav_int32 *pOut, const drwav_int16 *pIn, size_t sampleCount)
#define DRWAV_VERSION_MAJOR
#define DR_WAVE_FORMAT_ADPCM
DRWAV_API void drwav_alaw_to_s16(drwav_int16 *pOut, const drwav_uint8 *pIn, size_t sampleCount)
DRWAV_API void drwav_mulaw_to_s32(drwav_int32 *pOut, const drwav_uint8 *pIn, size_t sampleCount)
#define DRWAV_NOT_IMPLEMENTED
DRWAV_API drwav_uint64 drwav_read_pcm_frames_s32le(drwav *pWav, drwav_uint64 framesToRead, drwav_int32 *pBufferOut)
DRWAV_API void drwav_mulaw_to_f32(float *pOut, const drwav_uint8 *pIn, size_t sampleCount)
DRWAV_API drwav_result drwav_get_length_in_pcm_frames(drwav *pWav, drwav_uint64 *pLength)
size_t(* drwav_write_proc)(void *pUserData, const void *pData, size_t bytesToWrite)
DRWAV_API drwav_uint16 drwav_bytes_to_u16(const drwav_uint8 *data)
DRWAV_API drwav_uint64 drwav_read_pcm_frames_s16be(drwav *pWav, drwav_uint64 framesToRead, drwav_int16 *pBufferOut)
#define DRWAV_CONNECTION_RESET
#define DRWAV_ALREADY_CONNECTED
#define DRWAV_TOO_MANY_OPEN_FILES
DRWAV_API drwav_bool32 drwav_init_file_write_sequential_w(drwav *pWav, const wchar_t *filename, const drwav_data_format *pFormat, drwav_uint64 totalSampleCount, const drwav_allocation_callbacks *pAllocationCallbacks)
#define DRWAV_VERSION_REVISION
DRWAV_API float * drwav_open_file_and_read_pcm_frames_f32(const char *filename, unsigned int *channelsOut, unsigned int *sampleRateOut, drwav_uint64 *totalFrameCountOut, const drwav_allocation_callbacks *pAllocationCallbacks)
DRWAV_API drwav_int16 drwav_bytes_to_s16(const drwav_uint8 *data)
signed long long drwav_int64
#define DRWAV_PROTOCOL_NOT_SUPPORTED
DRWAV_API drwav_uint64 drwav_read_pcm_frames_s16(drwav *pWav, drwav_uint64 framesToRead, drwav_int16 *pBufferOut)
DRWAV_API drwav_result drwav_uninit(drwav *pWav)
DRWAV_API void drwav_u8_to_f32(float *pOut, const drwav_uint8 *pIn, size_t sampleCount)
DRWAV_API void drwav_u8_to_s16(drwav_int16 *pOut, const drwav_uint8 *pIn, size_t sampleCount)
unsigned long long drwav_uint64
DRWAV_API drwav_bool32 drwav_init_memory_with_metadata(drwav *pWav, const void *data, size_t dataSize, drwav_uint32 flags, const drwav_allocation_callbacks *pAllocationCallbacks)
#define DRWAV_DIRECTORY_NOT_EMPTY
#define DRWAV_CONNECTION_REFUSED
DRWAV_API drwav_uint64 drwav_write_pcm_frames(drwav *pWav, drwav_uint64 framesToWrite, const void *pData)
#define DR_WAVE_FORMAT_IEEE_FLOAT
DRWAV_API drwav_uint64 drwav_target_write_size_bytes(const drwav_data_format *pFormat, drwav_uint64 totalFrameCount, drwav_metadata *pMetadata, drwav_uint32 metadataCount)
DRWAV_API drwav_int16 * drwav_open_memory_and_read_pcm_frames_s16(const void *data, size_t dataSize, unsigned int *channelsOut, unsigned int *sampleRateOut, drwav_uint64 *totalFrameCountOut, const drwav_allocation_callbacks *pAllocationCallbacks)
unsigned char drwav_uint8
DRWAV_API void drwav_version(drwav_uint32 *pMajor, drwav_uint32 *pMinor, drwav_uint32 *pRevision)
DRWAV_API drwav_int32 * drwav_open_and_read_pcm_frames_s32(drwav_read_proc onRead, drwav_seek_proc onSeek, void *pUserData, unsigned int *channelsOut, unsigned int *sampleRateOut, drwav_uint64 *totalFrameCountOut, const drwav_allocation_callbacks *pAllocationCallbacks)
DRWAV_API drwav_int16 * drwav_open_and_read_pcm_frames_s16(drwav_read_proc onRead, drwav_seek_proc onSeek, void *pUserData, unsigned int *channelsOut, unsigned int *sampleRateOut, drwav_uint64 *totalFrameCountOut, const drwav_allocation_callbacks *pAllocationCallbacks)
DRWAV_API drwav_bool32 drwav_init_file_write_sequential(drwav *pWav, const char *filename, const drwav_data_format *pFormat, drwav_uint64 totalSampleCount, const drwav_allocation_callbacks *pAllocationCallbacks)
DRWAV_API float * drwav_open_and_read_pcm_frames_f32(drwav_read_proc onRead, drwav_seek_proc onSeek, void *pUserData, unsigned int *channelsOut, unsigned int *sampleRateOut, drwav_uint64 *totalFrameCountOut, const drwav_allocation_callbacks *pAllocationCallbacks)
DRWAV_API drwav_result drwav_get_cursor_in_pcm_frames(drwav *pWav, drwav_uint64 *pCursor)
DRWAV_API drwav_bool32 drwav_init(drwav *pWav, drwav_read_proc onRead, drwav_seek_proc onSeek, void *pUserData, const drwav_allocation_callbacks *pAllocationCallbacks)
DRWAV_API drwav_bool32 drwav_init_write(drwav *pWav, const drwav_data_format *pFormat, drwav_write_proc onWrite, drwav_seek_proc onSeek, void *pUserData, const drwav_allocation_callbacks *pAllocationCallbacks)
@ drwav_metadata_type_list_all_adtl
@ drwav_metadata_type_list_info_tracknumber
@ drwav_metadata_type_list_all_info_strings
@ drwav_metadata_type_none
@ drwav_metadata_type_list_info_artist
@ drwav_metadata_type_list_info_comment
@ drwav_metadata_type_list_info_date
@ drwav_metadata_type_bext
@ drwav_metadata_type_list_info_genre
@ drwav_metadata_type_list_info_album
@ drwav_metadata_type_list_label
@ drwav_metadata_type_acid
@ drwav_metadata_type_unknown
@ drwav_metadata_type_list_info_software
@ drwav_metadata_type_cue
@ drwav_metadata_type_list_labelled_cue_region
@ drwav_metadata_type_smpl
@ drwav_metadata_type_list_info_title
@ drwav_metadata_type_list_info_copyright
@ drwav_metadata_type_all_including_unknown
@ drwav_metadata_type_all
@ drwav_metadata_type_inst
@ drwav_metadata_type_list_note
#define DRWAV_INVALID_OPERATION
size_t(* drwav_read_proc)(void *pUserData, void *pBufferOut, size_t bytesToRead)
DRWAV_API void drwav_s24_to_s16(drwav_int16 *pOut, const drwav_uint8 *pIn, size_t sampleCount)
unsigned short drwav_uint16
#define DRWAV_IN_PROGRESS
DRWAV_API drwav_bool32 drwav_init_ex(drwav *pWav, drwav_read_proc onRead, drwav_seek_proc onSeek, drwav_chunk_proc onChunk, void *pReadSeekUserData, void *pChunkUserData, drwav_uint32 flags, const drwav_allocation_callbacks *pAllocationCallbacks)
@ drwav_acid_flag_acidizer
@ drwav_acid_flag_one_shot
@ drwav_acid_flag_root_note_set
@ drwav_acid_flag_stretch
@ drwav_acid_flag_disk_based
DRWAV_API drwav_uint64 drwav_read_pcm_frames(drwav *pWav, drwav_uint64 framesToRead, void *pBufferOut)
drwav_uint16 midiUnityNote
drwav_uint16 meterNumerator
drwav_uint16 meterDenominator
void *(* onRealloc)(void *p, size_t sz, void *pUserData)
void(* onFree)(void *p, void *pUserData)
void *(* onMalloc)(size_t sz, void *pUserData)
drwav_uint16 maxTruePeakLevel
drwav_uint16 loudnessValue
char pOriginationDate[10]
char * pOriginatorReference
drwav_uint16 maxShortTermLoudness
drwav_uint16 maxMomentaryLoudness
drwav_uint32 codingHistorySize
drwav_uint16 loudnessRange
drwav_uint64 timeReference
drwav_uint8 dataChunkId[4]
drwav_uint32 sampleByteOffset
drwav_uint32 playOrderPosition
drwav_uint32 cuePointCount
drwav_cue_point * pCuePoints
drwav_uint16 bitsPerSample
drwav_uint32 avgBytesPerSec
drwav_uint8 subFormat[16]
drwav_uint16 validBitsPerSample
drwav_uint16 extendedSize
drwav_uint32 stringLength
drwav_uint32 stringLength
drwav_uint32 stringLength
drwav_uint32 sampleLength
drwav_uint32 sampleFraction
drwav_uint32 firstSampleByteOffset
drwav_uint32 lastSampleByteOffset
drwav_uint32 manufacturerId
drwav_uint32 samplePeriodNanoseconds
drwav_uint32 midiPitchFraction
drwav_uint8 * pSamplerSpecificData
drwav_uint32 sampleLoopCount
drwav_uint32 samplerSpecificDataSizeInBytes
drwav_uint32 midiUnityNote
drwav_uint32 metadataCount
drwav_uint64 dataChunkDataSizeTargetWrite
drwav_uint16 predictor[2]
struct drwav::@11 msadpcm
drwav_container container
drwav_int32 prevFrames[2][2]
drwav_metadata_type allowedMetadataTypes
drwav_uint64 readCursorInPCMFrames
drwav_int32 cachedFrames[4]
drwav__memory_stream memoryStream
drwav_allocation_callbacks allocationCallbacks
drwav__memory_stream_write memoryStreamWrite
drwav_bool32 isSequentialWrite
drwav_uint16 translatedFormatTag
drwav_uint64 dataChunkDataSize
drwav_uint32 bytesRemainingInBlock
drwav_uint16 bitsPerSample
drwav_uint64 dataChunkDataPos
drwav_uint64 totalPCMFrameCount
drwav_metadata * pMetadata
drwav_uint32 cachedFrameCount
drwav_uint64 bytesRemaining