aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Alc/mixer.c59
-rw-r--r--OpenAL32/alBuffer.c115
2 files changed, 97 insertions, 77 deletions
diff --git a/Alc/mixer.c b/Alc/mixer.c
index 35b8653b..5c04b55a 100644
--- a/Alc/mixer.c
+++ b/Alc/mixer.c
@@ -71,6 +71,23 @@ static __inline ALfloat cos_lerp16(ALfloat val1, ALfloat val2, ALint frac)
return val1 / 32767.0f;
}
+static __inline ALfloat point8(ALfloat val1, ALfloat val2, ALint frac)
+{
+ return (val1-128.0f) / 127.0f;
+ (void)val2;
+ (void)frac;
+}
+static __inline ALfloat lerp8(ALfloat val1, ALfloat val2, ALint frac)
+{
+ val1 += (val2-val1) * (frac * (1.0/(1<<FRACTIONBITS)));
+ return (val1-128.0f) / 127.0f;
+}
+static __inline ALfloat cos_lerp8(ALfloat val1, ALfloat val2, ALint frac)
+{
+ val1 += (val2-val1) * ((1.0-cos(frac * (1.0/(1<<FRACTIONBITS)) * M_PI)) * 0.5);
+ return (val1-128.0f) / 127.0f;
+}
+
#define DECL_MIX_MONO(T,sampler) \
static void MixMono_##T##_##sampler(ALsource *Source, ALCdevice *Device, \
@@ -234,6 +251,10 @@ DECL_MIX_MONO(ALshort, point16)
DECL_MIX_MONO(ALshort, lerp16)
DECL_MIX_MONO(ALshort, cos_lerp16)
+DECL_MIX_MONO(ALubyte, point8)
+DECL_MIX_MONO(ALubyte, lerp8)
+DECL_MIX_MONO(ALubyte, cos_lerp8)
+
#define DECL_MIX_STEREO(T,sampler) \
static void MixStereo_##T##_##sampler(ALsource *Source, ALCdevice *Device, \
@@ -409,6 +430,10 @@ DECL_MIX_STEREO(ALshort, point16)
DECL_MIX_STEREO(ALshort, lerp16)
DECL_MIX_STEREO(ALshort, cos_lerp16)
+DECL_MIX_STEREO(ALubyte, point8)
+DECL_MIX_STEREO(ALubyte, lerp8)
+DECL_MIX_STEREO(ALubyte, cos_lerp8)
+
#define DECL_MIX_MC(T,chans,sampler) \
@@ -576,6 +601,10 @@ DECL_MIX_MC(ALshort, QuadChans, point16)
DECL_MIX_MC(ALshort, QuadChans, lerp16)
DECL_MIX_MC(ALshort, QuadChans, cos_lerp16)
+DECL_MIX_MC(ALubyte, QuadChans, point8)
+DECL_MIX_MC(ALubyte, QuadChans, lerp8)
+DECL_MIX_MC(ALubyte, QuadChans, cos_lerp8)
+
static const Channel X51Chans[] = { FRONT_LEFT, FRONT_RIGHT,
FRONT_CENTER, LFE,
@@ -588,6 +617,10 @@ DECL_MIX_MC(ALshort, X51Chans, point16)
DECL_MIX_MC(ALshort, X51Chans, lerp16)
DECL_MIX_MC(ALshort, X51Chans, cos_lerp16)
+DECL_MIX_MC(ALubyte, X51Chans, point8)
+DECL_MIX_MC(ALubyte, X51Chans, lerp8)
+DECL_MIX_MC(ALubyte, X51Chans, cos_lerp8)
+
static const Channel X61Chans[] = { FRONT_LEFT, FRONT_RIGHT,
FRONT_CENTER, LFE,
@@ -601,6 +634,10 @@ DECL_MIX_MC(ALshort, X61Chans, point16)
DECL_MIX_MC(ALshort, X61Chans, lerp16)
DECL_MIX_MC(ALshort, X61Chans, cos_lerp16)
+DECL_MIX_MC(ALubyte, X61Chans, point8)
+DECL_MIX_MC(ALubyte, X61Chans, lerp8)
+DECL_MIX_MC(ALubyte, X61Chans, cos_lerp8)
+
static const Channel X71Chans[] = { FRONT_LEFT, FRONT_RIGHT,
FRONT_CENTER, LFE,
@@ -614,6 +651,10 @@ DECL_MIX_MC(ALshort, X71Chans, point16)
DECL_MIX_MC(ALshort, X71Chans, lerp16)
DECL_MIX_MC(ALshort, X71Chans, cos_lerp16)
+DECL_MIX_MC(ALubyte, X71Chans, point8)
+DECL_MIX_MC(ALubyte, X71Chans, lerp8)
+DECL_MIX_MC(ALubyte, X71Chans, cos_lerp8)
+
#define DECL_MIX(T, sampler) \
static void Mix_##T##_##sampler(ALsource *Source, ALCdevice *Device, ALuint Channels, \
@@ -663,6 +704,10 @@ DECL_MIX(ALshort, point16)
DECL_MIX(ALshort, lerp16)
DECL_MIX(ALshort, cos_lerp16)
+DECL_MIX(ALubyte, point8)
+DECL_MIX(ALubyte, lerp8)
+DECL_MIX(ALubyte, cos_lerp8)
+
ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
{
@@ -724,7 +769,7 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
if(DataPosInt >= DataSize)
goto skipmix;
- memset(&Data[DataSize*Channels*Bytes], 0, BUFFER_PADDING*Channels*Bytes);
+ memset(&Data[DataSize*Channels*Bytes], (Bytes==1)?0x80:0, BUFFER_PADDING*Channels*Bytes);
if(BufferListItem->next)
{
ALbuffer *NextBuf = BufferListItem->next->buffer;
@@ -771,6 +816,10 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
Mix_ALshort_point16(Source, Device, Channels,
Data, &DataPosInt, &DataPosFrac, LoopEnd,
j, SamplesToDo, BufferSize);
+ else if(Bytes == 1)
+ Mix_ALubyte_point8(Source, Device, Channels,
+ Data, &DataPosInt, &DataPosFrac, LoopEnd,
+ j, SamplesToDo, BufferSize);
break;
case LINEAR_RESAMPLER:
if(Bytes == 4)
@@ -781,6 +830,10 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
Mix_ALshort_lerp16(Source, Device, Channels,
Data, &DataPosInt, &DataPosFrac, LoopEnd,
j, SamplesToDo, BufferSize);
+ else if(Bytes == 1)
+ Mix_ALubyte_lerp8(Source, Device, Channels,
+ Data, &DataPosInt, &DataPosFrac, LoopEnd,
+ j, SamplesToDo, BufferSize);
break;
case COSINE_RESAMPLER:
if(Bytes == 4)
@@ -791,6 +844,10 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
Mix_ALshort_cos_lerp16(Source, Device, Channels,
Data, &DataPosInt, &DataPosFrac, LoopEnd,
j, SamplesToDo, BufferSize);
+ else if(Bytes == 1)
+ Mix_ALubyte_cos_lerp8(Source, Device, Channels,
+ Data, &DataPosInt, &DataPosFrac, LoopEnd,
+ j, SamplesToDo, BufferSize);
break;
case RESAMPLER_MIN:
case RESAMPLER_MAX:
diff --git a/OpenAL32/alBuffer.c b/OpenAL32/alBuffer.c
index 24c30045..b55426b0 100644
--- a/OpenAL32/alBuffer.c
+++ b/OpenAL32/alBuffer.c
@@ -287,26 +287,45 @@ AL_API ALvoid AL_APIENTRY alBufferData(ALuint buffer,ALenum format,const ALvoid
{
case AL_FORMAT_MONO8:
case AL_FORMAT_MONO16:
- err = LoadData(ALBuf, data, size, freq, format, AL_FORMAT_MONO16);
+ case AL_FORMAT_MONO_FLOAT32:
+ case AL_FORMAT_STEREO8:
+ case AL_FORMAT_STEREO16:
+ case AL_FORMAT_STEREO_FLOAT32:
+ case AL_FORMAT_QUAD8:
+ case AL_FORMAT_QUAD16:
+ case AL_FORMAT_QUAD32:
+ case AL_FORMAT_51CHN8:
+ case AL_FORMAT_51CHN16:
+ case AL_FORMAT_51CHN32:
+ case AL_FORMAT_61CHN8:
+ case AL_FORMAT_61CHN16:
+ case AL_FORMAT_61CHN32:
+ case AL_FORMAT_71CHN8:
+ case AL_FORMAT_71CHN16:
+ case AL_FORMAT_71CHN32:
+ err = LoadData(ALBuf, data, size, freq, format, format);
if(err != AL_NO_ERROR)
alSetError(Context, err);
break;
- case AL_FORMAT_MONO_FLOAT32:
+
case AL_FORMAT_MONO_DOUBLE_EXT:
err = LoadData(ALBuf, data, size, freq, format, AL_FORMAT_MONO_FLOAT32);
if(err != AL_NO_ERROR)
alSetError(Context, err);
break;
+ case AL_FORMAT_STEREO_DOUBLE_EXT:
+ err = LoadData(ALBuf, data, size, freq, format, AL_FORMAT_STEREO_FLOAT32);
+ if(err != AL_NO_ERROR)
+ alSetError(Context, err);
+ break;
- case AL_FORMAT_STEREO8:
- case AL_FORMAT_STEREO16:
- err = LoadData(ALBuf, data, size, freq, format, AL_FORMAT_STEREO16);
+ case AL_FORMAT_QUAD8_LOKI:
+ err = LoadData(ALBuf, data, size, freq, format, AL_FORMAT_QUAD8);
if(err != AL_NO_ERROR)
alSetError(Context, err);
break;
- case AL_FORMAT_STEREO_FLOAT32:
- case AL_FORMAT_STEREO_DOUBLE_EXT:
- err = LoadData(ALBuf, data, size, freq, format, AL_FORMAT_STEREO_FLOAT32);
+ case AL_FORMAT_QUAD16_LOKI:
+ err = LoadData(ALBuf, data, size, freq, format, AL_FORMAT_QUAD16);
if(err != AL_NO_ERROR)
alSetError(Context, err);
break;
@@ -317,7 +336,8 @@ AL_API ALvoid AL_APIENTRY alBufferData(ALuint buffer,ALenum format,const ALvoid
ALuint OrigBytes = ((format==AL_FORMAT_REAR8) ? 1 :
((format==AL_FORMAT_REAR16) ? 2 : 4));
ALenum NewFormat = ((OrigBytes==4) ? AL_FORMAT_QUAD32 :
- AL_FORMAT_QUAD16);
+ ((OrigBytes==2) ? AL_FORMAT_QUAD16 :
+ AL_FORMAT_QUAD8));
ALuint NewChannels = aluChannelsFromFormat(NewFormat);
ALuint NewBytes = aluBytesFromFormat(NewFormat);
ALuint64 newsize, allocsize;
@@ -358,56 +378,6 @@ AL_API ALvoid AL_APIENTRY alBufferData(ALuint buffer,ALenum format,const ALvoid
alSetError(Context, AL_OUT_OF_MEMORY);
} break;
- case AL_FORMAT_QUAD8_LOKI:
- case AL_FORMAT_QUAD16_LOKI:
- case AL_FORMAT_QUAD8:
- case AL_FORMAT_QUAD16:
- err = LoadData(ALBuf, data, size, freq, format, AL_FORMAT_QUAD16);
- if(err != AL_NO_ERROR)
- alSetError(Context, err);
- break;
- case AL_FORMAT_QUAD32:
- err = LoadData(ALBuf, data, size, freq, format, AL_FORMAT_QUAD32);
- if(err != AL_NO_ERROR)
- alSetError(Context, err);
- break;
-
- case AL_FORMAT_51CHN8:
- case AL_FORMAT_51CHN16:
- err = LoadData(ALBuf, data, size, freq, format, AL_FORMAT_51CHN16);
- if(err != AL_NO_ERROR)
- alSetError(Context, err);
- break;
- case AL_FORMAT_51CHN32:
- err = LoadData(ALBuf, data, size, freq, format, AL_FORMAT_51CHN32);
- if(err != AL_NO_ERROR)
- alSetError(Context, err);
- break;
-
- case AL_FORMAT_61CHN8:
- case AL_FORMAT_61CHN16:
- err = LoadData(ALBuf, data, size, freq, format, AL_FORMAT_61CHN16);
- if(err != AL_NO_ERROR)
- alSetError(Context, err);
- break;
- case AL_FORMAT_61CHN32:
- err = LoadData(ALBuf, data, size, freq, format, AL_FORMAT_61CHN32);
- if(err != AL_NO_ERROR)
- alSetError(Context, err);
- break;
-
- case AL_FORMAT_71CHN8:
- case AL_FORMAT_71CHN16:
- err = LoadData(ALBuf, data, size, freq, format, AL_FORMAT_71CHN16);
- if(err != AL_NO_ERROR)
- alSetError(Context, err);
- break;
- case AL_FORMAT_71CHN32:
- err = LoadData(ALBuf, data, size, freq, format, AL_FORMAT_71CHN32);
- if(err != AL_NO_ERROR)
- alSetError(Context, err);
- break;
-
case AL_FORMAT_MONO_IMA4:
case AL_FORMAT_STEREO_IMA4: {
ALuint Channels = ((format==AL_FORMAT_MONO_IMA4) ? 1 : 2);
@@ -1094,11 +1064,11 @@ static ALenum LoadData(ALbuffer *ALBuf, const ALvoid *data, ALsizei size, ALuint
ALvoid *temp;
assert(NewChannels == OrigChannels);
- assert(NewBytes == 4 || NewBytes == 2);
- if(NewBytes == 4)
- assert(OrigBytes == 4 || OrigBytes == 8);
- else if(NewBytes == 2)
- assert(OrigBytes == 2 || OrigBytes == 1);
+ assert(NewBytes == 4 || NewBytes == 2 || NewBytes == 1);
+ if(OrigBytes == 8)
+ assert(NewBytes == 4);
+ else
+ assert(NewBytes == OrigBytes);
if((size%(OrigBytes*OrigChannels)) != 0)
return AL_INVALID_VALUE;
@@ -1133,17 +1103,13 @@ static ALenum LoadData(ALbuffer *ALBuf, const ALvoid *data, ALsizei size, ALuint
static void ConvertData(ALvoid *dst, const ALvoid *src, ALint origBytes, ALsizei len)
{
ALsizei i;
- ALint smp;
if(src == NULL)
return;
switch(origBytes)
{
case 1:
for(i = 0;i < len;i++)
- {
- smp = ((ALubyte*)src)[i] - 128;
- ((ALshort*)dst)[i] = ((smp < 0) ? (smp*32768/128) : (smp*32767/127));
- }
+ ((ALubyte*)dst)[i] = ((ALubyte*)src)[i];
break;
case 2:
@@ -1169,7 +1135,6 @@ static void ConvertData(ALvoid *dst, const ALvoid *src, ALint origBytes, ALsizei
static void ConvertDataRear(ALvoid *dst, const ALvoid *src, ALint origBytes, ALsizei len)
{
ALsizei i;
- ALint smp;
if(src == NULL)
return;
switch(origBytes)
@@ -1177,12 +1142,10 @@ static void ConvertDataRear(ALvoid *dst, const ALvoid *src, ALint origBytes, ALs
case 1:
for(i = 0;i < len;i+=4)
{
- ((ALshort*)dst)[i+0] = 0;
- ((ALshort*)dst)[i+1] = 0;
- smp = ((ALubyte*)src)[i/2+0] - 128;
- ((ALshort*)dst)[i+2] = ((smp < 0) ? (smp*32768/128) : (smp*32767/127));
- smp = ((ALubyte*)src)[i/2+1] - 128;
- ((ALshort*)dst)[i+3] = ((smp < 0) ? (smp*32768/128) : (smp*32767/127));
+ ((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;