Beatmup
wav_utilities.cpp
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
#include "
wav_utilities.h
"
20
21
using namespace
Beatmup::Audio::WAV
;
22
23
24
void
Header::set
(uint32_t sampleRate, uint16_t bitsPerSample, uint16_t channelCount, uint32_t dataSize) {
25
m_RIFF
=
__RIFF
;
26
m_WAVE
=
__WAVE
;
27
m_fmt_
=
__fmt_
;
28
m_data
=
__data
;
29
__16
= 16;
30
audioFormat
= 1;
31
this->sampleRate =
sampleRate
;
32
this->bitsPerSample =
bitsPerSample
;
33
this->
numChannels
= channelCount;
34
blockAlign
= channelCount *
bitsPerSample
/ 8;
35
byteRate
=
sampleRate
*
blockAlign
;
36
dataSizeBytes
= 0;
37
this->
dataSizeBytes
= dataSize;
38
this->
chunkSize
=
sizeof
(
Header
) + dataSize - 8;
39
}
40
41
42
void
InvalidWavFile::check
(
Header
& header) {
43
if
(header.
m_RIFF
!=
Header::__RIFF
)
44
throw
InvalidWavFile
(
"Incorrect WAV file: 'RIFF' marker missing"
);
45
46
if
(header.
m_WAVE
!=
Header::__WAVE
)
47
throw
InvalidWavFile
(
"Incorrect WAV file: 'WAVE' marker missing"
);
48
49
if
(header.
m_fmt_
!=
Header::__fmt_
)
50
throw
InvalidWavFile
(
"Incorrect WAV file: 'fmt ' marker missing"
);
51
52
if
(header.
m_data
!=
Header::__data
)
53
throw
InvalidWavFile
(
"Incorrect WAV file: 'data' marker missing"
);
54
55
if
(header.
__16
!= 16)
56
throw
InvalidWavFile
(
"Incorrect WAV file: bad subchunk size"
);
57
58
if
(header.
audioFormat
!= 1)
59
throw
InvalidWavFile
(
"Incorrect WAV file: unsupported audio format"
);
60
61
if
(
sizeof
(header) + header.
dataSizeBytes
!= header.
chunkSize
+ 8)
62
throw
InvalidWavFile
(
"Incorrect WAV file: size mismatch"
);
63
}
Beatmup::Audio::WAV::Header
WAV file header.
Definition:
wav_utilities.h:34
Beatmup::Audio::WAV::Header::__RIFF
static const uint32_t __RIFF
Definition:
wav_utilities.h:56
Beatmup::Audio::WAV::Header::m_fmt_
uint32_t m_fmt_
Definition:
wav_utilities.h:40
Beatmup::Audio::WAV::Header::byteRate
uint32_t byteRate
Definition:
wav_utilities.h:47
Beatmup::Audio::WAV::Header::dataSizeBytes
uint32_t dataSizeBytes
Definition:
wav_utilities.h:53
Beatmup::Audio::WAV::Header::m_data
uint32_t m_data
Definition:
wav_utilities.h:52
Beatmup::Audio::WAV::Header::chunkSize
uint32_t chunkSize
Definition:
wav_utilities.h:38
Beatmup::Audio::WAV::Header::sampleRate
uint32_t sampleRate
Definition:
wav_utilities.h:46
Beatmup::Audio::WAV::Header::m_RIFF
uint32_t m_RIFF
Definition:
wav_utilities.h:37
Beatmup::Audio::WAV::Header::blockAlign
uint16_t blockAlign
Definition:
wav_utilities.h:49
Beatmup::Audio::WAV::Header::__16
uint32_t __16
Definition:
wav_utilities.h:41
Beatmup::Audio::WAV::Header::__fmt_
static const uint32_t __fmt_
Definition:
wav_utilities.h:58
Beatmup::Audio::WAV::Header::__WAVE
static const uint32_t __WAVE
Definition:
wav_utilities.h:57
Beatmup::Audio::WAV::Header::audioFormat
uint16_t audioFormat
Definition:
wav_utilities.h:43
Beatmup::Audio::WAV::Header::m_WAVE
uint32_t m_WAVE
Definition:
wav_utilities.h:39
Beatmup::Audio::WAV::Header::set
void set(uint32_t sampleRate, uint16_t bitsPerSample, uint16_t channelCount, uint32_t dataSize)
Definition:
wav_utilities.cpp:24
Beatmup::Audio::WAV::Header::bitsPerSample
uint16_t bitsPerSample
Definition:
wav_utilities.h:50
Beatmup::Audio::WAV::Header::numChannels
uint16_t numChannels
Definition:
wav_utilities.h:44
Beatmup::Audio::WAV::Header::__data
static const uint32_t __data
Definition:
wav_utilities.h:59
Beatmup::Audio::WAV::InvalidWavFile::check
static void check(Header &header)
Definition:
wav_utilities.cpp:42
Beatmup::Audio::WAV::InvalidWavFile::InvalidWavFile
InvalidWavFile(const char *message)
Definition:
wav_utilities.h:70
Beatmup::Audio::WAV
WAV files reading and writing.
Definition:
wav_utilities.h:29
wav_utilities.h
core
audio
wav_utilities.cpp
Generated on Tue Nov 21 2023 13:54:26 for Beatmup by
1.9.1