const char*
fileBasename (const char* filename)
{
- const char* p = strrchr (filename, '/');
- return (p ? p + 1 : filename);
+ const char* pslash = strrchr (filename, '/');
+ const char* pbackslash = strrchr (filename, '\\');
+ const char* p = filename;
+ if (pbackslash && (! pslash || pbackslash >= pslash))
+ p = pbackslash+1;
+ else if (pslash && (! pbackslash || pslash >= pbackslash))
+ p = pslash+1;
+
+ return p;
}
char *
std::cout << " -m Do not demean the data (don't 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";
+ std::cout << " -r Print program version and exit\n";
std::cout << " -h Print this help message\n";
}
switch (c) {
case 'r':
std::cout << "Version " << g_szIdStr << std::endl;
+ exit(0);
break;
case 'q':
g_quiet = true;
return (1);
}
}
+
+ if (g_verbose || g_debug)
+ std::cout << "Version " << g_szIdStr << std::endl;
+
argc -= optind;
argv += optind;
if (argc > 3) {
}
return false;
}
+
+ if (wdq.any_packed_channels()) {
+ std::ostringstream os;
+ os << "File contains 'packed' channels." << std::endl;
+ os << "Convert to 'Advanced CODAS headers' before processing with wdq2wav.";
+ error_msg (os.str().c_str());
+ return false;
+ }
+
if (! g_quiet || g_verbose || g_debug) {
std::ostringstream os1;
- os1 << "File " << wdq_fname;
+ os1 << "File: " << wdq_fname;
info_msg (os1.str().c_str());
+ std::ostringstream os;
+ os << "Legacy Format: ";
+ if (wdq.m_bLegacy_format)
+ os << "Yes";
+ else
+ os << "No";
+ info_msg(os.str().c_str());
std::ostringstream os2;
time_t time = wdq.m_time_acq_start;
struct tm* tm = gmtime (&time);
close (m_fd);
}
+bool read_int1 (int fd, unsigned char& n)
+{
+ unsigned char tmp1;
+ if (read (fd, &tmp1, 1) != 1)
+ return false;
+
+ n = tmp1;
+ return true;
+}
+
bool read_int2 (int fd, unsigned short int& n)
{
unsigned char tmp1;
bool
WindaqFile::ReadHeader ()
{
- unsigned short int tmp2;
-
m_valid = false;
if ((m_fd = open (m_strFile.c_str(), O_RDONLY | O_BINARY)) < 0) {
m_error = "Unable to open file";
}
lseek (0, 0, SEEK_SET);
- if (! read_int2 (m_fd, tmp2))
+ unsigned short int element1;
+ if (! read_int2 (m_fd, element1))
return false;
- m_format = (tmp2 & 0xFF00) >> 8;
- printf ("format=%d\n",m_format);
- printf ("tmp2=%4x\n", tmp2);
- m_nChannels = tmp2 & 0x1f;
- m_sr_denom = (tmp2 & 0x7fff) >> 5;
- m_sr_numer = (tmp2 & 0x8000) << 1;
-
- if (! read_int2 (m_fd, tmp2))
+
+ short unsigned int byte1 = (element1 & 0xFF00) >> 8;
+ short unsigned int byte2 = element1 & 0xFF;
+ if (byte1 == 0 || byte1 == 1) {
+ m_bLegacy_format = false;
+ m_sr_denom = m_sr_numer = 0;
+ } else {
+ m_sr_denom = (element1 & 0x7fff) >> 5;
+ m_sr_numer = (element1 & 0x8000) << 1;
+ m_bLegacy_format = true;
+ }
+ unsigned short int element2;
+ if (! read_int2 (m_fd, element2))
return false;
- m_sr_numer |= tmp2;
- if (! read_int2 (m_fd, tmp2))
+ if (m_bLegacy_format)
+ m_sr_numer |= element2;
+
+ unsigned char element3;
+ if (! read_int1 (m_fd, element3))
return false;
+ m_channel_offset = element3;
+ if (g_debug)
+ std::cout << "Channel offset: " << m_channel_offset << std::endl;
- m_channel_offset = tmp2 & 0xFF;
- m_nBytes_channel_header = tmp2 >> 8;
+ unsigned char element4;
+ if (! read_int1 (m_fd, element4))
+ return false;
+ m_nBytes_channel_header = element4;
+ if (g_debug)
+ std::cout << "Channel header bytes: " << m_nBytes_channel_header << std::endl;
- if (! read_int2 (m_fd, m_nHeader_bytes))
+ unsigned short int element5;
+ if (! read_int2 (m_fd, element5))
return false;
+ m_nHeader_bytes = element5;
+ if (g_debug)
+ std::cout << "Header bytes: " << m_nHeader_bytes << std::endl;
m_nMaxChannels = (m_nHeader_bytes - 112) / 36;
- printf ("m_nMaxChannels = %d\n", m_nMaxChannels);
+ if (m_nMaxChannels >= 144)
+ m_nChannels = byte2 & 0xFF;
+ else
+ m_nChannels = byte2 & 0x1F;
- if (! read_int4 (m_fd, m_nData_bytes))
+ unsigned int element6;
+ if (! read_int4 (m_fd, element6))
return false;
+ m_nData_bytes = element6;
+ if (g_debug)
+ std::cout << "Data bytes: " << m_nData_bytes << std::endl;
m_nSamples = (m_nData_bytes / m_nChannels) / 2;
lseek (m_fd, 28, SEEK_SET);
- if (! read_float8 (m_fd, m_time_between_channel_samples))
+ double element13;
+ if (! read_float8 (m_fd, element13))
return false;
- printf ("time_between_channel_samples=%lf\n", m_time_between_channel_samples);
+ m_time_between_channel_samples = element13;
- if (m_format == 0 || m_format == 1)
- m_sample_rate = (double) m_nChannels / m_time_between_channel_samples;
+ if (m_bLegacy_format)
+ m_sample_rate = (double) m_sr_numer / (double) (m_sr_denom * m_nChannels);
else
- m_sample_rate = (double) m_sr_numer / (double) (m_sr_denom * m_nChannels);
+ m_sample_rate = (double) m_nChannels / m_time_between_channel_samples;
lseek (m_fd, 36, SEEK_SET);
if (! read_int4 (m_fd, m_time_acq_start))
if (! read_int4 (m_fd, m_time_acq_stop))
return false;
+ lseek (m_fd, 100, SEEK_SET);
+ unsigned short int element27;
+ if (! read_int2 (m_fd, element27))
+ return false;
+
+ m_bHires = (element27 & 0x0001) ? true : false;
+ if (g_debug) {
+ std::cout << "High resolution: ";
+ if (m_bHires)
+ std::cout << "Yes";
+ else
+ std::cout << "No";
+
+ std::cout << std::endl;
+ }
+
// Verify Windaq signature
lseek (m_fd, m_nHeader_bytes - 2, SEEK_SET);
- if (! read_int2 (m_fd, tmp2))
+ unsigned short int element35;
+ if (! read_int2 (m_fd, element35))
return false;
- if (tmp2 != 0x8001) {
+ if (element35 != 0x8001) {
std::ostringstream os;
- m_error = "File is not a valid WinDAQ file";
+ m_error = "Incorrect signagure: file is not a valid WinDAQ file";
return false;
}
m_valid = true;
return true;
}
+
+bool
+WindaqFile::any_packed_channels ()
+{
+ for (int iChannel = 0; iChannel < m_nChannels; iChannel++)
+ if (is_channel_packed (iChannel))
+ return true;
+
+ return false;
+}
+
+bool
+WindaqFile::is_channel_packed (const int channel)
+{
+ long iStart = m_channel_offset + channel * m_nBytes_channel_header;
+
+ lseek (m_fd, iStart + 31, SEEK_SET);
+ unsigned char iReadings_per_data_point;
+ if (! read_int1 (m_fd, iReadings_per_data_point))
+ return false;
+
+ if (iReadings_per_data_point > 1)
+ return true;
+ return false;
+}
+
WindaqChannel::WindaqChannel (WindaqFile& wdq, const int channel)
: r_wdq(wdq), m_data(0), m_slope(0), m_intercept (0), m_channel(channel),
m_valid(false)
unsigned char c = p[0]; p[0] = p[1]; p[1] = c;
#endif
- signed short int value = v >> 2;
+ signed short int value = v;
+ if (! r_wdq.m_bHires)
+ value >>= 2;
+
m_data[i] = value;
total_data += value;
return;
unsigned long int i;
+
for (i = 0; i < m_nSamples; i++) {
double value = input[i];
value = (slope * value) + intercept;