Skip to content

Commit

Permalink
Merge pull request #102 from pine64/anc-testing
Browse files Browse the repository at this point in the history
ANC Support
  • Loading branch information
Ralim authored Jul 20, 2024
2 parents 6c1f50f + 6a72642 commit dfdb3ad
Show file tree
Hide file tree
Showing 13 changed files with 696 additions and 403 deletions.
1 change: 1 addition & 0 deletions apps/anc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ endif

ifeq ($(ANC_ASSIST_ENABLED),1)
CFLAGS_app_anc.o += -DANC_ASSIST_ENABLED
CFLAGS_anc_assist.o += -DANC_ASSIST_ENABLED

ifeq ($(ANC_ASSIST_WNR_ENABLED),1)
CFLAGS_anc_assist.o += -DANC_ASSIST_WNR_ENABLED
Expand Down
49 changes: 26 additions & 23 deletions apps/anc/src/app_anc.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
#endif

#include "co_math.h"
//#define ANC_MODE_SWITCH_WITHOUT_FADE //Comment this line if you need fade
// function between anc mode
// #define ANC_MODE_SWITCH_WITHOUT_FADE //Comment this line if you need fade
// function between anc mode

#ifndef _ANC_FADE_STACK_SIZE
#define _ANC_FADE_STACK_SIZE (1 * 1024)
Expand Down Expand Up @@ -1060,31 +1060,41 @@ void app_anc_open_anc(void) {
capture_rate = anc_sample_rate[AUD_STREAM_CAPTURE];

pmu_anc_config(1);

int result = 0;
#ifdef ANC_FF_ENABLED
af_anc_open(ANC_FEEDFORWARD, playback_rate, capture_rate, handler);
anc_open(ANC_FEEDFORWARD);
anc_select_coef(anc_sample_rate[AUD_STREAM_PLAYBACK], anc_coef_idx,
ANC_FEEDFORWARD, ANC_GAIN_DELAY);
result = af_anc_open(ANC_FEEDFORWARD, playback_rate, capture_rate, handler);
TRACE(2, "af_anc_open %s %d -> %d\n", __FUNCTION__, __LINE__, result);
result = anc_open(ANC_FEEDFORWARD);
TRACE(2, "anc_open %s %d -> %d\n", __FUNCTION__, __LINE__, result);
result = anc_select_coef(anc_sample_rate[AUD_STREAM_PLAYBACK], anc_coef_idx,
ANC_FEEDFORWARD, ANC_GAIN_DELAY);
TRACE(2, "anc_select_coef %s %d -> %d\n", __FUNCTION__, __LINE__, result);
#endif

#ifdef ANC_FB_ENABLED
af_anc_open(ANC_FEEDBACK, playback_rate, capture_rate, handler);
anc_open(ANC_FEEDBACK);
anc_select_coef(anc_sample_rate[AUD_STREAM_PLAYBACK], anc_coef_idx,
ANC_FEEDBACK, ANC_GAIN_DELAY);
result = af_anc_open(ANC_FEEDBACK, playback_rate, capture_rate, handler);
TRACE(2, "anc_open %s %d -> %d\n", __FUNCTION__, __LINE__, result);
result = anc_open(ANC_FEEDBACK);
TRACE(2, "anc_open %s %d -> %d\n", __FUNCTION__, __LINE__, result);
result = anc_select_coef(anc_sample_rate[AUD_STREAM_PLAYBACK], anc_coef_idx,
ANC_FEEDBACK, ANC_GAIN_DELAY);
TRACE(2, "anc_select_coef %s %d -> %d\n", __FUNCTION__, __LINE__, result);
#endif

#ifdef AUDIO_ANC_FB_MC_HW
anc_open(ANC_MUSICCANCLE);
anc_select_coef(anc_sample_rate[AUD_STREAM_PLAYBACK], anc_coef_idx,
ANC_MUSICCANCLE, ANC_GAIN_NO_DELAY);
result = anc_open(ANC_MUSICCANCLE);
TRACE(2, "anc_open %s %d -> %d\n", __FUNCTION__, __LINE__, result);
result = anc_select_coef(anc_sample_rate[AUD_STREAM_PLAYBACK], anc_coef_idx,
ANC_MUSICCANCLE, ANC_GAIN_NO_DELAY);
TRACE(2, "anc_select_coef %s %d -> %d\n", __FUNCTION__, __LINE__, result);
#endif

#if defined(AUDIO_ANC_TT_HW)
anc_open(ANC_TALKTHRU);
anc_select_coef(anc_sample_rate[AUD_STREAM_PLAYBACK], anc_coef_idx,
ANC_TALKTHRU, ANC_GAIN_NO_DELAY);
TRACE(2, "anc_open %s %d -> %d\n", __FUNCTION__, __LINE__, result);
result = anc_select_coef(anc_sample_rate[AUD_STREAM_PLAYBACK], anc_coef_idx,
ANC_TALKTHRU, ANC_GAIN_NO_DELAY);
TRACE(2, "anc_select_coef %s %d -> %d\n", __FUNCTION__, __LINE__, result);
#endif

#ifdef AUDIO_ANC_FB_MC_HW
Expand Down Expand Up @@ -1521,13 +1531,6 @@ void app_anc_key(APP_KEY_STATUS *status, void *param) {
bool flag = app_anc_work_status();

#if defined(IBRT)
ibrt_ctrl_t *p_ibrt_ctrl = app_tws_ibrt_get_bt_ctrl_ctx();

TRACE(2, "[%s] current_role: %d", __func__, p_ibrt_ctrl->current_role);
if (p_ibrt_ctrl->current_role == IBRT_SLAVE) {
app_anc_notify_master_to_exchange_coef(0, 0);
return;
}
app_anc_status_sync(!flag);
#endif
app_anc_status_post(!flag);
Expand Down
8 changes: 7 additions & 1 deletion apps/main/key_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ void send_prev_track(void) {
uint8_t action[] = {IBRT_ACTION_BACKWARD};
app_ibrt_if_start_user_action(action, sizeof(action));
}

void send_enable_disable_anc(void) {
uint8_t action[] = {IBRT_ACTION_ANC_NOTIRY_MASTER_EXCHANGE_COEF};
app_ibrt_if_start_user_action(action, sizeof(action));
}

void app_key_single_tap(APP_KEY_STATUS *status, void *param) {
TRACE(2, "%s event %d", __func__, status->event);
/*
Expand Down Expand Up @@ -200,7 +206,7 @@ void app_key_long_press_down(APP_KEY_STATUS *status, void *param) {
send_prev_track();
} else {
// Bud's are working as a pair
app_anc_key(status, param);
send_enable_disable_anc();
}
}

Expand Down
33 changes: 25 additions & 8 deletions config/open_source/target.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ MBED ?= 0
RTOS ?= 1

#KERNEL ?= FREERTOS

NO_PWRKEY = 0 # We have powerkey input
# We have powerkey input
NO_PWRKEY = 0
LIBC_ROM ?= 1

# Extas added by Open source community
CONNECTED_BLUE_LIGHT = 1 # if set to 1, the blue light will flash when connected
# end our extras

export USER_SECURE_BOOT ?= 0
# enable:1
# disable:0
Expand Down Expand Up @@ -54,25 +58,38 @@ export BT_DEBUG_TPORTS ?= 0
TPORTS_KEY_COEXIST ?= 0

export SNIFF_MODE_CHECK ?= 0

# Merge L+R stream down to mono
AUDIO_OUTPUT_MONO ?= 0

AUDIO_OUTPUT_DIFF ?= 0

# Raise mic bias from 2.2V to 3.3V
DIGMIC_HIGH_VOLT ?= 0

#### ANC DEFINE START ######
export ANC_APP ?= 1
# Feed Forward ANC configuration (external mic)
export ANC_FF_ENABLED ?= 1
# Feed Backward ANC configuration (internal mic)
export ANC_FB_ENABLED ?= 1
# Wind noise reduction mode
export ANC_WNR_ENABLED ?= 0

# Music cancel mode. Conflicts with audio resampling
export AUDIO_ANC_FB_MC ?= 0
export AUDIO_SECTION_SUPPT ?= 0
export AUD_SECTION_STRUCT_VERSION ?= 2
# Music cancel hardware?
export AUDIO_ANC_FB_MC_HW ?=0
export APP_ANC_KEY ?= 1
# Feedback check for feedforward mic. Locked on due to blobs
export ANC_FB_CHECK ?= 1
##### ANC DEFINE END ######

# Build in ANC testing app (closed source)
APP_ANC_TEST ?= 0
export ANC_ASSIST_ENABLED ?= 0
##### ANC DEFINE END ######

# Allow test commands via bluetooth
TEST_OVER_THE_AIR ?= 0

HW_FIR_EQ_PROCESS ?= 0
Expand All @@ -93,7 +110,7 @@ PC_CMD_UART ?= 0

AUDIO_SECTION_ENABLE ?= 0

AUDIO_RESAMPLE ?= 1
AUDIO_RESAMPLE ?= 0

RESAMPLE_ANY_SAMPLE_RATE ?= 1

Expand Down Expand Up @@ -206,8 +223,8 @@ TILE_DATAPATH_ENABLED ?= 0
CUSTOM_INFORMATION_TILE_ENABLE ?= 0

INTERCONNECTION ?= 0

INTERACTION ?= 0 # Looks like Find-My-Device support?
# Looks like Find-My-Device support?
INTERACTION ?= 0

INTERACTION_FASTPAIR ?= 0

Expand Down
Loading

0 comments on commit dfdb3ad

Please sign in to comment.