[pulseaudio-discuss] [PATCH 14/23] core: mix: Use table for calc_stream_columes() in mix.c

Peter Meerwald pmeerw at pmeerw.net
Wed Feb 13 08:27:01 PST 2013


Signed-off-by: Peter Meerwald <pmeerw at pmeerw.net>
---
 src/pulsecore/mix.c |   46 ++++++++++++++++++++--------------------------
 1 file changed, 20 insertions(+), 26 deletions(-)

diff --git a/src/pulsecore/mix.c b/src/pulsecore/mix.c
index 93978eb..af854cc 100644
--- a/src/pulsecore/mix.c
+++ b/src/pulsecore/mix.c
@@ -104,6 +104,24 @@ static void calc_linear_float_stream_volumes(pa_mix_info streams[], unsigned nst
     }
 }
 
+typedef void (*pa_calc_stream_volumes_func_t) (pa_mix_info streams[], unsigned nstreams, const pa_cvolume *volume, const pa_sample_spec *spec);
+
+static const pa_calc_stream_volumes_func_t calc_stream_volumes_table[] = {
+  [PA_SAMPLE_U8]        = (pa_calc_stream_volumes_func_t) calc_linear_integer_stream_volumes,
+  [PA_SAMPLE_ALAW]      = (pa_calc_stream_volumes_func_t) calc_linear_integer_stream_volumes,
+  [PA_SAMPLE_ULAW]      = (pa_calc_stream_volumes_func_t) calc_linear_integer_stream_volumes,
+  [PA_SAMPLE_S16LE]     = (pa_calc_stream_volumes_func_t) calc_linear_integer_stream_volumes,
+  [PA_SAMPLE_S16BE]     = (pa_calc_stream_volumes_func_t) calc_linear_integer_stream_volumes,
+  [PA_SAMPLE_FLOAT32LE] = (pa_calc_stream_volumes_func_t) calc_linear_float_stream_volumes,
+  [PA_SAMPLE_FLOAT32BE] = (pa_calc_stream_volumes_func_t) calc_linear_float_stream_volumes,
+  [PA_SAMPLE_S32LE]     = (pa_calc_stream_volumes_func_t) calc_linear_integer_stream_volumes,
+  [PA_SAMPLE_S32BE]     = (pa_calc_stream_volumes_func_t) calc_linear_integer_stream_volumes,
+  [PA_SAMPLE_S24LE]     = (pa_calc_stream_volumes_func_t) calc_linear_integer_stream_volumes,
+  [PA_SAMPLE_S24BE]     = (pa_calc_stream_volumes_func_t) calc_linear_integer_stream_volumes,
+  [PA_SAMPLE_S24_32LE]  = (pa_calc_stream_volumes_func_t) calc_linear_integer_stream_volumes,
+  [PA_SAMPLE_S24_32BE]  = (pa_calc_stream_volumes_func_t) calc_linear_integer_stream_volumes
+};
+
 size_t pa_mix(
         pa_mix_info streams[],
         unsigned nstreams,
@@ -140,13 +158,13 @@ size_t pa_mix(
 
     end = (uint8_t*) data + length;
 
+    calc_stream_volumes_table[spec->format](streams, nstreams, volume, spec);
+
     switch (spec->format) {
 
         case PA_SAMPLE_S16NE:{
             unsigned channel = 0;
 
-            calc_linear_integer_stream_volumes(streams, nstreams, volume, spec);
-
             while (data < end) {
                 int32_t sum = 0;
                 unsigned i;
@@ -188,8 +206,6 @@ size_t pa_mix(
         case PA_SAMPLE_S16RE:{
             unsigned channel = 0;
 
-            calc_linear_integer_stream_volumes(streams, nstreams, volume, spec);
-
             while (data < end) {
                 int32_t sum = 0;
                 unsigned i;
@@ -225,8 +241,6 @@ size_t pa_mix(
         case PA_SAMPLE_S32NE:{
             unsigned channel = 0;
 
-            calc_linear_integer_stream_volumes(streams, nstreams, volume, spec);
-
             while (data < end) {
                 int64_t sum = 0;
                 unsigned i;
@@ -260,8 +274,6 @@ size_t pa_mix(
         case PA_SAMPLE_S32RE:{
             unsigned channel = 0;
 
-            calc_linear_integer_stream_volumes(streams, nstreams, volume, spec);
-
             while (data < end) {
                 int64_t sum = 0;
                 unsigned i;
@@ -295,8 +307,6 @@ size_t pa_mix(
         case PA_SAMPLE_S24NE: {
             unsigned channel = 0;
 
-            calc_linear_integer_stream_volumes(streams, nstreams, volume, spec);
-
             while (data < end) {
                 int64_t sum = 0;
                 unsigned i;
@@ -330,8 +340,6 @@ size_t pa_mix(
         case PA_SAMPLE_S24RE: {
             unsigned channel = 0;
 
-            calc_linear_integer_stream_volumes(streams, nstreams, volume, spec);
-
             while (data < end) {
                 int64_t sum = 0;
                 unsigned i;
@@ -365,8 +373,6 @@ size_t pa_mix(
         case PA_SAMPLE_S24_32NE: {
             unsigned channel = 0;
 
-            calc_linear_integer_stream_volumes(streams, nstreams, volume, spec);
-
             while (data < end) {
                 int64_t sum = 0;
                 unsigned i;
@@ -400,8 +406,6 @@ size_t pa_mix(
         case PA_SAMPLE_S24_32RE: {
             unsigned channel = 0;
 
-            calc_linear_integer_stream_volumes(streams, nstreams, volume, spec);
-
             while (data < end) {
                 int64_t sum = 0;
                 unsigned i;
@@ -435,8 +439,6 @@ size_t pa_mix(
         case PA_SAMPLE_U8: {
             unsigned channel = 0;
 
-            calc_linear_integer_stream_volumes(streams, nstreams, volume, spec);
-
             while (data < end) {
                 int32_t sum = 0;
                 unsigned i;
@@ -469,8 +471,6 @@ size_t pa_mix(
         case PA_SAMPLE_ULAW: {
             unsigned channel = 0;
 
-            calc_linear_integer_stream_volumes(streams, nstreams, volume, spec);
-
             while (data < end) {
                 int32_t sum = 0;
                 unsigned i;
@@ -506,8 +506,6 @@ size_t pa_mix(
         case PA_SAMPLE_ALAW: {
             unsigned channel = 0;
 
-            calc_linear_integer_stream_volumes(streams, nstreams, volume, spec);
-
             while (data < end) {
                 int32_t sum = 0;
                 unsigned i;
@@ -543,8 +541,6 @@ size_t pa_mix(
         case PA_SAMPLE_FLOAT32NE: {
             unsigned channel = 0;
 
-            calc_linear_float_stream_volumes(streams, nstreams, volume, spec);
-
             while (data < end) {
                 float sum = 0;
                 unsigned i;
@@ -576,8 +572,6 @@ size_t pa_mix(
         case PA_SAMPLE_FLOAT32RE: {
             unsigned channel = 0;
 
-            calc_linear_float_stream_volumes(streams, nstreams, volume, spec);
-
             while (data < end) {
                 float sum = 0;
                 unsigned i;
-- 
1.7.9.5



More information about the pulseaudio-discuss mailing list