整理audio_buffer代码
This commit is contained in:
parent
f6173ce4b6
commit
976aa1a4d9
@ -1,20 +1,26 @@
|
||||
#include "audio_buffer.h"
|
||||
|
||||
#include <cstring>
|
||||
#if CPU_AMD64
|
||||
#include <experimental/simd>
|
||||
#endif
|
||||
#include "audio_buffer_pool.h"
|
||||
#include "misc/cpu_simd.h"
|
||||
#include "misc/likely.h"
|
||||
|
||||
#if CPU_AMD64
|
||||
#include <experimental/simd>
|
||||
using namespace std::experimental;
|
||||
#endif
|
||||
|
||||
void(*audio_buffer::add_func)(audio_buffer& in_buffer, audio_buffer& from_buffer, float percent);
|
||||
void(*audio_buffer::multiple_func)(audio_buffer& in_buffer, float percent);
|
||||
|
||||
#if CPU_AMD64
|
||||
#define DEFINE_SIMD_FUNC(simd_max) \
|
||||
constexpr size_t simd_size = (simd_max) / sizeof(sample_t) / 8; \
|
||||
add_func = &add_simd<simd_size>; \
|
||||
multiple_func = &multiple_simd<simd_size>;
|
||||
|
||||
template<int simd_size>
|
||||
void add_simd(audio_buffer& in_buffer, audio_buffer& from_buffer, float percent) {
|
||||
using namespace std::experimental;
|
||||
using simd_type = simd_abi::fixed_size<simd_size>;
|
||||
|
||||
simd<sample_t, simd_type> percent_simd(percent);
|
||||
@ -40,7 +46,6 @@ void add_simd(audio_buffer& in_buffer, audio_buffer& from_buffer, float percent)
|
||||
|
||||
template<int simd_size>
|
||||
void multiple_simd(audio_buffer& in_buffer, float percent) {
|
||||
using namespace std::experimental;
|
||||
using simd_type = simd_abi::fixed_size<simd_size>;
|
||||
|
||||
simd<sample_t, simd_type> percent_simd(percent);
|
||||
@ -79,16 +84,9 @@ void multiple_no_simd(audio_buffer& in_buffer, float percent) {
|
||||
}
|
||||
|
||||
audio_buffer::audio_buffer() {
|
||||
#if __cplusplus >= 202600L
|
||||
using namespace std::experimental;
|
||||
#endif
|
||||
static bool func_initialized = false;
|
||||
if (UNLIKELY(!func_initialized)) {
|
||||
cpuid cpu;
|
||||
#define DEFINE_SIMD_FUNC(simd_max) \
|
||||
constexpr size_t simd_size = (simd_max) / sizeof(sample_t) / 8; \
|
||||
add_func = &add_simd<simd_size>; \
|
||||
multiple_func = &multiple_simd<simd_size>;
|
||||
cpuid const cpu;
|
||||
#if CPU_AMD64
|
||||
if (cpu.support_avx512()) {
|
||||
DEFINE_SIMD_FUNC(512)
|
||||
@ -97,12 +95,9 @@ audio_buffer::audio_buffer() {
|
||||
} else if (cpu.support_sse()) {
|
||||
DEFINE_SIMD_FUNC(128)
|
||||
}
|
||||
#endif
|
||||
#if CPU_ARM
|
||||
// if (cpu.support_neon128()) {
|
||||
#elif CPU_ARM
|
||||
// if (cpu.support_neon()) {
|
||||
// DEFINE_SIMD_FUNC(128)
|
||||
// } else if (cpu.support_neon64()) {
|
||||
// DEFINE_SIMD_FUNC(64)
|
||||
// }
|
||||
#endif
|
||||
if (!add_func) {
|
||||
@ -110,7 +105,6 @@ audio_buffer::audio_buffer() {
|
||||
multiple_func = &multiple_no_simd;
|
||||
}
|
||||
func_initialized = true;
|
||||
#undef DEFINE_SIMD_FUNC
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,3 +158,5 @@ void audio_buffer::free() {
|
||||
get_audio_buffer_pool()->free(header);
|
||||
headers_.clear();
|
||||
}
|
||||
|
||||
#undef DEFINE_SIMD_FUNC
|
||||
|
@ -6,7 +6,7 @@
|
||||
#ifdef _MSC_VER
|
||||
#include <intrin.h>
|
||||
#else
|
||||
#if !CPU_ARM
|
||||
#if CPU_AMD64
|
||||
#include <cpuid.h>
|
||||
#else
|
||||
#include <sys/sysctl.h>
|
||||
@ -22,8 +22,7 @@ enum class simd_type {
|
||||
avx,
|
||||
avx2,
|
||||
avx512,
|
||||
neon64,
|
||||
neon128,
|
||||
neon,
|
||||
};
|
||||
|
||||
inline std::vector<simd_type> get_simd_support_type() {
|
||||
@ -96,15 +95,7 @@ public:
|
||||
}
|
||||
|
||||
[[nodiscard]] bool support_neon() const {
|
||||
return support_neon64() || support_neon128();
|
||||
}
|
||||
|
||||
[[nodiscard]] bool support_neon64() const {
|
||||
return support_simd(simd_type::neon64);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool support_neon128() const {
|
||||
return support_simd(simd_type::neon128);
|
||||
return support_simd(simd_type::neon);
|
||||
}
|
||||
private:
|
||||
std::vector<simd_type> simd_types;
|
||||
|
3
third_party/mempool/mempool.h
vendored
3
third_party/mempool/mempool.h
vendored
@ -6,8 +6,6 @@ template<int32_t alignment = 64>
|
||||
class mempool {
|
||||
public:
|
||||
mempool(size_t pool_size = 1024000) { // 1024KB
|
||||
// 分配一个缓存对齐的内存
|
||||
// const auto space = static_cast<u_char*>(operator new(pool_size, std::align_val_t(alignment)));
|
||||
const auto space = static_cast<u_char*>(malloc(pool_size));
|
||||
|
||||
mem_pool_ = reinterpret_cast<ncx_slab_pool_t*>(space);
|
||||
@ -18,7 +16,6 @@ public:
|
||||
ncx_slab_init(mem_pool_);
|
||||
}
|
||||
~mempool() {
|
||||
// operator delete(mem_pool_->addr, std::align_val_t(alignment));
|
||||
free(mem_pool_->addr);
|
||||
}
|
||||
[[nodiscard]] void* alloc(size_t size) const {
|
||||
|
Loading…
x
Reference in New Issue
Block a user