下載代碼
可以從github
或gitee
下載代碼:
git clone https://github.com/espressif/esp-adf.git
git clone https://gitee.com/EspressifSystems/esp-adf.git #國內(nèi)站點(diǎn)
因?yàn)榇a里用了子模塊契讲,而且把esp-idf
作為子模塊來使用。我已經(jīng)另外下載有esp-idf
滑频,因此需要刪除這個子模塊后再更新子模塊:
git rm --cached esp-idf
rm -rf esp-idf
vim .gitmodules #刪除esp-idf相關(guān)內(nèi)容
vim .git/config #刪除esp-idf相關(guān)內(nèi)容
git submodule sync
git submodule update --init --recursive
配置ADF_PATH
下載完ADF后捡偏,進(jìn)入esp-adf
目錄,添加設(shè)置ADF_PATH
的環(huán)境變量的腳本:
touch export_adf.sh
vim export_adf.sh
#增加以下內(nèi)容
function realpath_int() {
wdir="$PWD"; [ "$PWD" = "/" ] && wdir=""
arg=$1
case "$arg" in
/*) scriptdir="${arg}";;
*) scriptdir="$wdir/${arg#./}";;
esac
scriptdir="${scriptdir%/*}"
echo "$scriptdir"
}
function adf_export_main() {
if [[ -z "${ADF_PATH}" ]]
then
if [[ -n "${BASH_SOURCE}" ]]
then
if [[ "$OSTYPE" == "darwin"* ]]; then
script_dir="$(realpath_int $BASH_SOURCE)"
else
script_name="$(readlink -f $BASH_SOURCE)"
script_dir="$(dirname $script_name)"
fi
export ADF_PATH="${script_dir}"
echo $ADF_PATH
fi
fi
}
adf_export_main
unset realpath_int
unset adf_export_main
#內(nèi)容結(jié)束
修改例程
在esp-adf/example/player
下有pipeline_bt_sink
的DEMO峡迷,有完整的藍(lán)牙播放功能银伟,我把均衡器也加上了你虹,均衡器的使用可以參考鏈接https://docs.espressif.com/projects/esp-adf/zh_CN/latest/api-reference/audio-processing/equalizer.html
,部分代碼摘錄如下:
void app_main(void){
audio_pipeline_handle_t pipeline;
audio_element_handle_t bt_stream_reader, i2s_stream_writer, equalizer;
esp_err_t err = nvs_flash_init();
if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
ESP_ERROR_CHECK(nvs_flash_erase());
err = nvs_flash_init();
}
esp_log_level_set("*", ESP_LOG_INFO);
esp_log_level_set(TAG, ESP_LOG_DEBUG);
bluetooth_service_cfg_t bt_cfg = {
.device_name = "XTC-Headphone",
.mode = BLUETOOTH_A2DP_SINK,
};
bluetooth_service_start(&bt_cfg);
audio_board_handle_t board_handle = audio_board_init();
audio_hal_ctrl_codec(board_handle->audio_hal, AUDIO_HAL_CODEC_MODE_DECODE, AUDIO_HAL_CTRL_START);
audio_pipeline_cfg_t pipeline_cfg = DEFAULT_AUDIO_PIPELINE_CONFIG();
pipeline = audio_pipeline_init(&pipeline_cfg);
equalizer_cfg_t eq_cfg = DEFAULT_EQUALIZER_CONFIG();
int set_gain[] = {-13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13, -13}; //根據(jù)自己的需求調(diào)整
/*
for (int i = 0; i < equalizer->channel; i++) {
for (int j = 0; j < NUMBER_BAND; j++) {
esp_equalizer_set_band_value(equalizer->eq_handle, equalizer->set_gain[NUMBER_BAND * i + j], j, i);
}
}
*/
eq_cfg.set_gain = set_gain;
equalizer = equalizer_init(&eq_cfg);
i2s_stream_cfg_t i2s_cfg = I2S_STREAM_CFG_DEFAULT();
i2s_cfg.type = AUDIO_STREAM_WRITER;
i2s_stream_writer = i2s_stream_init(&i2s_cfg);
bt_stream_reader = bluetooth_service_create_stream();
audio_pipeline_register(pipeline, bt_stream_reader, "bt");
audio_pipeline_register(pipeline, equalizer, "equalizer");
audio_pipeline_register(pipeline, i2s_stream_writer, "i2s");
audio_pipeline_link(pipeline, (const char *[]) {"bt", "equalizer", "i2s"}, 3);
//audio_pipeline_link(pipeline, (const char *[]) {"bt", "i2s"}, 2);
esp_periph_config_t periph_cfg = DEFAULT_ESP_PERIPH_SET_CONFIG();
esp_periph_set_handle_t set = esp_periph_set_init(&periph_cfg);
audio_board_key_init(set);
·······
}
編譯工程
我的編譯環(huán)境是win10下的子系統(tǒng)ubuntu 1804
彤避,打開一個命令行頁面傅物,在自己的esp-idf
目錄下運(yùn)行:
. ./export.sh
再在esp-adf
目錄下運(yùn)行:
. ./export.sh
即可編譯工程:
idf.py build
#如果需要配置工程,可以通過idf.py menuconfig可配置琉预,比如使用PSRAM
通過以下命令即可燒錄到板上進(jìn)行測試:
idf.py -p /dev/ttyS11 -b 921600 flash #win10子系統(tǒng)下使用串口的方式為 /dev/ttyS串口號