Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小白菜888
Obs Studio
提交
f3d0272f
O
Obs Studio
项目概览
小白菜888
/
Obs Studio
通知
4
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Obs Studio
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f3d0272f
编写于
7月 25, 2016
作者:
S
Simon
提交者:
jp9000
7月 25, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
obs-filters: Add speexdsp-based noise suppression filter
上级
0d294cc0
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
221 addition
and
2 deletion
+221
-2
plugins/obs-filters/CMakeLists.txt
plugins/obs-filters/CMakeLists.txt
+23
-2
plugins/obs-filters/data/locale/en-US.ini
plugins/obs-filters/data/locale/en-US.ini
+2
-0
plugins/obs-filters/noise-suppress-filter.c
plugins/obs-filters/noise-suppress-filter.c
+186
-0
plugins/obs-filters/obs-filters-config.h.in
plugins/obs-filters/obs-filters-config.h.in
+3
-0
plugins/obs-filters/obs-filters.c
plugins/obs-filters/obs-filters.c
+7
-0
未找到文件。
plugins/obs-filters/CMakeLists.txt
浏览文件 @
f3d0272f
project
(
obs-filters
)
find_package
(
Libspeexdsp QUIET
)
if
(
LIBSPEEXDSP_FOUND
)
set
(
obs-filters_LIBSPEEXDSP_SOURCES
noise-suppress-filter.c
)
set
(
obs-filters_LIBSPEEXDSP_LIBRARIES
${
LIBSPEEXDSP_LIBRARIES
}
)
else
()
message
(
STATUS
"Speexdsp library not found, speexdsp filters disabled"
)
endif
()
configure_file
(
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/obs-filters-config.h.in"
"
${
CMAKE_BINARY_DIR
}
/plugins/obs-filters/config/obs-filters-config.h"
)
set
(
obs-filters_config_HEADERS
"
${
CMAKE_BINARY_DIR
}
/plugins/obs-filters/config/obs-filters-config.h"
)
include_directories
(
${
LIBSPEEXDSP_INCLUDE_DIRS
}
"
${
CMAKE_BINARY_DIR
}
/plugins/obs-filters/config"
)
set
(
obs-filters_SOURCES
obs-filters.c
color-filter.c
...
...
@@ -15,8 +33,11 @@ set(obs-filters_SOURCES
mask-filter.c
)
add_library
(
obs-filters MODULE
${
obs-filters_SOURCES
}
)
${
obs-filters_SOURCES
}
${
obs-filters_config_HEADERS
}
${
obs-filters_LIBSPEEXDSP_SOURCES
}
)
target_link_libraries
(
obs-filters
libobs
)
libobs
${
obs-filters_LIBSPEEXDSP_LIBRARIES
}
)
install_obs_plugin_with_data
(
obs-filters data
)
plugins/obs-filters/data/locale/en-US.ini
浏览文件 @
f3d0272f
...
...
@@ -8,6 +8,7 @@ ColorKeyFilter="Color Key"
SharpnessFilter
=
"Sharpen"
ScaleFilter
=
"Scaling/Aspect Ratio"
NoiseGate
=
"Noise Gate"
NoiseSuppress
=
"Noise Suppression"
Gain
=
"Gain"
DelayMs
=
"Delay (milliseconds)"
Type
=
"Type"
...
...
@@ -59,3 +60,4 @@ ScaleFiltering.Point="Point"
ScaleFiltering.Bilinear
=
"Bilinear"
ScaleFiltering.Bicubic
=
"Bicubic"
ScaleFiltering.Lanczos
=
"Lanczos"
NoiseSuppress.SuppressLevel
=
"Suppression Level (dB)"
plugins/obs-filters/noise-suppress-filter.c
0 → 100644
浏览文件 @
f3d0272f
#include <stdint.h>
#include <inttypes.h>
#include <obs-module.h>
#include <speex/speex_preprocess.h>
/* -------------------------------------------------------- */
#define do_log(level, format, ...) \
blog(level, "[noise suppress: '%s'] " format, \
obs_source_get_name(ng->context), ##__VA_ARGS__)
#define warn(format, ...) do_log(LOG_WARNING, format, ##__VA_ARGS__)
#define info(format, ...) do_log(LOG_INFO, format, ##__VA_ARGS__)
#ifdef _DEBUG
#define debug(format, ...) do_log(LOG_DEBUG, format, ##__VA_ARGS__)
#else
#define debug(format, ...)
#endif
/* -------------------------------------------------------- */
#define S_SUPPRESS_LEVEL "suppress_level"
#define MT_ obs_module_text
#define TEXT_SUPPRESS_LEVEL MT_("NoiseSuppress.SuppressLevel")
#define MAX_PREPROC_CHANNELS 2
/* -------------------------------------------------------- */
struct
noise_suppress_data
{
obs_source_t
*
context
;
/* Speex preprocessor state */
SpeexPreprocessState
*
states
[
MAX_PREPROC_CHANNELS
];
/* 16 bit PCM buffers */
spx_int16_t
*
segment_buffers
[
MAX_PREPROC_CHANNELS
];
int
suppress_level
;
};
/* -------------------------------------------------------- */
#define SUP_MIN -60
#define SUP_MAX 0
static
const
float
c_32_to_16
=
(
float
)
INT16_MAX
;
static
const
float
c_16_to_32
=
((
float
)
INT16_MAX
+
1
.
0
f
);
/* -------------------------------------------------------- */
static
const
char
*
noise_suppress_name
(
void
*
unused
)
{
UNUSED_PARAMETER
(
unused
);
return
obs_module_text
(
"NoiseSuppress"
);
}
static
void
noise_suppress_destroy
(
void
*
data
)
{
struct
noise_suppress_data
*
ng
=
data
;
for
(
size_t
i
=
0
;
i
<
MAX_PREPROC_CHANNELS
;
i
++
)
{
speex_preprocess_state_destroy
(
ng
->
states
[
i
]);
bfree
(
ng
->
segment_buffers
[
i
]);
}
bfree
(
ng
);
}
static
inline
void
alloc_channel
(
struct
noise_suppress_data
*
ng
,
uint32_t
sample_rate
,
size_t
channel
,
uint32_t
size
)
{
if
(
ng
->
states
[
channel
])
return
;
debug
(
"Create channel %d speex state"
,
(
int
)
channel
);
ng
->
states
[
channel
]
=
speex_preprocess_state_init
(
size
,
sample_rate
);
if
(
!
ng
->
segment_buffers
[
channel
])
{
ng
->
segment_buffers
[
channel
]
=
bzalloc
(
size
*
sizeof
(
spx_int16_t
));
debug
(
"Create channel %d speex buffer: size = %"
PRIu32
,
(
int
)
channel
,
size
);
}
}
static
void
noise_suppress_update
(
void
*
data
,
obs_data_t
*
s
)
{
struct
noise_suppress_data
*
ng
=
data
;
int
suppress_level
=
(
int
)
obs_data_get_int
(
s
,
S_SUPPRESS_LEVEL
);
uint32_t
sample_rate
=
audio_output_get_sample_rate
(
obs_get_audio
());
uint32_t
segment_size
=
sample_rate
/
100
;
size_t
channels
=
audio_output_get_channels
(
obs_get_audio
());
ng
->
suppress_level
=
suppress_level
;
debug
(
"channels = %d"
,
(
int
)
channels
);
debug
(
"sample_rate = %"
PRIu32
,
sample_rate
);
debug
(
"segment_size = %u"
PRIu32
,
segment_size
);
debug
(
"block size = %d"
,
(
int
)
audio_output_get_block_size
(
obs_get_audio
()));
/* One speex state for each channel (limit 2) */
for
(
size_t
i
=
0
;
i
<
channels
;
i
++
)
alloc_channel
(
ng
,
sample_rate
,
i
,
segment_size
);
}
static
void
*
noise_suppress_create
(
obs_data_t
*
settings
,
obs_source_t
*
filter
)
{
struct
noise_suppress_data
*
ng
=
bzalloc
(
sizeof
(
struct
noise_suppress_data
));
ng
->
context
=
filter
;
noise_suppress_update
(
ng
,
settings
);
return
ng
;
}
static
inline
void
process_channel
(
struct
noise_suppress_data
*
ng
,
size_t
channel
,
size_t
frames
,
float
*
adata
[
2
])
{
/* Set args */
speex_preprocess_ctl
(
ng
->
states
[
channel
],
SPEEX_PREPROCESS_SET_NOISE_SUPPRESS
,
&
ng
->
suppress_level
);
/* Convert to 16bit */
for
(
size_t
i
=
0
;
i
<
frames
;
i
++
)
ng
->
segment_buffers
[
channel
][
i
]
=
(
spx_int16_t
)(
adata
[
channel
][
i
]
*
c_32_to_16
);
/* Execute */
speex_preprocess_run
(
ng
->
states
[
channel
],
ng
->
segment_buffers
[
channel
]);
/* Convert back to 32bit */
for
(
size_t
i
=
0
;
i
<
frames
;
i
++
)
adata
[
channel
][
i
]
=
(
float
)
ng
->
segment_buffers
[
channel
][
i
]
/
c_16_to_32
;
}
static
struct
obs_audio_data
*
noise_suppress_filter_audio
(
void
*
data
,
struct
obs_audio_data
*
audio
)
{
struct
noise_suppress_data
*
ng
=
data
;
float
*
adata
[
2
]
=
{(
float
*
)
audio
->
data
[
0
],
(
float
*
)
audio
->
data
[
1
]};
/* Execute for each available channel */
for
(
size_t
i
=
0
;
i
<
MAX_PREPROC_CHANNELS
;
i
++
)
{
if
(
ng
->
states
[
i
])
process_channel
(
ng
,
i
,
audio
->
frames
,
adata
);
}
return
audio
;
}
static
void
noise_suppress_defaults
(
obs_data_t
*
s
)
{
obs_data_set_default_int
(
s
,
S_SUPPRESS_LEVEL
,
-
30
);
}
static
obs_properties_t
*
noise_suppress_properties
(
void
*
data
)
{
obs_properties_t
*
ppts
=
obs_properties_create
();
obs_properties_add_int_slider
(
ppts
,
S_SUPPRESS_LEVEL
,
TEXT_SUPPRESS_LEVEL
,
SUP_MIN
,
SUP_MAX
,
0
);
UNUSED_PARAMETER
(
data
);
return
ppts
;
}
struct
obs_source_info
noise_suppress_filter
=
{
.
id
=
"noise_suppress_filter"
,
.
type
=
OBS_SOURCE_TYPE_FILTER
,
.
output_flags
=
OBS_SOURCE_AUDIO
,
.
get_name
=
noise_suppress_name
,
.
create
=
noise_suppress_create
,
.
destroy
=
noise_suppress_destroy
,
.
update
=
noise_suppress_update
,
.
filter_audio
=
noise_suppress_filter_audio
,
.
get_defaults
=
noise_suppress_defaults
,
.
get_properties
=
noise_suppress_properties
,
};
plugins/obs-filters/obs-filters-config.h.in
0 → 100644
浏览文件 @
f3d0272f
#pragma once
#define SPEEXDSP_ENABLED @LIBSPEEXDSP_FOUND@
plugins/obs-filters/obs-filters.c
浏览文件 @
f3d0272f
#include <obs-module.h>
#include "obs-filters-config.h"
OBS_DECLARE_MODULE
()
...
...
@@ -14,6 +15,9 @@ extern struct obs_source_info color_key_filter;
extern
struct
obs_source_info
sharpness_filter
;
extern
struct
obs_source_info
chroma_key_filter
;
extern
struct
obs_source_info
async_delay_filter
;
#ifdef SPEEXDSP_ENABLED
extern
struct
obs_source_info
noise_suppress_filter
;
#endif
extern
struct
obs_source_info
noise_gate_filter
;
bool
obs_module_load
(
void
)
...
...
@@ -28,6 +32,9 @@ bool obs_module_load(void)
obs_register_source
(
&
sharpness_filter
);
obs_register_source
(
&
chroma_key_filter
);
obs_register_source
(
&
async_delay_filter
);
#ifdef SPEEXDSP_ENABLED
obs_register_source
(
&
noise_suppress_filter
);
#endif
obs_register_source
(
&
noise_gate_filter
);
return
true
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录