r4121: Auto commit for Debian build
authorKevin M. Rosenberg <kevin@rosenberg.net>
Tue, 25 Feb 2003 18:15:06 +0000 (18:15 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Tue, 25 Feb 2003 18:15:06 +0000 (18:15 +0000)
debian/changelog
wdq2wav.cpp
wdq2wav.h

index 7c736f551d9ee819cd6bddcd70a7a31d2531b079..bf6f93792a2a0fcd523575fe7d194866eda98f40 100644 (file)
@@ -1,3 +1,9 @@
+wdq2wav (0.6.0-1) unstable; urgency=low
+
+  * Add demeaning option
+
+ -- Kevin M. Rosenberg <kmr@debian.org>  Tue, 25 Feb 2003 11:13:55 -0700
+
 wdq2wav (0.5.1-1) unstable; urgency=low
 
   * Avoid possible divide by 0
index a3320b2fe3d1eab06140478ed8b9112cdc69e4ba..81c52a4539c3b0411fd75979fec9fb20255f35e9 100644 (file)
@@ -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
 
 #include <wdq2wav.h>
 
-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<T>(x+0.5) : static_cast<T>(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<double> wdq.m_nSamples;
+    int mean = nearest<int>(dmean);
+    for (i = 0; i < r_wdq.m_nSamples; i++)
+      m_data[i] -= mean;
+  }
+  
   delete sample_row;
   return true;
 }
index 10697d3b618309f63ffc4e95dce3accd10422c7e..0a3f6022e50e4080d80ba5084393b27040fc80ae 100644 (file)
--- 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<T>(x+0.5) : static_cast<T>(x-0.5)); }