r3835: *** empty log message ***
[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.9 2003/01/21 13:06:17 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 #ifdef LINUX
39 #include <endian.h>
40 #if __BYTE_ORDER == __BIG_ENDIAN
41 #define WORDS_BIG_ENDIAN 1
42 #endif
43 #endif
44
45 extern const char* g_szIdStr;
46 extern bool g_quiet;
47 extern bool g_verbose;
48 extern bool g_debug;
49
50 #define MAX_INPUT_STR 256
51
52 void error_msg (const char *msg);
53 void info_msg (const char *msg);
54 void info_msg_sans_newline (const char *msg);
55
56 bool wdq2wav (const char* wdq_fname, const int channel, const char *wav_fname, bool play);
57
58 class WindaqFile
59 {
60 public:
61   WindaqFile (const char* fname);
62   ~WindaqFile ();
63   bool ReadHeader();
64
65   std::string m_strFile;
66   bool m_valid;
67   std::string m_error;
68   int m_fd;
69   unsigned int m_nChannels;
70   unsigned int m_nSamples;
71   double m_sample_rate;
72   unsigned int m_sr_denom, m_sr_numer;
73   unsigned short int m_nHeader_bytes, m_channel_offset, m_nBytes_channel_header;
74   unsigned int m_nData_bytes;
75   unsigned int m_time_acq_start;
76   unsigned int m_time_acq_stop;
77 };
78
79 class WindaqChannel 
80 {
81 public:
82   bool m_valid;
83   unsigned int m_channel;
84   std::string m_units;
85   double m_slope;
86   double m_intercept;
87   signed short int *m_data;
88   WindaqFile& r_wdq;
89   signed short int m_min_raw_data;
90   signed short int m_max_raw_data;
91   double m_max_scaled_data;
92   double m_min_scaled_data;
93
94   WindaqChannel (WindaqFile& wdq, const int channel);
95   ~WindaqChannel ();
96
97  private:
98   bool read_channel_data();
99 };
100
101
102 class WavFile 
103 {
104  public:
105   std::string m_strFile;
106   int m_fd;
107   bool m_valid;
108   unsigned long int m_nSamples;
109   double m_rate;
110   unsigned int m_nChannels;
111   unsigned int m_nBitsPerSample;
112   unsigned int m_nBytesPerSample;
113   signed short int* m_data;
114   unsigned long int m_nHeaderBytes;
115   unsigned long int m_nDataBytes;
116   unsigned long int m_nFileBytes;
117
118   WavFile (WindaqChannel& wdq_channel, const char* fname);
119   ~WavFile ();
120
121   bool WriteFile ();
122
123   bool Play();
124   
125  private:
126   bool fill_header();
127 };