ES7243E 模拟音频转I2S输入给BES I2S_Master数据运行流程分析

ES7243E 模拟音频转I2S输入给BES I2S_Master数据运行流程分析

LINE-IN接入

void aux_in_dothing_func(void)

{

FUNC_NAME_LINE_PRINT();

int activeCons;

osapi_lock_stack();

activeCons = btif_me_get_activeCons();

osapi_unlock_stack();

customer_app_pwl_stop();

osDelay(380);

app_status_indication_set(APP_STATUS_INDICATION_ALL_LED_OFF);

osDelay(380);

// aux_in_or_out_last = AUX_PLUG_IN;

//aux_in_detect_reset_func();

//if(AUX_PLUG_OUT == hal_gpio_pin_get_val((enum HAL_GPIO_PIN_T)AUX_PLUG_IN_OUT_TRIGGER_PIN))

//goto do_nothing;

//app_poweroff_timer_stop();

// app_ankey_timer_stop();

//audio_process_init();

app_bt_connectable_mode_stop_reconnecting();

osDelay(300);

app_audio_manager_sendrequest(APP_BT_STREAM_MANAGER_STOP,BT_STREAM_SBC, 0,0); //关闭蓝牙SBC音频

app_audio_manager_sendrequest(APP_BT_STREAM_MANAGER_START,BT_STREAM_LINEIN, 0,0);// 开启AUX 音频流

#ifdef AUDIO_LINEIN

case BT_STREAM_LINEIN:

TRACE(0,"xing:BT_STREAM_LINEIN OPEN");

// if(!bt_media_is_media_active_by_type(BT_STREAM_SBC | BT_STREAM_MEDIA | BT_STREAM_VOICE)) {

app_audio_sendrequest(APP_PLAY_LINEIN_AUDIO,(uint8_t)APP_BT_SETTING_OPEN, 0);

bt_media_set_current_media(BT_STREAM_LINEIN);

}

break;

#endif

#ifdef AUDIO_LINEIN

case APP_PLAY_LINEIN_AUDIO:

nRet = app_play_linein_onoff(true); //播放linein

break;

#endif

#ifdef AUDIO_LINEIN

case BT_STREAM_LINEIN:

if(bt_media_is_media_active_by_type(BT_STREAM_LINEIN))

{

app_audio_sendrequest(APP_PLAY_LINEIN_AUDIO,(uint8_t)APP_BT_SETTING_CLOSE, 0);

if(bt_media_get_current_media() & BT_STREAM_LINEIN)

bt_media_set_current_media(0);

bt_media_clear_media_type(stream_type,device_id);

}

break;

#endif

播放Linin 重点代码

int app_play_linein_onoff(bool onoff)

{

static bool isRun = false;

uint8_t *linein_audio_cap_buff = 0;

uint8_t *linein_audio_play_buff = 0;

uint8_t *linein_audio_loop_buf = NULL;

struct AF_STREAM_CONFIG_T stream_cfg;

uint8_t POSSIBLY_UNUSED *bt_eq_buff = NULL;

uint32_t POSSIBLY_UNUSED eq_buff_size;

uint8_t POSSIBLY_UNUSED play_samp_size;

TRACE(2,"app_play_linein_onoff work:%d op:%d", isRun, onoff);

if (isRun == onoff)

return 0;

if (onoff){

app_sysfreq_req(APP_SYSFREQ_USER_APP_0, APP_SYSFREQ_104M);

app_overlay_select(APP_OVERLAY_A2DP);

app_audio_mempool_init();

app_audio_mempool_get_buff(&linein_audio_cap_buff, LINEIN_CAPTURE_BUFFER_SIZE);

app_audio_mempool_get_buff(&linein_audio_play_buff, LINEIN_PLAYER_BUFFER_SIZE);

app_audio_mempool_get_buff(&linein_audio_loop_buf, LINEIN_PLAYER_BUFFER_SIZE<<2);

app_audio_pcmbuff_init(linein_audio_loop_buf, LINEIN_PLAYER_BUFFER_SIZE<<2);

#if (LINEIN_CAPTURE_CHANNEL == 1)

app_audio_mempool_get_buff((uint8_t **)&app_linein_play_cache, LINEIN_PLAYER_BUFFER_SIZE/2/2);

app_play_audio_lineinmode_init(LINEIN_CAPTURE_CHANNEL, LINEIN_PLAYER_BUFFER_SIZE/2/2);

#elif (LINEIN_CAPTURE_CHANNEL == 2)

app_play_audio_lineinmode_init(LINEIN_CAPTURE_CHANNEL, LINEIN_PLAYER_BUFFER_SIZE/2);

#endif

memset(&stream_cfg, 0, sizeof(stream_cfg));

#if (LINEIN_MODE == 1 || LINEIN_MODE == 6)

TRACE(0,"app_play_linein_onoff mode 01");

stream_cfg.bits = AUD_BITS_24; //

stream_cfg.channel_num = (enum AUD_CHANNEL_NUM_T)LINEIN_PLAYER_CHANNEL;

#if defined(AUDIO_RESAMPLE)

stream_cfg.sample_rate = AUD_SAMPRATE_44100;//add by zhoukang

#else

stream_cfg.sample_rate = AUD_SAMPRATE_44100;

#endif

af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK, &stream_cfg);// 调用音频框架 播放音频

audio_process_open(stream_cfg.sample_rate, stream_cfg.bits, stream_cfg.channel_num, stream_cfg.data_size/(stream_cfg.bits <= AUD_BITS_16 ? 2 : 4)/2, bt_eq_buff, eq_buff_size);

af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);//开启音频

