X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=wdq2wav.cpp;h=7a57e9181ddad913ac3674501b30fc4194e59d5e;hb=d7a27230e4058ce4d949c22b68c758c90c46572b;hp=592466ba657b00fb70f8bd166a9f4fccfe97adfa;hpb=31adb1e01d11e62be9adf5da1fbb05fdec239f99;p=wdq2wav.git diff --git a/wdq2wav.cpp b/wdq2wav.cpp index 592466b..7a57e91 100644 --- a/wdq2wav.cpp +++ b/wdq2wav.cpp @@ -16,7 +16,7 @@ ** Need command line options for verbose and debug output ** Should comment the reading and writing of files to document the file formats ** -** $Id: wdq2wav.cpp,v 1.3 2003/01/21 03:04:27 kevin Exp $ +** $Id: wdq2wav.cpp,v 1.7 2003/01/21 04:19:44 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 @@ -35,20 +35,26 @@ #include static bool g_verbose = true; -static bool g_debug = true; +static bool g_debug = false; void -error_msg (char *msg) +error_msg (const char *msg) { fprintf (stderr, "%s\n",msg); } void -info_msg (char* msg) +info_msg (const char* msg) { fprintf (stdout, "%s\n", msg); } +void +info_msg_sans_newline (const char* msg) +{ + fprintf (stdout, "%s", msg); +} + void usage () { @@ -93,11 +99,24 @@ wdq2wav (const char* wdq_fname, const int channel, const char *wav_fname) return false; } if (g_verbose) { - std::ostringstream os; - os << wdq_fname << ": Samples " << wdq.m_nSamples << - ", Channels " << wdq.m_nChannels << - ", Sample Rate " << wdq.m_sample_rate; - info_msg (os.str().c_str()); + std::ostringstream os1; + os1 << "File " << wdq_fname; + info_msg (os1.str().c_str()); + std::ostringstream os2; + time_t time = wdq.m_time_acq_start; + struct tm* tm = gmtime (&time); + os2 << " Time File Creation: " << asctime(tm); + info_msg_sans_newline (os2.str().c_str()); + std::ostringstream os3; + time = wdq.m_time_acq_stop; + tm = gmtime (&time); + os3 << " Time File Written: " << asctime(tm); + info_msg_sans_newline (os3.str().c_str()); + std::ostringstream os4; + os4 << " Samples: " << wdq.m_nSamples << + ", Channels: " << wdq.m_nChannels << + ", Sample Rate: " << wdq.m_sample_rate; + info_msg (os4.str().c_str()); } WindaqChannel wdq_channel (wdq, channel); @@ -108,16 +127,23 @@ wdq2wav (const char* wdq_fname, const int channel, const char *wav_fname) if (g_verbose) { std::ostringstream os1; - os1 << "Channel units: " << wdq_channel.m_units.c_str(); + os1 << "Channel " << channel; info_msg (os1.str().c_str()); std::ostringstream os2; - os2 << "Raw data: minimum " << wdq_channel.m_min_raw_data << - ", maximum " << wdq_channel.m_max_raw_data; + os2 << " Units: " << wdq_channel.m_units.c_str(); info_msg (os2.str().c_str()); std::ostringstream os3; - os3 << "Slope " << wdq_channel.m_slope << - ", Intercept " << wdq_channel.m_intercept; + os3 << " Raw minimum: " << wdq_channel.m_min_raw_data << + ", maximum: " << wdq_channel.m_max_raw_data; info_msg (os3.str().c_str()); + std::ostringstream os4; + os4 << " Scaled minimum: " << wdq_channel.m_min_scaled_data << + ", maximum: " << wdq_channel.m_max_scaled_data; + info_msg (os4.str().c_str()); + std::ostringstream os5; + os5 << " Slope " << wdq_channel.m_slope << + ", Intercept " << wdq_channel.m_intercept; + info_msg (os5.str().c_str()); } WavFile wav (wdq_channel, wav_fname); @@ -194,6 +220,18 @@ WindaqFile::ReadHeader () m_nData_bytes = tmp4; m_nSamples = (m_nData_bytes / m_nChannels) / 2; + lseek (m_fd, 36, SEEK_SET); + if (read (m_fd, &tmp4, sizeof(tmp4)) != sizeof(tmp4)) { + error_msg ("Error reading file"); + return false; + } + m_time_acq_start = tmp4; + if (read (m_fd, &tmp4, sizeof(tmp4)) != sizeof(tmp4)) { + error_msg ("Error reading file"); + return false; + } + m_time_acq_stop = tmp4; + // Verify Windaq signature lseek (m_fd, m_nHeader_bytes - 2, SEEK_SET); if (read (m_fd, &tmp2, sizeof(tmp2)) != sizeof(tmp2)) { @@ -371,8 +409,8 @@ WavFile::WriteFile () if ((m_fd = open (m_strFile.c_str(), O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == 0) { std::ostringstream os; - os << "Error opening output file ", << m_strFile.c_str(); - error_msg (os); + os << "Error opening output file " << m_strFile.c_str(); + error_msg (os.str().c_str()); return false; }