[med-svn] [SCM] aghermann branch, master, updated. 4f7a3b774136ffffbaf9b05d90bd568347bc5461

Andrei Zavada johnhommer at gmail.com
Fri Nov 16 00:50:16 UTC 2012


The following commit has been merged in the master branch:
commit 8125ac53bdd11714034e13cdbd5b2c3053dd424a
Author: Andrei Zavada <johnhommer at gmail.com>
Date:   Sun Oct 14 15:36:17 2012 +0300

    bring back libsamplerate for occasional use (when loading pattern for now)

diff --git a/configure.ac b/configure.ac
index 8eb03f4..618ac10 100644
--- a/configure.ac
+++ b/configure.ac
@@ -53,7 +53,7 @@ dnl Check for some functions
 AC_CHECK_FUNC( [mremap], [], AC_MSG_ERROR([Function mremap not available]))
 dnl Check for prerequisite lib dependencies
 PKG_CHECK_MODULES([LIBCONFIGXX], [libconfig++])
-dnl PKG_CHECK_MODULES([SAMPLERATE], [samplerate >= 0.1.7])
+PKG_CHECK_MODULES([SAMPLERATE], [samplerate >= 0.1.7])
 PKG_CHECK_MODULES([GSL], [gsl])
 PKG_CHECK_MODULES([FFTW3], [fftw3])
 PKG_CHECK_MODULES([ITPP], [itpp])
diff --git a/debian/control b/debian/control
index 0b4a0b3..721510f 100644
--- a/debian/control
+++ b/debian/control
@@ -2,7 +2,7 @@ Source: aghermann
 Section: science
 Priority: optional
 Maintainer: Andrei Zavada <johnhommer at gmail.com>
-Build-Depends: debhelper (>= 9), dh-autoreconf, hardening-wrapper, hardening-includes, autoconf-archive, libgomp1, libconfig++-dev, pkg-config, libgsl0-dev, libfftw3-dev, libgtk-3-dev, libitpp-dev, libunique-3.0-dev, libxml2-utils
+Build-Depends: debhelper (>= 9), dh-autoreconf, hardening-wrapper, hardening-includes, autoconf-archive, libgomp1, libconfig++-dev, pkg-config, libgsl0-dev, libfftw3-dev, libsamplerate-dev (>= 0.1.7), libgtk-3-dev, libitpp-dev, libunique-3.0-dev, libxml2-utils
 Standards-Version: 3.9.3
 Homepage: http://johnhommer.com/academic/code/aghermann
 Vcs-Git: git://git.debian.org/git/debian-med/aghermann.git
diff --git a/gentoo/aghermann.ebuild b/gentoo/aghermann.ebuild
index ca48f21..554bf6e 100644
--- a/gentoo/aghermann.ebuild
+++ b/gentoo/aghermann.ebuild
@@ -19,7 +19,8 @@ DEPEND=">=x11-libs/gtk+-3.0
 	sci-libs/itpp
 	sci-libs/fftw
 	dev-libs/libconfig
