Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
miniaudio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
miniaudio
Commits
34b40bdc
Commit
34b40bdc
authored
Jun 07, 2023
by
David Reid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update dr_wav with improved AIFF compatibility.
parent
e1bfeb21
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
98 additions
and
12 deletions
+98
-12
miniaudio.h
miniaudio.h
+98
-12
No files found.
miniaudio.h
View file @
34b40bdc
...
@@ -59984,6 +59984,7 @@ typedef struct
...
@@ -59984,6 +59984,7 @@ typedef struct
struct
struct
{
{
ma_bool8 isLE;
ma_bool8 isLE;
ma_bool8 isUnsigned;
} aiff;
} aiff;
} ma_dr_wav;
} ma_dr_wav;
MA_API ma_bool32 ma_dr_wav_init(ma_dr_wav* pWav, ma_dr_wav_read_proc onRead, ma_dr_wav_seek_proc onSeek, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks);
MA_API ma_bool32 ma_dr_wav_init(ma_dr_wav* pWav, ma_dr_wav_read_proc onRead, ma_dr_wav_seek_proc onSeek, void* pUserData, const ma_allocation_callbacks* pAllocationCallbacks);
...
@@ -76802,11 +76803,7 @@ MA_PRIVATE ma_result ma_dr_wav__read_chunk_header(ma_dr_wav_read_proc onRead, vo
...
@@ -76802,11 +76803,7 @@ MA_PRIVATE ma_result ma_dr_wav__read_chunk_header(ma_dr_wav_read_proc onRead, vo
return MA_INVALID_FILE;
return MA_INVALID_FILE;
}
}
pHeaderOut->sizeInBytes = ma_dr_wav_bytes_to_u32_ex(sizeInBytes, container);
pHeaderOut->sizeInBytes = ma_dr_wav_bytes_to_u32_ex(sizeInBytes, container);
if (container == ma_dr_wav_container_aiff) {
pHeaderOut->paddingSize = ma_dr_wav__chunk_padding_size_riff(pHeaderOut->sizeInBytes);
pHeaderOut->paddingSize = 0;
} else {
pHeaderOut->paddingSize = ma_dr_wav__chunk_padding_size_riff(pHeaderOut->sizeInBytes);
}
*pRunningBytesReadOut += 8;
*pRunningBytesReadOut += 8;
} else if (container == ma_dr_wav_container_w64) {
} else if (container == ma_dr_wav_container_w64) {
ma_uint8 sizeInBytes[8];
ma_uint8 sizeInBytes[8];
...
@@ -77645,6 +77642,7 @@ MA_PRIVATE ma_bool32 ma_dr_wav_init__internal(ma_dr_wav* pWav, ma_dr_wav_chunk_p
...
@@ -77645,6 +77642,7 @@ MA_PRIVATE ma_bool32 ma_dr_wav_init__internal(ma_dr_wav* pWav, ma_dr_wav_chunk_p
ma_bool8 foundChunk_fmt = MA_FALSE;
ma_bool8 foundChunk_fmt = MA_FALSE;
ma_bool8 foundChunk_data = MA_FALSE;
ma_bool8 foundChunk_data = MA_FALSE;
ma_bool8 isAIFCFormType = MA_FALSE;
ma_bool8 isAIFCFormType = MA_FALSE;
ma_uint64 aiffFrameCount = 0;
cursor = 0;
cursor = 0;
sequential = (flags & MA_DR_WAV_SEQUENTIAL) != 0;
sequential = (flags & MA_DR_WAV_SEQUENTIAL) != 0;
MA_DR_WAV_ZERO_OBJECT(&fmt);
MA_DR_WAV_ZERO_OBJECT(&fmt);
...
@@ -77905,6 +77903,7 @@ MA_PRIVATE ma_bool32 ma_dr_wav_init__internal(ma_dr_wav* pWav, ma_dr_wav_chunk_p
...
@@ -77905,6 +77903,7 @@ MA_PRIVATE ma_bool32 ma_dr_wav_init__internal(ma_dr_wav* pWav, ma_dr_wav_chunk_p
ma_uint8 commData[24];
ma_uint8 commData[24];
ma_uint32 commDataBytesToRead;
ma_uint32 commDataBytesToRead;
ma_uint16 channels;
ma_uint16 channels;
ma_uint32 frameCount;
ma_uint16 sampleSizeInBits;
ma_uint16 sampleSizeInBits;
ma_int64 sampleRate;
ma_int64 sampleRate;
ma_uint16 compressionFormat;
ma_uint16 compressionFormat;
...
@@ -77924,6 +77923,7 @@ MA_PRIVATE ma_bool32 ma_dr_wav_init__internal(ma_dr_wav* pWav, ma_dr_wav_chunk_p
...
@@ -77924,6 +77923,7 @@ MA_PRIVATE ma_bool32 ma_dr_wav_init__internal(ma_dr_wav* pWav, ma_dr_wav_chunk_p
return MA_FALSE;
return MA_FALSE;
}
}
channels = ma_dr_wav_bytes_to_u16_ex (commData + 0, pWav->container);
channels = ma_dr_wav_bytes_to_u16_ex (commData + 0, pWav->container);
frameCount = ma_dr_wav_bytes_to_u32_ex (commData + 2, pWav->container);
sampleSizeInBits = ma_dr_wav_bytes_to_u16_ex (commData + 6, pWav->container);
sampleSizeInBits = ma_dr_wav_bytes_to_u16_ex (commData + 6, pWav->container);
sampleRate = ma_dr_wav_aiff_extented_to_s64(commData + 8);
sampleRate = ma_dr_wav_aiff_extented_to_s64(commData + 8);
if (sampleRate < 0 || sampleRate > 0xFFFFFFFF) {
if (sampleRate < 0 || sampleRate > 0xFFFFFFFF) {
...
@@ -77933,14 +77933,19 @@ MA_PRIVATE ma_bool32 ma_dr_wav_init__internal(ma_dr_wav* pWav, ma_dr_wav_chunk_p
...
@@ -77933,14 +77933,19 @@ MA_PRIVATE ma_bool32 ma_dr_wav_init__internal(ma_dr_wav* pWav, ma_dr_wav_chunk_p
const ma_uint8* type = commData + 18;
const ma_uint8* type = commData + 18;
if (ma_dr_wav_fourcc_equal(type, "NONE")) {
if (ma_dr_wav_fourcc_equal(type, "NONE")) {
compressionFormat = MA_DR_WAVE_FORMAT_PCM;
compressionFormat = MA_DR_WAVE_FORMAT_PCM;
} else if (ma_dr_wav_fourcc_equal(type, "raw ")) {
compressionFormat = MA_DR_WAVE_FORMAT_PCM;
if (sampleSizeInBits == 8) {
pWav->aiff.isUnsigned = MA_TRUE;
}
} else if (ma_dr_wav_fourcc_equal(type, "sowt")) {
} else if (ma_dr_wav_fourcc_equal(type, "sowt")) {
compressionFormat = MA_DR_WAVE_FORMAT_PCM;
compressionFormat = MA_DR_WAVE_FORMAT_PCM;
pWav->aiff.isLE = MA_TRUE;
pWav->aiff.isLE = MA_TRUE;
} else if (ma_dr_wav_fourcc_equal(type, "fl32") || ma_dr_wav_fourcc_equal(type, "fl64") || ma_dr_wav_fourcc_equal(type, "FL32") || ma_dr_wav_fourcc_equal(type, "FL64")) {
} else if (ma_dr_wav_fourcc_equal(type, "fl32") || ma_dr_wav_fourcc_equal(type, "fl64") || ma_dr_wav_fourcc_equal(type, "FL32") || ma_dr_wav_fourcc_equal(type, "FL64")) {
compressionFormat = MA_DR_WAVE_FORMAT_IEEE_FLOAT;
compressionFormat = MA_DR_WAVE_FORMAT_IEEE_FLOAT;
} else if (ma_dr_wav_fourcc_equal(type, "alaw")) {
} else if (ma_dr_wav_fourcc_equal(type, "alaw")
|| ma_dr_wav_fourcc_equal(type, "ALAW")
) {
compressionFormat = MA_DR_WAVE_FORMAT_ALAW;
compressionFormat = MA_DR_WAVE_FORMAT_ALAW;
} else if (ma_dr_wav_fourcc_equal(type, "ulaw")) {
} else if (ma_dr_wav_fourcc_equal(type, "ulaw")
|| ma_dr_wav_fourcc_equal(type, "ULAW")
) {
compressionFormat = MA_DR_WAVE_FORMAT_MULAW;
compressionFormat = MA_DR_WAVE_FORMAT_MULAW;
} else if (ma_dr_wav_fourcc_equal(type, "ima4")) {
} else if (ma_dr_wav_fourcc_equal(type, "ima4")) {
compressionFormat = MA_DR_WAVE_FORMAT_DVI_ADPCM;
compressionFormat = MA_DR_WAVE_FORMAT_DVI_ADPCM;
...
@@ -77952,6 +77957,7 @@ MA_PRIVATE ma_bool32 ma_dr_wav_init__internal(ma_dr_wav* pWav, ma_dr_wav_chunk_p
...
@@ -77952,6 +77957,7 @@ MA_PRIVATE ma_bool32 ma_dr_wav_init__internal(ma_dr_wav* pWav, ma_dr_wav_chunk_p
} else {
} else {
compressionFormat = MA_DR_WAVE_FORMAT_PCM;
compressionFormat = MA_DR_WAVE_FORMAT_PCM;
}
}
aiffFrameCount = frameCount / channels;
fmt.formatTag = compressionFormat;
fmt.formatTag = compressionFormat;
fmt.channels = channels;
fmt.channels = channels;
fmt.sampleRate = (ma_uint32)sampleRate;
fmt.sampleRate = (ma_uint32)sampleRate;
...
@@ -77961,6 +77967,13 @@ MA_PRIVATE ma_bool32 ma_dr_wav_init__internal(ma_dr_wav* pWav, ma_dr_wav_chunk_p
...
@@ -77961,6 +77967,13 @@ MA_PRIVATE ma_bool32 ma_dr_wav_init__internal(ma_dr_wav* pWav, ma_dr_wav_chunk_p
if (fmt.blockAlign == 0 && compressionFormat == MA_DR_WAVE_FORMAT_DVI_ADPCM) {
if (fmt.blockAlign == 0 && compressionFormat == MA_DR_WAVE_FORMAT_DVI_ADPCM) {
fmt.blockAlign = 34 * fmt.channels;
fmt.blockAlign = 34 * fmt.channels;
}
}
if (compressionFormat == MA_DR_WAVE_FORMAT_ALAW || compressionFormat == MA_DR_WAVE_FORMAT_MULAW) {
if (fmt.bitsPerSample > 8) {
fmt.bitsPerSample = 8;
fmt.blockAlign = fmt.channels;
}
}
fmt.bitsPerSample += (fmt.bitsPerSample & 7);
if (isAIFCFormType) {
if (isAIFCFormType) {
if (ma_dr_wav__seek_forward(pWav->onSeek, (chunkSize - commDataBytesToRead), pWav->pUserData) == MA_FALSE) {
if (ma_dr_wav__seek_forward(pWav->onSeek, (chunkSize - commDataBytesToRead), pWav->pUserData) == MA_FALSE) {
return MA_FALSE;
return MA_FALSE;
...
@@ -78075,6 +78088,8 @@ MA_PRIVATE ma_bool32 ma_dr_wav_init__internal(ma_dr_wav* pWav, ma_dr_wav_chunk_p
...
@@ -78075,6 +78088,8 @@ MA_PRIVATE ma_bool32 ma_dr_wav_init__internal(ma_dr_wav* pWav, ma_dr_wav_chunk_p
pWav->dataChunkDataSize = dataChunkSize;
pWav->dataChunkDataSize = dataChunkSize;
if (sampleCountFromFactChunk != 0) {
if (sampleCountFromFactChunk != 0) {
pWav->totalPCMFrameCount = sampleCountFromFactChunk;
pWav->totalPCMFrameCount = sampleCountFromFactChunk;
} else if (aiffFrameCount != 0) {
pWav->totalPCMFrameCount = aiffFrameCount;
} else {
} else {
ma_uint32 bytesPerFrame = ma_dr_wav_get_bytes_per_pcm_frame(pWav);
ma_uint32 bytesPerFrame = ma_dr_wav_get_bytes_per_pcm_frame(pWav);
if (bytesPerFrame == 0) {
if (bytesPerFrame == 0) {
...
@@ -79196,20 +79211,32 @@ MA_API ma_uint64 ma_dr_wav_read_pcm_frames_be(ma_dr_wav* pWav, ma_uint64 framesT
...
@@ -79196,20 +79211,32 @@ MA_API ma_uint64 ma_dr_wav_read_pcm_frames_be(ma_dr_wav* pWav, ma_uint64 framesT
}
}
MA_API ma_uint64 ma_dr_wav_read_pcm_frames(ma_dr_wav* pWav, ma_uint64 framesToRead, void* pBufferOut)
MA_API ma_uint64 ma_dr_wav_read_pcm_frames(ma_dr_wav* pWav, ma_uint64 framesToRead, void* pBufferOut)
{
{
ma_uint64 framesRead = 0;
if (ma_dr_wav_is_container_be(pWav->container)) {
if (ma_dr_wav_is_container_be(pWav->container)) {
if (pWav->container != ma_dr_wav_container_aiff || pWav->aiff.isLE == MA_FALSE) {
if (pWav->container != ma_dr_wav_container_aiff || pWav->aiff.isLE == MA_FALSE) {
if (ma_dr_wav__is_little_endian()) {
if (ma_dr_wav__is_little_endian()) {
return
ma_dr_wav_read_pcm_frames_be(pWav, framesToRead, pBufferOut);
framesRead =
ma_dr_wav_read_pcm_frames_be(pWav, framesToRead, pBufferOut);
} else {
} else {
return
ma_dr_wav_read_pcm_frames_le(pWav, framesToRead, pBufferOut);
framesRead =
ma_dr_wav_read_pcm_frames_le(pWav, framesToRead, pBufferOut);
}
}
goto post_process;
}
}
}
}
if (ma_dr_wav__is_little_endian()) {
if (ma_dr_wav__is_little_endian()) {
return
ma_dr_wav_read_pcm_frames_le(pWav, framesToRead, pBufferOut);
framesRead =
ma_dr_wav_read_pcm_frames_le(pWav, framesToRead, pBufferOut);
} else {
} else {
return ma_dr_wav_read_pcm_frames_be(pWav, framesToRead, pBufferOut);
framesRead = ma_dr_wav_read_pcm_frames_be(pWav, framesToRead, pBufferOut);
}
post_process:
{
if (pWav->container == ma_dr_wav_container_aiff && pWav->bitsPerSample == 8 && pWav->aiff.isUnsigned == MA_FALSE) {
ma_uint64 iSample;
for (iSample = 0; iSample < framesRead * pWav->channels; iSample += 1) {
((ma_uint8*)pBufferOut)[iSample] += 128;
}
}
}
}
return framesRead;
}
}
MA_PRIVATE ma_bool32 ma_dr_wav_seek_to_first_pcm_frame(ma_dr_wav* pWav)
MA_PRIVATE ma_bool32 ma_dr_wav_seek_to_first_pcm_frame(ma_dr_wav* pWav)
{
{
...
@@ -79285,7 +79312,6 @@ MA_API ma_bool32 ma_dr_wav_seek_to_pcm_frame(ma_dr_wav* pWav, ma_uint64 targetFr
...
@@ -79285,7 +79312,6 @@ MA_API ma_bool32 ma_dr_wav_seek_to_pcm_frame(ma_dr_wav* pWav, ma_uint64 targetFr
return MA_FALSE;
return MA_FALSE;
}
}
totalSizeInBytes = pWav->totalPCMFrameCount * bytesPerFrame;
totalSizeInBytes = pWav->totalPCMFrameCount * bytesPerFrame;
MA_DR_WAV_ASSERT(totalSizeInBytes >= pWav->bytesRemaining);
currentBytePos = totalSizeInBytes - pWav->bytesRemaining;
currentBytePos = totalSizeInBytes - pWav->bytesRemaining;
targetBytePos = targetFrameIndex * bytesPerFrame;
targetBytePos = targetFrameIndex * bytesPerFrame;
if (currentBytePos < targetBytePos) {
if (currentBytePos < targetBytePos) {
...
@@ -79876,6 +79902,16 @@ MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_s16__alaw(ma_dr_wav* pWav, ma_uin
...
@@ -79876,6 +79902,16 @@ MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_s16__alaw(ma_dr_wav* pWav, ma_uin
break;
break;
}
}
ma_dr_wav_alaw_to_s16(pBufferOut, sampleData, (size_t)samplesRead);
ma_dr_wav_alaw_to_s16(pBufferOut, sampleData, (size_t)samplesRead);
#ifdef MA_DR_WAV_LIBSNDFILE_COMPAT
{
if (pWav->container == ma_dr_wav_container_aiff) {
ma_uint64 iSample;
for (iSample = 0; iSample < samplesRead; iSample += 1) {
pBufferOut[iSample] = -pBufferOut[iSample];
}
}
}
#endif
pBufferOut += samplesRead;
pBufferOut += samplesRead;
framesToRead -= framesRead;
framesToRead -= framesRead;
totalFramesRead += framesRead;
totalFramesRead += framesRead;
...
@@ -79914,6 +79950,16 @@ MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_s16__mulaw(ma_dr_wav* pWav, ma_ui
...
@@ -79914,6 +79950,16 @@ MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_s16__mulaw(ma_dr_wav* pWav, ma_ui
break;
break;
}
}
ma_dr_wav_mulaw_to_s16(pBufferOut, sampleData, (size_t)samplesRead);
ma_dr_wav_mulaw_to_s16(pBufferOut, sampleData, (size_t)samplesRead);
#ifdef MA_DR_WAV_LIBSNDFILE_COMPAT
{
if (pWav->container == ma_dr_wav_container_aiff) {
ma_uint64 iSample;
for (iSample = 0; iSample < samplesRead; iSample += 1) {
pBufferOut[iSample] = -pBufferOut[iSample];
}
}
}
#endif
pBufferOut += samplesRead;
pBufferOut += samplesRead;
framesToRead -= framesRead;
framesToRead -= framesRead;
totalFramesRead += framesRead;
totalFramesRead += framesRead;
...
@@ -80213,6 +80259,16 @@ MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_f32__alaw(ma_dr_wav* pWav, ma_uin
...
@@ -80213,6 +80259,16 @@ MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_f32__alaw(ma_dr_wav* pWav, ma_uin
break;
break;
}
}
ma_dr_wav_alaw_to_f32(pBufferOut, sampleData, (size_t)samplesRead);
ma_dr_wav_alaw_to_f32(pBufferOut, sampleData, (size_t)samplesRead);
#ifdef MA_DR_WAV_LIBSNDFILE_COMPAT
{
if (pWav->container == ma_dr_wav_container_aiff) {
ma_uint64 iSample;
for (iSample = 0; iSample < samplesRead; iSample += 1) {
pBufferOut[iSample] = -pBufferOut[iSample];
}
}
}
#endif
pBufferOut += samplesRead;
pBufferOut += samplesRead;
framesToRead -= framesRead;
framesToRead -= framesRead;
totalFramesRead += framesRead;
totalFramesRead += framesRead;
...
@@ -80248,6 +80304,16 @@ MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_f32__mulaw(ma_dr_wav* pWav, ma_ui
...
@@ -80248,6 +80304,16 @@ MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_f32__mulaw(ma_dr_wav* pWav, ma_ui
break;
break;
}
}
ma_dr_wav_mulaw_to_f32(pBufferOut, sampleData, (size_t)samplesRead);
ma_dr_wav_mulaw_to_f32(pBufferOut, sampleData, (size_t)samplesRead);
#ifdef MA_DR_WAV_LIBSNDFILE_COMPAT
{
if (pWav->container == ma_dr_wav_container_aiff) {
ma_uint64 iSample;
for (iSample = 0; iSample < samplesRead; iSample += 1) {
pBufferOut[iSample] = -pBufferOut[iSample];
}
}
}
#endif
pBufferOut += samplesRead;
pBufferOut += samplesRead;
framesToRead -= framesRead;
framesToRead -= framesRead;
totalFramesRead += framesRead;
totalFramesRead += framesRead;
...
@@ -80553,6 +80619,16 @@ MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_s32__alaw(ma_dr_wav* pWav, ma_uin
...
@@ -80553,6 +80619,16 @@ MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_s32__alaw(ma_dr_wav* pWav, ma_uin
break;
break;
}
}
ma_dr_wav_alaw_to_s32(pBufferOut, sampleData, (size_t)samplesRead);
ma_dr_wav_alaw_to_s32(pBufferOut, sampleData, (size_t)samplesRead);
#ifdef MA_DR_WAV_LIBSNDFILE_COMPAT
{
if (pWav->container == ma_dr_wav_container_aiff) {
ma_uint64 iSample;
for (iSample = 0; iSample < samplesRead; iSample += 1) {
pBufferOut[iSample] = -pBufferOut[iSample];
}
}
}
#endif
pBufferOut += samplesRead;
pBufferOut += samplesRead;
framesToRead -= framesRead;
framesToRead -= framesRead;
totalFramesRead += framesRead;
totalFramesRead += framesRead;
...
@@ -80588,6 +80664,16 @@ MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_s32__mulaw(ma_dr_wav* pWav, ma_ui
...
@@ -80588,6 +80664,16 @@ MA_PRIVATE ma_uint64 ma_dr_wav_read_pcm_frames_s32__mulaw(ma_dr_wav* pWav, ma_ui
break;
break;
}
}
ma_dr_wav_mulaw_to_s32(pBufferOut, sampleData, (size_t)samplesRead);
ma_dr_wav_mulaw_to_s32(pBufferOut, sampleData, (size_t)samplesRead);
#ifdef MA_DR_WAV_LIBSNDFILE_COMPAT
{
if (pWav->container == ma_dr_wav_container_aiff) {
ma_uint64 iSample;
for (iSample = 0; iSample < samplesRead; iSample += 1) {
pBufferOut[iSample] = -pBufferOut[iSample];
}
}
}
#endif
pBufferOut += samplesRead;
pBufferOut += samplesRead;
framesToRead -= framesRead;
framesToRead -= framesRead;
totalFramesRead += framesRead;
totalFramesRead += framesRead;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment