diff options
author | Chris Robinson <[email protected]> | 2008-11-01 16:35:16 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2008-11-01 16:35:16 -0700 |
commit | eda1e41152a8614533ec4c33982816185cdcc978 (patch) | |
tree | 8574e621dfe90743621cf833f36585ad1a8367cb /OpenAL32/alBuffer.c | |
parent | af5a5b76ece3a1e447b2b42b07e1b08c50b0c041 (diff) |
More buffer conversion refactoring
Diffstat (limited to 'OpenAL32/alBuffer.c')
-rw-r--r-- | OpenAL32/alBuffer.c | 90 |
1 files changed, 28 insertions, 62 deletions
diff --git a/OpenAL32/alBuffer.c b/OpenAL32/alBuffer.c index 8b6c4551..27ff69fc 100644 --- a/OpenAL32/alBuffer.c +++ b/OpenAL32/alBuffer.c @@ -309,74 +309,40 @@ ALAPI ALvoid ALAPIENTRY alBufferData(ALuint buffer,ALenum format,const ALvoid *d padding = freq / LOWPASSFREQCUTOFF; if(padding < 1) padding = 1; - switch(OrigBytes) - { - case 1: - size /= sizeof(ALubyte); - size *= 2; + size /= OrigBytes; + size *= 2; - // 8bit Samples are converted to 16 bit here - temp = realloc(ALBuf->data, (padding*NewChannels + size) * (1*sizeof(ALshort))); - if (temp) + // Samples are converted to 16 bit here + temp = realloc(ALBuf->data, (padding*NewChannels + size) * sizeof(ALshort)); + if(temp) + { + ALBuf->data = temp; + switch(OrigBytes) { - ALBuf->data = temp; - for (i = 0;i < size;i+=4) + case 1: + 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, padding*NewChannels*2); + break; - ALBuf->format = NewFormat; - ALBuf->eOriginalFormat = format; - ALBuf->size = size*1*sizeof(ALshort); - ALBuf->frequency = freq; - ALBuf->padding = padding; - } - else - alSetError(AL_OUT_OF_MEMORY); - break; - - case 2: - size /= sizeof(ALshort); - size *= 2; - - temp = realloc(ALBuf->data, (padding*NewChannels + size) * (1*sizeof(ALshort))); - if (temp) - { - ALBuf->data = temp; - for (i = 0;i < size;i+=4) + case 2: + 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, padding*NewChannels*2); + break; - ALBuf->format = NewFormat; - ALBuf->eOriginalFormat = format; - ALBuf->size = size*1*sizeof(ALshort); - ALBuf->frequency = freq; - ALBuf->padding = padding; - } - else - alSetError(AL_OUT_OF_MEMORY); - break; - - case 4: - size /= sizeof(ALfloat); - size *= 2; - - temp = realloc(ALBuf->data, (padding*NewChannels + size) * (1*sizeof(ALshort))); - if (temp) - { - ALint smp; - ALBuf->data = temp; - for (i = 0;i < size;i+=4) + case 4: + for(i = 0;i < size;i+=4) { + ALint smp; ALBuf->data[i+0] = 0; ALBuf->data[i+1] = 0; smp = (((ALfloat*)data)[i/2+0] * 32767.5f - 0.5); @@ -388,21 +354,21 @@ ALAPI ALvoid ALAPIENTRY alBufferData(ALuint buffer,ALenum format,const ALvoid *d smp = max(smp, -32768); ALBuf->data[i+3] = (ALshort)smp; } - memset(&(ALBuf->data[size]), 0, padding*NewChannels*2); + break; - ALBuf->format = NewFormat; - ALBuf->eOriginalFormat = format; - ALBuf->size = size*1*sizeof(ALshort); - ALBuf->frequency = freq; - ALBuf->padding = padding; + default: + assert(0); } - else - alSetError(AL_OUT_OF_MEMORY); - break; + memset(&(ALBuf->data[size]), 0, padding*NewChannels*sizeof(ALshort)); - default: - assert(0); + ALBuf->format = NewFormat; + ALBuf->eOriginalFormat = format; + ALBuf->size = size*sizeof(ALshort); + ALBuf->frequency = freq; + ALBuf->padding = padding; } + else + alSetError(AL_OUT_OF_MEMORY); } break; case AL_FORMAT_QUAD8_LOKI: |