r8646: support new windaq format
authorKevin M. Rosenberg <kevin@rosenberg.net>
Tue, 10 Feb 2004 23:19:38 +0000 (23:19 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Tue, 10 Feb 2004 23:19:38 +0000 (23:19 +0000)
msvc/wdq2wav/wdq2wav.vcproj
wdq2wav.cpp
wdq2wav.h

index 0307981d35f444050fc0c33053d1d4b3da75d1e7..8d4b606716c24dc0e4fcd40900c228cf4f5be69f 100755 (executable)
@@ -1,7 +1,7 @@
-<?xml version="1.0" encoding = "Windows-1252"?>\r
+<?xml version="1.0" encoding="Windows-1252"?>\r
 <VisualStudioProject\r
        ProjectType="Visual C++"\r
-       Version="7.00"\r
+       Version="7.10"\r
        Name="wdq2wav"\r
        ProjectGUID="{97BEA78D-B87B-48A9-B557-C47E39F6FAD8}"\r
        Keyword="Win32Proj">\r
@@ -19,6 +19,7 @@
                        <Tool\r
                                Name="VCCLCompilerTool"\r
                                Optimization="0"\r
+                               AdditionalIncludeDirectories="\home\kevin\debian\src\wdq2wav\;\home\kevin\debian\src\wdq2wav\msvc\wdq2wav"\r
                                PreprocessorDefinitions="WIN32;HAVE_STRING_H;__STDC__;__GNU_LIBRARY__"\r
                                MinimalRebuild="TRUE"\r
                                BasicRuntimeChecks="3"\r
                                Name="VCResourceCompilerTool"/>\r
                        <Tool\r
                                Name="VCWebServiceProxyGeneratorTool"/>\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"/>\r
                        <Tool\r
                                Name="VCWebDeploymentTool"/>\r
+                       <Tool\r
+                               Name="VCManagedWrapperGeneratorTool"/>\r
+                       <Tool\r
+                               Name="VCAuxiliaryManagedWrapperGeneratorTool"/>\r
                </Configuration>\r
                <Configuration\r
                        Name="Release|Win32"\r
@@ -64,7 +71,7 @@
                                Optimization="2"\r
                                InlineFunctionExpansion="1"\r
                                OmitFramePointers="TRUE"\r
-                               AdditionalIncludeDirectories="/home/kevin/debian/src/wdq2wav,/home/kevin/debian/src/wdq2wav/msvc/wdq2wav"\r
+                               AdditionalIncludeDirectories="\home\kevin\debian\src\wdq2wav\;\home\kevin\debian\src\wdq2wav\msvc\wdq2wav"\r
                                PreprocessorDefinitions="WIN32;HAVE_STRING_H;__STDC__;__GNU_LIBRARY__"\r
                                StringPooling="TRUE"\r
                                RuntimeLibrary="4"\r
                                Name="VCResourceCompilerTool"/>\r
                        <Tool\r
                                Name="VCWebServiceProxyGeneratorTool"/>\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"/>\r
                        <Tool\r
                                Name="VCWebDeploymentTool"/>\r
+                       <Tool\r
+                               Name="VCManagedWrapperGeneratorTool"/>\r
+                       <Tool\r
+                               Name="VCAuxiliaryManagedWrapperGeneratorTool"/>\r
                </Configuration>\r
        </Configurations>\r
+       <References>\r
+       </References>\r
        <Files>\r
                <Filter\r
                        Name="Source Files"\r
index 03b6557fa6b5ed38638ca46f1ce5e1e6be749b1b..3e5d7498cec955908607d6c5a7025192ee7f2f87 100644 (file)
@@ -335,6 +335,25 @@ bool read_int4 (int fd, unsigned int& n)
   return true;
 }
 
