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 0
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(__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) {
2830 if (pWav ==
NULL || onRead ==
NULL || onSeek ==
NULL) {
2855 unsigned short translatedFormatTag;
2887 for (i = 0; i < 12; ++i) {
2962 bytesRemainingInChunk =
header.sizeInBytes +
header.paddingSize;
2968 bytesRemainingInChunk -= 8;
2976 bytesRemainingInChunk -= 8;
2984 bytesRemainingInChunk -= 8;
2992 cursor += bytesRemainingInChunk;
3016 memset(&metadataParser, 0,
sizeof(metadataParser));
3041 remainingBytes =
header.sizeInBytes - bytesRead +
header.paddingSize;
3045 cursorForMetadata += remainingBytes;
3070 if (!foundDataChunk) {
3078 if (!sequential && onChunk !=
NULL) {
3085 if (callbackBytesRead > 0) {
3095 if (bytesRead > 0) {
3103 if (!foundDataChunk) {
3107 chunkSize =
header.sizeInBytes;
3112 dataChunkSize = chunkSize;
3118 dataChunkSize = chunkSize;
3126 if (foundDataChunk && sequential) {
3139 if (!foundDataChunk) {
3148 sampleCountFromFactChunk = sampleCount;
3150 sampleCountFromFactChunk = 0;
3160 if (!foundDataChunk) {
3169 chunkSize +=
header.paddingSize;
3173 cursor += chunkSize;
3175 if (!foundDataChunk) {
3184 if (!foundDataChunk) {
3207 if (sampleCountFromFactChunk != 0) {
3217 if ((blockCount * fmt.
blockAlign) < dataChunkSize) {
3222 totalBlockHeaderSizeInBytes = blockCount * (6*fmt.
channels);
3230 if ((blockCount * fmt.
blockAlign) < dataChunkSize) {
3235 totalBlockHeaderSizeInBytes = blockCount * (4*fmt.
channels);
3250 #ifdef DR_WAV_LIBSNDFILE_COMPAT
3279 if (!
drwav_preinit(pWav, onRead, onSeek, pReadSeekUserData, pAllocationCallbacks)) {
3288 if (!
drwav_preinit(pWav, onRead, onSeek, pUserData, pAllocationCallbacks)) {
3440 return bufFixedSize;
3446 if (len < bufFixedSize) {
3448 for (i = 0; i < bufFixedSize - len; ++i) {
3453 return bufFixedSize;
3460 size_t bytesWritten = 0;
3465 if (pMetadatas ==
NULL || metadataCount == 0) {
3469 for (iMetadata = 0; iMetadata < metadataCount; ++iMetadata) {
3481 switch (pMetadata->
type) {
3595 memset(reservedBuf, 0,
sizeof(reservedBuf));
3616 if ((chunkSize % 2) != 0) {
3623 for (iMetadata = 0; iMetadata < metadataCount; ++iMetadata) {
3634 if ((chunkSize % 2) != 0) {
3643 for (iMetadata = 0; iMetadata < metadataCount; ++iMetadata) {
3648 const char* pID =
NULL;
3650 switch (pMetadata->
type) {
3682 if ((subchunkSize % 2) != 0) {
3691 for (iMetadata = 0; iMetadata < metadataCount; ++iMetadata) {
3694 switch (pMetadata->
type)
3728 if ((chunkSize % 2) != 0) {
3737 for (iMetadata = 0; iMetadata < metadataCount; ++iMetadata) {
3741 switch (pMetadata->
type)
3747 const char *pID =
NULL;
3811 if ((subchunkSize % 2) != 0) {
3819 return bytesWritten;
3825 if (chunkSize > 0xFFFFFFFFUL) {
3826 chunkSize = 0xFFFFFFFFUL;
3834 if (dataChunkSize <= 0xFFFFFFFFUL) {
3837 return 0xFFFFFFFFUL;
3845 return 80 + 24 + dataChunkSize + dataSubchunkPaddingSize;
3850 return 24 + dataChunkSize;
3856 if (chunkSize > 0xFFFFFFFFUL) {
3857 chunkSize = 0xFFFFFFFFUL;
3865 return dataChunkSize;
3872 if (pWav ==
NULL || onWrite ==
NULL) {
3876 if (!isSequential && onSeek ==
NULL) {
3915 size_t runningPos = 0;
3932 if (initialDataChunkSize > (0xFFFFFFFFUL - 36)) {
3948 drwav_uint64 chunkSizeRIFF = 80 + 24 + initialDataChunkSize;
3962 drwav_uint64 initialRiffChunkSize = 8 + initialds64ChunkSize + initialDataChunkSize;
4005 drwav_uint64 chunkSizeDATA = 24 + initialDataChunkSize;
4045 if (pFormat ==
NULL) {
4074 fileSizeBytes = (8 + riffChunkSizeBytes);
4077 fileSizeBytes = riffChunkSizeBytes;
4080 fileSizeBytes = (8 + riffChunkSizeBytes);
4083 return fileSizeBytes;
4087 #ifndef DR_WAV_NO_STDIO
4366 #ifdef EPROTONOSUPPORT
4369 #ifdef ESOCKTNOSUPPORT
4384 #ifdef EADDRNOTAVAIL
4480 #ifdef ENOTRECOVERABLE
4495 #if defined(_MSC_VER) && _MSC_VER >= 1400
4499 if (ppFile !=
NULL) {
4503 if (pFilePath ==
NULL || pOpenMode ==
NULL || ppFile ==
NULL) {
4507 #if defined(_MSC_VER) && _MSC_VER >= 1400
4508 err = fopen_s(ppFile, pFilePath, pOpenMode);
4513 #if defined(_WIN32) || defined(__APPLE__)
4514 *ppFile = fopen(pFilePath, pOpenMode);
4516 #if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 && defined(_LARGEFILE64_SOURCE)
4517 *ppFile = fopen64(pFilePath, pOpenMode);
4519 *ppFile = fopen(pFilePath, pOpenMode);
4522 if (*ppFile ==
NULL) {
4548 #if defined(_MSC_VER) || defined(__MINGW64__) || (!defined(__STRICT_ANSI__) && !defined(_NO_EXT_KEYS))
4549 #define DRWAV_HAS_WFOPEN
4555 if (ppFile !=
NULL) {
4559 if (pFilePath ==
NULL || pOpenMode ==
NULL || ppFile ==
NULL) {
4563 #if defined(DRWAV_HAS_WFOPEN)
4566 #if defined(_MSC_VER) && _MSC_VER >= 1400
4567 errno_t err = _wfopen_s(ppFile, pFilePath, pOpenMode);
4572 *ppFile = _wfopen(pFilePath, pOpenMode);
4573 if (*ppFile ==
NULL) {
4577 (void)pAllocationCallbacks;
4588 const wchar_t* pFilePathTemp = pFilePath;
4589 char* pFilePathMB =
NULL;
4590 char pOpenModeMB[32] = {0};
4594 lenMB = wcsrtombs(
NULL, &pFilePathTemp, 0, &mbs);
4595 if (lenMB == (
size_t)-1) {
4600 if (pFilePathMB ==
NULL) {
4604 pFilePathTemp = pFilePath;
4606 wcsrtombs(pFilePathMB, &pFilePathTemp, lenMB + 1, &mbs);
4612 if (pOpenMode[i] == 0) {
4613 pOpenModeMB[i] =
'\0';
4617 pOpenModeMB[i] = (char)pOpenMode[i];
4622 *ppFile = fopen(pFilePathMB, pOpenModeMB);
4627 if (*ppFile ==
NULL) {
4638 return fread(pBufferOut, 1, bytesToRead, (FILE*)pUserData);
4643 return fwrite(pData, 1, bytesToWrite, (FILE*)pUserData);
4781 if (pFormat ==
NULL) {
4800 if (pFormat ==
NULL) {
4812 size_t bytesRemaining;
4818 if (bytesToRead > bytesRemaining) {
4819 bytesToRead = bytesRemaining;
4822 if (bytesToRead > 0) {
4849 if ((
drwav_uint32)offset <= pWav->memoryStream.dataSize) {
4862 size_t bytesRemaining;
4868 if (bytesRemaining < bytesToWrite) {
4879 if (pNewData ==
NULL) {
4896 return bytesToWrite;
4935 if (data ==
NULL || dataSize == 0) {
4952 if (data ==
NULL || dataSize == 0) {
4972 if (ppData ==
NULL || pDataSize ==
NULL) {
5004 if (pFormat ==
NULL) {
5036 if (paddingSize > 0) {
5072 int ds64BodyPos = 12 + 8;
5100 #ifndef DR_WAV_NO_STDIO
5119 if (pWav ==
NULL || bytesToRead == 0) {
5127 if (bytesToRead == 0) {
5131 if (pBufferOut !=
NULL) {
5136 while (bytesRead < bytesToRead) {
5137 size_t bytesToSeek = (bytesToRead - bytesRead);
5138 if (bytesToSeek > 0x7FFFFFFF) {
5139 bytesToSeek = 0x7FFFFFFF;
5146 bytesRead += bytesToSeek;
5150 while (bytesRead < bytesToRead) {
5153 size_t bytesToSeek = (bytesToRead - bytesRead);
5154 if (bytesToSeek >
sizeof(buffer)) {
5155 bytesToSeek =
sizeof(buffer);
5159 bytesRead += bytesSeeked;
5161 if (bytesSeeked < bytesToSeek) {
5180 if (pWav ==
NULL || framesToRead == 0) {
5190 if (bytesPerFrame == 0) {
5195 bytesToRead = framesToRead * bytesPerFrame;
5204 if (bytesToRead == 0) {
5208 return drwav_read_raw(pWav, (
size_t)bytesToRead, pBufferOut) / bytesPerFrame;
5215 if (pBufferOut !=
NULL) {
5294 if (targetFrameIndex < pWav->readCursorInPCMFrames) {
5304 while (offsetInFrames > 0) {
5319 if (framesRead != framesToRead) {
5323 offsetInFrames -= framesRead;
5338 if (currentBytePos < targetBytePos) {
5340 offset = (targetBytePos - currentBytePos);
5346 offset = targetBytePos;
5349 while (offset > 0) {
5350 int offset32 = ((offset > INT_MAX) ? INT_MAX : (
int)offset);
5366 if (pCursor ==
NULL) {
5383 if (pLength ==
NULL) {
5401 size_t bytesWritten;
5403 if (pWav ==
NULL || bytesToWrite == 0 || pData ==
NULL) {
5410 return bytesWritten;
5419 if (pWav ==
NULL || framesToWrite == 0 || pData ==
NULL) {
5431 while (bytesToWrite > 0) {
5432 size_t bytesJustWritten;
5435 bytesToWriteThisIteration = bytesToWrite;
5438 bytesJustWritten =
drwav_write_raw(pWav, (
size_t)bytesToWriteThisIteration, pRunningData);
5439 if (bytesJustWritten == 0) {
5443 bytesToWrite -= bytesJustWritten;
5444 bytesWritten += bytesJustWritten;
5445 pRunningData += bytesJustWritten;
5458 if (pWav ==
NULL || framesToWrite == 0 || pData ==
NULL) {
5472 while (bytesToWrite > 0) {
5475 size_t bytesJustWritten;
5478 bytesToWriteThisIteration = bytesToWrite;
5485 sampleCount =
sizeof(temp)/bytesPerSample;
5487 if (bytesToWriteThisIteration > ((
drwav_uint64)sampleCount)*bytesPerSample) {
5488 bytesToWriteThisIteration = ((
drwav_uint64)sampleCount)*bytesPerSample;
5494 bytesJustWritten =
drwav_write_raw(pWav, (
size_t)bytesToWriteThisIteration, temp);
5495 if (bytesJustWritten == 0) {
5499 bytesToWrite -= bytesJustWritten;
5500 bytesWritten += bytesJustWritten;
5501 pRunningData += bytesJustWritten;
5534 if (pWav->
onRead(pWav->
pUserData, header,
sizeof(header)) !=
sizeof(header)) {
5535 return totalFramesRead;
5549 if (pWav->
onRead(pWav->
pUserData, header,
sizeof(header)) !=
sizeof(header)) {
5550 return totalFramesRead;
5573 if (pBufferOut !=
NULL) {
5575 for (iSample = 0; iSample < pWav->
channels; iSample += 1) {
5583 totalFramesRead += 1;
5588 if (framesToRead == 0) {
5602 230, 230, 230, 230, 307, 409, 512, 614,
5603 768, 614, 512, 409, 307, 230, 230, 230
5605 static drwav_int32 coeff1Table[] = { 256, 512, 0, 192, 240, 460, 392 };
5606 static drwav_int32 coeff2Table[] = { 0, -256, 0, 64, 0, -208, -232 };
5613 return totalFramesRead;
5618 nibble0 = ((nibbles & 0xF0) >> 4);
if ((nibbles & 0x80)) { nibble0 |= 0xFFFFFFF0UL; }
5619 nibble1 = ((nibbles & 0x0F) >> 0);
if ((nibbles & 0x08)) { nibble1 |= 0xFFFFFFF0UL; }
5628 newSample0 =
drwav_clamp(newSample0, -32768, 32767);
5641 newSample1 =
drwav_clamp(newSample1, -32768, 32767);
5663 newSample0 =
drwav_clamp(newSample0, -32768, 32767);
5677 newSample1 =
drwav_clamp(newSample1, -32768, 32767);
5695 return totalFramesRead;
5705 -1, -1, -1, -1, 2, 4, 6, 8,
5706 -1, -1, -1, -1, 2, 4, 6, 8
5710 7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
5711 19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
5712 50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
5713 130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
5714 337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
5715 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
5716 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
5717 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
5718 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
5734 if (pWav->
onRead(pWav->
pUserData, header,
sizeof(header)) !=
sizeof(header)) {
5735 return totalFramesRead;
5742 return totalFramesRead;
5752 if (pWav->
onRead(pWav->
pUserData, header,
sizeof(header)) !=
sizeof(header)) {
5753 return totalFramesRead;
5760 return totalFramesRead;
5776 if (pBufferOut !=
NULL) {
5778 for (iSample = 0; iSample < pWav->
channels; iSample += 1) {
5785 totalFramesRead += 1;
5790 if (framesToRead == 0) {
5807 for (iChannel = 0; iChannel < pWav->
channels; ++iChannel) {
5812 return totalFramesRead;
5816 for (iByte = 0; iByte < 4; ++iByte) {
5817 drwav_uint8 nibble0 = ((nibbles[iByte] & 0x0F) >> 0);
5818 drwav_uint8 nibble1 = ((nibbles[iByte] & 0xF0) >> 4);
5824 if (nibble0 & 1) diff += step >> 2;
5825 if (nibble0 & 2) diff += step >> 1;
5826 if (nibble0 & 4) diff += step;
5827 if (nibble0 & 8) diff = -diff;
5829 predictor =
drwav_clamp(predictor + diff, -32768, 32767);
5839 if (nibble1 & 1) diff += step >> 2;
5840 if (nibble1 & 2) diff += step >> 1;
5841 if (nibble1 & 4) diff += step;
5842 if (nibble1 & 8) diff = -diff;
5844 predictor =
drwav_clamp(predictor + diff, -32768, 32767);
5854 return totalFramesRead;
5858 #ifndef DR_WAV_NO_CONVERSION_API
5860 0xEA80, 0xEB80, 0xE880, 0xE980, 0xEE80, 0xEF80, 0xEC80, 0xED80, 0xE280, 0xE380, 0xE080, 0xE180, 0xE680, 0xE780, 0xE480, 0xE580,
5861 0xF540, 0xF5C0, 0xF440, 0xF4C0, 0xF740, 0xF7C0, 0xF640, 0xF6C0, 0xF140, 0xF1C0, 0xF040, 0xF0C0, 0xF340, 0xF3C0, 0xF240, 0xF2C0,
5862 0xAA00, 0xAE00, 0xA200, 0xA600, 0xBA00, 0xBE00, 0xB200, 0xB600, 0x8A00, 0x8E00, 0x8200, 0x8600, 0x9A00, 0x9E00, 0x9200, 0x9600,
5863 0xD500, 0xD700, 0xD100, 0xD300, 0xDD00, 0xDF00, 0xD900, 0xDB00, 0xC500, 0xC700, 0xC100, 0xC300, 0xCD00, 0xCF00, 0xC900, 0xCB00,
5864 0xFEA8, 0xFEB8, 0xFE88, 0xFE98, 0xFEE8, 0xFEF8, 0xFEC8, 0xFED8, 0xFE28, 0xFE38, 0xFE08, 0xFE18, 0xFE68, 0xFE78, 0xFE48, 0xFE58,
5865 0xFFA8, 0xFFB8, 0xFF88, 0xFF98, 0xFFE8, 0xFFF8, 0xFFC8, 0xFFD8, 0xFF28, 0xFF38, 0xFF08, 0xFF18, 0xFF68, 0xFF78, 0xFF48, 0xFF58,
5866 0xFAA0, 0xFAE0, 0xFA20, 0xFA60, 0xFBA0, 0xFBE0, 0xFB20, 0xFB60, 0xF8A0, 0xF8E0, 0xF820, 0xF860, 0xF9A0, 0xF9E0, 0xF920, 0xF960,
5867 0xFD50, 0xFD70, 0xFD10, 0xFD30, 0xFDD0, 0xFDF0, 0xFD90, 0xFDB0, 0xFC50, 0xFC70, 0xFC10, 0xFC30, 0xFCD0, 0xFCF0, 0xFC90, 0xFCB0,
5868 0x1580, 0x1480, 0x1780, 0x1680, 0x1180, 0x1080, 0x1380, 0x1280, 0x1D80, 0x1C80, 0x1F80, 0x1E80, 0x1980, 0x1880, 0x1B80, 0x1A80,
5869 0x0AC0, 0x0A40, 0x0BC0, 0x0B40, 0x08C0, 0x0840, 0x09C0, 0x0940, 0x0EC0, 0x0E40, 0x0FC0, 0x0F40, 0x0CC0, 0x0C40, 0x0DC0, 0x0D40,
5870 0x5600, 0x5200, 0x5E00, 0x5A00, 0x4600, 0x4200, 0x4E00, 0x4A00, 0x7600, 0x7200, 0x7E00, 0x7A00, 0x6600, 0x6200, 0x6E00, 0x6A00,
5871 0x2B00, 0x2900, 0x2F00, 0x2D00, 0x2300, 0x2100, 0x2700, 0x2500, 0x3B00, 0x3900, 0x3F00, 0x3D00, 0x3300, 0x3100, 0x3700, 0x3500,
5872 0x0158, 0x0148, 0x0178, 0x0168, 0x0118, 0x0108, 0x0138, 0x0128, 0x01D8, 0x01C8, 0x01F8, 0x01E8, 0x0198, 0x0188, 0x01B8, 0x01A8,
5873 0x0058, 0x0048, 0x0078, 0x0068, 0x0018, 0x0008, 0x0038, 0x0028, 0x00D8, 0x00C8, 0x00F8, 0x00E8, 0x0098, 0x0088, 0x00B8, 0x00A8,
5874 0x0560, 0x0520, 0x05E0, 0x05A0, 0x0460, 0x0420, 0x04E0, 0x04A0, 0x0760, 0x0720, 0x07E0, 0x07A0, 0x0660, 0x0620, 0x06E0, 0x06A0,
5875 0x02B0, 0x0290, 0x02F0, 0x02D0, 0x0230, 0x0210, 0x0270, 0x0250, 0x03B0, 0x0390, 0x03F0, 0x03D0, 0x0330, 0x0310, 0x0370, 0x0350
5879 0x8284, 0x8684, 0x8A84, 0x8E84, 0x9284, 0x9684, 0x9A84, 0x9E84, 0xA284, 0xA684, 0xAA84, 0xAE84, 0xB284, 0xB684, 0xBA84, 0xBE84,
5880 0xC184, 0xC384, 0xC584, 0xC784, 0xC984, 0xCB84, 0xCD84, 0xCF84, 0xD184, 0xD384, 0xD584, 0xD784, 0xD984, 0xDB84, 0xDD84, 0xDF84,
5881 0xE104, 0xE204, 0xE304, 0xE404, 0xE504, 0xE604, 0xE704, 0xE804, 0xE904, 0xEA04, 0xEB04, 0xEC04, 0xED04, 0xEE04, 0xEF04, 0xF004,
5882 0xF0C4, 0xF144, 0xF1C4, 0xF244, 0xF2C4, 0xF344, 0xF3C4, 0xF444, 0xF4C4, 0xF544, 0xF5C4, 0xF644, 0xF6C4, 0xF744, 0xF7C4, 0xF844,
5883 0xF8A4, 0xF8E4, 0xF924, 0xF964, 0xF9A4, 0xF9E4, 0xFA24, 0xFA64, 0xFAA4, 0xFAE4, 0xFB24, 0xFB64, 0xFBA4, 0xFBE4, 0xFC24, 0xFC64,
5884 0xFC94, 0xFCB4, 0xFCD4, 0xFCF4, 0xFD14, 0xFD34, 0xFD54, 0xFD74, 0xFD94, 0xFDB4, 0xFDD4, 0xFDF4, 0xFE14, 0xFE34, 0xFE54, 0xFE74,
5885 0xFE8C, 0xFE9C, 0xFEAC, 0xFEBC, 0xFECC, 0xFEDC, 0xFEEC, 0xFEFC, 0xFF0C, 0xFF1C, 0xFF2C, 0xFF3C, 0xFF4C, 0xFF5C, 0xFF6C, 0xFF7C,
5886 0xFF88, 0xFF90, 0xFF98, 0xFFA0, 0xFFA8, 0xFFB0, 0xFFB8, 0xFFC0, 0xFFC8, 0xFFD0, 0xFFD8, 0xFFE0, 0xFFE8, 0xFFF0, 0xFFF8, 0x0000,
5887 0x7D7C, 0x797C, 0x757C, 0x717C, 0x6D7C, 0x697C, 0x657C, 0x617C, 0x5D7C, 0x597C, 0x557C, 0x517C, 0x4D7C, 0x497C, 0x457C, 0x417C,
5888 0x3E7C, 0x3C7C, 0x3A7C, 0x387C, 0x367C, 0x347C, 0x327C, 0x307C, 0x2E7C, 0x2C7C, 0x2A7C, 0x287C, 0x267C, 0x247C, 0x227C, 0x207C,
5889 0x1EFC, 0x1DFC, 0x1CFC, 0x1BFC, 0x1AFC, 0x19FC, 0x18FC, 0x17FC, 0x16FC, 0x15FC, 0x14FC, 0x13FC, 0x12FC, 0x11FC, 0x10FC, 0x0FFC,
5890 0x0F3C, 0x0EBC, 0x0E3C, 0x0DBC, 0x0D3C, 0x0CBC, 0x0C3C, 0x0BBC, 0x0B3C, 0x0ABC, 0x0A3C, 0x09BC, 0x093C, 0x08BC, 0x083C, 0x07BC,
5891 0x075C, 0x071C, 0x06DC, 0x069C, 0x065C, 0x061C, 0x05DC, 0x059C, 0x055C, 0x051C, 0x04DC, 0x049C, 0x045C, 0x041C, 0x03DC, 0x039C,
5892 0x036C, 0x034C, 0x032C, 0x030C, 0x02EC, 0x02CC, 0x02AC, 0x028C, 0x026C, 0x024C, 0x022C, 0x020C, 0x01EC, 0x01CC, 0x01AC, 0x018C,
5893 0x0174, 0x0164, 0x0154, 0x0144, 0x0134, 0x0124, 0x0114, 0x0104, 0x00F4, 0x00E4, 0x00D4, 0x00C4, 0x00B4, 0x00A4, 0x0094, 0x0084,
5894 0x0078, 0x0070, 0x0068, 0x0060, 0x0058, 0x0050, 0x0048, 0x0040, 0x0038, 0x0030, 0x0028, 0x0020, 0x0018, 0x0010, 0x0008, 0x0000
5914 if (bytesPerSample == 1) {
5921 if (bytesPerSample == 2) {
5922 for (i = 0; i < totalSampleCount; ++i) {
5927 if (bytesPerSample == 3) {
5931 if (bytesPerSample == 4) {
5938 if (bytesPerSample > 8) {
5945 for (i = 0; i < totalSampleCount; ++i) {
5947 unsigned int shift = (8 - bytesPerSample) * 8;
5950 for (j = 0; j < bytesPerSample; j += 1) {
5963 if (bytesPerSample == 4) {
5966 }
else if (bytesPerSample == 8) {
5988 if (bytesPerFrame == 0) {
5992 totalFramesRead = 0;
5994 while (framesToRead > 0) {
5996 if (framesRead == 0) {
6002 pBufferOut += framesRead*pWav->
channels;
6003 framesToRead -= framesRead;
6004 totalFramesRead += framesRead;
6007 return totalFramesRead;
6016 if (pBufferOut ==
NULL) {
6021 if (bytesPerFrame == 0) {
6025 totalFramesRead = 0;
6027 while (framesToRead > 0) {
6029 if (framesRead == 0) {
6035 pBufferOut += framesRead*pWav->
channels;
6036 framesToRead -= framesRead;
6037 totalFramesRead += framesRead;
6040 return totalFramesRead;
6049 if (pBufferOut ==
NULL) {
6054 if (bytesPerFrame == 0) {
6058 totalFramesRead = 0;
6060 while (framesToRead > 0) {
6062 if (framesRead == 0) {
6068 pBufferOut += framesRead*pWav->
channels;
6069 framesToRead -= framesRead;
6070 totalFramesRead += framesRead;
6073 return totalFramesRead;
6082 if (pBufferOut ==
NULL) {
6087 if (bytesPerFrame == 0) {
6091 totalFramesRead = 0;
6093 while (framesToRead > 0) {
6095 if (framesRead == 0) {
6101 pBufferOut += framesRead*pWav->
channels;
6102 framesToRead -= framesRead;
6103 totalFramesRead += framesRead;
6106 return totalFramesRead;
6111 if (pWav ==
NULL || framesToRead == 0) {
6115 if (pBufferOut ==
NULL) {
6176 for (i = 0; i < sampleCount; ++i) {
6188 for (i = 0; i < sampleCount; ++i) {
6189 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;
6199 for (i = 0; i < sampleCount; ++i) {
6210 for (i = 0; i < sampleCount; ++i) {
6213 c = ((x < -1) ? -1 : ((x > 1) ? 1 : x));
6215 r = (int)(c * 32767.5f);
6225 for (i = 0; i < sampleCount; ++i) {
6228 c = ((x < -1) ? -1 : ((x > 1) ? 1 : x));
6230 r = (int)(c * 32767.5);
6239 for (i = 0; i < sampleCount; ++i) {
6247 for (i = 0; i < sampleCount; ++i) {
6259 if (bytesPerSample == 1) {
6265 if (bytesPerSample == 2) {
6269 if (bytesPerSample == 3) {
6273 if (bytesPerSample == 4) {
6280 if (bytesPerSample > 8) {
6287 for (i = 0; i < sampleCount; ++i) {
6289 unsigned int shift = (8 - bytesPerSample) * 8;
6292 for (j = 0; j < bytesPerSample; j += 1) {
6299 *pOut++ = (float)((
drwav_int64)sample / 9223372036854775807.0);
6305 if (bytesPerSample == 4) {
6307 for (i = 0; i < sampleCount; ++i) {
6308 *pOut++ = ((
const float*)pIn)[i];
6311 }
else if (bytesPerSample == 8) {
6328 if (bytesPerFrame == 0) {
6332 totalFramesRead = 0;
6334 while (framesToRead > 0) {
6336 if (framesRead == 0) {
6342 pBufferOut += framesRead*pWav->
channels;
6343 framesToRead -= framesRead;
6344 totalFramesRead += framesRead;
6347 return totalFramesRead;
6359 while (framesToRead > 0) {
6361 if (framesRead == 0) {
6367 pBufferOut += framesRead*pWav->
channels;
6368 framesToRead -= framesRead;
6369 totalFramesRead += framesRead;
6372 return totalFramesRead;
6384 while (framesToRead > 0) {
6386 if (framesRead == 0) {
6392 pBufferOut += framesRead*pWav->
channels;
6393 framesToRead -= framesRead;
6394 totalFramesRead += framesRead;
6397 return totalFramesRead;
6412 if (bytesPerFrame == 0) {
6416 totalFramesRead = 0;
6418 while (framesToRead > 0) {
6420 if (framesRead == 0) {
6426 pBufferOut += framesRead*pWav->
channels;
6427 framesToRead -= framesRead;
6428 totalFramesRead += framesRead;
6431 return totalFramesRead;
6440 if (bytesPerFrame == 0) {
6444 totalFramesRead = 0;
6446 while (framesToRead > 0) {
6448 if (framesRead == 0) {
6454 pBufferOut += framesRead*pWav->
channels;
6455 framesToRead -= framesRead;
6456 totalFramesRead += framesRead;
6459 return totalFramesRead;
6468 if (bytesPerFrame == 0) {
6472 totalFramesRead = 0;
6474 while (framesToRead > 0) {
6476 if (framesRead == 0) {
6482 pBufferOut += framesRead*pWav->
channels;
6483 framesToRead -= framesRead;
6484 totalFramesRead += framesRead;
6487 return totalFramesRead;
6492 if (pWav ==
NULL || framesToRead == 0) {
6496 if (pBufferOut ==
NULL) {
6561 #ifdef DR_WAV_LIBSNDFILE_COMPAT
6568 for (i = 0; i < sampleCount; ++i) {
6569 *pOut++ = (pIn[i] / 256.0f) * 2 - 1;
6572 for (i = 0; i < sampleCount; ++i) {
6574 x = x * 0.00784313725490196078f;
6590 for (i = 0; i < sampleCount; ++i) {
6591 *pOut++ = pIn[i] * 0.000030517578125f;
6603 for (i = 0; i < sampleCount; ++i) {
6610 *pOut++ = (float)(x * 0.00000011920928955078125);
6621 for (i = 0; i < sampleCount; ++i) {
6622 *pOut++ = (float)(pIn[i] / 2147483648.0);
6634 for (i = 0; i < sampleCount; ++i) {
6635 *pOut++ = (float)pIn[i];
6647 for (i = 0; i < sampleCount; ++i) {
6660 for (i = 0; i < sampleCount; ++i) {
6672 if (bytesPerSample == 1) {
6678 if (bytesPerSample == 2) {
6682 if (bytesPerSample == 3) {
6686 if (bytesPerSample == 4) {
6687 for (i = 0; i < totalSampleCount; ++i) {
6695 if (bytesPerSample > 8) {
6702 for (i = 0; i < totalSampleCount; ++i) {
6704 unsigned int shift = (8 - bytesPerSample) * 8;
6707 for (j = 0; j < bytesPerSample; j += 1) {
6720 if (bytesPerSample == 4) {
6723 }
else if (bytesPerSample == 8) {
6746 if (bytesPerFrame == 0) {
6750 totalFramesRead = 0;
6752 while (framesToRead > 0) {
6754 if (framesRead == 0) {
6760 pBufferOut += framesRead*pWav->
channels;
6761 framesToRead -= framesRead;
6762 totalFramesRead += framesRead;
6765 return totalFramesRead;
6777 while (framesToRead > 0) {
6779 if (framesRead == 0) {
6785 pBufferOut += framesRead*pWav->
channels;
6786 framesToRead -= framesRead;
6787 totalFramesRead += framesRead;
6790 return totalFramesRead;
6802 while (framesToRead > 0) {
6804 if (framesRead == 0) {
6810 pBufferOut += framesRead*pWav->
channels;
6811 framesToRead -= framesRead;
6812 totalFramesRead += framesRead;
6815 return totalFramesRead;
6824 if (bytesPerFrame == 0) {
6828 totalFramesRead = 0;
6830 while (framesToRead > 0) {
6832 if (framesRead == 0) {
6838 pBufferOut += framesRead*pWav->
channels;
6839 framesToRead -= framesRead;
6840 totalFramesRead += framesRead;
6843 return totalFramesRead;
6852 if (bytesPerFrame == 0) {
6856 totalFramesRead = 0;
6858 while (framesToRead > 0) {
6860 if (framesRead == 0) {
6866 pBufferOut += framesRead*pWav->
channels;
6867 framesToRead -= framesRead;
6868 totalFramesRead += framesRead;
6871 return totalFramesRead;
6880 if (bytesPerFrame == 0) {
6884 totalFramesRead = 0;
6886 while (framesToRead > 0) {
6888 if (framesRead == 0) {
6894 pBufferOut += framesRead*pWav->
channels;
6895 framesToRead -= framesRead;
6896 totalFramesRead += framesRead;
6899 return totalFramesRead;
6904 if (pWav ==
NULL || framesToRead == 0) {
6908 if (pBufferOut ==
NULL) {
6973 for (i = 0; i < sampleCount; ++i) {
6974 *pOut++ = ((int)pIn[i] - 128) << 24;
6986 for (i = 0; i < sampleCount; ++i) {
6987 *pOut++ = pIn[i] << 16;
6999 for (i = 0; i < sampleCount; ++i) {
7000 unsigned int s0 = pIn[i*3 + 0];
7001 unsigned int s1 = pIn[i*3 + 1];
7002 unsigned int s2 = pIn[i*3 + 2];
7017 for (i = 0; i < sampleCount; ++i) {
7030 for (i = 0; i < sampleCount; ++i) {
7043 for (i = 0; i < sampleCount; ++i) {
7056 for (i= 0; i < sampleCount; ++i) {
7078 if (pSampleData ==
NULL) {
7098 if (totalFrameCount) {
7120 if (pSampleData ==
NULL) {
7140 if (totalFrameCount) {
7162 if (pSampleData ==
NULL) {
7182 if (totalFrameCount) {
7198 if (sampleRateOut) {
7201 if (totalFrameCountOut) {
7202 *totalFrameCountOut = 0;
7205 if (!
drwav_init(&wav, onRead, onSeek, pUserData, pAllocationCallbacks)) {
7219 if (sampleRateOut) {
7222 if (totalFrameCountOut) {
7223 *totalFrameCountOut = 0;
7226 if (!
drwav_init(&wav, onRead, onSeek, pUserData, pAllocationCallbacks)) {
7240 if (sampleRateOut) {
7243 if (totalFrameCountOut) {
7244 *totalFrameCountOut = 0;
7247 if (!
drwav_init(&wav, onRead, onSeek, pUserData, pAllocationCallbacks)) {
7254 #ifndef DR_WAV_NO_STDIO
7262 if (sampleRateOut) {
7265 if (totalFrameCountOut) {
7266 *totalFrameCountOut = 0;
7283 if (sampleRateOut) {
7286 if (totalFrameCountOut) {
7287 *totalFrameCountOut = 0;
7304 if (sampleRateOut) {
7307 if (totalFrameCountOut) {
7308 *totalFrameCountOut = 0;
7323 if (sampleRateOut) {
7329 if (totalFrameCountOut) {
7330 *totalFrameCountOut = 0;
7344 if (sampleRateOut) {
7350 if (totalFrameCountOut) {
7351 *totalFrameCountOut = 0;
7365 if (sampleRateOut) {
7371 if (totalFrameCountOut) {
7372 *totalFrameCountOut = 0;
7390 if (sampleRateOut) {
7393 if (totalFrameCountOut) {
7394 *totalFrameCountOut = 0;
7411 if (sampleRateOut) {
7414 if (totalFrameCountOut) {
7415 *totalFrameCountOut = 0;
7432 if (sampleRateOut) {
7435 if (totalFrameCountOut) {
7436 *totalFrameCountOut = 0;
7450 if (pAllocationCallbacks !=
NULL) {
7504 for (i = 0; i < 16; i += 1) {