2023-10-06 18:07:07 +08:00
|
|
|
|
// Copyright (c) 2016-2018 Kiwano - Nomango
|
|
|
|
|
|
//
|
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
|
|
//
|
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
|
|
//
|
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
|
// THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
#include <kiwano/core/BinaryData.h>
|
|
|
|
|
|
#include <kiwano/base/ObjectBase.h>
|
|
|
|
|
|
#include <kiwano/platform/NativeObject.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
namespace kiwano
|
|
|
|
|
|
{
|
|
|
|
|
|
namespace audio
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
KGE_DECLARE_SMART_PTR(AudioData);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \addtogroup Audio
|
|
|
|
|
|
* @{
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \~chinese
|
|
|
|
|
|
* @brief <EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD>ʽ
|
|
|
|
|
|
*/
|
|
|
|
|
|
enum class AudioFormat
|
|
|
|
|
|
{
|
|
|
|
|
|
PCM,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \~chinese
|
|
|
|
|
|
* @brief <EFBFBD><EFBFBD>ƵԪ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
*/
|
|
|
|
|
|
struct AudioMeta
|
|
|
|
|
|
{
|
|
|
|
|
|
AudioFormat format = AudioFormat::PCM; ///< <20><>Ƶ<EFBFBD><C6B5>ʽ
|
|
|
|
|
|
uint16_t channels = 2; ///< <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ1<CEAA><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ2
|
|
|
|
|
|
uint32_t samples_per_sec = 44100; ///< <20><><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD>11025 <20><>ʾ 11.025kHz<EFBFBD><EFBFBD>PCM<EFBFBD><EFBFBD>ʽ<EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD>Ϊ44.1kHz
|
|
|
|
|
|
uint16_t bits_per_sample = 16; ///< λ<>PCM<43><4D>ʽΪ 8 <20><> 16
|
|
|
|
|
|
uint16_t block_align = 4; ///< <20><><EFBFBD><EFBFBD><EFBFBD>룬PCM<43><4D>ʽͨ<CABD><CDA8><EFBFBD><EFBFBD> (channels * bits_per_sample) / 8
|
2023-10-08 15:05:45 +08:00
|
|
|
|
|
|
|
|
|
|
inline uint32_t avg_bytes_per_sec() const noexcept
|
|
|
|
|
|
{
|
|
|
|
|
|
return uint32_t(this->samples_per_sec * this->block_align);
|
|
|
|
|
|
}
|
2023-10-06 18:07:07 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \~chinese
|
|
|
|
|
|
* @brief <EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
*/
|
|
|
|
|
|
class AudioData : public NativeObject
|
|
|
|
|
|
{
|
|
|
|
|
|
public:
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @param data <20><>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @param meta <20><>ƵԪ<C6B5><D4AA><EFBFBD><EFBFBD>
|
|
|
|
|
|
AudioData(const BinaryData& data, const AudioMeta& meta);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1>ƵԪ<C6B5><D4AA><EFBFBD><EFBFBD>
|
|
|
|
|
|
AudioMeta GetMeta() const;
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|
|
|
|
|
BinaryData GetData() const;
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
AudioData() = default;
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
BinaryData data_;
|
|
|
|
|
|
AudioMeta meta_;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** @} */
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace audio
|
|
|
|
|
|
} // namespace kiwano
|