-	dev-libs/libxml2"
+	dev-libs/libxml2
+	media-libs/samplerate"
 
 src_install() {
 	emake DESTDIR="${D}" install || die "make install failed"
diff --git a/src/Makefile.am b/src/Makefile.am
index 00093b8..969d275 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -21,7 +21,7 @@ aghermann_LDADD = \
 	libsigfile/libsigfile.a \
 	sigproc/libsigproc.a \
 	common/libcommon.a \
-	$(FFTW3_LIBS) $(ITPP_LIBS) $(GTK_LIBS) $(GSL_LIBS) $(LIBCONFIGXX_LIBS) \
+	$(FFTW3_LIBS) $(ITPP_LIBS) $(SAMPLERATE_LIBS) $(GTK_LIBS) $(GSL_LIBS) $(LIBCONFIGXX_LIBS) \
 	$(OPENMP_LDADD) $(LIBFFTW3_LDADD)
 
 CLEANFILES = \
diff --git a/src/sigproc/sigproc.cc b/src/sigproc/sigproc.cc
index e2be3a6..2b1c058 100644
--- a/src/sigproc/sigproc.cc
+++ b/src/sigproc/sigproc.cc
@@ -33,49 +33,49 @@ template double sigproc::phase_diff( const valarray<TFloat>&, const valarray<TFl
 
 
 
-// valarray<float>
-// sigproc::
-// resample_f( const valarray<float>& signal,
-// 	    size_t start, size_t end,
-// 	    size_t to_size,
-// 	    int alg)
-// {
-// 	if ( unlikely (end <= start) || (end > signal.size()) )
-// 		throw runtime_error ("bad args for resample");
-
-// 	valarray<float>	resampled (to_size);
-// 	SRC_DATA S;
-// 	S.data_in       = const_cast<float*>(&signal[start]);
-// 	S.input_frames  = end - start;
-// 	S.output_frames = to_size;
-// 	S.data_out      = &resampled[0];
-// 	S.src_ratio     = (double)S.output_frames / S.input_frames;
-
-// 	src_simple( &S, alg, 1);
-
-// 	return resampled;
-// }
-
-// valarray<double>
-// sigproc::
-// resample( const valarray<double>& signal,
-// 	  size_t start, size_t end,
-// 	  size_t to_size,
-// 	  int alg)
-// {
-// 	valarray<float> tmp1 (end - start);
-// 	for ( size_t i = start; i < end; ++i )
-// 		tmp1[i] = signal[i];
-
-// 	valarray<float> tmp2
-// 		= sigproc::resample_f( tmp1, 0, end-start, to_size, alg);
-
-// 	valarray<double> ret (end-start);
-// 	for ( size_t i = 0; i < end-start; ++i )
-// 		ret[i] = tmp2[i];
-
-// 	return ret;
-// }
+valarray<float>
+sigproc::
+resample_f( const valarray<float>& signal,
+	    size_t start, size_t end,
+	    size_t to_size,
+	    int alg)
+{
+	if ( unlikely (end <= start) || (end > signal.size()) )
+		throw runtime_error ("bad args for resample");
+
+	valarray<float>	resampled (to_size);
+	SRC_DATA S;
+	S.data_in       = const_cast<float*>(&signal[start]);
+	S.input_frames  = end - start;
+	S.output_frames = to_size;
+	S.data_out      = &resampled[0];
+	S.src_ratio     = (double)S.output_frames / S.input_frames;
+
+	src_simple( &S, alg, 1);
+
+	return resampled;
+}
+
+valarray<double>
+sigproc::
+resample( const valarray<double>& signal,
+	  size_t start, size_t end,
+	  size_t to_size,
+	  int alg)
+{
+	valarray<float> tmp1 (end - start);
+	for ( size_t i = start; i < end; ++i )
+		tmp1[i] = signal[i];
+
+	valarray<float> tmp2
+		= sigproc::resample_f( tmp1, 0, end-start, to_size, alg);
+
+	valarray<double> ret (end-start);
+	for ( size_t i = 0; i < end-start; ++i )
+		ret[i] = tmp2[i];
+
+	return ret;
+}
 
 
 
diff --git a/src/sigproc/sigproc.hh b/src/sigproc/sigproc.hh
index 1d0c90c..15d0239 100644
--- a/src/sigproc/sigproc.hh
+++ b/src/sigproc/sigproc.hh
@@ -18,8 +18,7 @@
 #include <valarray>
 #include <stdexcept>
 #include <gsl/gsl_math.h>
-
-//#include <samplerate.h>
+#include <samplerate.h>
 
 #include "../common/lang.hh"
 #include "exstrom.hh"
@@ -44,24 +43,24 @@ void
 normalize( valarray<T>&);
 
 
-// valarray<float>
-// resample_f( const valarray<float>&,
-// 	    size_t, size_t, size_t, int);
-
-// inline valarray<float>
-// resample( const valarray<float>& signal,
-// 	  size_t start, size_t end,
-// 	  size_t to_size,
-// 	  int alg = SRC_SINC_FASTEST)
-// {
-// 	return resample_f( signal, start, end, to_size, alg);
-// }
-
-// valarray<double>
-// resample( const valarray<double>& signal,
-// 	  size_t start, size_t end,
-// 	  size_t to_size,
-// 	  int alg);
+valarray<float>
+resample_f( const valarray<float>&,
+	    size_t, size_t, size_t, int);
+
+inline valarray<float>
+resample( const valarray<float>& signal,
+	  size_t start, size_t end,
+	  size_t to_size,
+	  int alg = SRC_SINC_FASTEST)
+{
+	return resample_f( signal, start, end, to_size, alg);
+}
+
+valarray<double>
+resample( const valarray<double>& signal,
+	  size_t start, size_t end,
+	  size_t to_size,
+	  int alg);
 
 
 
diff --git a/src/tools/Makefile.am b/src/tools/Makefile.am
index 73dc74a..da0a303 100644
--- a/src/tools/Makefile.am
+++ b/src/tools/Makefile.am
@@ -11,7 +11,7 @@ edfcat_LDADD = \
 	../libsigfile/libsigfile.a \
 	../sigproc/libsigproc.a \
 	../common/libcommon.a \
-	$(FFTW3_LIBS) $(ITPP_LIBS) $(GSL_LIBS) \
+	$(FFTW3_LIBS) $(ITPP_LIBS) $(SAMPLERATE_LIBS) $(GSL_LIBS) \
 	$(OPENMP_LDADD) $(LIBFFTW3_LDADD)
 
 edfhed_SOURCES = \
@@ -20,7 +20,7 @@ edfhed_LDADD = \
 	../libsigfile/libsigfile.a \
 	../sigproc/libsigproc.a \
 	../common/libcommon.a \
-	$(FFTW3_LIBS) $(ITPP_LIBS) $(GSL_LIBS) \
+	$(FFTW3_LIBS) $(ITPP_LIBS) $(SAMPLERATE_LIBS) $(GSL_LIBS) \
 	$(OPENMP_LDADD) $(LIBFFTW3_LDADD)
 
 edfhed_gtk_SOURCES = \
@@ -32,6 +32,6 @@ edfhed_gtk_LDADD = \
 	../sigproc/libsigproc.a \
 	../common/libcommon.a \
 	../ui/libaghui.a \
-	$(FFTW3_LIBS) $(ITPP_LIBS) $(GTK_LIBS) $(GSL_LIBS) \
+	$(FFTW3_LIBS) $(ITPP_LIBS) $(SAMPLERATE_LIBS) $(GTK_LIBS) $(GSL_LIBS) \
 	$(OPENMP_LDADD) $(LIBFFTW3_LDADD)
 
diff --git a/src/ui/scoring-facility-patterns.cc b/src/ui/scoring-facility-patterns.cc
index 8a12f40..f1d40e5 100644
--- a/src/ui/scoring-facility-patterns.cc
+++ b/src/ui/scoring-facility-patterns.cc
@@ -272,11 +272,7 @@ load_pattern( const char *label, bool do_globally)
 			     &params.dzcdf_step, &params.dzcdf_sigma, &params.dzcdf_smooth,
 			     &tolerance_a, &tolerance_b, &tolerance_c,
 			     &samplerate, &full_sample, &context_before, &context_after) == 13 ) {
-			if ( samplerate != field_channel->samplerate() ) {
-				snprintf_buf( "Loaded pattern has samplerate different from the current samplerate (%zu vs %zu)",
-					      samplerate, field_channel->samplerate());
-				pop_ok_message( (GtkWindow*)_p.wPattern, __buf__);
-			}
+
 			pattern.resize( full_sample);
 			for ( size_t i = 0; i < full_sample; ++i ) {
 				double tmp;
@@ -288,6 +284,15 @@ load_pattern( const char *label, bool do_globally)
 					pattern[i] = tmp;
 			}
 
+			if ( samplerate != field_channel->samplerate() ) {
+				double fac = (double)field_channel->samplerate() / samplerate;
+				pattern =
+					sigproc::resample( pattern, 0, full_sample,
+							   fac * full_sample);
+				context_before *= fac;
+				context_after  *= fac;
+			}
+
 			display_scale = field_channel->signal_display_scale;
 			W_V.up();
 

-- 
Sleep experiment manager



More information about the debian-med-commit mailing list