-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudio_format.h
More file actions
33 lines (24 loc) · 751 Bytes
/
audio_format.h
File metadata and controls
33 lines (24 loc) · 751 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// SPDX-License-Identifier: MIT
#ifndef AUDIO_FORMAT_H
#define AUDIO_FORMAT_H
#include <cstddef>
namespace plac {
struct AudioFormat {
unsigned int bits;
unsigned int channels;
unsigned int rate;
};
constexpr bool operator==(const AudioFormat lhs, const AudioFormat rhs) {
return (lhs.bits == rhs.bits) && (lhs.channels == rhs.channels) && (lhs.rate == rhs.rate);
}
constexpr bool operator!=(const AudioFormat lhs, const AudioFormat rhs) {
return !(lhs == rhs);
}
constexpr size_t AsBytes(AudioFormat format, size_t frames) {
return frames * format.bits * format.channels / 8;
}
constexpr size_t AsFrames(AudioFormat format, size_t bytes) {
return bytes * 8 / format.bits / format.channels;
}
} // namespace plac
#endif