shithub: aubio

Download patch

ref: 10a54136f3a9a1d8b8ec899ae457a9a4d327e8cf
parent: daa4ca906d6c9352b5df093752ee7dcb50879b90
author: Paul Brossier <piem@piem.org>
date: Wed Oct 7 14:26:59 EDT 2009

src/mathutils.c: add aubio_is_power_of_two and aubio_next_power_of_two

--- a/configure.ac
+++ b/configure.ac
@@ -114,7 +114,7 @@
 AC_CHECK_LIB(pthread, pthread_create)
 
 dnl Check for header files
-AC_CHECK_HEADERS([string.h stdlib.h stdio.h math.h errno.h stdarg.h unistd.h signal.h],,)
+AC_CHECK_HEADERS([string.h stdlib.h stdio.h math.h limits.h errno.h stdarg.h unistd.h signal.h],,)
 AC_CHECK_HEADERS(fftw3.h,,AC_MSG_ERROR([Ouch! missing fftw3.h header]))
 AC_ARG_ENABLE(complex,
   AC_HELP_STRING([--enable-complex],[compile with complex.h [[default=auto]]]),
--- a/src/aubio_priv.h
+++ b/src/aubio_priv.h
@@ -62,6 +62,10 @@
 #include <string.h>
 #endif
 
+#if HAVE_LIMITS_H
+#include <limits.h> // for CHAR_BIT, in C99 standard
+#endif
+
 #include "types.h"
 
 /****
--- a/src/mathutils.c
+++ b/src/mathutils.c
@@ -409,6 +409,25 @@
   return aubio_freqtobin (freq, samplerate, fftsize);
 }
 
+uint_t
+aubio_is_power_of_two(uint_t a) {
+  if ((a & a-1) == 0) {
+    return 1;
+  } else {
+    return 0; 
+  }
+}
+
+uint_t
+aubio_next_power_of_two(uint_t a) {
+  uint_t i;
+  a--;
+  for (i = 0; i < sizeof(uint_t) * CHAR_BIT; i++ ) {
+    a = a | a >> 1;
+  }
+  return a+1;
+}
+
 smpl_t
 aubio_db_spl (fvec_t * o)
 {
--- a/src/mathutils.h
+++ b/src/mathutils.h
@@ -316,6 +316,12 @@
 /** convert midi value (0-128) to frequency (Hz) */
 smpl_t aubio_miditofreq (smpl_t midi);
 
+/** return 1 if a is a power of 2, 0 otherwise */
+uint_t aubio_is_power_of_two(uint_t a);
+
+/** return the next power of power of 2 greater than a */
+uint_t aubio_next_power_of_two(uint_t a);
+
 /** compute sound pressure level (SPL) in dB
 
   This quantity is often wrongly called 'loudness'.
--- a/wscript
+++ b/wscript
@@ -53,6 +53,7 @@
   conf.check(header_name='stdio.h')
   conf.check(header_name='math.h')
   conf.check(header_name='string.h')
+  conf.check(header_name='limits.h')
 
   # optionally use complex.h
   if (Options.options.disable_complex == False):