default: esd is obsolete, hence don't load it anymore by default
[pulseaudio-mirror.git] / src / pulsecore / svolume_orc.c
blob8e1e46cf1dba72edc4edb652e559a2a98cd65ed8
1 /***
2 This file is part of PulseAudio.
4 Copyright 2004-2006 Lennart Poettering
5 Copyright 2009 Wim Taymans <wim.taymans@collabora.co.uk>
6 Copyright 2010 Arun Raghavan <arun.raghavan@collabora.co.uk>
8 PulseAudio is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published
10 by the Free Software Foundation; either version 2.1 of the License,
11 or (at your option) any later version.
13 PulseAudio is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with PulseAudio; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 USA.
22 ***/
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
28 #include "cpu-orc.h"
29 #include <pulse/rtclock.h>
30 #include <pulsecore/sample-util.h>
31 #include <pulsecore/random.h>
32 #include <pulsecore/svolume-orc-gen.h>
34 pa_do_volume_func_t fallback;
36 static void
37 pa_volume_s16ne_orc(int16_t *samples, int32_t *volumes, unsigned channels, unsigned length)
39 if (channels == 2) {
40 int64_t v = (int64_t)volumes[1] << 32 | volumes[0];
41 pa_volume_s16ne_orc_2ch (samples, v, ((length / (sizeof(int16_t))) / 2));
42 } else if (channels == 1)
43 pa_volume_s16ne_orc_1ch (samples, volumes[0], length / (sizeof(int16_t)));
44 else
45 fallback(samples, volumes, channels, length);
48 #undef RUN_TEST
50 #ifdef RUN_TEST
51 #define CHANNELS 2
52 #define SAMPLES 1022
53 #define TIMES 1000
54 #define TIMES2 100
55 #define PADDING 16
57 static void run_test(void) {
58 int16_t samples[SAMPLES];
59 int16_t samples_ref[SAMPLES];
60 int16_t samples_orig[SAMPLES];
61 int32_t volumes[CHANNELS + PADDING];
62 int i, j, padding;
63 pa_do_volume_func_t func;
64 pa_usec_t start, stop;
65 int k;
66 pa_usec_t min = INT_MAX, max = 0;
67 double s1 = 0, s2 = 0;
69 func = pa_get_volume_func(PA_SAMPLE_S16NE);
71 printf("checking ORC %zd\n", sizeof(samples));
73 pa_random(samples, sizeof(samples));
74 memcpy(samples_ref, samples, sizeof(samples));
75 memcpy(samples_orig, samples, sizeof(samples));
77 for (i = 0; i < CHANNELS; i++)
78 volumes[i] = PA_CLAMP_VOLUME(rand() >> 1);
79 for (padding = 0; padding < PADDING; padding++, i++)
80 volumes[i] = volumes[padding];
82 func(samples_ref, volumes, CHANNELS, sizeof(samples));
83 pa_volume_s16ne_orc(samples, volumes, CHANNELS, sizeof(samples));
84 for (i = 0; i < SAMPLES; i++) {
85 if (samples[i] != samples_ref[i]) {
86 printf ("%d: %04x != %04x (%04x * %04x)\n", i, samples[i], samples_ref[i],
87 samples_orig[i], volumes[i % CHANNELS]);
91 for (k = 0; k < TIMES2; k++) {
92 start = pa_rtclock_now();
93 for (j = 0; j < TIMES; j++) {
94 memcpy(samples, samples_orig, sizeof(samples));
95 pa_volume_s16ne_orc(samples, volumes, CHANNELS, sizeof(samples));
97 stop = pa_rtclock_now();
99 if (min > (stop - start)) min = stop - start;
100 if (max < (stop - start)) max = stop - start;
101 s1 += stop - start;
102 s2 += (stop - start) * (stop - start);
104 pa_log_info("ORC: %llu usec (min = %llu, max = %llu, stddev = %g).", (long long unsigned int)s1,
105 (long long unsigned int)min, (long long unsigned int)max, sqrt(TIMES2 * s2 - s1 * s1) / TIMES2);
107 min = INT_MAX; max = 0;
108 s1 = s2 = 0;
109 for (k = 0; k < TIMES2; k++) {
110 start = pa_rtclock_now();
111 for (j = 0; j < TIMES; j++) {
112 memcpy(samples_ref, samples_orig, sizeof(samples));
113 func(samples_ref, volumes, CHANNELS, sizeof(samples));
115 stop = pa_rtclock_now();
117 if (min > (stop - start)) min = stop - start;
118 if (max < (stop - start)) max = stop - start;
119 s1 += stop - start;
120 s2 += (stop - start) * (stop - start);
122 pa_log_info("ref: %llu usec (min = %llu, max = %llu, stddev = %g).", (long long unsigned int)s1,
123 (long long unsigned int)min, (long long unsigned int)max, sqrt(TIMES2 * s2 - s1 * s1) / TIMES2);
125 pa_assert_se(memcmp(samples_ref, samples, sizeof(samples)) == 0);
127 #endif
129 void pa_volume_func_init_orc(void) {
130 pa_log_info("Initialising ORC optimized functions.");
132 #ifdef RUN_TEST
133 run_test();
134 #endif
136 fallback = pa_get_volume_func(PA_SAMPLE_S16NE);
137 pa_set_volume_func(PA_SAMPLE_S16NE, (pa_do_volume_func_t) pa_volume_s16ne_orc);