Beatmup
wav_utilities.h
Go to the documentation of this file.
1 /*
2  Beatmup image and signal processing library
3  Copyright (C) 2019, lnstadrum
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 #include <cstdint>
21 #include "../exception.h"
22 
23 namespace Beatmup {
24 namespace Audio {
25 
26 /**
27  WAV files reading and writing
28 */
29 namespace WAV {
30 
31  /**
32  WAV file header
33  */
34  class Header {
35  public:
36  uint32_t
37  m_RIFF, // "RIFF"
38  chunkSize, // file size minus 8,
39  m_WAVE, // "WAVE"
40  m_fmt_, // "fmt "
42  uint16_t
44  numChannels; // number of channels
45  uint32_t
46  sampleRate, // sampling frequency
48  uint16_t
50  bitsPerSample; // bps
51  uint32_t
53  dataSizeBytes; // remaining size in bytes
54 
55  static const uint32_t
56  __RIFF = 1179011410,
57  __WAVE = 1163280727,
58  __fmt_ = 544501094,
59  __data = 1635017060;
60 
61  void set(uint32_t sampleRate, uint16_t bitsPerSample, uint16_t channelCount, uint32_t dataSize);
62  };
63 
64 
65  /**
66  Communicates an error related to a WAV file content
67  */
68  class InvalidWavFile: public Exception {
69  public:
71  static void check(Header& header);
72  };
73 }
74 }
75 }
static const uint32_t __RIFF
Definition: wav_utilities.h:56
static const uint32_t __fmt_
Definition: wav_utilities.h:58
static const uint32_t __WAVE
Definition: wav_utilities.h:57
void set(uint32_t sampleRate, uint16_t bitsPerSample, uint16_t channelCount, uint32_t dataSize)
static const uint32_t __data
Definition: wav_utilities.h:59
Communicates an error related to a WAV file content.
Definition: wav_utilities.h:68
static void check(Header &header)
InvalidWavFile(const char *message)
Definition: wav_utilities.h:70
Base class for all exceptions.
Definition: exception.h:37
std::string message
Definition: exception.h:39