diff options
author | Siarhei Siamashka <siarhei.siamashka@nokia.com> | 2009-01-15 19:11:23 +0200 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2009-01-16 00:28:32 +0100 |
commit | 9e31e7dde636ca28ee551e8bcf8e4f4ca0ef553d (patch) | |
tree | efc05cd31c23eb871dcff2ed3776473e38a3d003 /sbc/sbc.c | |
parent | 5331a26b8a3c2d69d30a4334e023238db197080b (diff) |
SIMD-friendly variant of SBC encoder analysis filter
Added SIMD-friendly C implementation of SBC analysis filter (the
structure of code had to be changed a bit and constants in the
tables reordered). This code can be used as a reference for
developing platform specific SIMD optimizations. These functions
are put into a new file 'sbc_primitives.c', which is going to
contain all the basic stuff for SBC codec.
Diffstat (limited to 'sbc/sbc.c')
-rw-r--r-- | sbc/sbc.c | 155 |
1 files changed, 2 insertions, 153 deletions
@@ -46,6 +46,7 @@ #include "sbc_tables.h" #include "sbc.h" +#include "sbc_primitives.h" #define SBC_SYNCWORD 0x9C @@ -91,16 +92,6 @@ struct sbc_decoder_state { int offset[2][16]; }; -struct sbc_encoder_state { - int subbands; - int position[2]; - int16_t X[2][256]; - void (*sbc_analyze_4b_4s)(int16_t *pcm, int16_t *x, - int32_t *out, int out_stride); - void (*sbc_analyze_4b_8s)(int16_t *pcm, int16_t *x, - int32_t *out, int out_stride); -}; - /* * Calculates the CRC-8 of the first len bits in data */ @@ -653,146 +644,6 @@ static int sbc_synthesize_audio(struct sbc_decoder_state *state, } } -static inline void _sbc_analyze_four(const int16_t *in, int32_t *out) -{ - FIXED_A t1[4]; - FIXED_T t2[4]; - int i = 0, hop = 0; - - /* rounding coefficient */ - t1[0] = t1[1] = t1[2] = t1[3] = - (FIXED_A) 1 << (SBC_PROTO_FIXED4_SCALE - 1); - - /* low pass polyphase filter */ - for (hop = 0; hop < 40; hop += 8) { - t1[0] += (FIXED_A) in[hop] * _sbc_proto_fixed4[hop]; - t1[1] += (FIXED_A) in[hop + 1] * _sbc_proto_fixed4[hop + 1]; - t1[2] += (FIXED_A) in[hop + 2] * _sbc_proto_fixed4[hop + 2]; - t1[1] += (FIXED_A) in[hop + 3] * _sbc_proto_fixed4[hop + 3]; - t1[0] += (FIXED_A) in[hop + 4] * _sbc_proto_fixed4[hop + 4]; - t1[3] += (FIXED_A) in[hop + 5] * _sbc_proto_fixed4[hop + 5]; - t1[3] += (FIXED_A) in[hop + 7] * _sbc_proto_fixed4[hop + 7]; - } - - /* scaling */ - t2[0] = t1[0] >> SBC_PROTO_FIXED4_SCALE; - t2[1] = t1[1] >> SBC_PROTO_FIXED4_SCALE; - t2[2] = t1[2] >> SBC_PROTO_FIXED4_SCALE; - t2[3] = t1[3] >> SBC_PROTO_FIXED4_SCALE; - - /* do the cos transform */ - for (i = 0, hop = 0; i < 4; hop += 8, i++) { - out[i] = ((FIXED_A) t2[0] * cos_table_fixed_4[0 + hop] + - (FIXED_A) t2[1] * cos_table_fixed_4[1 + hop] + - (FIXED_A) t2[2] * cos_table_fixed_4[2 + hop] + - (FIXED_A) t2[3] * cos_table_fixed_4[5 + hop]) >> - (SBC_COS_TABLE_FIXED4_SCALE - SCALE_OUT_BITS); - } -} - -static void sbc_analyze_4b_4s(int16_t *pcm, int16_t *x, - int32_t *out, int out_stride) -{ - int i; - - /* Input 4 x 4 Audio Samples */ - for (i = 0; i < 16; i += 4) { - x[64 + i] = x[0 + i] = pcm[15 - i]; - x[65 + i] = x[1 + i] = pcm[14 - i]; - x[66 + i] = x[2 + i] = pcm[13 - i]; - x[67 + i] = x[3 + i] = pcm[12 - i]; - } - - /* Analyze four blocks */ - _sbc_analyze_four(x + 12, out); - out += out_stride; - _sbc_analyze_four(x + 8, out); - out += out_stride; - _sbc_analyze_four(x + 4, out); - out += out_stride; - _sbc_analyze_four(x, out); -} - -static inline void _sbc_analyze_eight(const int16_t *in, int32_t *out) -{ - FIXED_A t1[8]; - FIXED_T t2[8]; - int i, hop; - - /* rounding coefficient */ - t1[0] = t1[1] = t1[2] = t1[3] = t1[4] = t1[5] = t1[6] = t1[7] = - (FIXED_A) 1 << (SBC_PROTO_FIXED8_SCALE-1); - - /* low pass polyphase filter */ - for (hop = 0; hop < 80; hop += 16) { - t1[0] += (FIXED_A) in[hop] * _sbc_proto_fixed8[hop]; - t1[1] += (FIXED_A) in[hop + 1] * _sbc_proto_fixed8[hop + 1]; - t1[2] += (FIXED_A) in[hop + 2] * _sbc_proto_fixed8[hop + 2]; - t1[3] += (FIXED_A) in[hop + 3] * _sbc_proto_fixed8[hop + 3]; - t1[4] += (FIXED_A) in[hop + 4] * _sbc_proto_fixed8[hop + 4]; - t1[3] += (FIXED_A) in[hop + 5] * _sbc_proto_fixed8[hop + 5]; - t1[2] += (FIXED_A) in[hop + 6] * _sbc_proto_fixed8[hop + 6]; - t1[1] += (FIXED_A) in[hop + 7] * _sbc_proto_fixed8[hop + 7]; - t1[0] += (FIXED_A) in[hop + 8] * _sbc_proto_fixed8[hop + 8]; - t1[5] += (FIXED_A) in[hop + 9] * _sbc_proto_fixed8[hop + 9]; - t1[6] += (FIXED_A) in[hop + 10] * _sbc_proto_fixed8[hop + 10]; - t1[7] += (FIXED_A) in[hop + 11] * _sbc_proto_fixed8[hop + 11]; - t1[7] += (FIXED_A) in[hop + 13] * _sbc_proto_fixed8[hop + 13]; - t1[6] += (FIXED_A) in[hop + 14] * _sbc_proto_fixed8[hop + 14]; - t1[5] += (FIXED_A) in[hop + 15] * _sbc_proto_fixed8[hop + 15]; - } - - /* scaling */ - t2[0] = t1[0] >> SBC_PROTO_FIXED8_SCALE; - t2[1] = t1[1] >> SBC_PROTO_FIXED8_SCALE; - t2[2] = t1[2] >> SBC_PROTO_FIXED8_SCALE; - t2[3] = t1[3] >> SBC_PROTO_FIXED8_SCALE; - t2[4] = t1[4] >> SBC_PROTO_FIXED8_SCALE; - t2[5] = t1[5] >> SBC_PROTO_FIXED8_SCALE; - t2[6] = t1[6] >> SBC_PROTO_FIXED8_SCALE; - t2[7] = t1[7] >> SBC_PROTO_FIXED8_SCALE; - - /* do the cos transform */ - for (i = 0, hop = 0; i < 8; hop += 16, i++) { - out[i] = ((FIXED_A) t2[0] * cos_table_fixed_8[0 + hop] + - (FIXED_A) t2[1] * cos_table_fixed_8[1 + hop] + - (FIXED_A) t2[2] * cos_table_fixed_8[2 + hop] + - (FIXED_A) t2[3] * cos_table_fixed_8[3 + hop] + - (FIXED_A) t2[4] * cos_table_fixed_8[4 + hop] + - (FIXED_A) t2[5] * cos_table_fixed_8[9 + hop] + - (FIXED_A) t2[6] * cos_table_fixed_8[10 + hop] + - (FIXED_A) t2[7] * cos_table_fixed_8[11 + hop]) >> - (SBC_COS_TABLE_FIXED8_SCALE - SCALE_OUT_BITS); - } -} - -static void sbc_analyze_4b_8s(int16_t *pcm, int16_t *x, - int32_t *out, int out_stride) -{ - int i; - - /* Input 4 x 8 Audio Samples */ - for (i = 0; i < 32; i += 8) { - x[128 + i] = x[0 + i] = pcm[31 - i]; - x[129 + i] = x[1 + i] = pcm[30 - i]; - x[130 + i] = x[2 + i] = pcm[29 - i]; - x[131 + i] = x[3 + i] = pcm[28 - i]; - x[132 + i] = x[4 + i] = pcm[27 - i]; - x[133 + i] = x[5 + i] = pcm[26 - i]; - x[134 + i] = x[6 + i] = pcm[25 - i]; - x[135 + i] = x[7 + i] = pcm[24 - i]; - } - - /* Analyze four blocks */ - _sbc_analyze_eight(x + 24, out); - out += out_stride; - _sbc_analyze_eight(x + 16, out); - out += out_stride; - _sbc_analyze_eight(x + 8, out); - out += out_stride; - _sbc_analyze_eight(x, out); -} - static int sbc_analyze_audio(struct sbc_encoder_state *state, struct sbc_frame *frame) { @@ -1056,9 +907,7 @@ static void sbc_encoder_init(struct sbc_encoder_state *state, state->subbands = frame->subbands; state->position[0] = state->position[1] = 12 * frame->subbands; - /* Default implementation for analyze function */ - state->sbc_analyze_4b_4s = sbc_analyze_4b_4s; - state->sbc_analyze_4b_8s = sbc_analyze_4b_8s; + sbc_init_primitives(state); } struct sbc_priv { |