//捕获i2s数据

#if (LINEIN_CAPTURE_CHANNEL == 1) //?????

app_audio_mempool_get_buff((uint8_t **)&app_linein_play_cache, LINEIN_PLAYER_BUFFER_SIZE/2/2); //?????

app_play_audio_lineinmode_init(LINEIN_CAPTURE_CHANNEL, LINEIN_PLAYER_BUFFER_SIZE/2/2); //?????

#elif (LINEIN_CAPTURE_CHANNEL == 2)

app_play_audio_lineinmode_init(LINEIN_CAPTURE_CHANNEL, LINEIN_PLAYER_BUFFER_SIZE/2); //?????

#endif

memset(&stream_cfg, 0, sizeof(stream_cfg)); //???????

#if (LINEIN_MODE == 1 || LINEIN_MODE == 6) //?????

TRACE(0,"app_play_linein_onoff mode 01");

stream_cfg.bits = AUD_BITS_24; //

stream_cfg.channel_num = (enum AUD_CHANNEL_NUM_T)LINEIN_PLAYER_CHANNEL;

#if defined(AUDIO_RESAMPLE)

stream_cfg.sample_rate = AUD_SAMPRATE_44100;//add by zhoukang

#else

stream_cfg.sample_rate = AUD_SAMPRATE_44100;

#endif

#endif

Device设备选择的是配置i2s1 作为主 参数将传入af_open

#if (TJ_BOARD_ZP_H6506 == 1 || CSP_BOARD_WH301A == 1) //from I2S

#if FPGA==0

stream_cfg.device = AUD_STREAM_USE_I2S1_MASTER;//add by zhoukang 2021-08-17

#else

stream_cfg.device = AUD_STREAM_USE_I2S1_MASTER;//add by zhoukang 2021-08-17

#endif

音频输入路径

stream_cfg.io_path = AUD_INPUT_PATH_LINEIN;//add by zhoukang 2021-08-17

打开与启动

af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE, &stream_cfg);

af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);

关闭

af_stream_close(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);

相关推荐
全栈小517 小时前
【数据库】浙人医携手金仓数据库,打造全国首个多院区异构多活容灾架构
数据库·1024程序员节·金仓
CoderYanger3 天前
贪心算法:7.最长连续递增序列
java·算法·leetcode·贪心算法·1024程序员节
CoderYanger3 天前
贪心算法:6.递增的三元子序列
java·算法·leetcode·贪心算法·1024程序员节
CoderYanger3 天前
贪心算法:1.柠檬水找零
java·算法·leetcode·贪心算法·1024程序员节
CoderYanger3 天前
贪心算法:4.摆动序列
java·算法·leetcode·贪心算法·1024程序员节
CoderYanger3 天前
贪心算法:2.将数组和减半的最少操作次数
java·算法·leetcode·贪心算法·1024程序员节
CoderYanger3 天前
贪心算法:8.买卖股票的最佳时机
java·算法·leetcode·贪心算法·1024程序员节
CoderYanger3 天前
贪心算法:3.最大数
java·算法·leetcode·贪心算法·1024程序员节
CoderYanger3 天前
贪心算法:5.最长递增子序列
java·算法·leetcode·贪心算法·1024程序员节
liguojun20254 天前
智慧破局:重构体育场馆的运营与体验新生态
java·大数据·人工智能·物联网·重构·1024程序员节