Kiwano Engine v1.3.x
AudioData.h
1// Copyright (c) 2016-2018 Kiwano - Nomango
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21#pragma once
22#include <kiwano/core/BinaryData.h>
23#include <kiwano/base/ObjectBase.h>
24#include <kiwano/platform/NativeObject.hpp>
25
26namespace kiwano
27{
28namespace audio
29{
30
40enum class AudioFormat
41{
42 PCM,
43};
44
50{
51 AudioFormat format = AudioFormat::PCM;
52 uint16_t channels = 2;
53 uint32_t samples_per_sec = 44100;
54 uint16_t bits_per_sample = 16;
55 uint16_t block_align = 4;
56
57 inline uint32_t avg_bytes_per_sec() const noexcept
58 {
59 return uint32_t(this->samples_per_sec * this->block_align);
60 }
61};
62
67class AudioData : public NativeObject
68{
69public:
74 AudioData(const BinaryData& data, const AudioMeta& meta);
75
78 AudioMeta GetMeta() const;
79
82 BinaryData GetData() const;
83
84protected:
85 AudioData() = default;
86
87protected:
88 BinaryData data_;
89 AudioMeta meta_;
90};
91
94} // namespace audio
95} // namespace kiwano
含有本地指针的对象
Definition: NativeObject.hpp:32
音频数据
Definition: AudioData.h:68
BinaryData GetData() const
获取数据
Definition: AudioData.cpp:38
AudioMeta GetMeta() const
获取音频元数据
Definition: AudioData.cpp:33
AudioFormat
音频格式
Definition: AudioData.h:41
二进制数据
Definition: BinaryData.h:30
音频元数据
Definition: AudioData.h:50
uint16_t block_align
块对齐,PCM格式通常是 (channels * bits_per_sample) / 8
Definition: AudioData.h:55
uint16_t channels
声道,单声道为1,立体声为2
Definition: AudioData.h:52
AudioFormat format
音频格式
Definition: AudioData.h:51
uint16_t bits_per_sample
位深,PCM格式为 8 或 16
Definition: AudioData.h:54
uint32_t samples_per_sec
采样率,11025 表示 11.025kHz。PCM格式的采样率通常为44.1kHz
Definition: AudioData.h:53