+bool read_float8 (int fd, double& f)
+{
+  unsigned char buf[8];
+  if (read (fd, &buf, 8) != 8)
+    return false;
+
+#if WORDS_BIG_ENDIAN
+  unsigned char c;
+  c = buf[0]; buf[0] = buf[7]; buf[7] = c;
+  c = buf[1]; buf[1] = buf[6]; buf[6] = c;
+  c = buf[2]; buf[2] = buf[5]; buf[5] = c;
+  c = buf[3]; buf[3] = buf[4]; buf[4] = c;
+#endif
+
+  f = *(reinterpret_cast<double*>(buf));
+
+  return true;
+}
+
 bool
 WindaqFile::ReadHeader ()
 {
@@ -349,7 +368,9 @@ WindaqFile::ReadHeader ()
   lseek (0, 0, SEEK_SET);
   if (! read_int2 (m_fd, tmp2))
     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;
@@ -358,8 +379,6 @@ WindaqFile::ReadHeader ()
     return false;
 
   m_sr_numer |= tmp2;
-  m_sample_rate = (double) m_sr_numer / (double) (m_sr_denom * m_nChannels);
-
   if (! read_int2 (m_fd, tmp2))
     return false;
 
@@ -368,12 +387,25 @@ WindaqFile::ReadHeader ()
   
   if (! read_int2 (m_fd, m_nHeader_bytes))
     return false;
-  
+
+  m_nMaxChannels = (m_nHeader_bytes - 112) / 36;
+  printf ("m_nMaxChannels = %d\n", m_nMaxChannels);
+
   if (! read_int4 (m_fd, m_nData_bytes))
     return false;
 
   m_nSamples = (m_nData_bytes / m_nChannels) / 2;
 
+  lseek (m_fd, 28, SEEK_SET);
+  if (! read_float8 (m_fd, m_time_between_channel_samples))
+         return false;
+  printf ("time_between_channel_samples=%lf\n", m_time_between_channel_samples);
+
+  if (m_format == 0 || m_format == 1)
+        m_sample_rate = (double) m_nChannels / m_time_between_channel_samples;
+  else         
+         m_sample_rate = (double) m_sr_numer / (double) (m_sr_denom * m_nChannels);
+
   lseek (m_fd, 36, SEEK_SET);
   if (! read_int4 (m_fd, m_time_acq_start))
     return false;
@@ -395,7 +427,6 @@ WindaqFile::ReadHeader ()
   m_valid = true;
   return true;
 }
-
   
 WindaqChannel::WindaqChannel (WindaqFile& wdq, const int channel)
   : r_wdq(wdq), m_data(0), m_slope(0), m_intercept (0), m_channel(channel),
@@ -420,26 +451,6 @@ WindaqChannel::~WindaqChannel ()
     delete m_data;
 }
 
-bool get_float8 (int fd, double& f)
-{
-  unsigned char buf[8];
-  if (read (fd, &buf, 8) != 8)
-    return false;
-
-#if WORDS_BIG_ENDIAN
-  unsigned char c;
-  c = buf[0]; buf[0] = buf[7]; buf[7] = c;
-  c = buf[1]; buf[1] = buf[6]; buf[6] = c;
-  c = buf[2]; buf[2] = buf[5]; buf[5] = c;
-  c = buf[3]; buf[3] = buf[4]; buf[4] = c;
-#endif
-
-  f = *(reinterpret_cast<double*>(buf));
-
-  return true;
-}
-
-
 bool
 WindaqChannel::read_channel_data ()
 {
@@ -450,10 +461,10 @@ WindaqChannel::read_channel_data ()
   lseek (fd, r_wdq.m_channel_offset + 8 + 
         (m_channel - 1) * r_wdq.m_nBytes_channel_header,
         SEEK_SET);
-  if (! get_float8 (fd, m_slope))
+  if (! read_float8 (fd, m_slope))
     return false;
 
-  if (! get_float8 (fd, m_intercept))
+  if (! read_float8 (fd, m_intercept))
     return false;
 
   char units[7];
@@ -465,6 +476,7 @@ WindaqChannel::read_channel_data ()
   m_units = units;
  
   long int row_bytes = 2 * r_wdq.m_nChannels;
+
   signed short int *sample_row = new signed short int [row_bytes];
   
   signed short int* psample = &sample_row[m_channel - 1];
index 6cff82bace00595a989cb9cdccbff9cbd2f11773..688ddc68e269c428965d9d517d80fb479ee01534 100644 (file)
--- a/wdq2wav.h
+++ b/wdq2wav.h
@@ -72,6 +72,8 @@ public:
   bool m_valid;
   std::string m_error;
   int m_fd;
+  int m_format;
+  int m_nMaxChannels;
   int m_nChannels;
   unsigned long int m_nSamples;
   double m_sample_rate;
@@ -81,6 +83,7 @@ public:
   unsigned int m_nData_bytes;
   unsigned int m_time_acq_start;
   unsigned int m_time_acq_stop;
+  double m_time_between_channel_samples;
 };
 
 class WindaqChannel