From 951bf1b28d25a93b99cbe074a46b8313a9e5f9f0 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 19 Aug 2009 16:09:14 +0200 Subject: svolume: add ARM optimized volume scaling --- src/pulsecore/cpu-arm.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/pulsecore/cpu-arm.c (limited to 'src/pulsecore/cpu-arm.c') diff --git a/src/pulsecore/cpu-arm.c b/src/pulsecore/cpu-arm.c new file mode 100644 index 00000000..75646fe4 --- /dev/null +++ b/src/pulsecore/cpu-arm.c @@ -0,0 +1,43 @@ +/*** + This file is part of PulseAudio. + + Copyright 2004-2006 Lennart Poettering + Copyright 2009 Wim Taymans + + PulseAudio is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation; either version 2.1 of the License, + or (at your option) any later version. + + PulseAudio is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with PulseAudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include + +#include "cpu-arm.h" + +static pa_cpu_arm_flag_t pa_cpu_arm_flags; + +void pa_cpu_init_arm (void) { +#if defined (__arm__) + pa_cpu_arm_flags = 0; + + pa_log ("ARM init\n"); + + pa_volume_func_init_arm (pa_cpu_arm_flags); +#endif /* defined (__arm__) */ +} -- cgit From 8aa86f5247103432faf660cba33f5ce80fbbc2c7 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 19 Aug 2009 19:51:11 +0200 Subject: arm: implement ARM cpu detection --- src/pulsecore/cpu-arm.c | 107 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 102 insertions(+), 5 deletions(-) (limited to 'src/pulsecore/cpu-arm.c') diff --git a/src/pulsecore/cpu-arm.c b/src/pulsecore/cpu-arm.c index 75646fe4..93ad3891 100644 --- a/src/pulsecore/cpu-arm.c +++ b/src/pulsecore/cpu-arm.c @@ -25,19 +25,116 @@ #endif #include +#include +#include +#include +#include #include #include "cpu-arm.h" -static pa_cpu_arm_flag_t pa_cpu_arm_flags; +#if defined (__arm__) && defined (__linux__) + +#define MAX_BUFFER 4096 +static char * +get_cpuinfo_line (char *cpuinfo, const char *tag) { + char *line, *end, *colon; + + if (!(line = strstr (cpuinfo, tag))) + return NULL; + + if (!(end = strchr (line, '\n'))) + return NULL; + + if (!(colon = strchr (line, ':'))) + return NULL; + + if (++colon >= end) + return NULL; + + return pa_xstrndup (colon, end - colon); +} + +static char *get_cpuinfo(void) { + char *cpuinfo; + int n, fd; + + if (!(cpuinfo = malloc(MAX_BUFFER))) + return NULL; + + if ((fd = open("/proc/cpuinfo", O_RDONLY)) < 0) { + free (cpuinfo); + return NULL; + } + + if ((n = read(fd, cpuinfo, MAX_BUFFER-1)) < 0) { + free (cpuinfo); + close (fd); + return NULL; + } + cpuinfo[n] = 0; + close (fd); + + return cpuinfo; +} +#endif /* defined (__arm__) && defined (__linux__) */ void pa_cpu_init_arm (void) { #if defined (__arm__) - pa_cpu_arm_flags = 0; - - pa_log ("ARM init\n"); +#if defined (__linux__) + char *cpuinfo, *line; + int arch; + pa_cpu_arm_flag_t flags = 0; + + /* We need to read the CPU flags from /proc/cpuinfo because there is no user + * space support to get the CPU features. This only works on linux AFAIK. */ + if (!(cpuinfo = get_cpuinfo ())) { + pa_log ("Can't read cpuinfo"); + return; + } + + /* get the CPU architecture */ + if ((line = get_cpuinfo_line (cpuinfo, "CPU architecture"))) { + arch = strtoul (line, NULL, 0); + if (arch >= 6) + flags |= PA_CPU_ARM_V6; + if (arch >= 7) + flags |= PA_CPU_ARM_V7; + + free (line); + } + /* get the CPU features */ + if ((line = get_cpuinfo_line (cpuinfo, "Features"))) { + char *state = NULL, *current; + + while ((current = pa_split_spaces (line, &state))) { + if (!strcmp (current, "vfp")) + flags |= PA_CPU_ARM_VFP; + else if (!strcmp (current, "edsp")) + flags |= PA_CPU_ARM_EDSP; + else if (!strcmp (current, "neon")) + flags |= PA_CPU_ARM_NEON; + else if (!strcmp (current, "vfpv3")) + flags |= PA_CPU_ARM_VFPV3; + + free (current); + } + } + free (cpuinfo); + + pa_log_info ("CPU flags: %s%s%s%s%s%s", + (flags & PA_CPU_ARM_V6) ? "V6 " : "", + (flags & PA_CPU_ARM_V7) ? "V7 " : "", + (flags & PA_CPU_ARM_VFP) ? "VFP " : "", + (flags & PA_CPU_ARM_EDSP) ? "EDSP " : "", + (flags & PA_CPU_ARM_NEON) ? "NEON " : "", + (flags & PA_CPU_ARM_VFPV3) ? "VFPV3 " : ""); +#else /* defined (__linux__) */ + pa_log ("ARM cpu features not yet supported on this OS"); +#endif /* defined (__linux__) */ - pa_volume_func_init_arm (pa_cpu_arm_flags); + if (flags & PA_CPU_ARM_V6) + pa_volume_func_init_arm (flags); #endif /* defined (__arm__) */ } -- cgit From f09b51198f43d79b22cb92b5223d01a7ab339d9f Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 20 Aug 2009 10:56:20 +0200 Subject: whitespace fixes --- src/pulsecore/cpu-arm.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/pulsecore/cpu-arm.c') diff --git a/src/pulsecore/cpu-arm.c b/src/pulsecore/cpu-arm.c index 93ad3891..5a994b71 100644 --- a/src/pulsecore/cpu-arm.c +++ b/src/pulsecore/cpu-arm.c @@ -36,14 +36,14 @@ #if defined (__arm__) && defined (__linux__) -#define MAX_BUFFER 4096 +#define MAX_BUFFER 4096 static char * get_cpuinfo_line (char *cpuinfo, const char *tag) { char *line, *end, *colon; if (!(line = strstr (cpuinfo, tag))) return NULL; - + if (!(end = strchr (line, '\n'))) return NULL; @@ -106,20 +106,20 @@ void pa_cpu_init_arm (void) { } /* get the CPU features */ if ((line = get_cpuinfo_line (cpuinfo, "Features"))) { - char *state = NULL, *current; - - while ((current = pa_split_spaces (line, &state))) { - if (!strcmp (current, "vfp")) - flags |= PA_CPU_ARM_VFP; - else if (!strcmp (current, "edsp")) - flags |= PA_CPU_ARM_EDSP; - else if (!strcmp (current, "neon")) - flags |= PA_CPU_ARM_NEON; - else if (!strcmp (current, "vfpv3")) - flags |= PA_CPU_ARM_VFPV3; - - free (current); - } + char *state = NULL, *current; + + while ((current = pa_split_spaces (line, &state))) { + if (!strcmp (current, "vfp")) + flags |= PA_CPU_ARM_VFP; + else if (!strcmp (current, "edsp")) + flags |= PA_CPU_ARM_EDSP; + else if (!strcmp (current, "neon")) + flags |= PA_CPU_ARM_NEON; + else if (!strcmp (current, "vfpv3")) + flags |= PA_CPU_ARM_VFPV3; + + free (current); + } } free (cpuinfo); -- cgit