1
0
Fork 0

Sync dr_wav with upsteam (v0.11.4)

This commit is contained in:
David Reid 2020-01-29 00:09:35 -08:00 committed by Patryk Obara
parent a3c0d48865
commit b040cb32c3

View file

@ -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.11.2 - 2019-12-02
dr_wav - v0.11.4 - 2020-01-29
David Reid - mackron@gmail.com
*/
@ -1100,14 +1100,14 @@ static const drwav_uint8 drwavGUID_W64_SMPL[16] = {0x73,0x6D,0x70,0x6C, 0xF3,0xA
static DRWAV_INLINE drwav_bool32 drwav__guid_equal(const drwav_uint8 a[16], const drwav_uint8 b[16])
{
const drwav_uint32* a32 = (const drwav_uint32*)a;
const drwav_uint32* b32 = (const drwav_uint32*)b;
int i;
for (i = 0; i < 16; i += 1) {
if (a[i] != b[i]) {
return DRWAV_FALSE;
}
}
return
a32[0] == b32[0] &&
a32[1] == b32[1] &&
a32[2] == b32[2] &&
a32[3] == b32[3];
return DRWAV_TRUE;
}
static DRWAV_INLINE drwav_bool32 drwav__fourcc_equal(const unsigned char* a, const char* b)
@ -3440,6 +3440,7 @@ drwav_uint64 drwav_read_pcm_frames_s16__ima(drwav* pWav, drwav_uint64 framesToRe
drwav_uint32 iByte;
drwav_uint8 nibbles[4];
if (pWav->onRead(pWav->pUserData, &nibbles, 4) != 4) {
pWav->ima.cachedFrameCount = 0;
return totalFramesRead;
}
pWav->ima.bytesRemainingInBlock -= 4;
@ -3578,7 +3579,8 @@ static void drwav__pcm_to_s16(drwav_int16* pOut, const unsigned char* pIn, size_
unsigned int shift = (8 - bytesPerSample) * 8;
unsigned int j;
for (j = 0; j < bytesPerSample && j < 8; j += 1) {
for (j = 0; j < bytesPerSample; j += 1) {
DRWAV_ASSERT(j < 8);
sample |= (drwav_uint64)(pIn[j]) << shift;
shift += 8;
}
@ -3900,7 +3902,8 @@ static void drwav__pcm_to_f32(float* pOut, const unsigned char* pIn, size_t samp
unsigned int shift = (8 - bytesPerSample) * 8;
unsigned int j;
for (j = 0; j < bytesPerSample && j < 8; j += 1) {
for (j = 0; j < bytesPerSample; j += 1) {
DRWAV_ASSERT(j < 8);
sample |= (drwav_uint64)(pIn[j]) << shift;
shift += 8;
}
@ -4050,7 +4053,7 @@ drwav_uint64 drwav_read_pcm_frames_f32__alaw(drwav* pWav, drwav_uint64 framesToR
totalFramesRead = 0;
while (bytesPerFrame > 0) {
while (framesToRead > 0) {
drwav_uint64 framesRead = drwav_read_pcm_frames(pWav, drwav_min(framesToRead, sizeof(sampleData)/bytesPerFrame), sampleData);
if (framesRead == 0) {
break;
@ -4173,7 +4176,11 @@ void drwav_u8_to_f32(float* pOut, const drwav_uint8* pIn, size_t sampleCount)
}
#else
for (i = 0; i < sampleCount; ++i) {
*pOut++ = (pIn[i] / 255.0f) * 2 - 1;
float x = pIn[i];
x = x * 0.00784313725490196078f; /* 0..255 to 0..2 */
x = x - 1; /* 0..2 to -1..1 */
*pOut++ = x;
}
#endif
}
@ -4187,7 +4194,7 @@ void drwav_s16_to_f32(float* pOut, const drwav_int16* pIn, size_t sampleCount)
}
for (i = 0; i < sampleCount; ++i) {
*pOut++ = pIn[i] / 32768.0f;
*pOut++ = pIn[i] * 0.000030517578125f;
}
}
@ -4200,12 +4207,8 @@ void drwav_s24_to_f32(float* pOut, const drwav_uint8* pIn, size_t sampleCount)
}
for (i = 0; i < sampleCount; ++i) {
unsigned int s0 = pIn[i*3 + 0];
unsigned int s1 = pIn[i*3 + 1];
unsigned int s2 = pIn[i*3 + 2];
int sample32 = (int)((s0 << 8) | (s1 << 16) | (s2 << 24));
*pOut++ = (float)(sample32 / 2147483648.0);
double x = (double)(((drwav_int32)(((drwav_uint32)(pIn[i*3+0]) << 8) | ((drwav_uint32)(pIn[i*3+1]) << 16) | ((drwav_uint32)(pIn[i*3+2])) << 24)) >> 8);
*pOut++ = (float)(x * 0.00000011920928955078125);
}
}
@ -4302,7 +4305,8 @@ static void drwav__pcm_to_s32(drwav_int32* pOut, const unsigned char* pIn, size_
unsigned int shift = (8 - bytesPerSample) * 8;
unsigned int j;
for (j = 0; j < bytesPerSample && j < 8; j += 1) {
for (j = 0; j < bytesPerSample; j += 1) {
DRWAV_ASSERT(j < 8);
sample |= (drwav_uint64)(pIn[j]) << shift;
shift += 8;
}
@ -5051,6 +5055,14 @@ void drwav_free(void* p, const drwav_allocation_callbacks* pAllocationCallbacks)
/*
REVISION HISTORY
================
v0.11.4 - 2020-01-29
- Fix some static analysis warnings.
- Fix a bug when reading f32 samples from an A-law encoded stream.
v0.11.3 - 2020-01-12
- Minor changes to some f32 format conversion routines.
- Minor bug fix for ADPCM conversion when end of file is reached.
v0.11.2 - 2019-12-02
- Fix a possible crash when using custom memory allocators without a custom realloc() implementation.
- Fix an integer overflow bug.
@ -5339,7 +5351,7 @@ For more information, please refer to <http://unlicense.org/>
===============================================================================
ALTERNATIVE 2 - MIT No Attribution
===============================================================================
Copyright 2018 David Reid
Copyright 2020 David Reid
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in