From 69101b0d7cf43ad42e921b59633af75edbe47d19 Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Tue, 25 Feb 2003 18:15:06 +0000 Subject: [PATCH] r4121: Auto commit for Debian build --- debian/changelog | 6 ++++++ wdq2wav.cpp | 23 ++++++++++++++++++++--- wdq2wav.h | 5 ++++- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/debian/changelog b/debian/changelog index 7c736f5..bf6f937 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +wdq2wav (0.6.0-1) unstable; urgency=low + + * Add demeaning option + + -- Kevin M. Rosenberg Tue, 25 Feb 2003 11:13:55 -0700 + wdq2wav (0.5.1-1) unstable; urgency=low * Avoid possible divide by 0 diff --git a/wdq2wav.cpp b/wdq2wav.cpp index a3320b2..81c52a4 100644 --- a/wdq2wav.cpp +++ b/wdq2wav.cpp @@ -8,7 +8,7 @@ ** ** Copyright (c) 2003 Kevin Rosenberg ** -** $Id: wdq2wav.cpp,v 1.20 2003/02/24 13:01:02 kevin Exp $ +** $Id: wdq2wav.cpp,v 1.21 2003/02/25 18:14:10 kevin Exp $ ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License (version 2) as @@ -26,12 +26,13 @@ #include -const char* g_szIdStr = "$Id: wdq2wav.cpp,v 1.20 2003/02/24 13:01:02 kevin Exp $"; +const char* g_szIdStr = "$Id: wdq2wav.cpp,v 1.21 2003/02/25 18:14:10 kevin Exp $"; bool g_quiet = false; bool g_verbose = false; bool g_debug = false; bool g_ignore_zero = false; +bool g_demean = false; #ifdef WIN32 @@ -111,6 +112,7 @@ usage (const char* progname) std::cout << " -p Play channel through audio system\n"; std::cout << " -q Supress all messages\n"; std::cout << " -z Scale output without regard for windaq zero point\n"; + std::cout << " -m Demean the data (subtract the mean value from each sample)\n"; std::cout << " -v Verbose mode\n"; std::cout << " -d Debug mode\n"; std::cout << " -r Print program version\n"; @@ -126,7 +128,7 @@ main (int argc, char *argv[]) const char* progname = argv[0]; - while ((c = getopt (argc, argv, "rqvzdph")) != -1) { + while ((c = getopt (argc, argv, "rqvzmdph")) != -1) { switch (c) { case 'r': std::cout << "Version " << g_szIdStr << std::endl; @@ -134,6 +136,9 @@ main (int argc, char *argv[]) case 'q': g_quiet = true; break; + case 'm': + g_demean = true; + break; case 'v': g_verbose = true; break; @@ -434,6 +439,9 @@ bool get_float8 (int fd, double& f) return true; } +inline T nearest (double x) +{ return (x > 0 ? static_cast(x+0.5) : static_cast(x-0.5)); } + bool WindaqChannel::read_channel_data () { @@ -466,6 +474,7 @@ WindaqChannel::read_channel_data () lseek (fd, r_wdq.m_nHeader_bytes, SEEK_SET); unsigned long int i; signed short int data_max = 0, data_min = 0; + double total_data = 0; for (i = 0; i < r_wdq.m_nSamples; i++) { if (read (fd, sample_row, row_bytes) != row_bytes) { std::ostringstream os; @@ -483,6 +492,7 @@ WindaqChannel::read_channel_data () signed short int value = v >> 2; m_data[i] = value; + total_data += value; if (i == 0) { data_max = value; @@ -500,6 +510,13 @@ WindaqChannel::read_channel_data () m_max_scaled_data = (m_slope * data_max) + m_intercept; m_min_scaled_data = (m_slope * data_min) + m_intercept; + if (g_demean) { + double dmean = total_data / static_cast wdq.m_nSamples; + int mean = nearest(dmean); + for (i = 0; i < r_wdq.m_nSamples; i++) + m_data[i] -= mean; + } + delete sample_row; return true; } diff --git a/wdq2wav.h b/wdq2wav.h index 10697d3..0a3f602 100644 --- a/wdq2wav.h +++ b/wdq2wav.h @@ -8,7 +8,7 @@ ** ** Copyright (c) 2003 Kevin Rosenberg ** -** $Id: wdq2wav.h,v 1.12 2003/02/24 13:01:02 kevin Exp $ +** $Id: wdq2wav.h,v 1.13 2003/02/25 18:15:06 kevin Exp $ ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License (version 2) as @@ -131,3 +131,6 @@ class WavFile private: bool fill_header(); }; + +inline T nearest (double x) +{ return (x > 0 ? static_cast(x+0.5) : static_cast(x-0.5)); } -- 2.34.1