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).master
parent
3baf9d0e81
commit
884fe40fd1
27
Alc/mixer.c
27
Alc/mixer.c
|
@ -33,6 +33,7 @@
|
|||
#include "alBuffer.h"
|
||||
#include "alListener.h"
|
||||
#include "alAuxEffectSlot.h"
|
||||
#include "sample_cvt.h"
|
||||
#include "alu.h"
|
||||
#include "alconfig.h"
|
||||
|
||||
|
@ -201,6 +202,14 @@ static inline ALfloat Sample_ALshort(ALshort val)
|
|||
static inline ALfloat Sample_ALfloat(ALfloat val)
|
||||
{ return val; }
|
||||
|
||||
typedef ALubyte ALmulaw;
|
||||
static inline ALfloat Sample_ALmulaw(ALmulaw val)
|
||||
{ return muLawDecompressionTable[val] * (1.0f/32768.0f); }
|
||||
|
||||
typedef ALubyte ALalaw;
|
||||
static inline ALfloat Sample_ALalaw(ALalaw val)
|
||||
{ return aLawDecompressionTable[val] * (1.0f/32768.0f); }
|
||||
|
||||
#define DECL_TEMPLATE(T) \
|
||||
static inline void Load_##T(ALfloat *restrict dst, const T *restrict src, \
|
||||
ALint srcstep, ALsizei samples) \
|
||||
|
@ -213,24 +222,24 @@ static inline void Load_##T(ALfloat *restrict dst, const T *restrict src, \
|
|||
DECL_TEMPLATE(ALbyte)
|
||||
DECL_TEMPLATE(ALshort)
|
||||
DECL_TEMPLATE(ALfloat)
|
||||
DECL_TEMPLATE(ALmulaw)
|
||||
DECL_TEMPLATE(ALalaw)
|
||||
|
||||
#undef DECL_TEMPLATE
|
||||
|
||||
static void LoadSamples(ALfloat *restrict dst, const ALvoid *restrict src, ALint srcstep,
|
||||
enum FmtType srctype, ALsizei samples)
|
||||
{
|
||||
#define HANDLE_FMT(ET, ST) case ET: Load_##ST(dst, src, srcstep, samples); break
|
||||
switch(srctype)
|
||||
{
|
||||
case FmtByte:
|
||||
Load_ALbyte(dst, src, srcstep, samples);
|
||||
break;
|
||||
case FmtShort:
|
||||
Load_ALshort(dst, src, srcstep, samples);
|
||||
break;
|
||||
case FmtFloat:
|
||||
Load_ALfloat(dst, src, srcstep, samples);
|
||||
break;
|
||||
HANDLE_FMT(FmtByte, ALbyte);
|
||||
HANDLE_FMT(FmtShort, ALshort);
|
||||
HANDLE_FMT(FmtFloat, ALfloat);
|
||||
HANDLE_FMT(FmtMulaw, ALmulaw);
|
||||
HANDLE_FMT(FmtAlaw, ALalaw);
|
||||
}
|
||||
#undef HANDLE_FMT
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -47,6 +47,8 @@ enum FmtType {
|
|||
FmtByte = UserFmtByte,
|
||||
FmtShort = UserFmtShort,
|
||||
FmtFloat = UserFmtFloat,
|
||||
FmtMulaw = UserFmtMulaw,
|
||||
FmtAlaw = UserFmtAlaw,
|
||||
};
|
||||
enum FmtChannels {
|
||||
FmtMono = UserFmtMono,
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue