diff options
author | Joerg Mueller <nexyon@gmail.com> | 2011-05-29 15:25:05 +0400 |
---|---|---|
committer | Joerg Mueller <nexyon@gmail.com> | 2011-05-29 15:25:05 +0400 |
commit | 57d190ee104bedc0e0b715a09c5c4f8d8ee2cbbe (patch) | |
tree | fb99a32a5c3b0a22a8b828b7fd01978d208585c7 /intern | |
parent | 9cfd093a934097a3054f89b70168fa6ed5be695e (diff) |
3D Audio GSoC:
Changing converter functions to work when input and output buffer are the same.
Diffstat (limited to 'intern')
-rw-r--r-- | intern/audaspace/intern/AUD_ConverterFunctions.cpp | 68 |
1 files changed, 38 insertions, 30 deletions
diff --git a/intern/audaspace/intern/AUD_ConverterFunctions.cpp b/intern/audaspace/intern/AUD_ConverterFunctions.cpp index d3cc9fa8202..8f2ac21acd6 100644 --- a/intern/audaspace/intern/AUD_ConverterFunctions.cpp +++ b/intern/audaspace/intern/AUD_ConverterFunctions.cpp @@ -45,13 +45,13 @@ void AUD_convert_u8_s16(data_t* target, data_t* source, int length) { int16_t* t = (int16_t*) target; - for(int i = 0; i < length; i++) + for(int i = length - 1; i >= 0; i++) t[i] = (((int16_t)source[i]) - AUD_U8_0) << 8; } void AUD_convert_u8_s24_be(data_t* target, data_t* source, int length) { - for(int i = 0; i < length; i++) + for(int i = length - 1; i >= 0; i++) { target[i*3] = source[i] - AUD_U8_0; target[i*3+1] = 0; @@ -61,7 +61,7 @@ void AUD_convert_u8_s24_be(data_t* target, data_t* source, int length) void AUD_convert_u8_s24_le(data_t* target, data_t* source, int length) { - for(int i = 0; i < length; i++) + for(int i = length - 1; i >= 0; i++) { target[i*3+2] = source[i] - AUD_U8_0; target[i*3+1] = 0; @@ -72,21 +72,21 @@ void AUD_convert_u8_s24_le(data_t* target, data_t* source, int length) void AUD_convert_u8_s32(data_t* target, data_t* source, int length) { int32_t* t = (int32_t*) target; - for(int i = 0; i < length; i++) + for(int i = length - 1; i >= 0; i++) t[i] = (((int32_t)source[i]) - AUD_U8_0) << 24; } void AUD_convert_u8_float(data_t* target, data_t* source, int length) { float* t = (float*) target; - for(int i = 0; i < length; i++) + for(int i = length - 1; i >= 0; i++) t[i] = (((int32_t)source[i]) - AUD_U8_0) / ((float)AUD_U8_0); } void AUD_convert_u8_double(data_t* target, data_t* source, int length) { double* t = (double*) target; - for(int i = 0; i < length; i++) + for(int i = length - 1; i >= 0; i++) t[i] = (((int32_t)source[i]) - AUD_U8_0) / ((double)AUD_U8_0); } @@ -100,10 +100,12 @@ void AUD_convert_s16_u8(data_t* target, data_t* source, int length) void AUD_convert_s16_s24_be(data_t* target, data_t* source, int length) { int16_t* s = (int16_t*) source; - for(int i = 0; i < length; i++) + int16_t t; + for(int i = length - 1; i >= 0; i++) { - target[i*3] = s[i] >> 8 & 0xFF; - target[i*3+1] = s[i] & 0xFF; + t = s[i]; + target[i*3] = t >> 8 & 0xFF; + target[i*3+1] = t & 0xFF; target[i*3+2] = 0; } } @@ -111,10 +113,12 @@ void AUD_convert_s16_s24_be(data_t* target, data_t* source, int length) void AUD_convert_s16_s24_le(data_t* target, data_t* source, int length) { int16_t* s = (int16_t*) source; - for(int i = 0; i < length; i++) + int16_t t; + for(int i = length - 1; i >= 0; i++) { - target[i*3+2] = s[i] >> 8 & 0xFF; - target[i*3+1] = s[i] & 0xFF; + t = s[i]; + target[i*3+2] = t >> 8 & 0xFF; + target[i*3+1] = t & 0xFF; target[i*3] = 0; } } @@ -123,7 +127,7 @@ void AUD_convert_s16_s32(data_t* target, data_t* source, int length) { int16_t* s = (int16_t*) source; int32_t* t = (int32_t*) target; - for(int i = 0; i < length; i++) + for(int i = length - 1; i >= 0; i++) t[i] = ((int32_t)s[i]) << 16; } @@ -131,7 +135,7 @@ void AUD_convert_s16_float(data_t* target, data_t* source, int length) { int16_t* s = (int16_t*) source; float* t = (float*) target; - for(int i = 0; i < length; i++) + for(int i = length - 1; i >= 0; i++) t[i] = s[i] / AUD_S16_FLT; } @@ -139,7 +143,7 @@ void AUD_convert_s16_double(data_t* target, data_t* source, int length) { int16_t* s = (int16_t*) source; double* t = (double*) target; - for(int i = 0; i < length; i++) + for(int i = length - 1; i >= 0; i++) t[i] = s[i] / AUD_S16_FLT; } @@ -177,14 +181,14 @@ void AUD_convert_s24_s24(data_t* target, data_t* source, int length) void AUD_convert_s24_s32_be(data_t* target, data_t* source, int length) { int32_t* t = (int32_t*) target; - for(int i = 0; i < length; i++) + for(int i = length - 1; i >= 0; i++) t[i] = source[i*3] << 24 | source[i*3+1] << 16 | source[i*3+2] << 8; } void AUD_convert_s24_s32_le(data_t* target, data_t* source, int length) { int32_t* t = (int32_t*) target; - for(int i = 0; i < length; i++) + for(int i = length - 1; i >= 0; i++) t[i] = source[i*3+2] << 24 | source[i*3+1] << 16 | source[i*3] << 8; } @@ -192,7 +196,7 @@ void AUD_convert_s24_float_be(data_t* target, data_t* source, int length) { float* t = (float*) target; int32_t s; - for(int i = 0; i < length; i++) + for(int i = length - 1; i >= 0; i++) { s = source[i*3] << 24 | source[i*3+1] << 16 | source[i*3+2] << 8; t[i] = s / AUD_S32_FLT; @@ -203,7 +207,7 @@ void AUD_convert_s24_float_le(data_t* target, data_t* source, int length) { float* t = (float*) target; int32_t s; - for(int i = 0; i < length; i++) + for(int i = length - 1; i >= 0; i++) { s = source[i*3+2] << 24 | source[i*3+1] << 16 | source[i*3] << 8; t[i] = s / AUD_S32_FLT; @@ -214,7 +218,7 @@ void AUD_convert_s24_double_be(data_t* target, data_t* source, int length) { double* t = (double*) target; int32_t s; - for(int i = 0; i < length; i++) + for(int i = length - 1; i >= 0; i++) { s = source[i*3] << 24 | source[i*3+1] << 16 | source[i*3+2] << 8; t[i] = s / AUD_S32_FLT; @@ -225,7 +229,7 @@ void AUD_convert_s24_double_le(data_t* target, data_t* source, int length) { double* t = (double*) target; int32_t s; - for(int i = 0; i < length; i++) + for(int i = length - 1; i >= 0; i++) { s = source[i*3+2] << 24 | source[i*3+1] << 16 | source[i*3] << 8; t[i] = s / AUD_S32_FLT; @@ -250,22 +254,26 @@ void AUD_convert_s32_s16(data_t* target, data_t* source, int length) void AUD_convert_s32_s24_be(data_t* target, data_t* source, int length) { int32_t* s = (int32_t*) source; + int32_t t; for(int i = 0; i < length; i++) { - target[i*3] = s[i] >> 24 & 0xFF; - target[i*3+1] = s[i] >> 16 & 0xFF; - target[i*3+2] = s[i] >> 8 & 0xFF; + t = s[i]; + target[i*3] = t >> 24 & 0xFF; + target[i*3+1] = t >> 16 & 0xFF; + target[i*3+2] = t >> 8 & 0xFF; } } void AUD_convert_s32_s24_le(data_t* target, data_t* source, int length) { - int16_t* s = (int16_t*) source; + int32_t* s = (int32_t*) source; + int32_t t; for(int i = 0; i < length; i++) { - target[i*3+2] = s[i] >> 24 & 0xFF; - target[i*3+1] = s[i] >> 16 & 0xFF; - target[i*3] = s[i] >> 8 & 0xFF; + t = s[i]; + target[i*3+2] = t >> 24 & 0xFF; + target[i*3+1] = t >> 16 & 0xFF; + target[i*3] = t >> 8 & 0xFF; } } @@ -281,7 +289,7 @@ void AUD_convert_s32_double(data_t* target, data_t* source, int length) { int32_t* s = (int32_t*) source; double* t = (double*) target; - for(int i = 0; i < length; i++) + for(int i = length - 1; i >= 0; i++) t[i] = s[i] / AUD_S32_FLT; } @@ -371,7 +379,7 @@ void AUD_convert_float_double(data_t* target, data_t* source, int length) { float* s = (float*) source; double* t = (double*) target; - for(int i = 0; i < length; i++) + for(int i = length - 1; i >= 0; i++) t[i] = s[i]; } |