diff options
author | Chris Robinson <[email protected]> | 2007-12-31 05:46:20 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2007-12-31 05:46:20 -0800 |
commit | 1397417fcd399663a91534c45b7863b2492af530 (patch) | |
tree | fa950e4d4f6070e1dc0bbea1044f90501cf0e863 | |
parent | c9a539eade6b5930bd2995b6226f5982d189190b (diff) |
Handle AL_FORMAT_REAR* formats
-rw-r--r-- | OpenAL32/alBuffer.c | 104 | ||||
-rw-r--r-- | OpenAL32/alSource.c | 18 |
2 files changed, 122 insertions, 0 deletions
diff --git a/OpenAL32/alBuffer.c b/OpenAL32/alBuffer.c index c881e1e4..2bcb6562 100644 --- a/OpenAL32/alBuffer.c +++ b/OpenAL32/alBuffer.c @@ -287,6 +287,110 @@ ALAPI ALvoid ALAPIENTRY alBufferData(ALuint buffer,ALenum format,const ALvoid *d LoadData(ALBuf, data, size, freq, format, AL_FORMAT_STEREO16); break; + case AL_FORMAT_REAR8: + case AL_FORMAT_REAR16: + case AL_FORMAT_REAR32: { + ALuint NewFormat = AL_FORMAT_QUAD16; + ALuint NewChannels = aluChannelsFromFormat(NewFormat); + ALuint OrigBytes = ((format==AL_FORMAT_REAR8) ? 1 : + ((format==AL_FORMAT_REAR16) ? 2 : + 4)); + ALsizei i; + + assert(aluBytesFromFormat(NewFormat) == 2); + + if ((size%(OrigBytes*2)) != 0) + { + alSetError(AL_INVALID_VALUE); + break; + } + + switch(OrigBytes) + { + case 1: + size /= sizeof(ALubyte); + size *= 2; + + // 8bit Samples are converted to 16 bit here + // Allocate 8 extra samples + ALBuf->data = realloc(ALBuf->data, (8*NewChannels + size) * (1*sizeof(ALshort))); + if (ALBuf->data) + { + for (i = 0;i < size;i+=4) + { + ALBuf->data[i+0] = 0; + ALBuf->data[i+1] = 0; + ALBuf->data[i+2] = (ALshort)((((ALubyte*)data)[i/2+0]-128) << 8); + ALBuf->data[i+3] = (ALshort)((((ALubyte*)data)[i/2+1]-128) << 8); + } + memset(&(ALBuf->data[size]), 0, 16*NewChannels); + + ALBuf->format = NewFormat; + ALBuf->eOriginalFormat = format; + ALBuf->size = size*1*sizeof(ALshort); + ALBuf->frequency = freq; + } + else + alSetError(AL_OUT_OF_MEMORY); + break; + + case 2: + size /= sizeof(ALshort); + size *= 2; + + // Allocate 8 extra samples + ALBuf->data = realloc(ALBuf->data, (8*NewChannels + size) * (1*sizeof(ALshort))); + if (ALBuf->data) + { + for (i = 0;i < size;i+=4) + { + ALBuf->data[i+0] = 0; + ALBuf->data[i+1] = 0; + ALBuf->data[i+2] = ((ALshort*)data)[i/2+0]; + ALBuf->data[i+3] = ((ALshort*)data)[i/2+1]; + } + memset(&(ALBuf->data[size]), 0, 16*NewChannels); + + ALBuf->format = NewFormat; + ALBuf->eOriginalFormat = format; + ALBuf->size = size*1*sizeof(ALshort); + ALBuf->frequency = freq; + } + else + alSetError(AL_OUT_OF_MEMORY); + break; + + case 4: + size /= sizeof(ALfloat); + size *= 2; + + // Allocate 8 extra samples + ALBuf->data = realloc(ALBuf->data, (8*NewChannels + size) * (1*sizeof(ALshort))); + if (ALBuf->data) + { + for (i = 0;i < size;i+=4) + { + ALBuf->data[i+0] = 0; + ALBuf->data[i+1] = 0; + ALBuf->data[i+2] = (ALshort)(((ALfloat*)data)[i/2+0] * 32767.5f - 0.5); + ALBuf->data[i+3] = (ALshort)(((ALfloat*)data)[i/2+1] * 32767.5f - 0.5); + } + memset(&(ALBuf->data[size]), 0, 16*NewChannels); + + ALBuf->format = NewFormat; + ALBuf->eOriginalFormat = format; + ALBuf->size = size*1*sizeof(ALshort); + ALBuf->frequency = freq; + } + else + alSetError(AL_OUT_OF_MEMORY); + break; + + default: + assert(0); + } + } break; + case AL_FORMAT_QUAD8: case AL_FORMAT_QUAD16: case AL_FORMAT_QUAD32: diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c index 9b4909c5..7fad9b90 100644 --- a/OpenAL32/alSource.c +++ b/OpenAL32/alSource.c @@ -1916,6 +1916,14 @@ static ALboolean GetSourceOffset(ALsource *pSource, ALenum eName, ALfloat *pflOf // Round down to nearest ADPCM block *pflOffset = (ALfloat)((lBytesPlayed / (36 * lChannels)) * 36 * lChannels); } + else if (eOriginalFormat == AL_FORMAT_REAR8) + { + *pflOffset = (ALfloat)(lBytesPlayed >> 2); + } + else if (eOriginalFormat == AL_FORMAT_REAR16) + { + *pflOffset = (ALfloat)(lBytesPlayed >> 1); + } else if (aluBytesFromFormat(eOriginalFormat) == 1) { *pflOffset = (ALfloat)(lBytesPlayed >> 1); @@ -2071,6 +2079,16 @@ static ALint GetByteOffset(ALsource *pSource) lByteOffset = (ALint)(3.6111f * (ALfloat)lByteOffset); lByteOffset -= (lByteOffset % (lChannels * 2)); } + else if (pBuffer->eOriginalFormat == AL_FORMAT_REAR8) + { + lByteOffset = pSource->lOffset * 4; + lByteOffset -= (lByteOffset % (lChannels * 2)); + } + else if (pBuffer->eOriginalFormat == AL_FORMAT_REAR16) + { + lByteOffset = pSource->lOffset * 2; + lByteOffset -= (lByteOffset % (lChannels * 2)); + } else if (aluBytesFromFormat(pBuffer->eOriginalFormat) == 1) { lByteOffset = pSource->lOffset * 2; |