114 lines
3.6 KiB
C
114 lines
3.6 KiB
C
/*
|
|
* Copyright (C) 2017 Amlogic Corporation.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#define LOG_TAG "audio_hw_input_tv"
|
|
|
|
#include <stdio.h>
|
|
#include <sys/types.h>
|
|
|
|
#include "aml_noise_gate.h"
|
|
#include "device_patch_mgr.h"
|
|
#include "aml_ng.h"
|
|
#include "aml_audio_log.h"
|
|
|
|
bool is_ng_enable(struct component_noise_gate *noise_gate)
|
|
{
|
|
if (NULL == noise_gate) {
|
|
AM_LOGE("noise_gate is NULL, needs check it!!");
|
|
return false;
|
|
}
|
|
return (noise_gate->aml_ng_enable != 0 ? true : false);
|
|
}
|
|
|
|
void *get_ng_handle(struct component_noise_gate *noise_gate)
|
|
{
|
|
if (NULL == noise_gate) {
|
|
AM_LOGE("noise_gate is NULL, needs check it!!");
|
|
return NULL;
|
|
}
|
|
return noise_gate->aml_ng_handle;
|
|
}
|
|
|
|
void aml_noise_gate_init(struct component_noise_gate *noise_gate)
|
|
{
|
|
#ifdef USE_EQ_DRC
|
|
if (NULL == noise_gate) {
|
|
AM_LOGE("noise_gate is NULL, needs check it!!");
|
|
return;
|
|
}
|
|
if (noise_gate->aml_ng_enable) {
|
|
noise_gate->aml_ng_handle = init_noise_gate(noise_gate->aml_ng_level,
|
|
noise_gate->aml_ng_attack_time,
|
|
noise_gate->aml_ng_release_time);
|
|
AM_LOGI("init amlogic noise gate: level: %fdB, attack_time = %dms, release_time = %dms",
|
|
noise_gate->aml_ng_level, noise_gate->aml_ng_attack_time, noise_gate->aml_ng_release_time);
|
|
}
|
|
#endif
|
|
return;
|
|
}
|
|
|
|
void aml_noise_gate_deinit(struct component_noise_gate *noise_gate)
|
|
{
|
|
#ifdef USE_EQ_DRC
|
|
if (NULL == noise_gate) {
|
|
AM_LOGE("noise_gate is NULL, needs check it!!");
|
|
return;
|
|
}
|
|
if (noise_gate->aml_ng_handle) {
|
|
release_noise_gate(noise_gate->aml_ng_handle);
|
|
noise_gate->aml_ng_handle = NULL;
|
|
AM_LOGI("release amlogic noise gate successful");
|
|
}
|
|
#endif
|
|
return;
|
|
}
|
|
|
|
int aml_noise_gate_process(struct component_noise_gate *noise_gate, void *buffer, int samples, int sample_size)
|
|
{
|
|
int ret = 0;
|
|
#ifdef USE_EQ_DRC
|
|
if (NULL == noise_gate || NULL == buffer || samples <= 0 || sample_size<= 0) {
|
|
AM_LOGE("noise_gate or buffer is NULL / samples <= 0 / sample_size<= 0, needs check it!!");
|
|
return ret;
|
|
}
|
|
void *ng_handle = get_ng_handle(noise_gate);
|
|
if (NULL != ng_handle) {
|
|
ret = noise_evaluation(ng_handle, buffer, samples, sample_size);
|
|
}
|
|
#endif
|
|
return ret;
|
|
}
|
|
|
|
void aml_noise_gate_set_param(struct component_noise_gate *noise_gate,
|
|
int aml_ng_enable,
|
|
float noise_level,
|
|
int attack_time,
|
|
int release_time)
|
|
{
|
|
if (NULL == noise_gate) {
|
|
AM_LOGE("noise_gate is NULL, needs check it!!");
|
|
return;
|
|
}
|
|
noise_gate->aml_ng_level = noise_level;
|
|
noise_gate->aml_ng_enable = aml_ng_enable;
|
|
noise_gate->aml_ng_attack_time = attack_time;
|
|
noise_gate->aml_ng_release_time = release_time;
|
|
AM_LOGI(" audio noise gate level: %fdB, attack_time = %dms, release_time = %dms, aml_ng_enable = %d",
|
|
noise_level, attack_time, release_time, aml_ng_enable);
|
|
|
|
return;
|
|
}
|