aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2010-11-26 23:42:30 -0800
committerChris Robinson <[email protected]>2010-11-26 23:42:30 -0800
commit6abb9d151eef04d5770bbdd584cd7cdc565f970d (patch)
treee1c7ffc1602c755729b9c1d95b0d1e2f8f3e8c99
parent08827efae3bd6e095087507b0f9e65881832a8d1 (diff)
Use enums when selecting the mixer
-rw-r--r--Alc/mixer.c63
-rw-r--r--OpenAL32/Include/alBuffer.h106
-rw-r--r--OpenAL32/alBuffer.c10
3 files changed, 150 insertions, 29 deletions
diff --git a/Alc/mixer.c b/Alc/mixer.c
index eb5ede86..187ccbe7 100644
--- a/Alc/mixer.c
+++ b/Alc/mixer.c
@@ -558,38 +558,39 @@ DECL_TEMPLATE(ALubyte, X71Chans, cubic8)
#define DECL_TEMPLATE(T, sampler) \
-static void Mix_##T##_##sampler(ALsource *Source, ALCdevice *Device, ALuint Channels, \
+static void Mix_##T##_##sampler(ALsource *Source, ALCdevice *Device, \
+ enum FmtChannels FmtChannels, \
const ALvoid *Data, ALuint *DataPosInt, ALuint *DataPosFrac, \
ALuint OutPos, ALuint SamplesToDo, ALuint BufferSize) \
{ \
- switch(Channels) \
+ switch(FmtChannels) \
{ \
- case 1: /* Mono */ \
+ case FmtMono: \
Mix_##T##_Mono_##sampler(Source, Device, \
Data, DataPosInt, DataPosFrac, \
OutPos, SamplesToDo, BufferSize); \
break; \
- case 2: /* Stereo */ \
+ case FmtStereo: \
Mix_##T##_Stereo_##sampler(Source, Device, \
Data, DataPosInt, DataPosFrac, \
OutPos, SamplesToDo, BufferSize); \
break; \
- case 4: /* Quad */ \
+ case FmtQuad: \
Mix_##T##_QuadChans_##sampler(Source, Device, \
Data, DataPosInt, DataPosFrac, \
OutPos, SamplesToDo, BufferSize); \
break; \
- case 6: /* 5.1 */ \
+ case Fmt51ChanWFX: \
Mix_##T##_X51Chans_##sampler(Source, Device, \
Data, DataPosInt, DataPosFrac, \
OutPos, SamplesToDo, BufferSize); \
break; \
- case 7: /* 6.1 */ \
+ case Fmt61ChanWFX: \
Mix_##T##_X61Chans_##sampler(Source, Device, \
Data, DataPosInt, DataPosFrac, \
OutPos, SamplesToDo, BufferSize); \
break; \
- case 8: /* 7.1 */ \
+ case Fmt71ChanWFX: \
Mix_##T##_X71Chans_##sampler(Source, Device, \
Data, DataPosInt, DataPosFrac, \
OutPos, SamplesToDo, BufferSize); \
@@ -614,26 +615,26 @@ DECL_TEMPLATE(ALubyte, cubic8)
#define DECL_TEMPLATE(sampler) \
static void Mix_##sampler(ALsource *Source, ALCdevice *Device, \
- ALuint Channels, ALuint Bytes, \
+ enum FmtChannels FmtChannels, enum FmtType FmtType, \
const ALvoid *Data, ALuint *DataPosInt, ALuint *DataPosFrac, \
ALuint OutPos, ALuint SamplesToDo, ALuint BufferSize) \
{ \
- switch(Bytes) \
+ switch(FmtType) \
{ \
- case 1: \
- Mix_ALubyte_##sampler##8(Source, Device, Channels, \
+ case FmtUByte: \
+ Mix_ALubyte_##sampler##8(Source, Device, FmtChannels, \
Data, DataPosInt, DataPosFrac, \
OutPos, SamplesToDo, BufferSize); \
break; \
\
- case 2: \
- Mix_ALshort_##sampler##16(Source, Device, Channels, \
+ case FmtShort: \
+ Mix_ALshort_##sampler##16(Source, Device, FmtChannels, \
Data, DataPosInt, DataPosFrac, \
OutPos, SamplesToDo, BufferSize); \
break; \
\
- case 4: \
- Mix_ALfloat_##sampler##32(Source, Device, Channels, \
+ case FmtFloat: \
+ Mix_ALfloat_##sampler##32(Source, Device, FmtChannels, \
Data, DataPosInt, DataPosFrac, \
OutPos, SamplesToDo, BufferSize); \
break; \
@@ -650,16 +651,18 @@ DECL_TEMPLATE(cubic)
ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
{
ALbufferlistitem *BufferListItem;
- ALuint FrameSize, Channels, Bytes;
ALuint DataPosInt, DataPosFrac;
+ enum FmtChannels FmtChannels;
+ enum FmtType FmtType;
ALuint BuffersPlayed;
ALboolean Looping;
ALuint increment;
resampler_t Resampler;
ALenum State;
ALuint OutPos;
- ALuint i;
+ ALuint FrameSize;
ALint64 DataSize64;
+ ALuint i;
/* Get source info */
State = Source->state;
@@ -672,7 +675,9 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
Source->Resampler;
/* Get buffer info */
- FrameSize = Channels = Bytes = 0;
+ FrameSize = 0;
+ FmtChannels = FmtMono;
+ FmtType = FmtUByte;
BufferListItem = Source->queue;
for(i = 0;i < Source->BuffersInQueue;i++)
{
@@ -680,8 +685,8 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
if((ALBuffer=BufferListItem->buffer) != NULL)
{
FrameSize = aluFrameSizeFromFormat(ALBuffer->format);
- Channels = aluChannelsFromFormat(ALBuffer->format);
- Bytes = aluBytesFromFormat(ALBuffer->format);
+ FmtChannels = ALBuffer->FmtChannels;
+ FmtType = ALBuffer->FmtType;
break;
}
BufferListItem = BufferListItem->next;
@@ -731,7 +736,7 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
DataSize = (BufferPrePadding-DataPosInt)*FrameSize;
DataSize = min(BufferSize, DataSize);
- memset(&SrcData[SrcDataSize], (Bytes==1)?0x80:0, DataSize);
+ memset(&SrcData[SrcDataSize], (FmtType==FmtUByte)?0x80:0, DataSize);
SrcDataSize += DataSize;
BufferSize -= DataSize;
@@ -747,7 +752,7 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
SrcDataSize += DataSize;
BufferSize -= DataSize;
- memset(&SrcData[SrcDataSize], (Bytes==1)?0x80:0, BufferSize);
+ memset(&SrcData[SrcDataSize], (FmtType==FmtUByte)?0x80:0, BufferSize);
SrcDataSize += BufferSize;
BufferSize -= BufferSize;
}
@@ -772,7 +777,7 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
DataSize = (BufferPrePadding-DataPosInt)*FrameSize;
DataSize = min(BufferSize, DataSize);
- memset(&SrcData[SrcDataSize], (Bytes==1)?0x80:0, DataSize);
+ memset(&SrcData[SrcDataSize], (FmtType==FmtUByte)?0x80:0, DataSize);
SrcDataSize += DataSize;
BufferSize -= DataSize;
@@ -816,7 +821,7 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
{
ALuint DataSize = min(BufferSize, pos);
- memset(&SrcData[SrcDataSize], (Bytes==1)?0x80:0, DataSize);
+ memset(&SrcData[SrcDataSize], (FmtType==FmtUByte)?0x80:0, DataSize);
SrcDataSize += DataSize;
BufferSize -= DataSize;
@@ -872,7 +877,7 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
BufferListIter = Source->queue;
else if(!BufferListIter)
{
- memset(&SrcData[SrcDataSize], (Bytes==1)?0x80:0, BufferSize);
+ memset(&SrcData[SrcDataSize], (FmtType==FmtUByte)?0x80:0, BufferSize);
SrcDataSize += BufferSize;
BufferSize -= BufferSize;
}
@@ -893,17 +898,17 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
switch(Resampler)
{
case POINT_RESAMPLER:
- Mix_point(Source, Device, Channels, Bytes,
+ Mix_point(Source, Device, FmtChannels, FmtType,
SrcData, &DataPosInt, &DataPosFrac,
OutPos, SamplesToDo, BufferSize);
break;
case LINEAR_RESAMPLER:
- Mix_lerp(Source, Device, Channels, Bytes,
+ Mix_lerp(Source, Device, FmtChannels, FmtType,
SrcData, &DataPosInt, &DataPosFrac,
OutPos, SamplesToDo, BufferSize);
break;
case CUBIC_RESAMPLER:
- Mix_cubic(Source, Device, Channels, Bytes,
+ Mix_cubic(Source, Device, FmtChannels, FmtType,
SrcData, &DataPosInt, &DataPosFrac,
OutPos, SamplesToDo, BufferSize);
break;
diff --git a/OpenAL32/Include/alBuffer.h b/OpenAL32/Include/alBuffer.h
index e11fe210..06823ace 100644
--- a/OpenAL32/Include/alBuffer.h
+++ b/OpenAL32/Include/alBuffer.h
@@ -7,6 +7,109 @@
extern "C" {
#endif
+enum FmtType {
+ FmtUByte,
+ FmtShort,
+ FmtFloat,
+};
+
+enum FmtChannels {
+ FmtMono,
+ FmtStereo,
+ FmtQuad,
+ Fmt51ChanWFX,
+ Fmt61ChanWFX,
+ Fmt71ChanWFX,
+};
+
+
+static __inline void DecompFormat(ALenum format, enum FmtType *type,
+ enum FmtChannels *order)
+{
+ switch(format)
+ {
+ case AL_FORMAT_MONO8:
+ *type = FmtUByte;
+ *order = FmtMono;
+ break;
+ case AL_FORMAT_MONO16:
+ *type = FmtShort;
+ *order = FmtMono;
+ break;
+ case AL_FORMAT_MONO_FLOAT32:
+ *type = FmtFloat;
+ *order = FmtMono;
+ break;
+ case AL_FORMAT_STEREO8:
+ *type = FmtUByte;
+ *order = FmtStereo;
+ break;
+ case AL_FORMAT_STEREO16:
+ *type = FmtShort;
+ *order = FmtStereo;
+ break;
+ case AL_FORMAT_STEREO_FLOAT32:
+ *type = FmtFloat;
+ *order = FmtStereo;
+ break;
+ case AL_FORMAT_QUAD8_LOKI:
+ case AL_FORMAT_QUAD8:
+ *type = FmtUByte;
+ *order = FmtQuad;
+ break;
+ case AL_FORMAT_QUAD16_LOKI:
+ case AL_FORMAT_QUAD16:
+ *type = FmtShort;
+ *order = FmtQuad;
+ break;
+ case AL_FORMAT_QUAD32:
+ *type = FmtFloat;
+ *order = FmtQuad;
+ break;
+ case AL_FORMAT_51CHN8:
+ *type = FmtUByte;
+ *order = Fmt51ChanWFX;
+ break;
+ case AL_FORMAT_51CHN16:
+ *type = FmtShort;
+ *order = Fmt51ChanWFX;
+ break;
+ case AL_FORMAT_51CHN32:
+ *type = FmtFloat;
+ *order = Fmt51ChanWFX;
+ break;
+ case AL_FORMAT_61CHN8:
+ *type = FmtUByte;
+ *order = Fmt61ChanWFX;
+ break;
+ case AL_FORMAT_61CHN16:
+ *type = FmtShort;
+ *order = Fmt61ChanWFX;
+ break;
+ case AL_FORMAT_61CHN32:
+ *type = FmtFloat;
+ *order = Fmt61ChanWFX;
+ break;
+ case AL_FORMAT_71CHN8:
+ *type = FmtUByte;
+ *order = Fmt71ChanWFX;
+ break;
+ case AL_FORMAT_71CHN16:
+ *type = FmtShort;
+ *order = Fmt71ChanWFX;
+ break;
+ case AL_FORMAT_71CHN32:
+ *type = FmtFloat;
+ *order = Fmt71ChanWFX;
+ break;
+
+ default:
+ AL_PRINT("Unhandled format specified: 0x%X\n", format);
+ abort();
+ }
+}
+
+
typedef struct ALbuffer
{
ALvoid *data;
@@ -22,6 +125,9 @@ typedef struct ALbuffer
ALsizei LoopStart;
ALsizei LoopEnd;
+ enum FmtType FmtType;
+ enum FmtChannels FmtChannels;
+
ALuint refcount; // Number of sources using this buffer (deletion can only occur when this is 0)
// Index to itself
diff --git a/OpenAL32/alBuffer.c b/OpenAL32/alBuffer.c
index ed03df00..c923819d 100644
--- a/OpenAL32/alBuffer.c
+++ b/OpenAL32/alBuffer.c
@@ -361,6 +361,8 @@ AL_API ALvoid AL_APIENTRY alBufferData(ALuint buffer,ALenum format,const ALvoid
ALBuf->LoopStart = 0;
ALBuf->LoopEnd = newsize / NewChannels / NewBytes;
+ DecompFormat(NewFormat, &ALBuf->FmtType, &ALBuf->FmtChannels);
+
ALBuf->OriginalSize = size;
ALBuf->OriginalAlign = OrigBytes * 2;
}
@@ -409,6 +411,8 @@ AL_API ALvoid AL_APIENTRY alBufferData(ALuint buffer,ALenum format,const ALvoid
ALBuf->LoopStart = 0;
ALBuf->LoopEnd = newsize / Channels / NewBytes;
+ DecompFormat(NewFormat, &ALBuf->FmtType, &ALBuf->FmtChannels);
+
ALBuf->OriginalSize = size;
ALBuf->OriginalAlign = 36 * Channels;
}
@@ -462,6 +466,8 @@ AL_API ALvoid AL_APIENTRY alBufferData(ALuint buffer,ALenum format,const ALvoid
ALBuf->LoopStart = 0;
ALBuf->LoopEnd = newsize / Channels / NewBytes;
+ DecompFormat(NewFormat, &ALBuf->FmtType, &ALBuf->FmtChannels);
+
ALBuf->OriginalSize = size;
ALBuf->OriginalAlign = 1 * Channels;
}
@@ -503,6 +509,8 @@ AL_API ALvoid AL_APIENTRY alBufferData(ALuint buffer,ALenum format,const ALvoid
ALBuf->LoopStart = 0;
ALBuf->LoopEnd = newsize / NewChannels / NewBytes;
+ DecompFormat(NewFormat, &ALBuf->FmtType, &ALBuf->FmtChannels);
+
ALBuf->OriginalSize = size;
ALBuf->OriginalAlign = 1 * 2;
}
@@ -1085,6 +1093,8 @@ static ALenum LoadData(ALbuffer *ALBuf, const ALvoid *data, ALsizei size, ALuint
ALBuf->LoopStart = 0;
ALBuf->LoopEnd = newsize / NewChannels / NewBytes;
+ DecompFormat(NewFormat, &ALBuf->FmtType, &ALBuf->FmtChannels);
+
ALBuf->OriginalSize = size;
ALBuf->OriginalAlign = OrigBytes * OrigChannels;