diff options
author | Chris Robinson <[email protected]> | 2008-10-31 22:13:35 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2008-10-31 22:13:35 -0700 |
commit | 87f3a0dc1608e8d494b6c24f447420eb70aa1eec (patch) | |
tree | e73a17c917bba9477b888d8a6ee625df01b0d2bb /OpenAL32/alBuffer.c | |
parent | 2c80a80704d70951cabeebb857eae5b16e03af62 (diff) |
Restructure buffer data conversion code a bit
Diffstat (limited to 'OpenAL32/alBuffer.c')
-rw-r--r-- | OpenAL32/alBuffer.c | 87 |
1 files changed, 27 insertions, 60 deletions
diff --git a/OpenAL32/alBuffer.c b/OpenAL32/alBuffer.c index 1facdd31..0b02b5de 100644 --- a/OpenAL32/alBuffer.c +++ b/OpenAL32/alBuffer.c @@ -1028,82 +1028,49 @@ static void LoadData(ALbuffer *ALBuf, const ALubyte *data, ALsizei size, ALuint if(padding < 1) padding = 1; - switch(OrigBytes) + // Samples are converted to 16 bit here + size /= OrigBytes; + temp = realloc(ALBuf->data, (padding*NewChannels + size) * sizeof(ALshort)); + if(temp) { - case 1: - size /= sizeof(ALubyte); + ALBuf->data = temp; - // 8bit Samples are converted to 16 bit here - temp = realloc(ALBuf->data, (padding*NewChannels + size) * (1*sizeof(ALshort))); - if (temp) + switch(OrigBytes) { - ALBuf->data = temp; - for (i = 0;i < size;i++) + case 1: + for(i = 0;i < size;i++) ALBuf->data[i] = (ALshort)((data[i]-128) << 8); - memset(&(ALBuf->data[size]), 0, padding*NewChannels*2); - - ALBuf->format = NewFormat; - ALBuf->eOriginalFormat = OrigFormat; - ALBuf->size = size*1*sizeof(ALshort); - ALBuf->frequency = freq; - ALBuf->padding = padding; - } - else - alSetError(AL_OUT_OF_MEMORY); - break; - - case 2: - size /= sizeof(ALshort); - - // Allocate 8 extra samples - temp = realloc(ALBuf->data, (padding*NewChannels + size) * (1*sizeof(ALshort))); - if (temp) - { - ALBuf->data = temp; - memcpy(ALBuf->data, data, size*1*sizeof(ALshort)); - memset(&(ALBuf->data[size]), 0, padding*NewChannels*2); - - ALBuf->format = NewFormat; - ALBuf->eOriginalFormat = OrigFormat; - ALBuf->size = size*1*sizeof(ALshort); - ALBuf->frequency = freq; - ALBuf->padding = padding; - } - else - alSetError(AL_OUT_OF_MEMORY); - break; + break; - case 4: - size /= sizeof(ALfloat); + case 2: + memcpy(ALBuf->data, data, size*sizeof(ALshort)); + break; - // Allocate 8 extra samples - temp = realloc(ALBuf->data, (padding*NewChannels + size) * (1*sizeof(ALshort))); - if (temp) - { - ALint smp; - ALBuf->data = temp; - for (i = 0;i < size;i++) + case 4: + for(i = 0;i < size;i++) { + ALint smp; smp = (((ALfloat*)data)[i] * 32767.5f - 0.5f); smp = min(smp, 32767); smp = max(smp, -32768); ALBuf->data[i] = (ALshort)smp; } - memset(&(ALBuf->data[size]), 0, padding*NewChannels*2); + break; - ALBuf->format = NewFormat; - ALBuf->eOriginalFormat = OrigFormat; - ALBuf->size = size*1*sizeof(ALshort); - ALBuf->frequency = freq; - ALBuf->padding = padding; + default: + assert(0); } - else - alSetError(AL_OUT_OF_MEMORY); - break; - default: - assert(0); + memset(&(ALBuf->data[size]), 0, padding*NewChannels*sizeof(ALshort)); + + ALBuf->format = NewFormat; + ALBuf->eOriginalFormat = OrigFormat; + ALBuf->size = size*sizeof(ALshort); + ALBuf->frequency = freq; + ALBuf->padding = padding; } + else + alSetError(AL_OUT_OF_MEMORY); } |