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