**
** 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
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";
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;
case 'q':
g_quiet = true;
break;
+ case 'm':
+ g_demean = true;
+ break;
case 'v':
g_verbose = true;
break;
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 ()
{
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;
signed short int value = v >> 2;
m_data[i] = value;
+ total_data += value;
if (i == 0) {
data_max = value;
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;
}
**
** 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
private:
bool fill_header();
};
+
+inline T nearest (double x)
+{ return (x > 0 ? static_cast<T>(x+0.5) : static_cast<T>(x-0.5)); }