#ifndef YC_AUDIO_H
#define YC_AUDIO_H
// I2S配置(根据硬件调整)
#define I2S_CHANNEL I2S_NUM_0
#define I2S_BCK_PIN 42
#define I2S_WS_PIN 41
#define I2S_DATA_PIN 2
/*======= 系统配置 =======*/
#define FFT_SIZE 4096 // FFT点数
#define NOISE_BINS 50 // 噪声基底计算区间
#define MIN_DURATION 5 // 最小持续帧数(50ms/帧)
#define THRESHOLD_OFFSET 20.0 // 阈值相对噪声基底的偏移量
#define FREQ_TOLERANCE 50 // 频率允许误差±50Hz
#define NUM_CHANNELS (1) // For mono recording only!
#define CONFIG_BIT_SAMPLE 16 //位深
#define CONFIG_SAMPLE_RATE 16000 //采样率
#define SAMPLE_SIZE (CONFIG_BIT_SAMPLE * 1024) //16384
#define BYTE_RATE (CONFIG_SAMPLE_RATE * (CONFIG_BIT_SAMPLE / 8)) * NUM_CHANNELS //32000
//存储/带宽需求小:数据量约为16000样本/秒 × 位深(如16bit)= 256kbps
extern void audio_processing_task(void *arg);
#endif
// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
//
// 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.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "driver/spi_master.h"
#include "soc/gpio_struct.h"
#include "driver/gpio.h"
#include "driver/uart.h"
#include "soc/uart_struct.h"
#include <math.h>
#include "esp_dsp.h"
#include "esp_log.h"
#include "esp_err.h"
#include "sdkconfig.h"
#include "driver/i2s_pdm.h"
#include "driver/spi_common.h"
#include "yc_audio.h"
#include <sys/param.h>
static const char *TAG = "audio_detect";
/*======= 硬件配置 =======*/
__attribute__((aligned(1