mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-23 00:34:03 +02:00
Update dr_libs.
This commit is contained in:
+14
-10
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
FLAC audio decoder. Choice of public domain or MIT-0. See license statements at the end of this file.
|
||||
dr_flac - v0.12.19 - 2020-08-30
|
||||
dr_flac - v0.12.20 - 2020-09-08
|
||||
|
||||
David Reid - mackron@gmail.com
|
||||
|
||||
@@ -232,7 +232,7 @@ extern "C" {
|
||||
|
||||
#define DRFLAC_VERSION_MAJOR 0
|
||||
#define DRFLAC_VERSION_MINOR 12
|
||||
#define DRFLAC_VERSION_REVISION 19
|
||||
#define DRFLAC_VERSION_REVISION 20
|
||||
#define DRFLAC_VERSION_STRING DRFLAC_XSTRINGIFY(DRFLAC_VERSION_MAJOR) "." DRFLAC_XSTRINGIFY(DRFLAC_VERSION_MINOR) "." DRFLAC_XSTRINGIFY(DRFLAC_VERSION_REVISION)
|
||||
|
||||
#include <stddef.h> /* For size_t. */
|
||||
@@ -1828,14 +1828,15 @@ static DRFLAC_INLINE drflac_uint64 drflac__swap_endian_uint64(drflac_uint64 n)
|
||||
#error "This compiler does not support the byte swap intrinsic."
|
||||
#endif
|
||||
#else
|
||||
return ((n & (drflac_uint64)0xFF00000000000000) >> 56) |
|
||||
((n & (drflac_uint64)0x00FF000000000000) >> 40) |
|
||||
((n & (drflac_uint64)0x0000FF0000000000) >> 24) |
|
||||
((n & (drflac_uint64)0x000000FF00000000) >> 8) |
|
||||
((n & (drflac_uint64)0x00000000FF000000) << 8) |
|
||||
((n & (drflac_uint64)0x0000000000FF0000) << 24) |
|
||||
((n & (drflac_uint64)0x000000000000FF00) << 40) |
|
||||
((n & (drflac_uint64)0x00000000000000FF) << 56);
|
||||
/* Weird "<< 32" bitshift is required for C89 because it doesn't support 64-bit constants. Should be optimized out by a good compiler. */
|
||||
return ((n & ((drflac_uint64)0xFF000000 << 32)) >> 56) |
|
||||
((n & ((drflac_uint64)0x00FF0000 << 32)) >> 40) |
|
||||
((n & ((drflac_uint64)0x0000FF00 << 32)) >> 24) |
|
||||
((n & ((drflac_uint64)0x000000FF << 32)) >> 8) |
|
||||
((n & ((drflac_uint64)0xFF000000 )) << 8) |
|
||||
((n & ((drflac_uint64)0x00FF0000 )) << 24) |
|
||||
((n & ((drflac_uint64)0x0000FF00 )) << 40) |
|
||||
((n & ((drflac_uint64)0x000000FF )) << 56);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -11772,6 +11773,9 @@ DRFLAC_API drflac_bool32 drflac_next_cuesheet_track(drflac_cuesheet_track_iterat
|
||||
/*
|
||||
REVISION HISTORY
|
||||
================
|
||||
v0.12.20 - 2020-09-08
|
||||
- Fix a compilation error on older compilers.
|
||||
|
||||
v0.12.19 - 2020-08-30
|
||||
- Fix a bug due to an undefined 32-bit shift.
|
||||
|
||||
|
||||
+7
-2
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
MP3 audio decoder. Choice of public domain or MIT-0. See license statements at the end of this file.
|
||||
dr_mp3 - v0.6.16 - 2020-08-02
|
||||
dr_mp3 - v0.6.17 - 2020-09-28
|
||||
|
||||
David Reid - mackron@gmail.com
|
||||
|
||||
@@ -95,7 +95,7 @@ extern "C" {
|
||||
|
||||
#define DRMP3_VERSION_MAJOR 0
|
||||
#define DRMP3_VERSION_MINOR 6
|
||||
#define DRMP3_VERSION_REVISION 16
|
||||
#define DRMP3_VERSION_REVISION 17
|
||||
#define DRMP3_VERSION_STRING DRMP3_XSTRINGIFY(DRMP3_VERSION_MAJOR) "." DRMP3_XSTRINGIFY(DRMP3_VERSION_MINOR) "." DRMP3_XSTRINGIFY(DRMP3_VERSION_REVISION)
|
||||
|
||||
#include <stddef.h> /* For size_t. */
|
||||
@@ -713,6 +713,8 @@ static __inline__ __attribute__((always_inline)) drmp3_int32 drmp3_clip_int16_ar
|
||||
__asm__ ("ssat %0, #16, %1" : "=r"(x) : "r"(a));
|
||||
return x;
|
||||
}
|
||||
#else
|
||||
#define DRMP3_HAVE_ARMV6 0
|
||||
#endif
|
||||
|
||||
|
||||
@@ -4430,6 +4432,9 @@ counts rather than sample counts.
|
||||
/*
|
||||
REVISION HISTORY
|
||||
================
|
||||
v0.6.17 - 2020-09-28
|
||||
- Bring up to date with minimp3.
|
||||
|
||||
v0.6.16 - 2020-08-02
|
||||
- Simplify sized types.
|
||||
|
||||
|
||||
+169
-63
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
WAV audio loader and writer. Choice of public domain or MIT-0. See license statements at the end of this file.
|
||||
dr_wav - v0.12.10 - 2020-08-24
|
||||
dr_wav - v0.12.12 - 2020-09-28
|
||||
|
||||
David Reid - mackron@gmail.com
|
||||
|
||||
@@ -18,7 +18,7 @@ Changes to Chunk Callback
|
||||
dr_wav supports the ability to fire a callback when a chunk is encounted (except for WAVE and FMT chunks). The callback has been updated to include both the
|
||||
container (RIFF or Wave64) and the FMT chunk which contains information about the format of the data in the wave file.
|
||||
|
||||
Previously, there was no direct way to determine the container, and therefore no way discriminate against the different IDs in the chunk header (RIFF and
|
||||
Previously, there was no direct way to determine the container, and therefore no way to discriminate against the different IDs in the chunk header (RIFF and
|
||||
Wave64 containers encode chunk ID's differently). The `container` parameter can be used to know which ID to use.
|
||||
|
||||
Sometimes it can be useful to know the data format at the time the chunk callback is fired. A pointer to a `drwav_fmt` object is now passed into the chunk
|
||||
@@ -144,7 +144,7 @@ extern "C" {
|
||||
|
||||
#define DRWAV_VERSION_MAJOR 0
|
||||
#define DRWAV_VERSION_MINOR 12
|
||||
#define DRWAV_VERSION_REVISION 10
|
||||
#define DRWAV_VERSION_REVISION 12
|
||||
#define DRWAV_VERSION_STRING DRWAV_XSTRINGIFY(DRWAV_VERSION_MAJOR) "." DRWAV_XSTRINGIFY(DRWAV_VERSION_MINOR) "." DRWAV_XSTRINGIFY(DRWAV_VERSION_REVISION)
|
||||
|
||||
#include <stddef.h> /* For size_t. */
|
||||
@@ -298,7 +298,8 @@ typedef enum
|
||||
typedef enum
|
||||
{
|
||||
drwav_container_riff,
|
||||
drwav_container_w64
|
||||
drwav_container_w64,
|
||||
drwav_container_rf64
|
||||
} drwav_container;
|
||||
|
||||
typedef struct
|
||||
@@ -419,8 +420,8 @@ Returns the number of bytes read + seeked.
|
||||
To read data from the chunk, call onRead(), passing in pReadSeekUserData as the first parameter. Do the same for seeking with onSeek(). The return value must
|
||||
be the total number of bytes you have read _plus_ seeked.
|
||||
|
||||
Use the `container` argument to discriminate the fields in `pChunkHeader->id`. If the container is `drwav_container_riff` you should use `id.fourcc`,
|
||||
otherwise you should use `id.guid`.
|
||||
Use the `container` argument to discriminate the fields in `pChunkHeader->id`. If the container is `drwav_container_riff` or `drwav_container_rf64` you should
|
||||
use `id.fourcc`, otherwise you should use `id.guid`.
|
||||
|
||||
The `pFMT` parameter can be used to determine the data format of the wave file. Use `drwav_fmt_get_format()` to get the sample format, which will be one of the
|
||||
`DR_WAVE_FORMAT_*` identifiers.
|
||||
@@ -881,8 +882,8 @@ Helper for initializing a writer which outputs data to a memory buffer.
|
||||
|
||||
dr_wav will manage the memory allocations, however it is up to the caller to free the data with drwav_free().
|
||||
|
||||
The buffer will remain allocated even after drwav_uninit() is called. Indeed, the buffer should not be
|
||||
considered valid until after drwav_uninit() has been called anyway.
|
||||
The buffer will remain allocated even after drwav_uninit() is called. The buffer should not be considered valid
|
||||
until after drwav_uninit() has been called.
|
||||
*/
|
||||
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(drwav* pWav, void** ppData, size_t* pDataSize, const drwav_data_format* pFormat, drwav_uint64 totalSampleCount, const drwav_allocation_callbacks* pAllocationCallbacks);
|
||||
@@ -1236,14 +1237,15 @@ static DRWAV_INLINE drwav_uint64 drwav__bswap64(drwav_uint64 n)
|
||||
#error "This compiler does not support the byte swap intrinsic."
|
||||
#endif
|
||||
#else
|
||||
return ((n & (drwav_uint64)0xFF00000000000000) >> 56) |
|
||||
((n & (drwav_uint64)0x00FF000000000000) >> 40) |
|
||||
((n & (drwav_uint64)0x0000FF0000000000) >> 24) |
|
||||
((n & (drwav_uint64)0x000000FF00000000) >> 8) |
|
||||
((n & (drwav_uint64)0x00000000FF000000) << 8) |
|
||||
((n & (drwav_uint64)0x0000000000FF0000) << 24) |
|
||||
((n & (drwav_uint64)0x000000000000FF00) << 40) |
|
||||
((n & (drwav_uint64)0x00000000000000FF) << 56);
|
||||
/* Weird "<< 32" bitshift is required for C89 because it doesn't support 64-bit constants. Should be optimized out by a good compiler. */
|
||||
return ((n & ((drwav_uint64)0xFF000000 << 32)) >> 56) |
|
||||
((n & ((drwav_uint64)0x00FF0000 << 32)) >> 40) |
|
||||
((n & ((drwav_uint64)0x0000FF00 << 32)) >> 24) |
|
||||
((n & ((drwav_uint64)0x000000FF << 32)) >> 8) |
|
||||
((n & ((drwav_uint64)0xFF000000 )) << 8) |
|
||||
((n & ((drwav_uint64)0x00FF0000 )) << 24) |
|
||||
((n & ((drwav_uint64)0x0000FF00 )) << 40) |
|
||||
((n & ((drwav_uint64)0x000000FF )) << 56);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1537,7 +1539,7 @@ static drwav_bool32 drwav_init_write__internal(drwav* pWav, const drwav_data_for
|
||||
|
||||
static drwav_result drwav__read_chunk_header(drwav_read_proc onRead, void* pUserData, drwav_container container, drwav_uint64* pRunningBytesReadOut, drwav_chunk_header* pHeaderOut)
|
||||
{
|
||||
if (container == drwav_container_riff) {
|
||||
if (container == drwav_container_riff || container == drwav_container_rf64) {
|
||||
drwav_uint8 sizeInBytes[4];
|
||||
|
||||
if (onRead(pUserData, pHeaderOut->id.fourcc, 4) != 4) {
|
||||
@@ -1629,7 +1631,7 @@ static drwav_bool32 drwav__read_fmt(drwav_read_proc onRead, drwav_seek_proc onSe
|
||||
|
||||
|
||||
/* Skip non-fmt chunks. */
|
||||
while ((container == drwav_container_riff && !drwav__fourcc_equal(header.id.fourcc, "fmt ")) || (container == drwav_container_w64 && !drwav__guid_equal(header.id.guid, drwavGUID_W64_FMT))) {
|
||||
while (((container == drwav_container_riff || container == drwav_container_rf64) && !drwav__fourcc_equal(header.id.fourcc, "fmt ")) || (container == drwav_container_w64 && !drwav__guid_equal(header.id.guid, drwavGUID_W64_FMT))) {
|
||||
if (!drwav__seek_forward(onSeek, header.sizeInBytes + header.paddingSize, pUserData)) {
|
||||
return DRWAV_FALSE;
|
||||
}
|
||||
@@ -1643,7 +1645,7 @@ static drwav_bool32 drwav__read_fmt(drwav_read_proc onRead, drwav_seek_proc onSe
|
||||
|
||||
|
||||
/* Validation. */
|
||||
if (container == drwav_container_riff) {
|
||||
if (container == drwav_container_riff || container == drwav_container_rf64) {
|
||||
if (!drwav__fourcc_equal(header.id.fourcc, "fmt ")) {
|
||||
return DRWAV_FALSE;
|
||||
}
|
||||
@@ -1817,9 +1819,9 @@ static drwav_bool32 drwav_init__internal(drwav* pWav, drwav_chunk_proc onChunk,
|
||||
drwav_uint8 riff[4];
|
||||
drwav_fmt fmt;
|
||||
unsigned short translatedFormatTag;
|
||||
drwav_uint64 sampleCountFromFactChunk;
|
||||
drwav_bool32 foundDataChunk;
|
||||
drwav_uint64 dataChunkSize;
|
||||
drwav_uint64 dataChunkSize = 0; /* <-- Important! Don't explicitly set this to 0 anywhere else. Calculation of the size of the data chunk is performed in different paths depending on the container. */
|
||||
drwav_uint64 sampleCountFromFactChunk = 0; /* Same as dataChunkSize - make sure this is the only place this is initialized to 0. */
|
||||
drwav_uint64 chunkSize;
|
||||
|
||||
cursor = 0;
|
||||
@@ -1852,12 +1854,14 @@ static drwav_bool32 drwav_init__internal(drwav* pWav, drwav_chunk_proc onChunk,
|
||||
return DRWAV_FALSE;
|
||||
}
|
||||
}
|
||||
} else if (drwav__fourcc_equal(riff, "RF64")) {
|
||||
pWav->container = drwav_container_rf64;
|
||||
} else {
|
||||
return DRWAV_FALSE; /* Unknown or unsupported container. */
|
||||
}
|
||||
|
||||
|
||||
if (pWav->container == drwav_container_riff) {
|
||||
if (pWav->container == drwav_container_riff || pWav->container == drwav_container_rf64) {
|
||||
drwav_uint8 chunkSizeBytes[4];
|
||||
drwav_uint8 wave[4];
|
||||
|
||||
@@ -1866,8 +1870,14 @@ static drwav_bool32 drwav_init__internal(drwav* pWav, drwav_chunk_proc onChunk,
|
||||
return DRWAV_FALSE;
|
||||
}
|
||||
|
||||
if (drwav__bytes_to_u32(chunkSizeBytes) < 36) {
|
||||
return DRWAV_FALSE; /* Chunk size should always be at least 36 bytes. */
|
||||
if (pWav->container == drwav_container_riff) {
|
||||
if (drwav__bytes_to_u32(chunkSizeBytes) < 36) {
|
||||
return DRWAV_FALSE; /* Chunk size should always be at least 36 bytes. */
|
||||
}
|
||||
} else {
|
||||
if (drwav__bytes_to_u32(chunkSizeBytes) != 0xFFFFFFFF) {
|
||||
return DRWAV_FALSE; /* Chunk size should always be set to -1/0xFFFFFFFF for RF64. The actual size is retrieved later. */
|
||||
}
|
||||
}
|
||||
|
||||
if (drwav__on_read(pWav->onRead, pWav->pUserData, wave, sizeof(wave), &cursor) != sizeof(wave)) {
|
||||
@@ -1900,6 +1910,54 @@ static drwav_bool32 drwav_init__internal(drwav* pWav, drwav_chunk_proc onChunk,
|
||||
}
|
||||
|
||||
|
||||
/* For RF64, the "ds64" chunk must come next, before the "fmt " chunk. */
|
||||
if (pWav->container == drwav_container_rf64) {
|
||||
drwav_uint8 sizeBytes[8];
|
||||
drwav_uint64 bytesRemainingInChunk;
|
||||
drwav_chunk_header header;
|
||||
drwav_result result = drwav__read_chunk_header(pWav->onRead, pWav->pUserData, pWav->container, &cursor, &header);
|
||||
if (result != DRWAV_SUCCESS) {
|
||||
return DRWAV_FALSE;
|
||||
}
|
||||
|
||||
if (!drwav__fourcc_equal(header.id.fourcc, "ds64")) {
|
||||
return DRWAV_FALSE; /* Expecting "ds64". */
|
||||
}
|
||||
|
||||
bytesRemainingInChunk = header.sizeInBytes + header.paddingSize;
|
||||
|
||||
/* We don't care about the size of the RIFF chunk - skip it. */
|
||||
if (!drwav__seek_forward(pWav->onSeek, 8, pWav->pUserData)) {
|
||||
return DRWAV_FALSE;
|
||||
}
|
||||
bytesRemainingInChunk -= 8;
|
||||
cursor += 8;
|
||||
|
||||
|
||||
/* Next 8 bytes is the size of the "data" chunk. */
|
||||
if (drwav__on_read(pWav->onRead, pWav->pUserData, sizeBytes, sizeof(sizeBytes), &cursor) != sizeof(sizeBytes)) {
|
||||
return DRWAV_FALSE;
|
||||
}
|
||||
bytesRemainingInChunk -= 8;
|
||||
dataChunkSize = drwav__bytes_to_u64(sizeBytes);
|
||||
|
||||
|
||||
/* Next 8 bytes is the same count which we would usually derived from the FACT chunk if it was available. */
|
||||
if (drwav__on_read(pWav->onRead, pWav->pUserData, sizeBytes, sizeof(sizeBytes), &cursor) != sizeof(sizeBytes)) {
|
||||
return DRWAV_FALSE;
|
||||
}
|
||||
bytesRemainingInChunk -= 8;
|
||||
sampleCountFromFactChunk = drwav__bytes_to_u64(sizeBytes);
|
||||
|
||||
|
||||
/* Skip over everything else. */
|
||||
if (!drwav__seek_forward(pWav->onSeek, bytesRemainingInChunk, pWav->pUserData)) {
|
||||
return DRWAV_FALSE;
|
||||
}
|
||||
cursor += bytesRemainingInChunk;
|
||||
}
|
||||
|
||||
|
||||
/* The next bytes should be the "fmt " chunk. */
|
||||
if (!drwav__read_fmt(pWav->onRead, pWav->onSeek, pWav->pUserData, pWav->container, &cursor, &fmt)) {
|
||||
return DRWAV_FALSE; /* Failed to read the "fmt " chunk. */
|
||||
@@ -1921,9 +1979,6 @@ static drwav_bool32 drwav_init__internal(drwav* pWav, drwav_chunk_proc onChunk,
|
||||
}
|
||||
|
||||
|
||||
|
||||
sampleCountFromFactChunk = 0;
|
||||
|
||||
/*
|
||||
We need to enumerate over each chunk for two reasons:
|
||||
1) The "data" chunk may not be the next one
|
||||
@@ -1932,7 +1987,6 @@ static drwav_bool32 drwav_init__internal(drwav* pWav, drwav_chunk_proc onChunk,
|
||||
In order to correctly report each chunk back to the client we will need to keep looping until the end of the file.
|
||||
*/
|
||||
foundDataChunk = DRWAV_FALSE;
|
||||
dataChunkSize = 0;
|
||||
|
||||
/* The next chunk we care about is the "data" chunk. This is not necessarily the next chunk so we'll need to loop. */
|
||||
for (;;)
|
||||
@@ -1968,10 +2022,12 @@ static drwav_bool32 drwav_init__internal(drwav* pWav, drwav_chunk_proc onChunk,
|
||||
}
|
||||
|
||||
chunkSize = header.sizeInBytes;
|
||||
if (pWav->container == drwav_container_riff) {
|
||||
if (pWav->container == drwav_container_riff || pWav->container == drwav_container_rf64) {
|
||||
if (drwav__fourcc_equal(header.id.fourcc, "data")) {
|
||||
foundDataChunk = DRWAV_TRUE;
|
||||
dataChunkSize = chunkSize;
|
||||
if (pWav->container != drwav_container_rf64) { /* The data chunk size for RF64 will always be set to 0xFFFFFFFF here. It was set to it's true value earlier. */
|
||||
dataChunkSize = chunkSize;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (drwav__guid_equal(header.id.guid, drwavGUID_W64_DATA)) {
|
||||
@@ -2011,7 +2067,7 @@ static drwav_bool32 drwav_init__internal(drwav* pWav, drwav_chunk_proc onChunk,
|
||||
sampleCountFromFactChunk = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else if (pWav->container == drwav_container_w64) {
|
||||
if (drwav__guid_equal(header.id.guid, drwavGUID_W64_FACT)) {
|
||||
if (drwav__on_read(pWav->onRead, pWav->pUserData, &sampleCountFromFactChunk, 8, &cursor) != 8) {
|
||||
return DRWAV_FALSE;
|
||||
@@ -2022,10 +2078,12 @@ static drwav_bool32 drwav_init__internal(drwav* pWav, drwav_chunk_proc onChunk,
|
||||
pWav->dataChunkDataPos = cursor;
|
||||
}
|
||||
}
|
||||
} else if (pWav->container == drwav_container_rf64) {
|
||||
/* We retrieved the sample count from the ds64 chunk earlier so no need to do that here. */
|
||||
}
|
||||
|
||||
/* "smpl" chunk. */
|
||||
if (pWav->container == drwav_container_riff) {
|
||||
if (pWav->container == drwav_container_riff || pWav->container == drwav_container_rf64) {
|
||||
if (drwav__fourcc_equal(header.id.fourcc, "smpl")) {
|
||||
drwav_uint8 smplHeaderData[36]; /* 36 = size of the smpl header section, not including the loop data. */
|
||||
if (chunkSize >= sizeof(smplHeaderData)) {
|
||||
@@ -2193,13 +2251,12 @@ DRWAV_API drwav_bool32 drwav_init_ex(drwav* pWav, drwav_read_proc onRead, drwav_
|
||||
|
||||
static drwav_uint32 drwav__riff_chunk_size_riff(drwav_uint64 dataChunkSize)
|
||||
{
|
||||
drwav_uint32 dataSubchunkPaddingSize = drwav__chunk_padding_size_riff(dataChunkSize);
|
||||
|
||||
if (dataChunkSize <= (0xFFFFFFFFUL - 36 - dataSubchunkPaddingSize)) {
|
||||
return 36 + (drwav_uint32)(dataChunkSize + dataSubchunkPaddingSize);
|
||||
} else {
|
||||
return 0xFFFFFFFF;
|
||||
drwav_uint64 chunkSize = 4 + 24 + dataChunkSize + drwav__chunk_padding_size_riff(dataChunkSize); /* 4 = "WAVE". 24 = "fmt " chunk. */
|
||||
if (chunkSize > 0xFFFFFFFFUL) {
|
||||
chunkSize = 0xFFFFFFFFUL;
|
||||
}
|
||||
|
||||
return (drwav_uint32)chunkSize; /* Safe cast due to the clamp above. */
|
||||
}
|
||||
|
||||
static drwav_uint32 drwav__data_chunk_size_riff(drwav_uint64 dataChunkSize)
|
||||
@@ -2223,6 +2280,21 @@ static drwav_uint64 drwav__data_chunk_size_w64(drwav_uint64 dataChunkSize)
|
||||
return 24 + dataChunkSize; /* +24 because W64 includes the size of the GUID and size fields. */
|
||||
}
|
||||
|
||||
static drwav_uint64 drwav__riff_chunk_size_rf64(drwav_uint64 dataChunkSize)
|
||||
{
|
||||
drwav_uint64 chunkSize = 4 + 36 + 24 + dataChunkSize + drwav__chunk_padding_size_riff(dataChunkSize); /* 4 = "WAVE". 36 = "ds64" chunk. 24 = "fmt " chunk. */
|
||||
if (chunkSize > 0xFFFFFFFFUL) {
|
||||
chunkSize = 0xFFFFFFFFUL;
|
||||
}
|
||||
|
||||
return chunkSize;
|
||||
}
|
||||
|
||||
static drwav_uint64 drwav__data_chunk_size_rf64(drwav_uint64 dataChunkSize)
|
||||
{
|
||||
return dataChunkSize;
|
||||
}
|
||||
|
||||
|
||||
static size_t drwav__write(drwav* pWav, const void* pData, size_t dataSize)
|
||||
{
|
||||
@@ -2342,23 +2414,42 @@ static drwav_bool32 drwav_init_write__internal(drwav* pWav, const drwav_data_for
|
||||
|
||||
/* "RIFF" chunk. */
|
||||
if (pFormat->container == drwav_container_riff) {
|
||||
drwav_uint32 chunkSizeRIFF = 36 + (drwav_uint32)initialDataChunkSize; /* +36 = "RIFF"+[RIFF Chunk Size]+"WAVE" + [sizeof "fmt " chunk] */
|
||||
drwav_uint32 chunkSizeRIFF = 28 + (drwav_uint32)initialDataChunkSize; /* +28 = "WAVE" + [sizeof "fmt " chunk] */
|
||||
runningPos += drwav__write(pWav, "RIFF", 4);
|
||||
runningPos += drwav__write_u32ne_to_le(pWav, chunkSizeRIFF);
|
||||
runningPos += drwav__write(pWav, "WAVE", 4);
|
||||
} else {
|
||||
drwav_uint64 chunkSizeRIFF = 80 + 24 + initialDataChunkSize; /* +24 because W64 includes the size of the GUID and size fields. */
|
||||
} else if (pFormat->container == drwav_container_w64) {
|
||||
drwav_uint64 chunkSizeRIFF = 80 + 24 + initialDataChunkSize; /* +24 because W64 includes the size of the GUID and size fields. */
|
||||
runningPos += drwav__write(pWav, drwavGUID_W64_RIFF, 16);
|
||||
runningPos += drwav__write_u64ne_to_le(pWav, chunkSizeRIFF);
|
||||
runningPos += drwav__write(pWav, drwavGUID_W64_WAVE, 16);
|
||||
} else if (pFormat->container == drwav_container_rf64) {
|
||||
runningPos += drwav__write(pWav, "RF64", 4);
|
||||
runningPos += drwav__write_u32ne_to_le(pWav, 0xFFFFFFFF); /* Always 0xFFFFFFFF for RF64. Set to a proper value in the "ds64" chunk. */
|
||||
runningPos += drwav__write(pWav, "WAVE", 4);
|
||||
}
|
||||
|
||||
|
||||
/* "ds64" chunk (RF64 only). */
|
||||
if (pFormat->container == drwav_container_rf64) {
|
||||
drwav_uint32 initialds64ChunkSize = 28; /* 28 = [Size of RIFF (8 bytes)] + [Size of DATA (8 bytes)] + [Sample Count (8 bytes)] + [Table Length (4 bytes)]. Table length always set to 0. */
|
||||
drwav_uint64 initialRiffChunkSize = 8 + initialds64ChunkSize + initialDataChunkSize; /* +8 for the ds64 header. */
|
||||
|
||||
runningPos += drwav__write(pWav, "ds64", 4);
|
||||
runningPos += drwav__write_u32ne_to_le(pWav, initialds64ChunkSize); /* Size of ds64. */
|
||||
runningPos += drwav__write_u64ne_to_le(pWav, initialRiffChunkSize); /* Size of RIFF. Set to true value at the end. */
|
||||
runningPos += drwav__write_u64ne_to_le(pWav, initialDataChunkSize); /* Size of DATA. Set to true value at the end. */
|
||||
runningPos += drwav__write_u64ne_to_le(pWav, totalSampleCount); /* Sample count. */
|
||||
runningPos += drwav__write_u32ne_to_le(pWav, 0); /* Table length. Always set to zero in our case since we're not doing any other chunks than "DATA". */
|
||||
}
|
||||
|
||||
|
||||
/* "fmt " chunk. */
|
||||
if (pFormat->container == drwav_container_riff) {
|
||||
if (pFormat->container == drwav_container_riff || pFormat->container == drwav_container_rf64) {
|
||||
chunkSizeFMT = 16;
|
||||
runningPos += drwav__write(pWav, "fmt ", 4);
|
||||
runningPos += drwav__write_u32ne_to_le(pWav, (drwav_uint32)chunkSizeFMT);
|
||||
} else {
|
||||
} else if (pFormat->container == drwav_container_w64) {
|
||||
chunkSizeFMT = 40;
|
||||
runningPos += drwav__write(pWav, drwavGUID_W64_FMT, 16);
|
||||
runningPos += drwav__write_u64ne_to_le(pWav, chunkSizeFMT);
|
||||
@@ -2378,25 +2469,15 @@ static drwav_bool32 drwav_init_write__internal(drwav* pWav, const drwav_data_for
|
||||
drwav_uint32 chunkSizeDATA = (drwav_uint32)initialDataChunkSize;
|
||||
runningPos += drwav__write(pWav, "data", 4);
|
||||
runningPos += drwav__write_u32ne_to_le(pWav, chunkSizeDATA);
|
||||
} else {
|
||||
drwav_uint64 chunkSizeDATA = 24 + initialDataChunkSize; /* +24 because W64 includes the size of the GUID and size fields. */
|
||||
} else if (pFormat->container == drwav_container_w64) {
|
||||
drwav_uint64 chunkSizeDATA = 24 + initialDataChunkSize; /* +24 because W64 includes the size of the GUID and size fields. */
|
||||
runningPos += drwav__write(pWav, drwavGUID_W64_DATA, 16);
|
||||
runningPos += drwav__write_u64ne_to_le(pWav, chunkSizeDATA);
|
||||
} else if (pFormat->container == drwav_container_rf64) {
|
||||
runningPos += drwav__write(pWav, "data", 4);
|
||||
runningPos += drwav__write_u32ne_to_le(pWav, 0xFFFFFFFF); /* Always set to 0xFFFFFFFF for RF64. The true size of the data chunk is specified in the ds64 chunk. */
|
||||
}
|
||||
|
||||
|
||||
/* Simple validation. */
|
||||
if (pFormat->container == drwav_container_riff) {
|
||||
if (runningPos != 20 + chunkSizeFMT + 8) {
|
||||
return DRWAV_FALSE;
|
||||
}
|
||||
} else {
|
||||
if (runningPos != 40 + chunkSizeFMT + 24) {
|
||||
return DRWAV_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Set some properties for the client's convenience. */
|
||||
pWav->container = pFormat->container;
|
||||
pWav->channels = (drwav_uint16)pFormat->channels;
|
||||
@@ -2440,14 +2521,17 @@ DRWAV_API drwav_uint64 drwav_target_write_size_bytes(const drwav_data_format* pF
|
||||
/* Casting totalSampleCount to drwav_int64 for VC6 compatibility. No issues in practice because nobody is going to exhaust the whole 63 bits. */
|
||||
drwav_uint64 targetDataSizeBytes = (drwav_uint64)((drwav_int64)totalSampleCount * pFormat->channels * pFormat->bitsPerSample/8.0);
|
||||
drwav_uint64 riffChunkSizeBytes;
|
||||
drwav_uint64 fileSizeBytes;
|
||||
drwav_uint64 fileSizeBytes = 0;
|
||||
|
||||
if (pFormat->container == drwav_container_riff) {
|
||||
riffChunkSizeBytes = drwav__riff_chunk_size_riff(targetDataSizeBytes);
|
||||
fileSizeBytes = (8 + riffChunkSizeBytes); /* +8 because WAV doesn't include the size of the ChunkID and ChunkSize fields. */
|
||||
} else {
|
||||
fileSizeBytes = (8 + riffChunkSizeBytes); /* +8 because WAV doesn't include the size of the ChunkID and ChunkSize fields. */
|
||||
} else if (pFormat->container == drwav_container_w64) {
|
||||
riffChunkSizeBytes = drwav__riff_chunk_size_w64(targetDataSizeBytes);
|
||||
fileSizeBytes = riffChunkSizeBytes;
|
||||
} else if (pFormat->container == drwav_container_rf64) {
|
||||
riffChunkSizeBytes = drwav__riff_chunk_size_rf64(targetDataSizeBytes);
|
||||
fileSizeBytes = (8 + riffChunkSizeBytes); /* +8 because WAV doesn't include the size of the ChunkID and ChunkSize fields. */
|
||||
}
|
||||
|
||||
return fileSizeBytes;
|
||||
@@ -3353,7 +3437,7 @@ DRWAV_API drwav_result drwav_uninit(drwav* pWav)
|
||||
drwav_uint32 paddingSize = 0;
|
||||
|
||||
/* Padding. Do not adjust pWav->dataChunkDataSize - this should not include the padding. */
|
||||
if (pWav->container == drwav_container_riff) {
|
||||
if (pWav->container == drwav_container_riff || pWav->container == drwav_container_rf64) {
|
||||
paddingSize = drwav__chunk_padding_size_riff(pWav->dataChunkDataSize);
|
||||
} else {
|
||||
paddingSize = drwav__chunk_padding_size_w64(pWav->dataChunkDataSize);
|
||||
@@ -3381,7 +3465,7 @@ DRWAV_API drwav_result drwav_uninit(drwav* pWav)
|
||||
drwav_uint32 dataChunkSize = drwav__data_chunk_size_riff(pWav->dataChunkDataSize);
|
||||
drwav__write_u32ne_to_le(pWav, dataChunkSize);
|
||||
}
|
||||
} else {
|
||||
} else if (pWav->container == drwav_container_w64) {
|
||||
/* The "RIFF" chunk size. */
|
||||
if (pWav->onSeek(pWav->pUserData, 16, drwav_seek_origin_start)) {
|
||||
drwav_uint64 riffChunkSize = drwav__riff_chunk_size_w64(pWav->dataChunkDataSize);
|
||||
@@ -3393,6 +3477,21 @@ DRWAV_API drwav_result drwav_uninit(drwav* pWav)
|
||||
drwav_uint64 dataChunkSize = drwav__data_chunk_size_w64(pWav->dataChunkDataSize);
|
||||
drwav__write_u64ne_to_le(pWav, dataChunkSize);
|
||||
}
|
||||
} else if (pWav->container == drwav_container_rf64) {
|
||||
/* We only need to update the ds64 chunk. The "RIFF" and "data" chunks always have their sizes set to 0xFFFFFFFF for RF64. */
|
||||
int ds64BodyPos = 12 + 8;
|
||||
|
||||
/* The "RIFF" chunk size. */
|
||||
if (pWav->onSeek(pWav->pUserData, ds64BodyPos + 0, drwav_seek_origin_start)) {
|
||||
drwav_uint64 riffChunkSize = drwav__riff_chunk_size_rf64(pWav->dataChunkDataSize);
|
||||
drwav__write_u64ne_to_le(pWav, riffChunkSize);
|
||||
}
|
||||
|
||||
/* The "data" chunk size. */
|
||||
if (pWav->onSeek(pWav->pUserData, ds64BodyPos + 8, drwav_seek_origin_start)) {
|
||||
drwav_uint64 dataChunkSize = drwav__data_chunk_size_rf64(pWav->dataChunkDataSize);
|
||||
drwav__write_u64ne_to_le(pWav, dataChunkSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5934,6 +6033,13 @@ two different ways to initialize a drwav object.
|
||||
/*
|
||||
REVISION HISTORY
|
||||
================
|
||||
v0.12.12 - 2020-09-28
|
||||
- Add support for RF64.
|
||||
- Fix a bug in writing mode where the size of the RIFF chunk incorrectly includes the header section.
|
||||
|
||||
v0.12.11 - 2020-09-08
|
||||
- Fix a compilation error on older compilers.
|
||||
|
||||
v0.12.10 - 2020-08-24
|
||||
- Fix a bug when seeking with ADPCM formats.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user