aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2010-11-27 22:55:20 -0800
committerChris Robinson <[email protected]>2010-11-27 22:55:20 -0800
commit2fd8d6916bae6b681f065e5dfe1f962641f41533 (patch)
treeb7571b820aa7cc8ada05ebd58c7efa7f4b8d5c95
parentb4eaf1ab5a675ff0d75fbec2239fb0ce44d3e06c (diff)
Support rear formats directly in the mixer
-rw-r--r--Alc/mixer.c23
-rw-r--r--OpenAL32/Include/alBuffer.h1
-rw-r--r--OpenAL32/Include/alu.h10
-rw-r--r--OpenAL32/alBuffer.c216
-rw-r--r--OpenAL32/alSource.c31
5 files changed, 74 insertions, 207 deletions
diff --git a/Alc/mixer.c b/Alc/mixer.c
index 6f2bf005..ecf3d062 100644
--- a/Alc/mixer.c
+++ b/Alc/mixer.c
@@ -525,6 +525,24 @@ DECL_TEMPLATE(ALubyte, QuadChans, lerp8)
DECL_TEMPLATE(ALubyte, QuadChans, cubic8)
+static const Channel RearChans[] = { BACK_LEFT, BACK_RIGHT };
+DECL_TEMPLATE(ALdouble, RearChans, point64)
+DECL_TEMPLATE(ALdouble, RearChans, lerp64)
+DECL_TEMPLATE(ALdouble, RearChans, cubic64)
+
+DECL_TEMPLATE(ALfloat, RearChans, point32)
+DECL_TEMPLATE(ALfloat, RearChans, lerp32)
+DECL_TEMPLATE(ALfloat, RearChans, cubic32)
+
+DECL_TEMPLATE(ALshort, RearChans, point16)
+DECL_TEMPLATE(ALshort, RearChans, lerp16)
+DECL_TEMPLATE(ALshort, RearChans, cubic16)
+
+DECL_TEMPLATE(ALubyte, RearChans, point8)
+DECL_TEMPLATE(ALubyte, RearChans, lerp8)
+DECL_TEMPLATE(ALubyte, RearChans, cubic8)
+
+
static const Channel X51Chans[] = { FRONT_LEFT, FRONT_RIGHT,
FRONT_CENTER, LFE,
BACK_LEFT, BACK_RIGHT };
@@ -612,6 +630,11 @@ static void Mix_##T##_##sampler(ALsource *Source, ALCdevice *Device, \
Data, DataPosInt, DataPosFrac, \
OutPos, SamplesToDo, BufferSize); \
break; \
+ case FmtRear: \
+ Mix_##T##_RearChans_##sampler(Source, Device, \
+ Data, DataPosInt, DataPosFrac, \
+ OutPos, SamplesToDo, BufferSize); \
+ break; \
case Fmt51ChanWFX: \
Mix_##T##_X51Chans_##sampler(Source, Device, \
Data, DataPosInt, DataPosFrac, \
diff --git a/OpenAL32/Include/alBuffer.h b/OpenAL32/Include/alBuffer.h
index c8220a12..7d5b4fc2 100644
--- a/OpenAL32/Include/alBuffer.h
+++ b/OpenAL32/Include/alBuffer.h
@@ -41,6 +41,7 @@ enum FmtChannels {
FmtMono,
FmtStereo,
FmtQuad,
+ FmtRear,
Fmt51ChanWFX,
Fmt61ChanWFX,
Fmt71ChanWFX,
diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h
index 533dd9da..698fccfd 100644
--- a/OpenAL32/Include/alu.h
+++ b/OpenAL32/Include/alu.h
@@ -105,6 +105,7 @@ static __inline ALuint aluBytesFromFormat(ALenum format)
case AL_FORMAT_STEREO8:
case AL_FORMAT_QUAD8_LOKI:
case AL_FORMAT_QUAD8:
+ case AL_FORMAT_REAR8:
case AL_FORMAT_51CHN8:
case AL_FORMAT_61CHN8:
case AL_FORMAT_71CHN8:
@@ -114,6 +115,7 @@ static __inline ALuint aluBytesFromFormat(ALenum format)
case AL_FORMAT_STEREO16:
case AL_FORMAT_QUAD16_LOKI:
case AL_FORMAT_QUAD16:
+ case AL_FORMAT_REAR16:
case AL_FORMAT_51CHN16:
case AL_FORMAT_61CHN16:
case AL_FORMAT_71CHN16:
@@ -122,6 +124,7 @@ static __inline ALuint aluBytesFromFormat(ALenum format)
case AL_FORMAT_MONO_FLOAT32:
case AL_FORMAT_STEREO_FLOAT32:
case AL_FORMAT_QUAD32:
+ case AL_FORMAT_REAR32:
case AL_FORMAT_51CHN32:
case AL_FORMAT_61CHN32:
case AL_FORMAT_71CHN32:
@@ -134,6 +137,7 @@ static __inline ALuint aluBytesFromFormat(ALenum format)
case AL_FORMAT_MONO_MULAW:
case AL_FORMAT_STEREO_MULAW:
case AL_FORMAT_QUAD_MULAW:
+ case AL_FORMAT_REAR_MULAW:
case AL_FORMAT_51CHN_MULAW:
case AL_FORMAT_61CHN_MULAW:
case AL_FORMAT_71CHN_MULAW:
@@ -169,6 +173,12 @@ static __inline ALuint aluChannelsFromFormat(ALenum format)
case AL_FORMAT_QUAD_MULAW:
return 4;
+ case AL_FORMAT_REAR8:
+ case AL_FORMAT_REAR16:
+ case AL_FORMAT_REAR32:
+ case AL_FORMAT_REAR_MULAW:
+ return 2;
+
case AL_FORMAT_51CHN8:
case AL_FORMAT_51CHN16:
case AL_FORMAT_51CHN32:
diff --git a/OpenAL32/alBuffer.c b/OpenAL32/alBuffer.c
index ce301dc3..7f08fd59 100644
--- a/OpenAL32/alBuffer.c
+++ b/OpenAL32/alBuffer.c
@@ -36,9 +36,7 @@
static ALenum LoadData(ALbuffer *ALBuf, const ALvoid *data, ALsizei size, ALuint freq, ALenum OrigFormat, ALenum NewFormat);
static void ConvertData(ALvoid *dst, enum FmtType dstType, const ALvoid *src, enum SrcFmtType srcType, ALsizei len);
-static void ConvertDataRear(ALvoid *dst, const ALvoid *src, ALint origBytes, ALsizei len);
static void ConvertDataIMA4(ALvoid *dst, const ALvoid *src, ALint origChans, ALsizei len);
-static void ConvertDataMULawRear(ALvoid *dst, const ALvoid *src, ALsizei len);
#define LookupBuffer(m, k) ((ALbuffer*)LookupUIntMapKey(&(m), (k)))
@@ -297,6 +295,9 @@ AL_API ALvoid AL_APIENTRY alBufferData(ALuint buffer,ALenum format,const ALvoid
case AL_FORMAT_QUAD8:
case AL_FORMAT_QUAD16:
case AL_FORMAT_QUAD32:
+ case AL_FORMAT_REAR8:
+ case AL_FORMAT_REAR16:
+ case AL_FORMAT_REAR32:
case AL_FORMAT_51CHN8:
case AL_FORMAT_51CHN16:
case AL_FORMAT_51CHN32:
@@ -333,55 +334,11 @@ AL_API ALvoid AL_APIENTRY alBufferData(ALuint buffer,ALenum format,const ALvoid
alSetError(Context, err);
} break;
- case AL_FORMAT_REAR8:
- case AL_FORMAT_REAR16:
- case AL_FORMAT_REAR32: {
- ALuint OrigBytes = ((format==AL_FORMAT_REAR8) ? 1 :
- ((format==AL_FORMAT_REAR16) ? 2 : 4));
- ALenum NewFormat = ((OrigBytes==4) ? AL_FORMAT_QUAD32 :
- ((OrigBytes==2) ? AL_FORMAT_QUAD16 :
- AL_FORMAT_QUAD8));
- ALuint NewChannels = aluChannelsFromFormat(NewFormat);
- ALuint NewBytes = aluBytesFromFormat(NewFormat);
- ALuint64 newsize;
-
- if((size%(OrigBytes*2)) != 0)
- {
- alSetError(Context, AL_INVALID_VALUE);
- break;
- }
-
- newsize = size / OrigBytes;
- newsize *= 2;
- newsize *= NewBytes;
-
- if(newsize > INT_MAX)
- {
- alSetError(Context, AL_OUT_OF_MEMORY);
- break;
- }
- temp = realloc(ALBuf->data, newsize);
- if(temp)
- {
- ALBuf->data = temp;
- ConvertDataRear(ALBuf->data, data, OrigBytes, newsize/NewBytes);
-
- ALBuf->format = NewFormat;
- ALBuf->eOriginalFormat = format;
- ALBuf->size = newsize;
- ALBuf->frequency = freq;
-
- ALBuf->LoopStart = 0;
- ALBuf->LoopEnd = newsize / NewChannels / NewBytes;
-
- DecomposeFormat(NewFormat, &ALBuf->FmtType, &ALBuf->FmtChannels);
-
- ALBuf->OriginalSize = size;
- ALBuf->OriginalAlign = OrigBytes * 2;
- }
- else
- alSetError(Context, AL_OUT_OF_MEMORY);
- } break;
+ case AL_FORMAT_REAR_MULAW:
+ err = LoadData(ALBuf, data, size, freq, format, AL_FORMAT_REAR16);
+ if(err != AL_NO_ERROR)
+ alSetError(Context, err);
+ break;
case AL_FORMAT_MONO_IMA4:
case AL_FORMAT_STEREO_IMA4: {
@@ -433,49 +390,6 @@ AL_API ALvoid AL_APIENTRY alBufferData(ALuint buffer,ALenum format,const ALvoid
alSetError(Context, AL_OUT_OF_MEMORY);
} break;
- case AL_FORMAT_REAR_MULAW: {
- ALenum NewFormat = AL_FORMAT_QUAD16;
- ALuint NewChannels = aluChannelsFromFormat(NewFormat);
- ALuint NewBytes = aluBytesFromFormat(NewFormat);
- ALuint64 newsize;
-
- if((size%(1*2)) != 0)
- {
- alSetError(Context, AL_INVALID_VALUE);
- break;
- }
-
- newsize = size * 2;
- newsize *= NewBytes;
-
- if(newsize > INT_MAX)
- {
- alSetError(Context, AL_OUT_OF_MEMORY);
- break;
- }
- temp = realloc(ALBuf->data, newsize);
- if(temp)
- {
- ALBuf->data = temp;
- ConvertDataMULawRear(ALBuf->data, data, newsize/NewBytes);
-
- ALBuf->format = NewFormat;
- ALBuf->eOriginalFormat = format;
- ALBuf->size = newsize;
- ALBuf->frequency = freq;
-
- ALBuf->LoopStart = 0;
- ALBuf->LoopEnd = newsize / NewChannels / NewBytes;
-
- DecomposeFormat(NewFormat, &ALBuf->FmtType, &ALBuf->FmtChannels);
-
- ALBuf->OriginalSize = size;
- ALBuf->OriginalAlign = 1 * 2;
- }
- else
- alSetError(Context, AL_OUT_OF_MEMORY);
- } break;
-
default:
alSetError(Context, AL_INVALID_ENUM);
break;
@@ -543,6 +457,10 @@ AL_API ALvoid AL_APIENTRY alBufferSubDataSOFT(ALuint buffer,ALenum format,const
case AL_FORMAT_QUAD16:
case AL_FORMAT_QUAD32:
case AL_FORMAT_QUAD_MULAW:
+ case AL_FORMAT_REAR8:
+ case AL_FORMAT_REAR16:
+ case AL_FORMAT_REAR32:
+ case AL_FORMAT_REAR_MULAW:
case AL_FORMAT_51CHN8:
case AL_FORMAT_51CHN16:
case AL_FORMAT_51CHN32:
@@ -569,22 +487,6 @@ AL_API ALvoid AL_APIENTRY alBufferSubDataSOFT(ALuint buffer,ALenum format,const
data, SrcType, length);
} break;
- case AL_FORMAT_REAR8:
- case AL_FORMAT_REAR16:
- case AL_FORMAT_REAR32: {
- ALuint OldBytes = ((format==AL_FORMAT_REAR8) ? 1 :
- ((format==AL_FORMAT_REAR16) ? 2 : 4));
- ALuint Bytes = aluBytesFromFormat(ALBuf->format);
-
- offset /= OldBytes;
- offset *= 2;
- offset *= Bytes;
- length /= OldBytes;
- length *= 2;
-
- ConvertDataRear(&((ALubyte*)ALBuf->data)[offset], data, Bytes, length);
- } break;
-
case AL_FORMAT_MONO_IMA4:
case AL_FORMAT_STEREO_IMA4: {
ALuint Channels = aluChannelsFromFormat(ALBuf->format);
@@ -599,16 +501,6 @@ AL_API ALvoid AL_APIENTRY alBufferSubDataSOFT(ALuint buffer,ALenum format,const
ConvertDataIMA4(&((ALubyte*)ALBuf->data)[offset], data, Channels, length);
} break;
- case AL_FORMAT_REAR_MULAW: {
- ALuint Bytes = aluBytesFromFormat(ALBuf->format);
-
- offset *= 2;
- offset *= Bytes;
- length *= 2;
-
- ConvertDataMULawRear(&((ALubyte*)ALBuf->data)[offset], data, length);
- } break;
-
default:
alSetError(Context, AL_INVALID_ENUM);
break;
@@ -1001,48 +893,6 @@ AL_API void AL_APIENTRY alGetBufferiv(ALuint buffer, ALenum eParam, ALint* plVal
}
-static void ConvertDataRear(ALvoid *dst, const ALvoid *src, ALint origBytes, ALsizei len)
-{
- ALsizei i;
- if(src == NULL)
- return;
- switch(origBytes)
- {
- case 1:
- for(i = 0;i < len;i+=4)
- {
- ((ALubyte*)dst)[i+0] = 0;
- ((ALubyte*)dst)[i+1] = 0;
- ((ALubyte*)dst)[i+2] = ((ALubyte*)src)[i/2+0];
- ((ALubyte*)dst)[i+3] = ((ALubyte*)src)[i/2+1];
- }
- break;
-
- case 2:
- for(i = 0;i < len;i+=4)
- {
- ((ALshort*)dst)[i+0] = 0;
- ((ALshort*)dst)[i+1] = 0;
- ((ALshort*)dst)[i+2] = ((ALshort*)src)[i/2+0];
- ((ALshort*)dst)[i+3] = ((ALshort*)src)[i/2+1];
- }
- break;
-
- case 4:
- for(i = 0;i < len;i+=4)
- {
- ((ALfloat*)dst)[i+0] = 0.f;
- ((ALfloat*)dst)[i+1] = 0.f;
- ((ALfloat*)dst)[i+2] = ((ALfloat*)src)[i/2+0];
- ((ALfloat*)dst)[i+3] = ((ALfloat*)src)[i/2+1];
- }
- break;
-
- default:
- assert(0);
- }
-}
-
static void ConvertDataIMA4(ALvoid *dst, const ALvoid *src, ALint chans, ALsizei len)
{
const ALubyte *IMAData;
@@ -1102,20 +952,6 @@ static void ConvertDataIMA4(ALvoid *dst, const ALvoid *src, ALint chans, ALsizei
}
}
-static void ConvertDataMULawRear(ALvoid *dst, const ALvoid *src, ALsizei len)
-{
- ALsizei i;
- if(src == NULL)
- return;
- for(i = 0;i < len;i+=4)
- {
- ((ALshort*)dst)[i+0] = 0;
- ((ALshort*)dst)[i+1] = 0;
- ((ALshort*)dst)[i+2] = muLawDecompressionTable[((ALubyte*)src)[i/2+0]];
- ((ALshort*)dst)[i+3] = muLawDecompressionTable[((ALubyte*)src)[i/2+1]];
- }
-}
-
typedef ALubyte ALmulaw;
@@ -1473,6 +1309,18 @@ void DecomposeInputFormat(ALenum format, enum SrcFmtType *type,
*type = SrcFmtFloat;
*order = SrcFmtQuad;
break;
+ case AL_FORMAT_REAR8:
+ *type = SrcFmtUByte;
+ *order = SrcFmtRear;
+ break;
+ case AL_FORMAT_REAR16:
+ *type = SrcFmtShort;
+ *order = SrcFmtRear;
+ break;
+ case AL_FORMAT_REAR32:
+ *type = SrcFmtFloat;
+ *order = SrcFmtRear;
+ break;
case AL_FORMAT_51CHN8:
*type = SrcFmtUByte;
*order = SrcFmtX51;
@@ -1521,6 +1369,10 @@ void DecomposeInputFormat(ALenum format, enum SrcFmtType *type,
*type = SrcFmtMulaw;
*order = SrcFmtQuad;
break;
+ case AL_FORMAT_REAR_MULAW:
+ *type = SrcFmtMulaw;
+ *order = SrcFmtRear;
+ break;
case AL_FORMAT_51CHN_MULAW:
*type = SrcFmtMulaw;
*order = SrcFmtX51;
@@ -1590,6 +1442,18 @@ void DecomposeFormat(ALenum format, enum FmtType *type, enum FmtChannels *order)
*type = FmtFloat;
*order = FmtQuad;
break;
+ case AL_FORMAT_REAR8:
+ *type = FmtUByte;
+ *order = FmtRear;
+ break;
+ case AL_FORMAT_REAR16:
+ *type = FmtShort;
+ *order = FmtRear;
+ break;
+ case AL_FORMAT_REAR32:
+ *type = FmtFloat;
+ *order = FmtRear;
+ break;
case AL_FORMAT_51CHN8:
*type = FmtUByte;
*order = Fmt51ChanWFX;
diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c
index 8cd1d4a1..70d197ff 100644
--- a/OpenAL32/alSource.c
+++ b/OpenAL32/alSource.c
@@ -1887,26 +1887,6 @@ static ALvoid GetSourceOffset(ALsource *Source, ALenum name, ALdouble *offset, A
FrameBlockSize * BlockSize);
}
}
- else if(OriginalFormat == AL_FORMAT_REAR_MULAW)
- {
- offset[0] = (ALdouble)(readPos / 2 / Bytes * 1);
- offset[1] = (ALdouble)(writePos / 2 / Bytes * 1);
- }
- else if(OriginalFormat == AL_FORMAT_REAR8)
- {
- offset[0] = (ALdouble)(readPos / 2 / Bytes * 1);
- offset[1] = (ALdouble)(writePos / 2 / Bytes * 1);
- }
- else if(OriginalFormat == AL_FORMAT_REAR16)
- {
- offset[0] = (ALdouble)(readPos / 2 / Bytes * 2);
- offset[1] = (ALdouble)(writePos / 2 / Bytes * 2);
- }
- else if(OriginalFormat == AL_FORMAT_REAR32)
- {
- offset[0] = (ALdouble)(readPos / 2 / Bytes * 4);
- offset[1] = (ALdouble)(writePos / 2 / Bytes * 4);
- }
else
{
ALuint OrigBytes = aluBytesFromFormat(OriginalFormat);
@@ -2048,17 +2028,6 @@ static ALint FramesFromBytes(ALint offset, ALenum format)
offset /= 36 * 2;
offset *= 65;
}
- else if(format == AL_FORMAT_REAR_MULAW)
- {
- /* Rear is 2 channels */
- offset /= 1 * 2;
- }
- else if(format == AL_FORMAT_REAR8)
- offset /= 1 * 2;
- else if(format == AL_FORMAT_REAR16)
- offset /= 2 * 2;
- else if(format == AL_FORMAT_REAR32)
- offset /= 4 * 2;
else
offset /= aluFrameSizeFromFormat(format);
return offset;