aboutsummaryrefslogtreecommitdiffstats
path: root/OpenAL32
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-01-17 08:49:49 -0800
committerChris Robinson <[email protected]>2018-01-17 08:49:49 -0800
commit884fe40fd1262fe642a86d29f27e157e2b562212 (patch)
treebc41817b5349d69f0fd825a753d41204a52257d7 /OpenAL32
parent3baf9d0e81c16555fc417697a5445b7cd674db02 (diff)
Store mulaw and alaw samples directly in the buffer
They're now decompressed on the fly in the mixer. This is not a significant performance issue given that it only needs a 512-byte lookup table, and the buffer stores half as much data (it may actually be faster, requiring less overall memory).
Diffstat (limited to 'OpenAL32')
-rw-r--r--OpenAL32/Include/alBuffer.h2
-rw-r--r--OpenAL32/Include/sample_cvt.h3
-rw-r--r--OpenAL32/alBuffer.c39
-rw-r--r--OpenAL32/sample_cvt.c4
4 files changed, 22 insertions, 26 deletions
diff --git a/OpenAL32/Include/alBuffer.h b/OpenAL32/Include/alBuffer.h
index b13e1231..7653db6a 100644
--- a/OpenAL32/Include/alBuffer.h
+++ b/OpenAL32/Include/alBuffer.h
@@ -47,6 +47,8 @@ enum FmtType {
FmtByte = UserFmtByte,
FmtShort = UserFmtShort,
FmtFloat = UserFmtFloat,
+ FmtMulaw = UserFmtMulaw,
+ FmtAlaw = UserFmtAlaw,
};
enum FmtChannels {
FmtMono = UserFmtMono,
diff --git a/OpenAL32/Include/sample_cvt.h b/OpenAL32/Include/sample_cvt.h
index 12bb1fa6..35ead20c 100644
--- a/OpenAL32/Include/sample_cvt.h
+++ b/OpenAL32/Include/sample_cvt.h
@@ -4,6 +4,9 @@
#include "AL/al.h"
#include "alBuffer.h"
+extern const ALshort muLawDecompressionTable[256];
+extern const ALshort aLawDecompressionTable[256];
+
void ConvertData(ALvoid *dst, enum UserFmtType dstType, const ALvoid *src, enum UserFmtType srcType, ALsizei numchans, ALsizei len, ALsizei align);
#endif /* SAMPLE_CVT_H */
diff --git a/OpenAL32/alBuffer.c b/OpenAL32/alBuffer.c
index 376741bd..a4b19a95 100644
--- a/OpenAL32/alBuffer.c
+++ b/OpenAL32/alBuffer.c
@@ -171,6 +171,8 @@ AL_API ALvoid AL_APIENTRY alBufferData(ALuint buffer, ALenum format, const ALvoi
case UserFmtShort:
case UserFmtUShort:
case UserFmtFloat:
+ case UserFmtMulaw:
+ case UserFmtAlaw:
framesize = FrameSizeFromUserFmt(srcchannels, srctype) * align;
if((size%framesize) != 0)
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
@@ -206,30 +208,6 @@ AL_API ALvoid AL_APIENTRY alBufferData(ALuint buffer, ALenum format, const ALvoi
SET_ERROR_AND_GOTO(context, err, done);
break;
- case UserFmtMulaw:
- case UserFmtAlaw:
- framesize = FrameSizeFromUserFmt(srcchannels, srctype) * align;
- if((size%framesize) != 0)
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
-
- switch(srcchannels)
- {
- case UserFmtMono: newformat = AL_FORMAT_MONO16; break;
- case UserFmtStereo: newformat = AL_FORMAT_STEREO16; break;
- case UserFmtRear: newformat = AL_FORMAT_REAR16; break;
- case UserFmtQuad: newformat = AL_FORMAT_QUAD16; break;
- case UserFmtX51: newformat = AL_FORMAT_51CHN16; break;
- case UserFmtX61: newformat = AL_FORMAT_61CHN16; break;
- case UserFmtX71: newformat = AL_FORMAT_71CHN16; break;
- case UserFmtBFormat2D: newformat = AL_FORMAT_BFORMAT2D_16; break;
- case UserFmtBFormat3D: newformat = AL_FORMAT_BFORMAT3D_16; break;
- }
- err = LoadData(albuf, freq, newformat, size/framesize*align,
- srcchannels, srctype, data, align, AL_TRUE);
- if(err != AL_NO_ERROR)
- SET_ERROR_AND_GOTO(context, err, done);
- break;
-
case UserFmtIMA4:
framesize = (align-1)/2 + 4;
framesize *= ChannelsFromUserFmt(srcchannels);
@@ -1193,6 +1171,8 @@ ALsizei BytesFromFmt(enum FmtType type)
case FmtByte: return sizeof(ALbyte);
case FmtShort: return sizeof(ALshort);
case FmtFloat: return sizeof(ALfloat);
+ case FmtMulaw: return sizeof(ALubyte);
+ case FmtAlaw: return sizeof(ALubyte);
}
return 0;
}
@@ -1222,14 +1202,19 @@ static ALboolean DecomposeFormat(ALenum format, enum FmtChannels *chans, enum Fm
{ AL_MONO8_SOFT, FmtMono, FmtByte },
{ AL_MONO16_SOFT, FmtMono, FmtShort },
{ AL_MONO32F_SOFT, FmtMono, FmtFloat },
+ { AL_FORMAT_MONO_MULAW, FmtMono, FmtMulaw },
+ { AL_FORMAT_MONO_ALAW_EXT, FmtMono, FmtAlaw },
{ AL_STEREO8_SOFT, FmtStereo, FmtByte },
{ AL_STEREO16_SOFT, FmtStereo, FmtShort },
{ AL_STEREO32F_SOFT, FmtStereo, FmtFloat },
+ { AL_FORMAT_STEREO_MULAW, FmtStereo, FmtMulaw },
+ { AL_FORMAT_STEREO_ALAW_EXT, FmtStereo, FmtAlaw },
{ AL_REAR8_SOFT, FmtRear, FmtByte },
{ AL_REAR16_SOFT, FmtRear, FmtShort },
{ AL_REAR32F_SOFT, FmtRear, FmtFloat },
+ { AL_FORMAT_REAR_MULAW, FmtRear, FmtMulaw },
{ AL_FORMAT_QUAD8_LOKI, FmtQuad, FmtByte },
{ AL_FORMAT_QUAD16_LOKI, FmtQuad, FmtShort },
@@ -1237,26 +1222,32 @@ static ALboolean DecomposeFormat(ALenum format, enum FmtChannels *chans, enum Fm
{ AL_QUAD8_SOFT, FmtQuad, FmtByte },
{ AL_QUAD16_SOFT, FmtQuad, FmtShort },
{ AL_QUAD32F_SOFT, FmtQuad, FmtFloat },
+ { AL_FORMAT_QUAD_MULAW, FmtQuad, FmtMulaw },
{ AL_5POINT1_8_SOFT, FmtX51, FmtByte },
{ AL_5POINT1_16_SOFT, FmtX51, FmtShort },
{ AL_5POINT1_32F_SOFT, FmtX51, FmtFloat },
+ { AL_FORMAT_51CHN_MULAW, FmtX51, FmtMulaw },
{ AL_6POINT1_8_SOFT, FmtX61, FmtByte },
{ AL_6POINT1_16_SOFT, FmtX61, FmtShort },
{ AL_6POINT1_32F_SOFT, FmtX61, FmtFloat },
+ { AL_FORMAT_61CHN_MULAW, FmtX61, FmtMulaw },
{ AL_7POINT1_8_SOFT, FmtX71, FmtByte },
{ AL_7POINT1_16_SOFT, FmtX71, FmtShort },
{ AL_7POINT1_32F_SOFT, FmtX71, FmtFloat },
+ { AL_FORMAT_71CHN_MULAW, FmtX71, FmtMulaw },
{ AL_BFORMAT2D_8_SOFT, FmtBFormat2D, FmtByte },
{ AL_BFORMAT2D_16_SOFT, FmtBFormat2D, FmtShort },
{ AL_BFORMAT2D_32F_SOFT, FmtBFormat2D, FmtFloat },
+ { AL_FORMAT_BFORMAT2D_MULAW, FmtBFormat2D, FmtMulaw },
{ AL_BFORMAT3D_8_SOFT, FmtBFormat3D, FmtByte },
{ AL_BFORMAT3D_16_SOFT, FmtBFormat3D, FmtShort },
{ AL_BFORMAT3D_32F_SOFT, FmtBFormat3D, FmtFloat },
+ { AL_FORMAT_BFORMAT3D_MULAW, FmtBFormat3D, FmtMulaw },
};
ALuint i;
diff --git a/OpenAL32/sample_cvt.c b/OpenAL32/sample_cvt.c
index 535d8b6d..af73695b 100644
--- a/OpenAL32/sample_cvt.c
+++ b/OpenAL32/sample_cvt.c
@@ -68,7 +68,7 @@ static const int MSADPCMAdaptionCoeff[7][2] = {
/* A quick'n'dirty lookup table to decode a muLaw-encoded byte sample into a
* signed 16-bit sample */
-static const ALshort muLawDecompressionTable[256] = {
+const ALshort muLawDecompressionTable[256] = {
-32124,-31100,-30076,-29052,-28028,-27004,-25980,-24956,
-23932,-22908,-21884,-20860,-19836,-18812,-17788,-16764,
-15996,-15484,-14972,-14460,-13948,-13436,-12924,-12412,
@@ -128,7 +128,7 @@ static const char muLawCompressTable[256] = {
/* A quick'n'dirty lookup table to decode an aLaw-encoded byte sample into a
* signed 16-bit sample */
-static const ALshort aLawDecompressionTable[256] = {
+const ALshort aLawDecompressionTable[256] = {
-5504, -5248, -6016, -5760, -4480, -4224, -4992, -4736,
-7552, -7296, -8064, -7808, -6528, -6272, -7040, -6784,
-2752, -2624, -3008, -2880, -2240, -2112, -2496, -2368,