HARDT - The Ham Radio DSP Toolkit
hwav.h
1 #ifndef __HWAV_H
2 #define __HWAV_H
3 
4 #include "hsoundcard.h"
5 #include <iostream>
6 #include "stdlib.h"
7 #include <stdio.h>
8 #include <iostream>
9 #include <string.h>
10 
11 #include <cstdlib>
12 #include <string>
13 #include <unistd.h>
14 
24 class HWav
25 {
26  private:
27 
28  // Header initializer. All fields that must be modified uses
29  // little endian byte order
30  //
31  // See http://soundfile.sapp.org/doc/WaveFormat/ for a very good
32  // primer on the wav format. The test data used in this test is
33  // sourced from that page.
34  const uint8_t emptyHeader[44] = {
35  0x52, // 'R'
36  0x49, // 'I'
37  0x46, // 'F'
38  0x46, // 'F'
39  0x00, // Size of data
40  0x00, // ..
41  0x00, // ..
42  0x00, // ..
43  0x57, // 'W'
44  0x41, // 'A'
45  0x56, // 'V'
46  0x45, // 'E'
47 
48  0x66, // 'f'
49  0x6d, // 'm'
50  0x74, // 't'
51  0x20, // (blankspace)
52  0x10, // Chunksize for 'fmt' chunk. Always 16 bytes for wav
53  0x00, // ..
54  0x00, // ..
55  0x00, // ..
56  0x01, // Audio format = 1 (PCM)
57  0x00, // ..
58  0x00, // Number of channels
59  0x00, // ..
60  0x00, // Samplerate
61  0x00, // ..
62  0x00, // ..
63  0x00, // ..
64  0x00, // Byterate
65  0x00, // ..
66  0x00, // ..
67  0x00, // ..
68  0x00, // Blockalign = total number of bytes for all channels for 1 sample
69  0x00, // ..
70  0x00, // Bits per sample
71  0x00, // ..
72 
73  0x64, // 'd'
74  0x61, // 'a'
75  0x74, // 't'
76  0x61, // 'a'
77  0x00, // Total size of data
78  0x00, // ..
79  0x00, // ..
80  0x00, // ..
81  };
82 
83  const char* _filename;
84 
85  protected:
86 
90  struct WavHeader
92  {
93 
94  uint8_t ChunkId[4];
95  uint32_t ChunkSize;
96  uint8_t Format[4];
97 
98  uint8_t SubChunk_1_Id[4];
99  uint32_t SubChunk_1_Size;
100  uint16_t AudioFormat;
101  uint16_t NumChannels;
102  uint32_t SampleRate;
103  uint32_t ByteRate;
104  uint16_t BlockAlign;
105  uint16_t BitsPerSample;
106 
107  uint8_t SubChunk_2_Id[4];
108  uint32_t SubChunk_2_Size;
109  };
111 
113  WavHeader _header;
114 
116  HWav(HWav const& wav):
117  _header(wav._header),
118  _filename(wav._filename)
119  {}
120 
122  HWav(const char* filename, H_SAMPLE_FORMAT format, int channels, H_SAMPLE_RATE rate);
123 
124  public:
125 
127  H_SAMPLE_FORMAT GetFormat();
128 
130  int GetChannels();
131 
133  H_SAMPLE_RATE GetRate();
134 
136  size_t GetSize();
137 
140  const char* GetFilename();
141 
143  HWav(const char* filename);
144 };
145 
146 #endif
HWav::GetRate
H_SAMPLE_RATE GetRate()
Definition: hwav.cpp:102
HWav::GetFormat
H_SAMPLE_FORMAT GetFormat()
Definition: hwav.cpp:83
HWav::_header
WavHeader _header
Definition: hwav.h:113
HWav::GetFilename
const char * GetFilename()
Definition: hwav.cpp:133
HWav
Definition: hwav.h:24
HWav::HWav
HWav(HWav const &wav)
Definition: hwav.h:116
HWav::GetChannels
int GetChannels()
Definition: hwav.cpp:97
HWav::GetSize
size_t GetSize()
Definition: hwav.cpp:128