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 2
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__)
165 #define DRWAV_FALSE 0
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
296 unsigned int paddingSize;
354 typedef size_t (*
drwav_read_proc)(
void* pUserData,
void* pBufferOut,
size_t bytesToRead);
367 typedef 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);
422 size_t currentReadPos;
432 size_t currentWritePos;
687 char* pOriginatorName;
688 char* pOriginatorReference;
689 char pOriginationDate[10];
690 char pOriginationTime[8];
698 char* pCodingHistory;
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
1310 #ifndef DRWAV_ASSERT
1312 #define DRWAV_ASSERT(expression) assert(expression)
1314 #ifndef DRWAV_MALLOC
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))))
1339 #define DRWAV_MAX_SIMD_VECTOR_SIZE 64
1342 #if defined(__x86_64__) || defined(_M_X64)
1344 #elif defined(__i386) || defined(_M_IX86)
1346 #elif defined(__arm__) || defined(_M_ARM)
1351 #define DRWAV_INLINE __forceinline
1352 #elif defined(__GNUC__)
1360 #if defined(__STRICT_ANSI__)
1361 #define DRWAV_INLINE __inline__ __attribute__((always_inline))
1363 #define DRWAV_INLINE inline __attribute__((always_inline))
1365 #elif defined(__WATCOMC__)
1366 #define DRWAV_INLINE __inline
1368 #define DRWAV_INLINE
1371 #if defined(SIZE_MAX)
1372 #define DRWAV_SIZE_MAX SIZE_MAX
1374 #if defined(_WIN64) || defined(_LP64) || defined(__LP64__)
1375 #define DRWAV_SIZE_MAX ((drwav_uint64)0xFFFFFFFFFFFFFFFF)
1377 #define DRWAV_SIZE_MAX 0xFFFFFFFF
1381 #if defined(_MSC_VER) && _MSC_VER >= 1400
1382 #define DRWAV_HAS_BYTESWAP16_INTRINSIC
1383 #define DRWAV_HAS_BYTESWAP32_INTRINSIC
1384 #define DRWAV_HAS_BYTESWAP64_INTRINSIC
1385 #elif defined(__clang__)
1386 #if defined(__has_builtin)
1387 #if __has_builtin(__builtin_bswap16)
1388 #define DRWAV_HAS_BYTESWAP16_INTRINSIC
1390 #if __has_builtin(__builtin_bswap32)
1391 #define DRWAV_HAS_BYTESWAP32_INTRINSIC
1393 #if __has_builtin(__builtin_bswap64)
1394 #define DRWAV_HAS_BYTESWAP64_INTRINSIC
1397 #elif defined(__GNUC__)
1398 #if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
1399 #define DRWAV_HAS_BYTESWAP32_INTRINSIC
1400 #define DRWAV_HAS_BYTESWAP64_INTRINSIC
1402 #if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))
1403 #define DRWAV_HAS_BYTESWAP16_INTRINSIC
1431 #ifndef DRWAV_MAX_SAMPLE_RATE
1432 #define DRWAV_MAX_SAMPLE_RATE 384000
1434 #ifndef DRWAV_MAX_CHANNELS
1435 #define DRWAV_MAX_CHANNELS 256
1437 #ifndef DRWAV_MAX_BITS_PER_SAMPLE
1438 #define DRWAV_MAX_BITS_PER_SAMPLE 64
1441 static const drwav_uint8 drwavGUID_W64_RIFF[16] = {0x72,0x69,0x66,0x66, 0x2E,0x91, 0xCF,0x11, 0xA5,0xD6, 0x28,0xDB,0x04,0xC1,0x00,0x00};
1442 static const drwav_uint8 drwavGUID_W64_WAVE[16] = {0x77,0x61,0x76,0x65, 0xF3,0xAC, 0xD3,0x11, 0x8C,0xD1, 0x00,0xC0,0x4F,0x8E,0xDB,0x8A};
1444 static const drwav_uint8 drwavGUID_W64_FMT [16] = {0x66,0x6D,0x74,0x20, 0xF3,0xAC, 0xD3,0x11, 0x8C,0xD1, 0x00,0xC0,0x4F,0x8E,0xDB,0x8A};
1445 static const drwav_uint8 drwavGUID_W64_FACT[16] = {0x66,0x61,0x63,0x74, 0xF3,0xAC, 0xD3,0x11, 0x8C,0xD1, 0x00,0xC0,0x4F,0x8E,0xDB,0x8A};
1446 static const drwav_uint8 drwavGUID_W64_DATA[16] = {0x64,0x61,0x74,0x61, 0xF3,0xAC, 0xD3,0x11, 0x8C,0xD1, 0x00,0xC0,0x4F,0x8E,0xDB,0x8A};
1452 #if defined(DRWAV_X86) || defined(DRWAV_X64)
1454 #elif defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN
1458 return (*(
char*)&n) == 1;
1466 for (i = 0; i < 16; ++i) {
1474 #ifdef DRWAV_HAS_BYTESWAP16_INTRINSIC
1475 #if defined(_MSC_VER)
1476 return _byteswap_ushort(n);
1477 #elif defined(__GNUC__) || defined(__clang__)
1478 return __builtin_bswap16(n);
1480 #error "This compiler does not support the byte swap intrinsic."
1483 return ((n & 0xFF00) >> 8) |
1484 ((n & 0x00FF) << 8);
1490 #ifdef DRWAV_HAS_BYTESWAP32_INTRINSIC
1491 #if defined(_MSC_VER)
1492 return _byteswap_ulong(n);
1493 #elif defined(__GNUC__) || defined(__clang__)
1494 #if defined(DRWAV_ARM) && (defined(__ARM_ARCH) && __ARM_ARCH >= 6) && !defined(DRWAV_64BIT)
1497 __asm__ __volatile__ (
1498 #
if defined(DRWAV_64BIT)
1499 "rev %w[out], %w[in]" : [out]
"=r"(r) : [in]
"r"(n)
1501 "rev %[out], %[in]" : [out]
"=r"(r) : [in]
"r"(n)
1506 return __builtin_bswap32(n);
1509 #error "This compiler does not support the byte swap intrinsic."
1512 return ((n & 0xFF000000) >> 24) |
1513 ((n & 0x00FF0000) >> 8) |
1514 ((n & 0x0000FF00) << 8) |
1515 ((n & 0x000000FF) << 24);
1521 #ifdef DRWAV_HAS_BYTESWAP64_INTRINSIC
1522 #if defined(_MSC_VER)
1523 return _byteswap_uint64(n);
1524 #elif defined(__GNUC__) || defined(__clang__)
1525 return __builtin_bswap64(n);
1527 #error "This compiler does not support the byte swap intrinsic."
1531 return ((n & ((
drwav_uint64)0xFF000000 << 32)) >> 56) |
1551 for (iSample = 0; iSample < sampleCount; iSample += 1) {
1568 for (iSample = 0; iSample < sampleCount; iSample += 1) {
1583 for (iSample = 0; iSample < sampleCount; iSample += 1) {
1604 for (iSample = 0; iSample < sampleCount; iSample += 1) {
1625 for (iSample = 0; iSample < sampleCount; iSample += 1) {
1634 switch (bytesPerSample)
1658 switch (bytesPerSample)
1663 drwav__bswap_samples_f16((drwav_float16*)pSamples, sampleCount);
1734 if (pAllocationCallbacks ==
NULL) {
1752 if (pAllocationCallbacks ==
NULL) {
1782 if (p ==
NULL || pAllocationCallbacks ==
NULL) {
1794 if (pAllocationCallbacks !=
NULL) {
1796 return *pAllocationCallbacks;
1804 return allocationCallbacks;
1818 return (
unsigned int)(chunkSize % 2);
1823 return (
unsigned int)(chunkSize % 8);
1835 if (onRead(pUserData, pHeaderOut->
id.
fourcc, 4) != 4) {
1839 if (onRead(pUserData, sizeInBytes, 4) != 4) {
1845 *pRunningBytesReadOut += 8;
1849 if (onRead(pUserData, pHeaderOut->
id.
guid, 16) != 16) {
1853 if (onRead(pUserData, sizeInBytes, 8) != 8) {
1859 *pRunningBytesReadOut += 24;
1868 while (bytesRemainingToSeek > 0) {
1869 if (bytesRemainingToSeek > 0x7FFFFFFF) {
1873 bytesRemainingToSeek -= 0x7FFFFFFF;
1878 bytesRemainingToSeek = 0;
1887 if (offset <= 0x7FFFFFFF) {
1895 offset -= 0x7FFFFFFF;
1898 if (offset <= 0x7FFFFFFF) {
1905 offset -= 0x7FFFFFFF;
1928 *pRunningBytesReadOut +=
header.sizeInBytes +
header.paddingSize;
1949 if (onRead(pUserData, fmt,
sizeof(fmt)) !=
sizeof(fmt)) {
1952 *pRunningBytesReadOut +=
sizeof(fmt);
1966 if (
header.sizeInBytes > 16) {
1968 int bytesReadSoFar = 0;
1970 if (onRead(pUserData, fmt_cbSize,
sizeof(fmt_cbSize)) !=
sizeof(fmt_cbSize)) {
1973 *pRunningBytesReadOut +=
sizeof(fmt_cbSize);
1975 bytesReadSoFar = 18;
2009 *pRunningBytesReadOut += (
header.sizeInBytes - bytesReadSoFar);
2012 if (
header.paddingSize > 0) {
2016 *pRunningBytesReadOut +=
header.paddingSize;
2030 bytesRead = onRead(pUserData, pBufferOut, bytesToRead);
2031 *pCursor += bytesRead;
2041 if (!onSeek(pUserData, offset, origin)) {
2056 #define DRWAV_SMPL_BYTES 36
2057 #define DRWAV_SMPL_LOOP_BYTES 24
2058 #define DRWAV_INST_BYTES 7
2059 #define DRWAV_ACID_BYTES 24
2060 #define DRWAV_CUE_BYTES 4
2061 #define DRWAV_BEXT_BYTES 602
2062 #define DRWAV_BEXT_DESCRIPTION_BYTES 256
2063 #define DRWAV_BEXT_ORIGINATOR_NAME_BYTES 32
2064 #define DRWAV_BEXT_ORIGINATOR_REF_BYTES 32
2065 #define DRWAV_BEXT_RESERVED_BYTES 180
2066 #define DRWAV_BEXT_UMID_BYTES 64
2067 #define DRWAV_CUE_POINT_BYTES 24
2068 #define DRWAV_LIST_LABEL_OR_NOTE_BYTES 4
2069 #define DRWAV_LIST_LABELLED_TEXT_BYTES 20
2071 #define DRWAV_METADATA_ALIGNMENT 8
2083 void *pReadSeekUserData;
2128 size_t extra = bytes + (align ? (align - 1) : 0);
2135 free(pParser->
pData);
2158 if (pCursor !=
NULL) {
2173 if (bytesJustRead ==
sizeof(smplHeaderData)) {
2192 if (bytesJustRead ==
sizeof(smplLoopData)) {
2212 return totalBytesRead;
2223 if (bytesJustRead ==
sizeof(cueHeaderSectionData)) {
2236 if (bytesJustRead ==
sizeof(cuePointData)) {
2253 return totalBytesRead;
2263 if (bytesRead ==
sizeof(instData)) {
2284 if (bytesRead ==
sizeof(acidData)) {
2303 while (*str++ && result < maxToRead) {
2318 memcpy(result, str, len);
2334 if (bytesRead ==
sizeof(bextData)) {
2342 pReadPointer = bextData;
2389 if (extraBytes > 0) {
2412 if (bytesJustRead ==
sizeof(cueIDBuffer)) {
2415 pMetadata->
type = type;
2419 if (sizeIncludingNullTerminator > 0) {
2431 return totalBytesRead;
2442 if (bytesJustRead ==
sizeof(buffer)) {
2458 if (sizeIncludingNullTerminator > 0) {
2470 return totalBytesRead;
2483 pMetadata->
type = type;
2484 if (stringSizeWithNullTerminator > 0) {
2490 if (bytesRead == chunkSize) {
2557 size_t bytesJustRead;
2565 if (bytesJustRead ==
sizeof(buffer)) {
2569 if (bytesJustRead ==
sizeof(buffer)) {
2643 size_t bytesJustRead;
2650 allocSizeNeeded += strlen(buffer) + 1;
2657 allocSizeNeeded += strlen(buffer) + 1;
2664 allocSizeNeeded += strlen(buffer) + 1;
2683 while (bytesRead < pChunkHeader->sizeInBytes) {
2689 if (bytesJustRead !=
sizeof(subchunkId)) {
2713 if (bytesJustRead !=
sizeof(subchunkSizeBuffer)) {
2726 if (subchunkBytesRead == subchunkDataSize) {
2743 if (subchunkBytesRead == subchunkDataSize) {
2774 bytesRead += subchunkBytesRead;
2777 if (subchunkBytesRead < subchunkDataSize) {
2778 drwav_uint64 bytesToSeek = subchunkDataSize - subchunkBytesRead;
2783 bytesRead += bytesToSeek;
2786 if ((subchunkDataSize % 2) == 1) {
2823 return bytesPerFrame;
2841 if (pWav ==
NULL || onRead ==
NULL || onSeek ==
NULL) {
2866 unsigned short translatedFormatTag;
2898 for (i = 0; i < 12; ++i) {
2973 bytesRemainingInChunk =
header.sizeInBytes +
header.paddingSize;
2979 bytesRemainingInChunk -= 8;
2987 bytesRemainingInChunk -= 8;
2995 bytesRemainingInChunk -= 8;
3003 cursor += bytesRemainingInChunk;
3027 memset(&metadataParser, 0,
sizeof(metadataParser));
3052 remainingBytes =
header.sizeInBytes - bytesRead +
header.paddingSize;
3056 cursorForMetadata += remainingBytes;
3081 if (!foundDataChunk) {
3089 if (!sequential && onChunk !=
NULL) {
3096 if (callbackBytesRead > 0) {
3106 if (bytesRead > 0) {
3114 if (!foundDataChunk) {
3118 chunkSize =
header.sizeInBytes;
3123 dataChunkSize = chunkSize;
3129 dataChunkSize = chunkSize;
3137 if (foundDataChunk && sequential) {
3150 if (!foundDataChunk) {
3159 sampleCountFromFactChunk = sampleCount;
3161 sampleCountFromFactChunk = 0;
3171 if (!foundDataChunk) {
3180 chunkSize +=
header.paddingSize;
3184 cursor += chunkSize;
3186 if (!foundDataChunk) {
3195 if (!foundDataChunk) {
3218 if (sampleCountFromFactChunk != 0) {
3228 if ((blockCount * fmt.
blockAlign) < dataChunkSize) {
3233 totalBlockHeaderSizeInBytes = blockCount * (6*fmt.
channels);
3241 if ((blockCount * fmt.
blockAlign) < dataChunkSize) {
3246 totalBlockHeaderSizeInBytes = blockCount * (4*fmt.
channels);
3266 #ifdef DR_WAV_LIBSNDFILE_COMPAT
3295 if (!
drwav_preinit(pWav, onRead, onSeek, pReadSeekUserData, pAllocationCallbacks)) {
3304 if (!
drwav_preinit(pWav, onRead, onSeek, pUserData, pAllocationCallbacks)) {
3456 return bufFixedSize;
3462 if (len < bufFixedSize) {
3464 for (i = 0; i < bufFixedSize - len; ++i) {
3469 return bufFixedSize;
3476 size_t bytesWritten = 0;
3481 if (pMetadatas ==
NULL || metadataCount == 0) {
3485 for (iMetadata = 0; iMetadata < metadataCount; ++iMetadata) {
3497 switch (pMetadata->
type) {
3611 memset(reservedBuf, 0,
sizeof(reservedBuf));
3632 if ((chunkSize % 2) != 0) {
3639 for (iMetadata = 0; iMetadata < metadataCount; ++iMetadata) {
3650 if ((chunkSize % 2) != 0) {
3659 for (iMetadata = 0; iMetadata < metadataCount; ++iMetadata) {
3664 const char* pID =
NULL;
3666 switch (pMetadata->
type) {
3698 if ((subchunkSize % 2) != 0) {
3707 for (iMetadata = 0; iMetadata < metadataCount; ++iMetadata) {
3710 switch (pMetadata->
type)
3744 if ((chunkSize % 2) != 0) {
3753 for (iMetadata = 0; iMetadata < metadataCount; ++iMetadata) {
3757 switch (pMetadata->
type)
3763 const char *pID =
NULL;
3827 if ((subchunkSize % 2) != 0) {
3835 return bytesWritten;
3841 if (chunkSize > 0xFFFFFFFFUL) {
3842 chunkSize = 0xFFFFFFFFUL;
3850 if (dataChunkSize <= 0xFFFFFFFFUL) {
3853 return 0xFFFFFFFFUL;
3861 return 80 + 24 + dataChunkSize + dataSubchunkPaddingSize;
3866 return 24 + dataChunkSize;
3872 if (chunkSize > 0xFFFFFFFFUL) {
3873 chunkSize = 0xFFFFFFFFUL;
3881 return dataChunkSize;
3888 if (pWav ==
NULL || onWrite ==
NULL) {
3892 if (!isSequential && onSeek ==
NULL) {
3931 size_t runningPos = 0;
3948 if (initialDataChunkSize > (0xFFFFFFFFUL - 36)) {
3964 drwav_uint64 chunkSizeRIFF = 80 + 24 + initialDataChunkSize;
3978 drwav_uint64 initialRiffChunkSize = 8 + initialds64ChunkSize + initialDataChunkSize;
4021 drwav_uint64 chunkSizeDATA = 24 + initialDataChunkSize;
4061 if (pFormat ==
NULL) {
4090 fileSizeBytes = (8 + riffChunkSizeBytes);
4093 fileSizeBytes = riffChunkSizeBytes;
4096 fileSizeBytes = (8 + riffChunkSizeBytes);
4099 return fileSizeBytes;
4103 #ifndef DR_WAV_NO_STDIO
4382 #ifdef EPROTONOSUPPORT
4385 #ifdef ESOCKTNOSUPPORT
4400 #ifdef EADDRNOTAVAIL
4496 #ifdef ENOTRECOVERABLE
4511 #if defined(_MSC_VER) && _MSC_VER >= 1400
4515 if (ppFile !=
NULL) {
4519 if (pFilePath ==
NULL || pOpenMode ==
NULL || ppFile ==
NULL) {
4523 #if defined(_MSC_VER) && _MSC_VER >= 1400
4524 err = fopen_s(ppFile, pFilePath, pOpenMode);
4529 #if defined(_WIN32) || defined(__APPLE__)
4530 *ppFile = fopen(pFilePath, pOpenMode);
4532 #if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 && defined(_LARGEFILE64_SOURCE)
4533 *ppFile = fopen64(pFilePath, pOpenMode);
4535 *ppFile = fopen(pFilePath, pOpenMode);
4538 if (*ppFile ==
NULL) {
4564 #if defined(_MSC_VER) || defined(__MINGW64__) || (!defined(__STRICT_ANSI__) && !defined(_NO_EXT_KEYS))
4565 #define DRWAV_HAS_WFOPEN
4571 if (ppFile !=
NULL) {
4575 if (pFilePath ==
NULL || pOpenMode ==
NULL || ppFile ==
NULL) {
4579 #if defined(DRWAV_HAS_WFOPEN)
4582 #if defined(_MSC_VER) && _MSC_VER >= 1400
4583 errno_t err = _wfopen_s(ppFile, pFilePath, pOpenMode);
4588 *ppFile = _wfopen(pFilePath, pOpenMode);
4589 if (*ppFile ==
NULL) {
4593 (void)pAllocationCallbacks;
4604 const wchar_t* pFilePathTemp = pFilePath;
4605 char* pFilePathMB =
NULL;
4606 char pOpenModeMB[32] = {0};
4610 lenMB = wcsrtombs(
NULL, &pFilePathTemp, 0, &mbs);
4611 if (lenMB == (
size_t)-1) {
4616 if (pFilePathMB ==
NULL) {
4620 pFilePathTemp = pFilePath;
4622 wcsrtombs(pFilePathMB, &pFilePathTemp, lenMB + 1, &mbs);
4628 if (pOpenMode[i] == 0) {
4629 pOpenModeMB[i] =
'\0';
4633 pOpenModeMB[i] = (char)pOpenMode[i];
4638 *ppFile = fopen(pFilePathMB, pOpenModeMB);
4643 if (*ppFile ==
NULL) {
4654 return fread(pBufferOut, 1, bytesToRead, (FILE*)pUserData);
4659 return fwrite(pData, 1, bytesToWrite, (FILE*)pUserData);
4797 if (pFormat ==
NULL) {
4816 if (pFormat ==
NULL) {
4828 size_t bytesRemaining;
4834 if (bytesToRead > bytesRemaining) {
4835 bytesToRead = bytesRemaining;
4838 if (bytesToRead > 0) {
4865 if ((
drwav_uint32)offset <= pWav->memoryStream.dataSize) {
4878 size_t bytesRemaining;
4884 if (bytesRemaining < bytesToWrite) {
4895 if (pNewData ==
NULL) {
4912 return bytesToWrite;
4951 if (data ==
NULL || dataSize == 0) {
4968 if (data ==
NULL || dataSize == 0) {
4988 if (ppData ==
NULL || pDataSize ==
NULL) {
5020 if (pFormat ==
NULL) {
5052 if (paddingSize > 0) {
5088 int ds64BodyPos = 12 + 8;
5116 #ifndef DR_WAV_NO_STDIO
5135 if (pWav ==
NULL || bytesToRead == 0) {
5143 if (bytesToRead == 0) {
5147 if (pBufferOut !=
NULL) {
5152 while (bytesRead < bytesToRead) {
5153 size_t bytesToSeek = (bytesToRead - bytesRead);
5154 if (bytesToSeek > 0x7FFFFFFF) {
5155 bytesToSeek = 0x7FFFFFFF;
5162 bytesRead += bytesToSeek;
5166 while (bytesRead < bytesToRead) {
5169 size_t bytesToSeek = (bytesToRead - bytesRead);
5170 if (bytesToSeek >
sizeof(buffer)) {
5171 bytesToSeek =
sizeof(buffer);
5175 bytesRead += bytesSeeked;
5177 if (bytesSeeked < bytesToSeek) {
5196 if (pWav ==
NULL || framesToRead == 0) {
5206 if (bytesPerFrame == 0) {
5211 bytesToRead = framesToRead * bytesPerFrame;
5220 if (bytesToRead == 0) {
5224 return drwav_read_raw(pWav, (
size_t)bytesToRead, pBufferOut) / bytesPerFrame;
5231 if (pBufferOut !=
NULL) {
5310 if (targetFrameIndex < pWav->readCursorInPCMFrames) {
5320 while (offsetInFrames > 0) {
5335 if (framesRead != framesToRead) {
5339 offsetInFrames -= framesRead;
5354 if (currentBytePos < targetBytePos) {
5356 offset = (targetBytePos - currentBytePos);
5362 offset = targetBytePos;
5365 while (offset > 0) {
5366 int offset32 = ((offset > INT_MAX) ? INT_MAX : (
int)offset);
5382 if (pCursor ==
NULL) {
5399 if (pLength ==
NULL) {
5417 size_t bytesWritten;
5419 if (pWav ==
NULL || bytesToWrite == 0 || pData ==
NULL) {
5426 return bytesWritten;
5435 if (pWav ==
NULL || framesToWrite == 0 || pData ==
NULL) {
5447 while (bytesToWrite > 0) {
5448 size_t bytesJustWritten;
5451 bytesToWriteThisIteration = bytesToWrite;
5454 bytesJustWritten =
drwav_write_raw(pWav, (
size_t)bytesToWriteThisIteration, pRunningData);
5455 if (bytesJustWritten == 0) {
5459 bytesToWrite -= bytesJustWritten;
5460 bytesWritten += bytesJustWritten;
5461 pRunningData += bytesJustWritten;
5474 if (pWav ==
NULL || framesToWrite == 0 || pData ==
NULL) {
5488 while (bytesToWrite > 0) {
5491 size_t bytesJustWritten;
5494 bytesToWriteThisIteration = bytesToWrite;
5501 sampleCount =
sizeof(temp)/bytesPerSample;
5503 if (bytesToWriteThisIteration > ((
drwav_uint64)sampleCount)*bytesPerSample) {
5504 bytesToWriteThisIteration = ((
drwav_uint64)sampleCount)*bytesPerSample;
5510 bytesJustWritten =
drwav_write_raw(pWav, (
size_t)bytesToWriteThisIteration, temp);
5511 if (bytesJustWritten == 0) {
5515 bytesToWrite -= bytesJustWritten;
5516 bytesWritten += bytesJustWritten;
5517 pRunningData += bytesJustWritten;
5550 if (pWav->
onRead(pWav->
pUserData, header,
sizeof(header)) !=
sizeof(header)) {
5551 return totalFramesRead;
5565 if (pWav->
onRead(pWav->
pUserData, header,
sizeof(header)) !=
sizeof(header)) {
5566 return totalFramesRead;
5589 if (pBufferOut !=
NULL) {
5591 for (iSample = 0; iSample < pWav->
channels; iSample += 1) {
5599 totalFramesRead += 1;
5604 if (framesToRead == 0) {
5618 230, 230, 230, 230, 307, 409, 512, 614,
5619 768, 614, 512, 409, 307, 230, 230, 230
5621 static drwav_int32 coeff1Table[] = { 256, 512, 0, 192, 240, 460, 392 };
5622 static drwav_int32 coeff2Table[] = { 0, -256, 0, 64, 0, -208, -232 };
5629 return totalFramesRead;
5634 nibble0 = ((nibbles & 0xF0) >> 4);
if ((nibbles & 0x80)) { nibble0 |= 0xFFFFFFF0UL; }
5635 nibble1 = ((nibbles & 0x0F) >> 0);
if ((nibbles & 0x08)) { nibble1 |= 0xFFFFFFF0UL; }
5644 newSample0 =
drwav_clamp(newSample0, -32768, 32767);
5657 newSample1 =
drwav_clamp(newSample1, -32768, 32767);
5679 newSample0 =
drwav_clamp(newSample0, -32768, 32767);
5693 newSample1 =
drwav_clamp(newSample1, -32768, 32767);
5711 return totalFramesRead;
5721 -1, -1, -1, -1, 2, 4, 6, 8,
5722 -1, -1, -1, -1, 2, 4, 6, 8
5726 7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
5727 19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
5728 50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
5729 130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
5730 337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
5731 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
5732 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
5733 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
5734 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
5750 if (pWav->
onRead(pWav->
pUserData, header,
sizeof(header)) !=
sizeof(header)) {
5751 return totalFramesRead;
5758 return totalFramesRead;
5768 if (pWav->
onRead(pWav->
pUserData, header,
sizeof(header)) !=
sizeof(header)) {
5769 return totalFramesRead;
5776 return totalFramesRead;
5792 if (pBufferOut !=
NULL) {
5794 for (iSample = 0; iSample < pWav->
channels; iSample += 1) {
5801 totalFramesRead += 1;
5806 if (framesToRead == 0) {
5823 for (iChannel = 0; iChannel < pWav->
channels; ++iChannel) {
5828 return totalFramesRead;
5832 for (iByte = 0; iByte < 4; ++iByte) {
5833 drwav_uint8 nibble0 = ((nibbles[iByte] & 0x0F) >> 0);
5834 drwav_uint8 nibble1 = ((nibbles[iByte] & 0xF0) >> 4);
5840 if (nibble0 & 1) diff += step >> 2;
5841 if (nibble0 & 2) diff += step >> 1;
5842 if (nibble0 & 4) diff += step;
5843 if (nibble0 & 8) diff = -diff;
5845 predictor =
drwav_clamp(predictor + diff, -32768, 32767);
5855 if (nibble1 & 1) diff += step >> 2;
5856 if (nibble1 & 2) diff += step >> 1;
5857 if (nibble1 & 4) diff += step;
5858 if (nibble1 & 8) diff = -diff;
5860 predictor =
drwav_clamp(predictor + diff, -32768, 32767);
5870 return totalFramesRead;
5874 #ifndef DR_WAV_NO_CONVERSION_API
5876 0xEA80, 0xEB80, 0xE880, 0xE980, 0xEE80, 0xEF80, 0xEC80, 0xED80, 0xE280, 0xE380, 0xE080, 0xE180, 0xE680, 0xE780, 0xE480, 0xE580,
5877 0xF540, 0xF5C0, 0xF440, 0xF4C0, 0xF740, 0xF7C0, 0xF640, 0xF6C0, 0xF140, 0xF1C0, 0xF040, 0xF0C0, 0xF340, 0xF3C0, 0xF240, 0xF2C0,
5878 0xAA00, 0xAE00, 0xA200, 0xA600, 0xBA00, 0xBE00, 0xB200, 0xB600, 0x8A00, 0x8E00, 0x8200, 0x8600, 0x9A00, 0x9E00, 0x9200, 0x9600,
5879 0xD500, 0xD700, 0xD100, 0xD300, 0xDD00, 0xDF00, 0xD900, 0xDB00, 0xC500, 0xC700, 0xC100, 0xC300, 0xCD00, 0xCF00, 0xC900, 0xCB00,
5880 0xFEA8, 0xFEB8, 0xFE88, 0xFE98, 0xFEE8, 0xFEF8, 0xFEC8, 0xFED8, 0xFE28, 0xFE38, 0xFE08, 0xFE18, 0xFE68, 0xFE78, 0xFE48, 0xFE58,
5881 0xFFA8, 0xFFB8, 0xFF88, 0xFF98, 0xFFE8, 0xFFF8, 0xFFC8, 0xFFD8, 0xFF28, 0xFF38, 0xFF08, 0xFF18, 0xFF68, 0xFF78, 0xFF48, 0xFF58,
5882 0xFAA0, 0xFAE0, 0xFA20, 0xFA60, 0xFBA0, 0xFBE0, 0xFB20, 0xFB60, 0xF8A0, 0xF8E0, 0xF820, 0xF860, 0xF9A0, 0xF9E0, 0xF920, 0xF960,
5883 0xFD50, 0xFD70, 0xFD10, 0xFD30, 0xFDD0, 0xFDF0, 0xFD90, 0xFDB0, 0xFC50, 0xFC70, 0xFC10, 0xFC30, 0xFCD0, 0xFCF0, 0xFC90, 0xFCB0,
5884 0x1580, 0x1480, 0x1780, 0x1680, 0x1180, 0x1080, 0x1380, 0x1280, 0x1D80, 0x1C80, 0x1F80, 0x1E80, 0x1980, 0x1880, 0x1B80, 0x1A80,
5885 0x0AC0, 0x0A40, 0x0BC0, 0x0B40, 0x08C0, 0x0840, 0x09C0, 0x0940, 0x0EC0, 0x0E40, 0x0FC0, 0x0F40, 0x0CC0, 0x0C40, 0x0DC0, 0x0D40,
5886 0x5600, 0x5200, 0x5E00, 0x5A00, 0x4600, 0x4200, 0x4E00, 0x4A00, 0x7600, 0x7200, 0x7E00, 0x7A00, 0x6600, 0x6200, 0x6E00, 0x6A00,
5887 0x2B00, 0x2900, 0x2F00, 0x2D00, 0x2300, 0x2100, 0x2700, 0x2500, 0x3B00, 0x3900, 0x3F00, 0x3D00, 0x3300, 0x3100, 0x3700, 0x3500,
5888 0x0158, 0x0148, 0x0178, 0x0168, 0x0118, 0x0108, 0x0138, 0x0128, 0x01D8, 0x01C8, 0x01F8, 0x01E8, 0x0198, 0x0188, 0x01B8, 0x01A8,
5889 0x0058, 0x0048, 0x0078, 0x0068, 0x0018, 0x0008, 0x0038, 0x0028, 0x00D8, 0x00C8, 0x00F8, 0x00E8, 0x0098, 0x0088, 0x00B8, 0x00A8,
5890 0x0560, 0x0520, 0x05E0, 0x05A0, 0x0460, 0x0420, 0x04E0, 0x04A0, 0x0760, 0x0720, 0x07E0, 0x07A0, 0x0660, 0x0620, 0x06E0, 0x06A0,
5891 0x02B0, 0x0290, 0x02F0, 0x02D0, 0x0230, 0x0210, 0x0270, 0x0250, 0x03B0, 0x0390, 0x03F0, 0x03D0, 0x0330, 0x0310, 0x0370, 0x0350
5895 0x8284, 0x8684, 0x8A84, 0x8E84, 0x9284, 0x9684, 0x9A84, 0x9E84, 0xA284, 0xA684, 0xAA84, 0xAE84, 0xB284, 0xB684, 0xBA84, 0xBE84,
5896 0xC184, 0xC384, 0xC584, 0xC784, 0xC984, 0xCB84, 0xCD84, 0xCF84, 0xD184, 0xD384, 0xD584, 0xD784, 0xD984, 0xDB84, 0xDD84, 0xDF84,
5897 0xE104, 0xE204, 0xE304, 0xE404, 0xE504, 0xE604, 0xE704, 0xE804, 0xE904, 0xEA04, 0xEB04, 0xEC04, 0xED04, 0xEE04, 0xEF04, 0xF004,
5898 0xF0C4, 0xF144, 0xF1C4, 0xF244, 0xF2C4, 0xF344, 0xF3C4, 0xF444, 0xF4C4, 0xF544, 0xF5C4, 0xF644, 0xF6C4, 0xF744, 0xF7C4, 0xF844,
5899 0xF8A4, 0xF8E4, 0xF924, 0xF964, 0xF9A4, 0xF9E4, 0xFA24, 0xFA64, 0xFAA4, 0xFAE4, 0xFB24, 0xFB64, 0xFBA4, 0xFBE4, 0xFC24, 0xFC64,
5900 0xFC94, 0xFCB4, 0xFCD4, 0xFCF4, 0xFD14, 0xFD34, 0xFD54, 0xFD74, 0xFD94, 0xFDB4, 0xFDD4, 0xFDF4, 0xFE14, 0xFE34, 0xFE54, 0xFE74,
5901 0xFE8C, 0xFE9C, 0xFEAC, 0xFEBC, 0xFECC, 0xFEDC, 0xFEEC, 0xFEFC, 0xFF0C, 0xFF1C, 0xFF2C, 0xFF3C, 0xFF4C, 0xFF5C, 0xFF6C, 0xFF7C,
5902 0xFF88, 0xFF90, 0xFF98, 0xFFA0, 0xFFA8, 0xFFB0, 0xFFB8, 0xFFC0, 0xFFC8, 0xFFD0, 0xFFD8, 0xFFE0, 0xFFE8, 0xFFF0, 0xFFF8, 0x0000,
5903 0x7D7C, 0x797C, 0x757C, 0x717C, 0x6D7C, 0x697C, 0x657C, 0x617C, 0x5D7C, 0x597C, 0x557C, 0x517C, 0x4D7C, 0x497C, 0x457C, 0x417C,
5904 0x3E7C, 0x3C7C, 0x3A7C, 0x387C, 0x367C, 0x347C, 0x327C, 0x307C, 0x2E7C, 0x2C7C, 0x2A7C, 0x287C, 0x267C, 0x247C, 0x227C, 0x207C,
5905 0x1EFC, 0x1DFC, 0x1CFC, 0x1BFC, 0x1AFC, 0x19FC, 0x18FC, 0x17FC, 0x16FC, 0x15FC, 0x14FC, 0x13FC, 0x12FC, 0x11FC, 0x10FC, 0x0FFC,
5906 0x0F3C, 0x0EBC, 0x0E3C, 0x0DBC, 0x0D3C, 0x0CBC, 0x0C3C, 0x0BBC, 0x0B3C, 0x0ABC, 0x0A3C, 0x09BC, 0x093C, 0x08BC, 0x083C, 0x07BC,
5907 0x075C, 0x071C, 0x06DC, 0x069C, 0x065C, 0x061C, 0x05DC, 0x059C, 0x055C, 0x051C, 0x04DC, 0x049C, 0x045C, 0x041C, 0x03DC, 0x039C,
5908 0x036C, 0x034C, 0x032C, 0x030C, 0x02EC, 0x02CC, 0x02AC, 0x028C, 0x026C, 0x024C, 0x022C, 0x020C, 0x01EC, 0x01CC, 0x01AC, 0x018C,
5909 0x0174, 0x0164, 0x0154, 0x0144, 0x0134, 0x0124, 0x0114, 0x0104, 0x00F4, 0x00E4, 0x00D4, 0x00C4, 0x00B4, 0x00A4, 0x0094, 0x0084,
5910 0x0078, 0x0070, 0x0068, 0x0060, 0x0058, 0x0050, 0x0048, 0x0040, 0x0038, 0x0030, 0x0028, 0x0020, 0x0018, 0x0010, 0x0008, 0x0000
5930 if (bytesPerSample == 1) {
5937 if (bytesPerSample == 2) {
5938 for (i = 0; i < totalSampleCount; ++i) {
5943 if (bytesPerSample == 3) {
5947 if (bytesPerSample == 4) {
5954 if (bytesPerSample > 8) {
5961 for (i = 0; i < totalSampleCount; ++i) {
5963 unsigned int shift = (8 - bytesPerSample) * 8;
5966 for (j = 0; j < bytesPerSample; j += 1) {
5979 if (bytesPerSample == 4) {
5982 }
else if (bytesPerSample == 8) {
6004 if (bytesPerFrame == 0) {
6008 totalFramesRead = 0;
6010 while (framesToRead > 0) {
6012 if (framesRead == 0) {
6018 pBufferOut += framesRead*pWav->
channels;
6019 framesToRead -= framesRead;
6020 totalFramesRead += framesRead;
6023 return totalFramesRead;
6032 if (pBufferOut ==
NULL) {
6037 if (bytesPerFrame == 0) {
6041 totalFramesRead = 0;
6043 while (framesToRead > 0) {
6045 if (framesRead == 0) {
6051 pBufferOut += framesRead*pWav->
channels;
6052 framesToRead -= framesRead;
6053 totalFramesRead += framesRead;
6056 return totalFramesRead;
6065 if (pBufferOut ==
NULL) {
6070 if (bytesPerFrame == 0) {
6074 totalFramesRead = 0;
6076 while (framesToRead > 0) {
6078 if (framesRead == 0) {
6084 pBufferOut += framesRead*pWav->
channels;
6085 framesToRead -= framesRead;
6086 totalFramesRead += framesRead;
6089 return totalFramesRead;
6098 if (pBufferOut ==
NULL) {
6103 if (bytesPerFrame == 0) {
6107 totalFramesRead = 0;
6109 while (framesToRead > 0) {
6111 if (framesRead == 0) {
6117 pBufferOut += framesRead*pWav->
channels;
6118 framesToRead -= framesRead;
6119 totalFramesRead += framesRead;
6122 return totalFramesRead;
6127 if (pWav ==
NULL || framesToRead == 0) {
6131 if (pBufferOut ==
NULL) {
6192 for (i = 0; i < sampleCount; ++i) {
6204 for (i = 0; i < sampleCount; ++i) {
6205 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;
6215 for (i = 0; i < sampleCount; ++i) {
6226 for (i = 0; i < sampleCount; ++i) {
6229 c = ((x < -1) ? -1 : ((x > 1) ? 1 : x));
6231 r = (int)(c * 32767.5f);
6241 for (i = 0; i < sampleCount; ++i) {
6244 c = ((x < -1) ? -1 : ((x > 1) ? 1 : x));
6246 r = (int)(c * 32767.5);
6255 for (i = 0; i < sampleCount; ++i) {
6263 for (i = 0; i < sampleCount; ++i) {
6275 if (bytesPerSample == 1) {
6281 if (bytesPerSample == 2) {
6285 if (bytesPerSample == 3) {
6289 if (bytesPerSample == 4) {
6296 if (bytesPerSample > 8) {
6303 for (i = 0; i < sampleCount; ++i) {
6305 unsigned int shift = (8 - bytesPerSample) * 8;
6308 for (j = 0; j < bytesPerSample; j += 1) {
6315 *pOut++ = (float)((
drwav_int64)sample / 9223372036854775807.0);
6321 if (bytesPerSample == 4) {
6323 for (i = 0; i < sampleCount; ++i) {
6324 *pOut++ = ((
const float*)pIn)[i];
6327 }
else if (bytesPerSample == 8) {
6344 if (bytesPerFrame == 0) {
6348 totalFramesRead = 0;
6350 while (framesToRead > 0) {
6352 if (framesRead == 0) {
6358 pBufferOut += framesRead*pWav->
channels;
6359 framesToRead -= framesRead;
6360 totalFramesRead += framesRead;
6363 return totalFramesRead;
6375 while (framesToRead > 0) {
6377 if (framesRead == 0) {
6383 pBufferOut += framesRead*pWav->
channels;
6384 framesToRead -= framesRead;
6385 totalFramesRead += framesRead;
6388 return totalFramesRead;
6400 while (framesToRead > 0) {
6402 if (framesRead == 0) {
6408 pBufferOut += framesRead*pWav->
channels;
6409 framesToRead -= framesRead;
6410 totalFramesRead += framesRead;
6413 return totalFramesRead;
6428 if (bytesPerFrame == 0) {
6432 totalFramesRead = 0;
6434 while (framesToRead > 0) {
6436 if (framesRead == 0) {
6442 pBufferOut += framesRead*pWav->
channels;
6443 framesToRead -= framesRead;
6444 totalFramesRead += framesRead;
6447 return totalFramesRead;
6456 if (bytesPerFrame == 0) {
6460 totalFramesRead = 0;
6462 while (framesToRead > 0) {
6464 if (framesRead == 0) {
6470 pBufferOut += framesRead*pWav->
channels;
6471 framesToRead -= framesRead;
6472 totalFramesRead += framesRead;
6475 return totalFramesRead;
6484 if (bytesPerFrame == 0) {
6488 totalFramesRead = 0;
6490 while (framesToRead > 0) {
6492 if (framesRead == 0) {
6498 pBufferOut += framesRead*pWav->
channels;
6499 framesToRead -= framesRead;
6500 totalFramesRead += framesRead;
6503 return totalFramesRead;
6508 if (pWav ==
NULL || framesToRead == 0) {
6512 if (pBufferOut ==
NULL) {
6577 #ifdef DR_WAV_LIBSNDFILE_COMPAT
6584 for (i = 0; i < sampleCount; ++i) {
6585 *pOut++ = (pIn[i] / 256.0f) * 2 - 1;
6588 for (i = 0; i < sampleCount; ++i) {
6590 x = x * 0.00784313725490196078f;
6606 for (i = 0; i < sampleCount; ++i) {
6607 *pOut++ = pIn[i] * 0.000030517578125f;
6619 for (i = 0; i < sampleCount; ++i) {
6626 *pOut++ = (float)(x * 0.00000011920928955078125);
6637 for (i = 0; i < sampleCount; ++i) {
6638 *pOut++ = (float)(pIn[i] / 2147483648.0);
6650 for (i = 0; i < sampleCount; ++i) {
6651 *pOut++ = (float)pIn[i];
6663 for (i = 0; i < sampleCount; ++i) {
6676 for (i = 0; i < sampleCount; ++i) {
6688 if (bytesPerSample == 1) {
6694 if (bytesPerSample == 2) {
6698 if (bytesPerSample == 3) {
6702 if (bytesPerSample == 4) {
6703 for (i = 0; i < totalSampleCount; ++i) {
6711 if (bytesPerSample > 8) {
6718 for (i = 0; i < totalSampleCount; ++i) {
6720 unsigned int shift = (8 - bytesPerSample) * 8;
6723 for (j = 0; j < bytesPerSample; j += 1) {
6736 if (bytesPerSample == 4) {
6739 }
else if (bytesPerSample == 8) {
6762 if (bytesPerFrame == 0) {
6766 totalFramesRead = 0;
6768 while (framesToRead > 0) {
6770 if (framesRead == 0) {
6776 pBufferOut += framesRead*pWav->
channels;
6777 framesToRead -= framesRead;
6778 totalFramesRead += framesRead;
6781 return totalFramesRead;
6793 while (framesToRead > 0) {
6795 if (framesRead == 0) {
6801 pBufferOut += framesRead*pWav->
channels;
6802 framesToRead -= framesRead;
6803 totalFramesRead += framesRead;
6806 return totalFramesRead;
6818 while (framesToRead > 0) {
6820 if (framesRead == 0) {
6826 pBufferOut += framesRead*pWav->
channels;
6827 framesToRead -= framesRead;
6828 totalFramesRead += framesRead;
6831 return totalFramesRead;
6840 if (bytesPerFrame == 0) {
6844 totalFramesRead = 0;
6846 while (framesToRead > 0) {
6848 if (framesRead == 0) {
6854 pBufferOut += framesRead*pWav->
channels;
6855 framesToRead -= framesRead;
6856 totalFramesRead += framesRead;
6859 return totalFramesRead;
6868 if (bytesPerFrame == 0) {
6872 totalFramesRead = 0;
6874 while (framesToRead > 0) {
6876 if (framesRead == 0) {
6882 pBufferOut += framesRead*pWav->
channels;
6883 framesToRead -= framesRead;
6884 totalFramesRead += framesRead;
6887 return totalFramesRead;
6896 if (bytesPerFrame == 0) {
6900 totalFramesRead = 0;
6902 while (framesToRead > 0) {
6904 if (framesRead == 0) {
6910 pBufferOut += framesRead*pWav->
channels;
6911 framesToRead -= framesRead;
6912 totalFramesRead += framesRead;
6915 return totalFramesRead;
6920 if (pWav ==
NULL || framesToRead == 0) {
6924 if (pBufferOut ==
NULL) {
6989 for (i = 0; i < sampleCount; ++i) {
6990 *pOut++ = ((int)pIn[i] - 128) << 24;
7002 for (i = 0; i < sampleCount; ++i) {
7003 *pOut++ = pIn[i] << 16;
7015 for (i = 0; i < sampleCount; ++i) {
7016 unsigned int s0 = pIn[i*3 + 0];
7017 unsigned int s1 = pIn[i*3 + 1];
7018 unsigned int s2 = pIn[i*3 + 2];
7033 for (i = 0; i < sampleCount; ++i) {
7046 for (i = 0; i < sampleCount; ++i) {
7059 for (i = 0; i < sampleCount; ++i) {
7072 for (i= 0; i < sampleCount; ++i) {
7094 if (pSampleData ==
NULL) {
7114 if (totalFrameCount) {
7136 if (pSampleData ==
NULL) {
7156 if (totalFrameCount) {
7178 if (pSampleData ==
NULL) {
7198 if (totalFrameCount) {
7214 if (sampleRateOut) {
7217 if (totalFrameCountOut) {
7218 *totalFrameCountOut = 0;
7221 if (!
drwav_init(&wav, onRead, onSeek, pUserData, pAllocationCallbacks)) {
7235 if (sampleRateOut) {
7238 if (totalFrameCountOut) {
7239 *totalFrameCountOut = 0;
7242 if (!
drwav_init(&wav, onRead, onSeek, pUserData, pAllocationCallbacks)) {
7256 if (sampleRateOut) {
7259 if (totalFrameCountOut) {
7260 *totalFrameCountOut = 0;
7263 if (!
drwav_init(&wav, onRead, onSeek, pUserData, pAllocationCallbacks)) {
7270 #ifndef DR_WAV_NO_STDIO
7278 if (sampleRateOut) {
7281 if (totalFrameCountOut) {
7282 *totalFrameCountOut = 0;
7299 if (sampleRateOut) {
7302 if (totalFrameCountOut) {
7303 *totalFrameCountOut = 0;
7320 if (sampleRateOut) {
7323 if (totalFrameCountOut) {
7324 *totalFrameCountOut = 0;
7339 if (sampleRateOut) {
7345 if (totalFrameCountOut) {
7346 *totalFrameCountOut = 0;
7360 if (sampleRateOut) {
7366 if (totalFrameCountOut) {
7367 *totalFrameCountOut = 0;
7381 if (sampleRateOut) {
7387 if (totalFrameCountOut) {
7388 *totalFrameCountOut = 0;
7406 if (sampleRateOut) {
7409 if (totalFrameCountOut) {
7410 *totalFrameCountOut = 0;
7427 if (sampleRateOut) {
7430 if (totalFrameCountOut) {
7431 *totalFrameCountOut = 0;
7448 if (sampleRateOut) {
7451 if (totalFrameCountOut) {
7452 *totalFrameCountOut = 0;
7466 if (pAllocationCallbacks !=
NULL) {
7520 for (i = 0; i < 16; i += 1) {