e92e1ac6ed12eee201ff32aae34b513322f5ef2e
[wdq2wav.git] / wdq2wav.h
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **   Name:          wdq2wav.h
5 **   Purpose:       Header file for wdq2wav.cpp
6 **   Programmer:    Kevin Rosenberg <kevin@rosenberg.net>
7 **   Date Started:  Jan 2003
8 **
9 **  Copyright (c) 2003 Kevin Rosenberg
10 **
11 **  $Id: wdq2wav.h,v 1.8 2003/01/21 12:59:56 kevin Exp $
12 **
13 **  This program is free software; you can redistribute it and/or modify
14 **  it under the terms of the GNU General Public License (version 2) as
15 **  published by the Free Software Foundation.
16 **
17 **  This program is distributed in the hope that it will be useful,
18 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
19 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 **  GNU General Public License for more details.
21 **
22 **  You should have received a copy of the GNU General Public License
23 **  along with this program; if not, write to the Free Software
24 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25 ******************************************************************************/
26
27 #include <iostream>
28 #include <cstdio>
29 #include <cstring>
30 #include <string>
31 #include <sstream>
32 #include <ctime>
33 #include <fcntl.h>
34 #include <unistd.h>
35 #include <sys/types.h>
36 #include <sys/stat.h>
37
38 extern const char* g_szIdStr;
39 extern bool g_quiet;
40 extern bool g_verbose;
41 extern bool g_debug;
42
43 #define MAX_INPUT_STR 256
44
45 void error_msg (const char *msg);
46 void info_msg (const char *msg);
47 void info_msg_sans_newline (const char *msg);
48
49 bool wdq2wav (const char* wdq_fname, const int channel, const char *wav_fname, bool play);
50
51 class WindaqFile
52 {
53 public:
54   WindaqFile (const char* fname);
55   ~WindaqFile ();
56   bool ReadHeader();
57
58   std::string m_strFile;
59   bool m_valid;
60   std::string m_error;
61   int m_fd;
62   unsigned int m_nChannels;
63   unsigned int m_nSamples;
64   double m_sample_rate;
65   unsigned int m_sr_denom, m_sr_numer;
66   unsigned short int m_nHeader_bytes, m_channel_offset, m_nBytes_channel_header;
67   unsigned int m_nData_bytes;
68   unsigned int m_time_acq_start;
69   unsigned int m_time_acq_stop;
70 };
71
72 class WindaqChannel 
73 {
74 public:
75   bool m_valid;
76   unsigned int m_channel;
77   std::string m_units;
78   double m_slope;
79   double m_intercept;
80   signed short int *m_data;
81   WindaqFile& r_wdq;
82   signed short int m_min_raw_data;
83   signed short int m_max_raw_data;
84   double m_max_scaled_data;
85   double m_min_scaled_data;
86
87   WindaqChannel (WindaqFile& wdq, const int channel);
88   ~WindaqChannel ();
89
90  private:
91   bool read_channel_data();
92 };
93
94
95 class WavFile 
96 {
97  public:
98   std::string m_strFile;
99   int m_fd;
100   bool m_valid;
101   unsigned long int m_nSamples;
102   double m_rate;
103   unsigned int m_nChannels;
104   unsigned int m_nBitsPerSample;
105   unsigned int m_nBytesPerSample;
106   signed short int* m_data;
107   unsigned long int m_nHeaderBytes;
108   unsigned long int m_nDataBytes;
109   unsigned long int m_nFileBytes;
110
111   WavFile (WindaqChannel& wdq_channel, const char* fname);
112   ~WavFile ();
113
114   bool WriteFile ();
115
116   bool Play();
117   
118  private:
119   bool fill_header();
120 };