├── .DS_Store ├── .gitignore ├── .gitmodules ├── README.md ├── components ├── .DS_Store ├── bsp │ ├── .DS_Store │ ├── bsp.c │ ├── component.mk │ ├── hal_i2c.c │ ├── hal_i2s.c │ ├── include │ │ ├── .DS_Store │ │ ├── bsp.h │ │ ├── hal_eth.h │ │ ├── hal_i2c.h │ │ ├── hal_i2s.h │ │ └── wm8978.h │ └── wm8978.c ├── dsp_lib │ ├── .DS_Store │ ├── BasicMathFunctions │ │ ├── xtensa_abs_f32.c │ │ ├── xtensa_add_f32.c │ │ ├── xtensa_dot_prod_f32.c │ │ ├── xtensa_mult_f32.c │ │ ├── xtensa_negate_f32.c │ │ ├── xtensa_offset_f32.c │ │ ├── xtensa_scale_f32.c │ │ └── xtensa_sub_f32.c │ ├── CommonTables │ │ ├── xtensa_common_tables.c │ │ └── xtensa_const_structs.c │ ├── ComplexMathFunctions │ │ ├── xtensa_cmplx_conj_f32.c │ │ ├── xtensa_cmplx_dot_prod_f32.c │ │ ├── xtensa_cmplx_mag_f32.c │ │ ├── xtensa_cmplx_mag_squared_f32.c │ │ ├── xtensa_cmplx_mult_cmplx_f32.c │ │ └── xtensa_cmplx_mult_real_f32.c │ ├── ControllerFunctions │ │ ├── xtensa_pid_init_f32.c │ │ ├── xtensa_pid_reset_f32.c │ │ └── xtensa_sin_cos_f32.c │ ├── FastMathFunctions │ │ ├── xtensa_cos_f32.c │ │ └── xtensa_sin_f32.c │ ├── FilteringFunctions │ │ ├── xtensa_biquad_cascade_df1_f32.c │ │ ├── xtensa_biquad_cascade_df1_init_f32.c │ │ ├── xtensa_biquad_cascade_df2T_f32.c │ │ ├── xtensa_biquad_cascade_df2T_init_f32.c │ │ ├── xtensa_biquad_cascade_stereo_df2T_f32.c │ │ ├── xtensa_biquad_cascade_stereo_df2T_init_f32.c │ │ ├── xtensa_conv_f32.c │ │ ├── xtensa_conv_partial_f32.c │ │ ├── xtensa_correlate_f32.c │ │ ├── xtensa_fir_decimate_f32.c │ │ ├── xtensa_fir_decimate_init_f32.c │ │ ├── xtensa_fir_f32.c │ │ ├── xtensa_fir_init_f32.c │ │ ├── xtensa_fir_interpolate_f32.c │ │ ├── xtensa_fir_interpolate_init_f32.c │ │ ├── xtensa_fir_lattice_f32.c │ │ ├── xtensa_fir_lattice_init_f32.c │ │ ├── xtensa_fir_sparse_f32.c │ │ ├── xtensa_fir_sparse_init_f32.c │ │ ├── xtensa_iir_lattice_f32.c │ │ ├── xtensa_iir_lattice_init_f32.c │ │ ├── xtensa_lms_f32.c │ │ ├── xtensa_lms_init_f32.c │ │ ├── xtensa_lms_norm_f32.c │ │ └── xtensa_lms_norm_init_f32.c │ ├── Include │ │ ├── xtensa_common_tables.h │ │ ├── xtensa_const_structs.h │ │ └── xtensa_math.h │ ├── MatrixFunctions │ │ ├── arm_mat_add_f32.c │ │ ├── arm_mat_cmplx_mult_f32.c │ │ ├── arm_mat_init_f32.c │ │ ├── arm_mat_inverse_f32.c │ │ ├── arm_mat_mult_f32.c │ │ ├── arm_mat_scale_f32.c │ │ ├── arm_mat_sub_f32.c │ │ └── arm_mat_trans_f32.c │ ├── StatisticsFunctions │ │ ├── xtensa_max_f32.c │ │ ├── xtensa_mean_f32.c │ │ ├── xtensa_min_f32.c │ │ ├── xtensa_power_f32.c │ │ ├── xtensa_rms_f32.c │ │ ├── xtensa_std_f32.c │ │ └── xtensa_var_f32.c │ ├── TransformFunctions │ │ ├── .DS_Store │ │ ├── xtensa_bitreversal.c │ │ ├── xtensa_bitreversal2.c │ │ ├── xtensa_cfft_f32.c │ │ ├── xtensa_cfft_radix2_f32.c │ │ ├── xtensa_cfft_radix2_init_f32.c │ │ ├── xtensa_cfft_radix4_f32.c │ │ ├── xtensa_cfft_radix4_init_f32.c │ │ ├── xtensa_cfft_radix8_f32.c │ │ ├── xtensa_dct4_f32.c │ │ ├── xtensa_dct4_init_f32.c │ │ ├── xtensa_rfft_f32.c │ │ ├── xtensa_rfft_fast_f32.c │ │ ├── xtensa_rfft_fast_init_f32.c │ │ └── xtensa_rfft_init_f32.c │ └── component.mk ├── helix │ ├── component.mk │ ├── example.c │ ├── include │ │ ├── assembly.h │ │ ├── coder.h │ │ ├── mp3common.h │ │ ├── mp3dec.h │ │ ├── mpadecobjfixpt.h │ │ └── statname.h │ └── src │ │ ├── bitstream.c │ │ ├── buffers.c │ │ ├── dct32.c │ │ ├── dequant.c │ │ ├── dqchan.c │ │ ├── huffman.c │ │ ├── hufftabs.c │ │ ├── imdct.c │ │ ├── mp3dec.c │ │ ├── mp3tabs.c │ │ ├── polyphase.c │ │ ├── scalfact.c │ │ ├── stproc.c │ │ ├── subband.c │ │ └── trigtabs.c ├── ringb │ ├── component.mk │ ├── include │ │ └── ringbuf.h │ └── ringbuf.c └── util │ ├── component.mk │ └── include │ └── util.h ├── example ├── dsp_test │ ├── .DS_Store │ ├── Makefile │ ├── README.md │ ├── dsp_ref.py │ ├── main │ │ ├── component.mk │ │ └── dsp_test.c │ └── sdkconfig ├── hello_world │ ├── .DS_Store │ ├── Makefile │ ├── README.md │ ├── main │ │ ├── component.mk │ │ └── main.c │ └── sdkconfig ├── play_mp3 │ ├── .DS_Store │ ├── Makefile │ ├── README.md │ ├── main │ │ ├── component.mk │ │ └── main.c │ └── sdkconfig └── play_wav │ ├── .DS_Store │ ├── Makefile │ ├── README.md │ ├── main │ ├── component.mk │ └── main.c │ └── sdkconfig └── project.mk /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whyengineer/esp32-lin/6fa39f4cd5f7782b3a2a052767f0fb06be2378ff/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | sdkconfig.old 3 | .vscode 4 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whyengineer/esp32-lin/6fa39f4cd5f7782b3a2a052767f0fb06be2378ff/.gitmodules -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WhyEngineer Audio Board ESP32-LIN 2 | -------------------------------------------------------------------------------- /components/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whyengineer/esp32-lin/6fa39f4cd5f7782b3a2a052767f0fb06be2378ff/components/.DS_Store -------------------------------------------------------------------------------- /components/bsp/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whyengineer/esp32-lin/6fa39f4cd5f7782b3a2a052767f0fb06be2378ff/components/bsp/.DS_Store -------------------------------------------------------------------------------- /components/bsp/component.mk: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /components/bsp/hal_i2c.c: -------------------------------------------------------------------------------- 1 | #include "hal_i2c.h" 2 | #include "driver/i2c.h" 3 | 4 | #define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/ 5 | #define ACK_CHECK_DIS 0x0 /*!< I2C master will not check ack from slave */ 6 | #define ACK_VAL 0x0 /*!< I2C ack value */ 7 | #define NACK_VAL 0x1 /*!< I2C nack value */ 8 | 9 | #define I2C_EXAMPLE_MASTER_TX_BUF_DISABLE 0 /*!< I2C master do not need buffer */ 10 | #define I2C_EXAMPLE_MASTER_RX_BUF_DISABLE 0 /*!< I2C master do not need buffer */ 11 | 12 | 13 | void hal_i2c_init(uint8_t port ,uint8_t sda,uint8_t scl) 14 | { 15 | int i2c_master_port = (i2c_port_t)port; 16 | i2c_config_t conf; 17 | conf.mode = I2C_MODE_MASTER; 18 | conf.sda_io_num = sda; 19 | conf.sda_pullup_en = GPIO_PULLDOWN_DISABLE; 20 | conf.scl_io_num = scl; 21 | conf.scl_pullup_en = GPIO_PULLDOWN_DISABLE; 22 | conf.master.clk_speed = 100000; 23 | i2c_param_config(i2c_master_port, &conf); 24 | i2c_driver_install(i2c_master_port, conf.mode, 25 | I2C_EXAMPLE_MASTER_RX_BUF_DISABLE, 26 | I2C_EXAMPLE_MASTER_TX_BUF_DISABLE, 0); 27 | } 28 | esp_err_t hal_i2c_master_mem_write(i2c_port_t i2c_num, uint8_t DevAddr,uint8_t MemAddr,uint8_t* data_wr, size_t size) 29 | { 30 | if (size == 0) { 31 | return ESP_OK; 32 | } 33 | i2c_cmd_handle_t cmd = i2c_cmd_link_create();//a cmd list 34 | i2c_master_start(cmd); 35 | i2c_master_write_byte(cmd, ( DevAddr << 1 ) | I2C_MASTER_WRITE, ACK_CHECK_EN); 36 | i2c_master_write_byte(cmd, MemAddr, ACK_CHECK_EN); 37 | i2c_master_write(cmd, data_wr, size, ACK_CHECK_EN); 38 | i2c_master_stop(cmd); 39 | esp_err_t ret = i2c_master_cmd_begin(i2c_num, cmd, 1000 / portTICK_RATE_MS); 40 | i2c_cmd_link_delete(cmd); 41 | return ret; 42 | } 43 | esp_err_t hal_i2c_master_mem_read(i2c_port_t i2c_num, uint8_t DevAddr,uint8_t MemAddr,uint8_t* data_rd, size_t size) 44 | { 45 | if (size == 0) { 46 | return ESP_OK; 47 | } 48 | i2c_cmd_handle_t cmd = i2c_cmd_link_create();//a cmd list 49 | i2c_master_start(cmd); 50 | i2c_master_write_byte(cmd, ( DevAddr << 1 ) | I2C_MASTER_WRITE, ACK_CHECK_EN); 51 | i2c_master_write_byte(cmd, MemAddr, ACK_CHECK_EN); 52 | i2c_master_start(cmd); 53 | i2c_master_write_byte(cmd, ( DevAddr << 1 ) | I2C_MASTER_READ, ACK_CHECK_EN); 54 | if (size > 1) { 55 | i2c_master_read(cmd, data_rd, size - 1, ACK_VAL); 56 | } 57 | i2c_master_read_byte(cmd, data_rd + size - 1, NACK_VAL); 58 | i2c_master_stop(cmd); 59 | esp_err_t ret = i2c_master_cmd_begin(i2c_num, cmd, 1000 / portTICK_RATE_MS); 60 | i2c_cmd_link_delete(cmd); 61 | return ret; 62 | } 63 | 64 | -------------------------------------------------------------------------------- /components/bsp/hal_i2s.c: -------------------------------------------------------------------------------- 1 | #include "freertos/FreeRTOS.h" 2 | #include "driver/i2s.h" 3 | #include "hal_i2s.h" 4 | #include "soc/io_mux_reg.h" 5 | #include "soc/soc.h" 6 | 7 | void hal_i2s_init(uint8_t i2s_num,uint32_t rate,uint8_t bits,uint8_t ch) 8 | { 9 | 10 | i2s_channel_fmt_t chanel; 11 | if(ch==2) 12 | chanel=I2S_CHANNEL_FMT_RIGHT_LEFT; 13 | else 14 | chanel=I2S_CHANNEL_FMT_ONLY_LEFT; 15 | 16 | i2s_config_t i2s_config = { 17 | .mode = I2S_MODE_MASTER | I2S_MODE_TX|I2S_MODE_RX, 18 | .sample_rate = rate, 19 | .bits_per_sample = bits, 20 | .channel_format = chanel, //2-channels 21 | .communication_format = I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB, 22 | .dma_buf_count = 3, 23 | .dma_buf_len = 1024, // 24 | .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1 //Interrupt level 1 25 | }; 26 | i2s_pin_config_t pin_config = { 27 | .bck_io_num = 33, 28 | .ws_io_num = 25, 29 | .data_out_num = 26, 30 | .data_in_num = 27 //Not used 31 | }; 32 | i2s_driver_install(i2s_num, &i2s_config, 0, NULL); 33 | i2s_set_pin(i2s_num, &pin_config); 34 | //clk out 35 | PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1); 36 | //REG_SET_FIELD(PIN_CTRL, CLK_OUT1, 0) 37 | REG_WRITE(PIN_CTRL, 0xFFFFFFF0);; 38 | //i2s_set_clk(i2s_num, rate, bits, ch); 39 | } 40 | void hal_i2s_deinit(uint8_t i2s_num){ 41 | i2s_driver_uninstall(i2s_num); 42 | } 43 | int hal_i2s_read(uint8_t i2s_num,char* dest,size_t size,TickType_t timeout) 44 | { 45 | return i2s_read_bytes(i2s_num, dest, size, timeout); 46 | } 47 | int hal_i2s_write(uint8_t i2s_num,char* dest,size_t size,TickType_t timeout) 48 | { 49 | return i2s_write_bytes(i2s_num, dest, size, timeout); 50 | } 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /components/bsp/include/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whyengineer/esp32-lin/6fa39f4cd5f7782b3a2a052767f0fb06be2378ff/components/bsp/include/.DS_Store -------------------------------------------------------------------------------- /components/bsp/include/bsp.h: -------------------------------------------------------------------------------- 1 | #ifndef BSP_H 2 | #define BSP_H 3 | 4 | 5 | #include "hal_i2c.h" 6 | #include "hal_i2s.h" 7 | #include "wm8978.h" 8 | #include "driver/gpio.h" 9 | #include "driver/sdmmc_host.h" 10 | #include "driver/sdmmc_defs.h" 11 | 12 | #define LED_R 5 13 | #define LED_G 21 14 | #define LED_B 22 15 | 16 | #define KEY_1 34 17 | #define KEY_2 35 18 | #define KEY_3 32 19 | 20 | #define SD_CD 23 21 | 22 | 23 | 24 | typedef enum{ 25 | KEY_1_PUSH=0U, 26 | KEY_1_RELEASE, 27 | KEY_2_PUSH, 28 | KEY_2_RELEASE, 29 | KEY_3_PUSH, 30 | KEY_3_RELEASE, 31 | KEY_NULL, 32 | }key_event_t; 33 | 34 | typedef struct{ 35 | uint32_t vol; 36 | int sd; 37 | key_event_t key_e; 38 | }bsp_event_t; 39 | 40 | void bsp_init(); 41 | BaseType_t bsp_event_get(void* buf,TickType_t timeout); 42 | 43 | 44 | #endif -------------------------------------------------------------------------------- /components/bsp/include/hal_eth.h: -------------------------------------------------------------------------------- 1 | #ifndef HAL_ETH_H 2 | #define HAL_ETH_H 3 | 4 | #include "esp_eth.h" 5 | esp_err_t hal_eht_init(); 6 | 7 | #endif -------------------------------------------------------------------------------- /components/bsp/include/hal_i2c.h: -------------------------------------------------------------------------------- 1 | #ifndef _HAL_I2C_H 2 | #define _HAL_I2C_H 3 | 4 | #include "driver/i2c.h" 5 | esp_err_t hal_i2c_master_mem_read(i2c_port_t i2c_num, uint8_t DevAddr,uint8_t MemAddr,uint8_t* data_rd, size_t size); 6 | esp_err_t hal_i2c_master_mem_write(i2c_port_t i2c_num, uint8_t DevAddr,uint8_t MemAddr,uint8_t* data_wr, size_t size); 7 | void hal_i2c_init(uint8_t port ,uint8_t sda,uint8_t scl); 8 | 9 | #endif 10 | 11 | -------------------------------------------------------------------------------- /components/bsp/include/hal_i2s.h: -------------------------------------------------------------------------------- 1 | #ifndef HAL_I2S_H 2 | #define HAL_I2S_H 3 | 4 | 5 | #include "driver/i2s.h" 6 | 7 | void hal_i2s_init(uint8_t i2s_num,uint32_t rate,uint8_t bits,uint8_t ch); 8 | void hal_i2s_deinit(uint8_t i2s_num); 9 | int hal_i2s_read(uint8_t i2s_num,char* dest,size_t size,TickType_t timeout); 10 | int hal_i2s_write(uint8_t i2s_num,char* dest,size_t size,TickType_t timeout); 11 | #endif 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /components/bsp/include/wm8978.h: -------------------------------------------------------------------------------- 1 | #ifndef __WM8978_H 2 | #define __WM8978_H 3 | 4 | #include "hal_i2c.h" 5 | 6 | #define WM8978_ADDR 0X1A 7 | 8 | #define EQ1_80Hz 0X00 9 | #define EQ1_105Hz 0X01 10 | #define EQ1_135Hz 0X02 11 | #define EQ1_175Hz 0X03 12 | 13 | #define EQ2_230Hz 0X00 14 | #define EQ2_300Hz 0X01 15 | #define EQ2_385Hz 0X02 16 | #define EQ2_500Hz 0X03 17 | 18 | #define EQ3_650Hz 0X00 19 | #define EQ3_850Hz 0X01 20 | #define EQ3_1100Hz 0X02 21 | #define EQ3_14000Hz 0X03 22 | 23 | #define EQ4_1800Hz 0X00 24 | #define EQ4_2400Hz 0X01 25 | #define EQ4_3200Hz 0X02 26 | #define EQ4_4100Hz 0X03 27 | 28 | #define EQ5_5300Hz 0X00 29 | #define EQ5_6900Hz 0X01 30 | #define EQ5_9000Hz 0X02 31 | #define EQ5_11700Hz 0X03 32 | 33 | 34 | #define WM8978_RESET 0x00 35 | 36 | #define WM8978_POWER_MANAGEMENT_1 0x01 37 | 38 | #define WM8978_POWER_MANAGEMENT_2 0x02 39 | 40 | #define WM8978_POWER_MANAGEMENT_3 0x03 41 | 42 | #define WM8978_AUDIO_INTERFACE 0x04 43 | 44 | #define WM8978_COMPANDING_CONTROL 0x05 45 | 46 | #define WM8978_CLOCKING 0x06 47 | 48 | #define WM8978_ADDITIONAL_CONTROL 0x07 49 | 50 | #define WM8978_GPIO_CONTROL 0x08 51 | 52 | #define WM8978_JACK_DETECT_CONTROL_1 0x09 53 | 54 | #define WM8978_DAC_CONTROL 0x0A 55 | 56 | #define WM8978_LEFT_DAC_DIGITAL_VOLUME 0x0B 57 | 58 | #define WM8978_RIGHT_DAC_DIGITAL_VOLUME 0x0C 59 | 60 | #define WM8978_JACK_DETECT_CONTROL_2 0x0D 61 | 62 | #define WM8978_ADC_CONTROL 0x0E 63 | 64 | #define WM8978_LEFT_ADC_DIGITAL_VOLUME 0x0F 65 | 66 | #define WM8978_RIGHT_ADC_DIGITAL_VOLUME 0x10 67 | 68 | #define WM8978_EQ1 0x12 69 | 70 | #define WM8978_EQ2 0x13 71 | 72 | #define WM8978_EQ3 0x14 73 | 74 | #define WM8978_EQ4 0x15 75 | 76 | #define WM8978_EQ5 0x16 77 | 78 | #define WM8978_DAC_LIMITER_1 0x18 79 | 80 | #define WM8978_DAC_LIMITER_2 0x19 81 | 82 | #define WM8978_NOTCH_FILTER_1 0x1b 83 | 84 | #define WM8978_NOTCH_FILTER_2 0x1c 85 | 86 | #define WM8978_NOTCH_FILTER_3 0x1d 87 | 88 | #define WM8978_NOTCH_FILTER_4 0x1e 89 | 90 | #define WM8978_ALC_CONTROL_1 0x20 91 | 92 | #define WM8978_ALC_CONTROL_2 0x21 93 | 94 | #define WM8978_ALC_CONTROL_3 0x22 95 | 96 | #define WM8978_NOISE_GATE 0x23 97 | 98 | #define WM8978_PLL_N 0x24 99 | 100 | #define WM8978_PLL_K1 0x25 101 | 102 | #define WM8978_PLL_K2 0x26 103 | 104 | #define WM8978_PLL_K3 0x27 105 | 106 | #define WM8978_3D_CONTROL 0x29 107 | 108 | #define WM8978_BEEP_CONTROL 0x2b 109 | 110 | #define WM8978_INPUT_CONTROL 0x2c 111 | 112 | #define WM8978_LEFT_INP_PGA_CONTROL 0x2d 113 | 114 | #define WM8978_RIGHT_INP_PGA_CONTROL 0x2e 115 | 116 | #define WM8978_LEFT_ADC_BOOST_CONTROL 0x2f 117 | 118 | #define WM8978_RIGHT_ADC_BOOST_CONTROL 0x30 119 | 120 | #define WM8978_OUTPUT_CONTROL 0x31 121 | 122 | #define WM8978_LEFT_MIXER_CONTROL 0x32 123 | 124 | #define WM8978_RIGHT_MIXER_CONTROL 0x33 125 | 126 | #define WM8978_LOUT1_HP_CONTROL 0x34 127 | 128 | #define WM8978_ROUT1_HP_CONTROL 0x35 129 | 130 | #define WM8978_LOUT2_SPK_CONTROL 0x36 131 | 132 | #define WM8978_ROUT2_SPK_CONTROL 0x37 133 | 134 | #define WM8978_OUT3_MIXER_CONTROL 0x38 135 | 136 | #define WM8978_OUT4_MIXER_CONTROL 0x39 137 | 138 | 139 | 140 | uint8_t WM8978_Init(void); 141 | void WM8978_ADDA_Cfg(uint8_t dacen,uint8_t adcen); 142 | void WM8978_Input_Cfg(uint8_t micen,uint8_t lineinen,uint8_t auxen); 143 | void WM8978_Output_Cfg(uint8_t dacen,uint8_t bpsen); 144 | void WM8978_MIC_Gain(uint8_t gain); 145 | void WM8978_LINEIN_Gain(uint8_t gain); 146 | void WM8978_AUX_Gain(uint8_t gain); 147 | uint8_t WM8978_Write_Reg(uint8_t reg,uint16_t val); 148 | uint16_t WM8978_Read_Reg(uint8_t reg); 149 | void WM8978_HPvol_Set(uint8_t voll,uint8_t volr); 150 | void WM8978_SPKvol_Set(uint8_t volx); 151 | void WM8978_I2S_Cfg(uint8_t fmt,uint8_t len); 152 | void WM8978_3D_Set(uint8_t depth); 153 | void WM8978_EQ_3D_Dir(uint8_t dir); 154 | void WM8978_EQ1_Set(uint8_t cfreq,uint8_t gain); 155 | void WM8978_EQ2_Set(uint8_t cfreq,uint8_t gain); 156 | void WM8978_EQ3_Set(uint8_t cfreq,uint8_t gain); 157 | void WM8978_EQ4_Set(uint8_t cfreq,uint8_t gain); 158 | void WM8978_EQ5_Set(uint8_t cfreq,uint8_t gain); 159 | void WM8978_DAC_VOL_SET(uint8_t vol); 160 | 161 | #endif 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | -------------------------------------------------------------------------------- /components/dsp_lib/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whyengineer/esp32-lin/6fa39f4cd5f7782b3a2a052767f0fb06be2378ff/components/dsp_lib/.DS_Store -------------------------------------------------------------------------------- /components/dsp_lib/BasicMathFunctions/xtensa_abs_f32.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "xtensa_math.h" 4 | #include 5 | 6 | /** 7 | * @ingroup groupMath 8 | */ 9 | 10 | /** 11 | * @defgroup BasicAbs Vector Absolute Value 12 | * 13 | * Computes the absolute value of a vector on an element-by-element basis. 14 | * 15 | *
16 |  *     pDst[n] = abs(pSrc[n]),   0 <= n < blockSize.
17 |  * 
18 | * 19 | * The functions support in-place computation allowing the source and 20 | * destination pointers to reference the same memory buffer. 21 | * There are separate functions for floating-point, Q7, Q15, and Q31 data types. 22 | */ 23 | 24 | /** 25 | * @addtogroup BasicAbs 26 | * @{ 27 | */ 28 | 29 | /** 30 | * @brief Floating-point vector absolute value. 31 | * @param[in] *pSrc points to the input buffer 32 | * @param[out] *pDst points to the output buffer 33 | * @param[in] blockSize number of samples in each vector 34 | * @return none. 35 | */ 36 | 37 | void xtensa_abs_f32( 38 | float32_t * pSrc, 39 | float32_t * pDst, 40 | uint32_t blockSize) 41 | { 42 | uint32_t blkCnt; /* loop counter */ 43 | 44 | 45 | /* Initialize blkCnt with number of samples */ 46 | blkCnt = blockSize; 47 | 48 | while (blkCnt > 0U) 49 | { 50 | /* C = |A| */ 51 | /* Calculate absolute and then store the results in the destination buffer. */ 52 | *pDst++ = fabsf(*pSrc++); 53 | 54 | /* Decrement the loop counter */ 55 | blkCnt--; 56 | } 57 | } 58 | 59 | /** 60 | * @} end of BasicAbs group 61 | */ 62 | -------------------------------------------------------------------------------- /components/dsp_lib/BasicMathFunctions/xtensa_add_f32.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "xtensa_math.h" 4 | 5 | /** 6 | * @ingroup groupMath 7 | */ 8 | 9 | /** 10 | * @defgroup BasicAdd Vector Addition 11 | * 12 | * Element-by-element addition of two vectors. 13 | * 14 | *
15 |  *     pDst[n] = pSrcA[n] + pSrcB[n],   0 <= n < blockSize.
16 |  * 
17 | * 18 | * There are separate functions for floating-point, Q7, Q15, and Q31 data types. 19 | */ 20 | 21 | /** 22 | * @addtogroup BasicAdd 23 | * @{ 24 | */ 25 | 26 | /** 27 | * @brief Floating-point vector addition. 28 | * @param[in] *pSrcA points to the first input vector 29 | * @param[in] *pSrcB points to the second input vector 30 | * @param[out] *pDst points to the output vector 31 | * @param[in] blockSize number of samples in each vector 32 | * @return none. 33 | */ 34 | 35 | void xtensa_add_f32( 36 | float32_t * pSrcA, 37 | float32_t * pSrcB, 38 | float32_t * pDst, 39 | uint32_t blockSize) 40 | { 41 | uint32_t blkCnt; /* loop counter */ 42 | blkCnt = blockSize; 43 | 44 | 45 | while (blkCnt > 0U) 46 | { 47 | /* C = A + B */ 48 | /* Add and then store the results in the destination buffer. */ 49 | *pDst++ = (*pSrcA++) + (*pSrcB++); 50 | 51 | /* Decrement the loop counter */ 52 | blkCnt--; 53 | } 54 | } 55 | 56 | /** 57 | * @} end of BasicAdd group 58 | */ 59 | -------------------------------------------------------------------------------- /components/dsp_lib/BasicMathFunctions/xtensa_dot_prod_f32.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "xtensa_math.h" 4 | 5 | /** 6 | * @ingroup groupMath 7 | */ 8 | 9 | /** 10 | * @defgroup dot_prod Vector Dot Product 11 | * 12 | * Computes the dot product of two vectors. 13 | * The vectors are multiplied element-by-element and then summed. 14 | * 15 | *
16 |  *     sum = pSrcA[0]*pSrcB[0] + pSrcA[1]*pSrcB[1] + ... + pSrcA[blockSize-1]*pSrcB[blockSize-1]
17 |  * 
18 | * 19 | * There are separate functions for floating-point, Q7, Q15, and Q31 data types. 20 | */ 21 | 22 | /** 23 | * @addtogroup dot_prod 24 | * @{ 25 | */ 26 | 27 | /** 28 | * @brief Dot product of floating-point vectors. 29 | * @param[in] *pSrcA points to the first input vector 30 | * @param[in] *pSrcB points to the second input vector 31 | * @param[in] blockSize number of samples in each vector 32 | * @param[out] *result output result returned here 33 | * @return none. 34 | */ 35 | 36 | 37 | void xtensa_dot_prod_f32( 38 | float32_t * pSrcA, 39 | float32_t * pSrcB, 40 | uint32_t blockSize, 41 | float32_t * result) 42 | { 43 | float32_t sum = 0.0f; /* Temporary result storage */ 44 | uint32_t blkCnt; /* loop counter */ 45 | 46 | 47 | 48 | 49 | /* Initialize blkCnt with number of samples */ 50 | blkCnt = blockSize; 51 | 52 | 53 | 54 | while (blkCnt > 0U) 55 | { 56 | /* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]* B[blockSize-1] */ 57 | /* Calculate dot product and then store the result in a temporary buffer. */ 58 | sum += (*pSrcA++) * (*pSrcB++); 59 | 60 | /* Decrement the loop counter */ 61 | blkCnt--; 62 | } 63 | /* Store the result back in the destination buffer */ 64 | *result = sum; 65 | } 66 | 67 | /** 68 | * @} end of dot_prod group 69 | */ 70 | -------------------------------------------------------------------------------- /components/dsp_lib/BasicMathFunctions/xtensa_mult_f32.c: -------------------------------------------------------------------------------- 1 | 2 | #include "xtensa_math.h" 3 | 4 | /** 5 | * @ingroup groupMath 6 | */ 7 | 8 | /** 9 | * @defgroup BasicMult Vector Multiplication 10 | * 11 | * Element-by-element multiplication of two vectors. 12 | * 13 | *
14 |  *     pDst[n] = pSrcA[n] * pSrcB[n],   0 <= n < blockSize.
15 |  * 
16 | * 17 | * There are separate functions for floating-point, Q7, Q15, and Q31 data types. 18 | */ 19 | 20 | /** 21 | * @addtogroup BasicMult 22 | * @{ 23 | */ 24 | 25 | /** 26 | * @brief Floating-point vector multiplication. 27 | * @param[in] *pSrcA points to the first input vector 28 | * @param[in] *pSrcB points to the second input vector 29 | * @param[out] *pDst points to the output vector 30 | * @param[in] blockSize number of samples in each vector 31 | * @return none. 32 | */ 33 | 34 | void xtensa_mult_f32( 35 | float32_t * pSrcA, 36 | float32_t * pSrcB, 37 | float32_t * pDst, 38 | uint32_t blockSize) 39 | { 40 | uint32_t blkCnt; /* loop counters */ 41 | 42 | /* Initialize blkCnt with number of samples */ 43 | blkCnt = blockSize; 44 | 45 | 46 | while (blkCnt > 0U) 47 | { 48 | /* C = A * B */ 49 | /* Multiply the inputs and store the results in output buffer */ 50 | *pDst++ = (*pSrcA++) * (*pSrcB++); 51 | 52 | /* Decrement the blockSize loop counter */ 53 | blkCnt--; 54 | } 55 | } 56 | 57 | /** 58 | * @} end of BasicMult group 59 | */ 60 | -------------------------------------------------------------------------------- /components/dsp_lib/BasicMathFunctions/xtensa_negate_f32.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "xtensa_math.h" 4 | 5 | /** 6 | * @ingroup groupMath 7 | */ 8 | 9 | /** 10 | * @defgroup negate Vector Negate 11 | * 12 | * Negates the elements of a vector. 13 | * 14 | *
15 |  *     pDst[n] = -pSrc[n],   0 <= n < blockSize.
16 |  * 
17 | * 18 | * The functions support in-place computation allowing the source and 19 | * destination pointers to reference the same memory buffer. 20 | * There are separate functions for floating-point, Q7, Q15, and Q31 data types. 21 | */ 22 | 23 | /** 24 | * @addtogroup negate 25 | * @{ 26 | */ 27 | 28 | /** 29 | * @brief Negates the elements of a floating-point vector. 30 | * @param[in] *pSrc points to the input vector 31 | * @param[out] *pDst points to the output vector 32 | * @param[in] blockSize number of samples in the vector 33 | * @return none. 34 | */ 35 | 36 | void xtensa_negate_f32( 37 | float32_t * pSrc, 38 | float32_t * pDst, 39 | uint32_t blockSize) 40 | { 41 | uint32_t blkCnt; /* loop counter */ 42 | 43 | 44 | 45 | 46 | /* Initialize blkCnt with number of samples */ 47 | blkCnt = blockSize; 48 | 49 | while (blkCnt > 0U) 50 | { 51 | /* C = -A */ 52 | /* Negate and then store the results in the destination buffer. */ 53 | *pDst++ = -*pSrc++; 54 | 55 | /* Decrement the loop counter */ 56 | blkCnt--; 57 | } 58 | } 59 | 60 | /** 61 | * @} end of negate group 62 | */ 63 | -------------------------------------------------------------------------------- /components/dsp_lib/BasicMathFunctions/xtensa_offset_f32.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "xtensa_math.h" 4 | 5 | /** 6 | * @ingroup groupMath 7 | */ 8 | 9 | /** 10 | * @defgroup offset Vector Offset 11 | * 12 | * Adds a constant offset to each element of a vector. 13 | * 14 | *
15 |  *     pDst[n] = pSrc[n] + offset,   0 <= n < blockSize.
16 |  * 
17 | * 18 | * The functions support in-place computation allowing the source and 19 | * destination pointers to reference the same memory buffer. 20 | * There are separate functions for floating-point, Q7, Q15, and Q31 data types. 21 | */ 22 | 23 | /** 24 | * @addtogroup offset 25 | * @{ 26 | */ 27 | 28 | /** 29 | * @brief Adds a constant offset to a floating-point vector. 30 | * @param[in] *pSrc points to the input vector 31 | * @param[in] offset is the offset to be added 32 | * @param[out] *pDst points to the output vector 33 | * @param[in] blockSize number of samples in the vector 34 | * @return none. 35 | */ 36 | 37 | 38 | void xtensa_offset_f32( 39 | float32_t * pSrc, 40 | float32_t offset, 41 | float32_t * pDst, 42 | uint32_t blockSize) 43 | { 44 | uint32_t blkCnt; /* loop counter */ 45 | 46 | 47 | /* Initialize blkCnt with number of samples */ 48 | blkCnt = blockSize; 49 | 50 | while (blkCnt > 0U) 51 | { 52 | /* C = A + offset */ 53 | /* Add offset and then store the result in the destination buffer. */ 54 | *pDst++ = (*pSrc++) + offset; 55 | 56 | /* Decrement the loop counter */ 57 | blkCnt--; 58 | } 59 | } 60 | 61 | /** 62 | * @} end of offset group 63 | */ 64 | -------------------------------------------------------------------------------- /components/dsp_lib/BasicMathFunctions/xtensa_scale_f32.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "xtensa_math.h" 4 | 5 | /** 6 | * @ingroup groupMath 7 | */ 8 | 9 | /** 10 | * @defgroup scale Vector Scale 11 | * 12 | * Multiply a vector by a scalar value. For floating-point data, the algorithm used is: 13 | * 14 | *
15 |  *     pDst[n] = pSrc[n] * scale,   0 <= n < blockSize.
16 |  * 
17 | * 18 | * In the fixed-point Q7, Q15, and Q31 functions, scale is represented by 19 | * a fractional multiplication scaleFract and an arithmetic shift shift. 20 | * The shift allows the gain of the scaling operation to exceed 1.0. 21 | * The algorithm used with fixed-point data is: 22 | * 23 | *
24 |  *     pDst[n] = (pSrc[n] * scaleFract) << shift,   0 <= n < blockSize.
25 |  * 
26 | * 27 | * The overall scale factor applied to the fixed-point data is 28 | *
29 |  *     scale = scaleFract * 2^shift.
30 |  * 
31 | * 32 | * The functions support in-place computation allowing the source and destination 33 | * pointers to reference the same memory buffer. 34 | */ 35 | 36 | /** 37 | * @addtogroup scale 38 | * @{ 39 | */ 40 | 41 | /** 42 | * @brief Multiplies a floating-point vector by a scalar. 43 | * @param[in] *pSrc points to the input vector 44 | * @param[in] scale scale factor to be applied 45 | * @param[out] *pDst points to the output vector 46 | * @param[in] blockSize number of samples in the vector 47 | * @return none. 48 | */ 49 | 50 | 51 | void xtensa_scale_f32( 52 | float32_t * pSrc, 53 | float32_t scale, 54 | float32_t * pDst, 55 | uint32_t blockSize) 56 | { 57 | uint32_t blkCnt; /* loop counter */ 58 | 59 | 60 | 61 | /* Initialize blkCnt with number of samples */ 62 | blkCnt = blockSize; 63 | 64 | 65 | while (blkCnt > 0U) 66 | { 67 | /* C = A * scale */ 68 | /* Scale the input and then store the result in the destination buffer. */ 69 | *pDst++ = (*pSrc++) * scale; 70 | 71 | /* Decrement the loop counter */ 72 | blkCnt--; 73 | } 74 | } 75 | 76 | /** 77 | * @} end of scale group 78 | */ 79 | -------------------------------------------------------------------------------- /components/dsp_lib/BasicMathFunctions/xtensa_sub_f32.c: -------------------------------------------------------------------------------- 1 | 2 | #include "xtensa_math.h" 3 | 4 | /** 5 | * @ingroup groupMath 6 | */ 7 | 8 | /** 9 | * @defgroup BasicSub Vector Subtraction 10 | * 11 | * Element-by-element subtraction of two vectors. 12 | * 13 | *
14 |  *     pDst[n] = pSrcA[n] - pSrcB[n],   0 <= n < blockSize.
15 |  * 
16 | * 17 | * There are separate functions for floating-point, Q7, Q15, and Q31 data types. 18 | */ 19 | 20 | /** 21 | * @addtogroup BasicSub 22 | * @{ 23 | */ 24 | 25 | 26 | /** 27 | * @brief Floating-point vector subtraction. 28 | * @param[in] *pSrcA points to the first input vector 29 | * @param[in] *pSrcB points to the second input vector 30 | * @param[out] *pDst points to the output vector 31 | * @param[in] blockSize number of samples in each vector 32 | * @return none. 33 | */ 34 | 35 | void xtensa_sub_f32( 36 | float32_t * pSrcA, 37 | float32_t * pSrcB, 38 | float32_t * pDst, 39 | uint32_t blockSize) 40 | { 41 | uint32_t blkCnt; /* loop counter */ 42 | 43 | 44 | 45 | /* Initialize blkCnt with number of samples */ 46 | blkCnt = blockSize; 47 | 48 | while (blkCnt > 0U) 49 | { 50 | /* C = A - B */ 51 | /* Subtract and then store the results in the destination buffer. */ 52 | *pDst++ = (*pSrcA++) - (*pSrcB++); 53 | 54 | /* Decrement the loop counter */ 55 | blkCnt--; 56 | } 57 | } 58 | 59 | /** 60 | * @} end of BasicSub group 61 | */ 62 | -------------------------------------------------------------------------------- /components/dsp_lib/CommonTables/xtensa_const_structs.c: -------------------------------------------------------------------------------- 1 | 2 | #include "xtensa_const_structs.h" 3 | 4 | /* Floating-point structs */ 5 | const xtensa_cfft_instance_f32 xtensa_cfft_sR_f32_len16 = { 6 | 16, twiddleCoef_16, xtensaBitRevIndexTable16, XTENSABITREVINDEXTABLE_16_TABLE_LENGTH 7 | }; 8 | 9 | const xtensa_cfft_instance_f32 xtensa_cfft_sR_f32_len32 = { 10 | 32, twiddleCoef_32, xtensaBitRevIndexTable32, XTENSABITREVINDEXTABLE_32_TABLE_LENGTH 11 | }; 12 | 13 | const xtensa_cfft_instance_f32 xtensa_cfft_sR_f32_len64 = { 14 | 64, twiddleCoef_64, xtensaBitRevIndexTable64, XTENSABITREVINDEXTABLE_64_TABLE_LENGTH 15 | }; 16 | 17 | const xtensa_cfft_instance_f32 xtensa_cfft_sR_f32_len128 = { 18 | 128, twiddleCoef_128, xtensaBitRevIndexTable128, XTENSABITREVINDEXTABLE_128_TABLE_LENGTH 19 | }; 20 | 21 | const xtensa_cfft_instance_f32 xtensa_cfft_sR_f32_len256 = { 22 | 256, twiddleCoef_256, xtensaBitRevIndexTable256, XTENSABITREVINDEXTABLE_256_TABLE_LENGTH 23 | }; 24 | 25 | const xtensa_cfft_instance_f32 xtensa_cfft_sR_f32_len512 = { 26 | 512, twiddleCoef_512, xtensaBitRevIndexTable512, XTENSABITREVINDEXTABLE_512_TABLE_LENGTH 27 | }; 28 | 29 | const xtensa_cfft_instance_f32 xtensa_cfft_sR_f32_len1024 = { 30 | 1024, twiddleCoef_1024, xtensaBitRevIndexTable1024, XTENSABITREVINDEXTABLE_1024_TABLE_LENGTH 31 | }; 32 | 33 | const xtensa_cfft_instance_f32 xtensa_cfft_sR_f32_len2048 = { 34 | 2048, twiddleCoef_2048, xtensaBitRevIndexTable2048, XTENSABITREVINDEXTABLE_2048_TABLE_LENGTH 35 | }; 36 | 37 | const xtensa_cfft_instance_f32 xtensa_cfft_sR_f32_len4096 = { 38 | 4096, twiddleCoef_4096, xtensaBitRevIndexTable4096, XTENSABITREVINDEXTABLE_4096_TABLE_LENGTH 39 | }; 40 | 41 | 42 | 43 | /* Structure for real-value inputs */ 44 | /* Floating-point structs */ 45 | const xtensa_rfft_fast_instance_f32 xtensa_rfft_fast_sR_f32_len32 = { 46 | { 16, twiddleCoef_32, xtensaBitRevIndexTable32, XTENSABITREVINDEXTABLE_16_TABLE_LENGTH }, 47 | 32U, 48 | (float32_t *)twiddleCoef_rfft_32 49 | }; 50 | 51 | const xtensa_rfft_fast_instance_f32 xtensa_rfft_fast_sR_f32_len64 = { 52 | { 32, twiddleCoef_32, xtensaBitRevIndexTable32, XTENSABITREVINDEXTABLE_32_TABLE_LENGTH }, 53 | 64U, 54 | (float32_t *)twiddleCoef_rfft_64 55 | }; 56 | 57 | const xtensa_rfft_fast_instance_f32 xtensa_rfft_fast_sR_f32_len128 = { 58 | { 64, twiddleCoef_64, xtensaBitRevIndexTable64, XTENSABITREVINDEXTABLE_64_TABLE_LENGTH }, 59 | 128U, 60 | (float32_t *)twiddleCoef_rfft_128 61 | }; 62 | 63 | const xtensa_rfft_fast_instance_f32 xtensa_rfft_fast_sR_f32_len256 = { 64 | { 128, twiddleCoef_128, xtensaBitRevIndexTable128, XTENSABITREVINDEXTABLE_128_TABLE_LENGTH }, 65 | 256U, 66 | (float32_t *)twiddleCoef_rfft_256 67 | }; 68 | 69 | const xtensa_rfft_fast_instance_f32 xtensa_rfft_fast_sR_f32_len512 = { 70 | { 256, twiddleCoef_256, xtensaBitRevIndexTable256, XTENSABITREVINDEXTABLE_256_TABLE_LENGTH }, 71 | 512U, 72 | (float32_t *)twiddleCoef_rfft_512 73 | }; 74 | 75 | const xtensa_rfft_fast_instance_f32 xtensa_rfft_fast_sR_f32_len1024 = { 76 | { 512, twiddleCoef_512, xtensaBitRevIndexTable512, XTENSABITREVINDEXTABLE_512_TABLE_LENGTH }, 77 | 1024U, 78 | (float32_t *)twiddleCoef_rfft_1024 79 | }; 80 | 81 | const xtensa_rfft_fast_instance_f32 xtensa_rfft_fast_sR_f32_len2048 = { 82 | { 1024, twiddleCoef_1024, xtensaBitRevIndexTable1024, XTENSABITREVINDEXTABLE_1024_TABLE_LENGTH }, 83 | 2048U, 84 | (float32_t *)twiddleCoef_rfft_2048 85 | }; 86 | 87 | const xtensa_rfft_fast_instance_f32 xtensa_rfft_fast_sR_f32_len4096 = { 88 | { 2048, twiddleCoef_2048, xtensaBitRevIndexTable2048, XTENSABITREVINDEXTABLE_2048_TABLE_LENGTH }, 89 | 4096U, 90 | (float32_t *)twiddleCoef_rfft_4096 91 | }; 92 | -------------------------------------------------------------------------------- /components/dsp_lib/ComplexMathFunctions/xtensa_cmplx_conj_f32.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "xtensa_math.h" 4 | 5 | /** 6 | * @ingroup groupCmplxMath 7 | */ 8 | 9 | /** 10 | * @defgroup cmplx_conj Complex Conjugate 11 | * 12 | * Conjugates the elements of a complex data vector. 13 | * 14 | * The pSrc points to the source data and 15 | * pDst points to the where the result should be written. 16 | * numSamples specifies the number of complex samples 17 | * and the data in each array is stored in an interleaved fashion 18 | * (real, imag, real, imag, ...). 19 | * Each array has a total of 2*numSamples values. 20 | * The underlying algorithm is used: 21 | * 22 | *
23 |  * for(n=0; n
28 |  *
29 |  * There are separate functions for floating-point, Q15, and Q31 data types.
30 |  */
31 | 
32 | /**
33 |  * @addtogroup cmplx_conj
34 |  * @{
35 |  */
36 | 
37 | /**
38 |  * @brief  Floating-point complex conjugate.
39 |  * @param  *pSrc points to the input vector
40 |  * @param  *pDst points to the output vector
41 |  * @param  numSamples number of complex samples in each vector
42 |  * @return none.
43 |  */
44 | 
45 | void xtensa_cmplx_conj_f32(
46 |   float32_t * pSrc,
47 |   float32_t * pDst,
48 |   uint32_t numSamples)
49 | {
50 |   uint32_t blkCnt;                               /* loop counter */
51 | 
52 | 
53 |   blkCnt = numSamples;
54 | 
55 | 
56 |   while (blkCnt > 0U)
57 |   {
58 |     /* realOut + j (imagOut) = realIn + j (-1) imagIn */
59 |     /* Calculate Complex Conjugate and then store the results in the destination buffer. */
60 |     *pDst++ = *pSrc++;
61 |     *pDst++ = -*pSrc++;
62 | 
63 |     /* Decrement the loop counter */
64 |     blkCnt--;
65 |   }
66 | }
67 | 
68 | /**
69 |  * @} end of cmplx_conj group
70 |  */
71 | 


--------------------------------------------------------------------------------
/components/dsp_lib/ComplexMathFunctions/xtensa_cmplx_dot_prod_f32.c:
--------------------------------------------------------------------------------
 1 | 
 2 | 
 3 | #include "xtensa_math.h"
 4 | 
 5 | /**
 6 |  * @ingroup groupCmplxMath
 7 |  */
 8 | 
 9 | /**
10 |  * @defgroup cmplx_dot_prod Complex Dot Product
11 |  *
12 |  * Computes the dot product of two complex vectors.
13 |  * The vectors are multiplied element-by-element and then summed.
14 |  *
15 |  * The pSrcA points to the first complex input vector and
16 |  * pSrcB points to the second complex input vector.
17 |  * numSamples specifies the number of complex samples
18 |  * and the data in each array is stored in an interleaved fashion
19 |  * (real, imag, real, imag, ...).
20 |  * Each array has a total of 2*numSamples values.
21 |  *
22 |  * The underlying algorithm is used:
23 |  * 
24 |  * realResult=0;
25 |  * imagResult=0;
26 |  * for(n=0; n
31 |  *
32 |  * There are separate functions for floating-point, Q15, and Q31 data types.
33 |  */
34 | 
35 | /**
36 |  * @addtogroup cmplx_dot_prod
37 |  * @{
38 |  */
39 | 
40 | /**
41 |  * @brief  Floating-point complex dot product
42 |  * @param  *pSrcA points to the first input vector
43 |  * @param  *pSrcB points to the second input vector
44 |  * @param  numSamples number of complex samples in each vector
45 |  * @param  *realResult real part of the result returned here
46 |  * @param  *imagResult imaginary part of the result returned here
47 |  * @return none.
48 |  */
49 | 
50 | void xtensa_cmplx_dot_prod_f32(
51 |   float32_t * pSrcA,
52 |   float32_t * pSrcB,
53 |   uint32_t numSamples,
54 |   float32_t * realResult,
55 |   float32_t * imagResult)
56 | {
57 |   float32_t real_sum = 0.0f, imag_sum = 0.0f;    /* Temporary result storage */
58 |   float32_t a0,b0,c0,d0;
59 | 
60 | 
61 | 
62 | 
63 |   while (numSamples > 0U)
64 |   {
65 |       a0 = *pSrcA++;
66 |       b0 = *pSrcA++;
67 |       c0 = *pSrcB++;
68 |       d0 = *pSrcB++;
69 | 
70 |       real_sum += a0 * c0;
71 |       imag_sum += a0 * d0;
72 |       real_sum -= b0 * d0;
73 |       imag_sum += b0 * c0;
74 | 
75 |       /* Decrement the loop counter */
76 |       numSamples--;
77 |   }
78 | 
79 | 
80 |   /* Store the real and imaginary results in the destination buffers */
81 |   *realResult = real_sum;
82 |   *imagResult = imag_sum;
83 | }
84 | 
85 | /**
86 |  * @} end of cmplx_dot_prod group
87 |  */
88 | 


--------------------------------------------------------------------------------
/components/dsp_lib/ComplexMathFunctions/xtensa_cmplx_mag_f32.c:
--------------------------------------------------------------------------------
 1 | 
 2 | 
 3 | #include "xtensa_math.h"
 4 | 
 5 | /**
 6 |  * @ingroup groupCmplxMath
 7 |  */
 8 | 
 9 | /**
10 |  * @defgroup cmplx_mag Complex Magnitude
11 |  *
12 |  * Computes the magnitude of the elements of a complex data vector.
13 |  *
14 |  * The pSrc points to the source data and
15 |  * pDst points to the where the result should be written.
16 |  * numSamples specifies the number of complex samples
17 |  * in the input array and the data is stored in an interleaved fashion
18 |  * (real, imag, real, imag, ...).
19 |  * The input array has a total of 2*numSamples values;
20 |  * the output array has a total of numSamples values.
21 |  * The underlying algorithm is used:
22 |  *
23 |  * 
24 |  * for(n=0; n
28 |  *
29 |  * There are separate functions for floating-point, Q15, and Q31 data types.
30 |  */
31 | 
32 | /**
33 |  * @addtogroup cmplx_mag
34 |  * @{
35 |  */
36 | /**
37 |  * @brief Floating-point complex magnitude.
38 |  * @param[in]       *pSrc points to complex input buffer
39 |  * @param[out]      *pDst points to real output buffer
40 |  * @param[in]       numSamples number of complex samples in the input vector
41 |  * @return none.
42 |  *
43 |  */
44 | 
45 | 
46 | void xtensa_cmplx_mag_f32(
47 |   float32_t * pSrc,
48 |   float32_t * pDst,
49 |   uint32_t numSamples)
50 | {
51 |   float32_t realIn, imagIn;                      /* Temporary variables to hold input values */
52 | 
53 | 
54 | 
55 |   while (numSamples > 0U)
56 |   {
57 |     /* out = sqrt((real * real) + (imag * imag)) */
58 |     realIn = *pSrc++;
59 |     imagIn = *pSrc++;
60 |     /* store the result in the destination buffer. */
61 |     xtensa_sqrt_f32((realIn * realIn) + (imagIn * imagIn), pDst++);
62 | 
63 |     /* Decrement the loop counter */
64 |     numSamples--;
65 |   }
66 | 
67 | 
68 | }
69 | 
70 | /**
71 |  * @} end of cmplx_mag group
72 |  */
73 | 


--------------------------------------------------------------------------------
/components/dsp_lib/ComplexMathFunctions/xtensa_cmplx_mag_squared_f32.c:
--------------------------------------------------------------------------------
 1 | 
 2 | 
 3 | #include "xtensa_math.h"
 4 | 
 5 | /**
 6 |  * @ingroup groupCmplxMath
 7 |  */
 8 | 
 9 | /**
10 |  * @defgroup cmplx_mag_squared Complex Magnitude Squared
11 |  *
12 |  * Computes the magnitude squared of the elements of a complex data vector.
13 |  *
14 |  * The pSrc points to the source data and
15 |  * pDst points to the where the result should be written.
16 |  * numSamples specifies the number of complex samples
17 |  * in the input array and the data is stored in an interleaved fashion
18 |  * (real, imag, real, imag, ...).
19 |  * The input array has a total of 2*numSamples values;
20 |  * the output array has a total of numSamples values.
21 |  *
22 |  * The underlying algorithm is used:
23 |  *
24 |  * 
25 |  * for(n=0; n
29 |  *
30 |  * There are separate functions for floating-point, Q15, and Q31 data types.
31 |  */
32 | 
33 | /**
34 |  * @addtogroup cmplx_mag_squared
35 |  * @{
36 |  */
37 | 
38 | 
39 | /**
40 |  * @brief  Floating-point complex magnitude squared
41 |  * @param[in]  *pSrc points to the complex input vector
42 |  * @param[out]  *pDst points to the real output vector
43 |  * @param[in]  numSamples number of complex samples in the input vector
44 |  * @return none.
45 |  */
46 | 
47 | void xtensa_cmplx_mag_squared_f32(
48 |   float32_t * pSrc,
49 |   float32_t * pDst,
50 |   uint32_t numSamples)
51 | {
52 |   float32_t real, imag;                          /* Temporary variables to store real and imaginary values */
53 |   uint32_t blkCnt;                               /* loop counter */
54 | 
55 |   blkCnt = numSamples;
56 |   while (blkCnt > 0U)
57 |   {
58 |     /* C[0] = (A[0] * A[0] + A[1] * A[1]) */
59 |     real = *pSrc++;
60 |     imag = *pSrc++;
61 | 
62 |     /* out = (real * real) + (imag * imag) */
63 |     /* store the result in the destination buffer. */
64 |     *pDst++ = (real * real) + (imag * imag);
65 | 
66 |     /* Decrement the loop counter */
67 |     blkCnt--;
68 |   }
69 | }
70 | 
71 | /**
72 |  * @} end of cmplx_mag_squared group
73 |  */
74 | 


--------------------------------------------------------------------------------
/components/dsp_lib/ComplexMathFunctions/xtensa_cmplx_mult_cmplx_f32.c:
--------------------------------------------------------------------------------
 1 | 
 2 | 
 3 | #include "xtensa_math.h"
 4 | 
 5 | /**
 6 |  * @ingroup groupCmplxMath
 7 |  */
 8 | 
 9 | /**
10 |  * @defgroup CmplxByCmplxMult Complex-by-Complex Multiplication
11 |  *
12 |  * Multiplies a complex vector by another complex vector and generates a complex result.
13 |  * The data in the complex arrays is stored in an interleaved fashion
14 |  * (real, imag, real, imag, ...).
15 |  * The parameter numSamples represents the number of complex
16 |  * samples processed.  The complex arrays have a total of 2*numSamples
17 |  * real values.
18 |  *
19 |  * The underlying algorithm is used:
20 |  *
21 |  * 
22 |  * for(n=0; n
27 |  *
28 |  * There are separate functions for floating-point, Q15, and Q31 data types.
29 |  */
30 | 
31 | /**
32 |  * @addtogroup CmplxByCmplxMult
33 |  * @{
34 |  */
35 | 
36 | 
37 | /**
38 |  * @brief  Floating-point complex-by-complex multiplication
39 |  * @param[in]  *pSrcA points to the first input vector
40 |  * @param[in]  *pSrcB points to the second input vector
41 |  * @param[out]  *pDst  points to the output vector
42 |  * @param[in]  numSamples number of complex samples in each vector
43 |  * @return none.
44 |  */
45 | 
46 | void xtensa_cmplx_mult_cmplx_f32(
47 |   float32_t * pSrcA,
48 |   float32_t * pSrcB,
49 |   float32_t * pDst,
50 |   uint32_t numSamples)
51 | {
52 |   float32_t a1, b1, c1, d1;                      /* Temporary variables to store real and imaginary values */
53 |   uint32_t blkCnt;                               /* loop counters */
54 | 
55 |   blkCnt = numSamples;
56 | 
57 | 
58 |   while (blkCnt > 0U)
59 |   {
60 |     /* C[2 * i] = A[2 * i] * B[2 * i] - A[2 * i + 1] * B[2 * i + 1].  */
61 |     /* C[2 * i + 1] = A[2 * i] * B[2 * i + 1] + A[2 * i + 1] * B[2 * i].  */
62 |     a1 = *pSrcA++;
63 |     b1 = *pSrcA++;
64 |     c1 = *pSrcB++;
65 |     d1 = *pSrcB++;
66 | 
67 |     /* store the result in the destination buffer. */
68 |     *pDst++ = (a1 * c1) - (b1 * d1);
69 |     *pDst++ = (a1 * d1) + (b1 * c1);
70 | 
71 |     /* Decrement the numSamples loop counter */
72 |     blkCnt--;
73 |   }
74 | }
75 | 
76 | /**
77 |  * @} end of CmplxByCmplxMult group
78 |  */
79 | 


--------------------------------------------------------------------------------
/components/dsp_lib/ComplexMathFunctions/xtensa_cmplx_mult_real_f32.c:
--------------------------------------------------------------------------------
 1 | 
 2 | 
 3 | #include "xtensa_math.h"
 4 | 
 5 | /**
 6 |  * @ingroup groupCmplxMath
 7 |  */
 8 | 
 9 | /**
10 |  * @defgroup CmplxByRealMult Complex-by-Real Multiplication
11 |  *
12 |  * Multiplies a complex vector by a real vector and generates a complex result.
13 |  * The data in the complex arrays is stored in an interleaved fashion
14 |  * (real, imag, real, imag, ...).
15 |  * The parameter numSamples represents the number of complex
16 |  * samples processed.  The complex arrays have a total of 2*numSamples
17 |  * real values while the real array has a total of numSamples
18 |  * real values.
19 |  *
20 |  * The underlying algorithm is used:
21 |  *
22 |  * 
23 |  * for(n=0; n
28 |  *
29 |  * There are separate functions for floating-point, Q15, and Q31 data types.
30 |  */
31 | 
32 | /**
33 |  * @addtogroup CmplxByRealMult
34 |  * @{
35 |  */
36 | 
37 | 
38 | /**
39 |  * @brief  Floating-point complex-by-real multiplication
40 |  * @param[in]  *pSrcCmplx points to the complex input vector
41 |  * @param[in]  *pSrcReal points to the real input vector
42 |  * @param[out]  *pCmplxDst points to the complex output vector
43 |  * @param[in]  numSamples number of samples in each vector
44 |  * @return none.
45 |  */
46 | 
47 | void xtensa_cmplx_mult_real_f32(
48 |   float32_t * pSrcCmplx,
49 |   float32_t * pSrcReal,
50 |   float32_t * pCmplxDst,
51 |   uint32_t numSamples)
52 | {
53 |   float32_t in;                                  /* Temporary variable to store input value */
54 |   uint32_t blkCnt;                               /* loop counters */
55 | 
56 | 
57 |   blkCnt = numSamples;
58 | 
59 | 
60 |   while (blkCnt > 0U)
61 |   {
62 |     /* C[2 * i] = A[2 * i] * B[i].            */
63 |     /* C[2 * i + 1] = A[2 * i + 1] * B[i].        */
64 |     in = *pSrcReal++;
65 |     /* store the result in the destination buffer. */
66 |     *pCmplxDst++ = (*pSrcCmplx++) * (in);
67 |     *pCmplxDst++ = (*pSrcCmplx++) * (in);
68 | 
69 |     /* Decrement the numSamples loop counter */
70 |     blkCnt--;
71 |   }
72 | }
73 | 
74 | /**
75 |  * @} end of CmplxByRealMult group
76 |  */
77 | 


--------------------------------------------------------------------------------
/components/dsp_lib/ControllerFunctions/xtensa_pid_init_f32.c:
--------------------------------------------------------------------------------
 1 | 
 2 | 
 3 | #include "xtensa_math.h"
 4 | 
 5 |  /**
 6 |  * @addtogroup PID
 7 |  * @{
 8 |  */
 9 | 
10 | /**
11 |  * @brief  Initialization function for the floating-point PID Control.
12 |  * @param[in,out] *S points to an instance of the PID structure.
13 |  * @param[in]     resetStateFlag  flag to reset the state. 0 = no change in state & 1 = reset the state.
14 |  * @return none.
15 |  * \par Description:
16 |  * \par
17 |  * The resetStateFlag specifies whether to set state to zero or not. \n
18 |  * The function computes the structure fields: A0, A1 A2
19 |  * using the proportional gain( \c Kp), integral gain( \c Ki) and derivative gain( \c Kd)
20 |  * also sets the state variables to all zeros.
21 |  */
22 | 
23 | void xtensa_pid_init_f32(
24 |   xtensa_pid_instance_f32 * S,
25 |   int32_t resetStateFlag)
26 | {
27 | 
28 |   /* Derived coefficient A0 */
29 |   S->A0 = S->Kp + S->Ki + S->Kd;
30 | 
31 |   /* Derived coefficient A1 */
32 |   S->A1 = (-S->Kp) - ((float32_t) 2.0 * S->Kd);
33 | 
34 |   /* Derived coefficient A2 */
35 |   S->A2 = S->Kd;
36 | 
37 |   /* Check whether state needs reset or not */
38 |   if (resetStateFlag)
39 |   {
40 |     /* Clear the state buffer.  The size will be always 3 samples */
41 |     memset(S->state, 0, 3U * sizeof(float32_t));
42 |   }
43 | 
44 | }
45 | 
46 | /**
47 |  * @} end of PID group
48 |  */
49 | 


--------------------------------------------------------------------------------
/components/dsp_lib/ControllerFunctions/xtensa_pid_reset_f32.c:
--------------------------------------------------------------------------------
 1 | 
 2 | 
 3 | #include "xtensa_math.h"
 4 | 
 5 |  /**
 6 |  * @addtogroup PID
 7 |  * @{
 8 |  */
 9 | 
10 | /**
11 | * @brief  Reset function for the floating-point PID Control.
12 | * @param[in] *S	Instance pointer of PID control data structure.
13 | * @return none.
14 | * \par Description:
15 | * The function resets the state buffer to zeros.
16 | */
17 | void xtensa_pid_reset_f32(
18 |   xtensa_pid_instance_f32 * S)
19 | {
20 | 
21 |   /* Clear the state buffer.  The size will be always 3 samples */
22 |   memset(S->state, 0, 3U * sizeof(float32_t));
23 | }
24 | 
25 | /**
26 |  * @} end of PID group
27 |  */
28 | 


--------------------------------------------------------------------------------
/components/dsp_lib/ControllerFunctions/xtensa_sin_cos_f32.c:
--------------------------------------------------------------------------------
  1 | 
  2 | 
  3 | #include "xtensa_math.h"
  4 | #include "xtensa_common_tables.h"
  5 | 
  6 | /**
  7 |  * @ingroup groupController
  8 |  */
  9 | 
 10 | /**
 11 |  * @defgroup SinCos Sine Cosine
 12 |  *
 13 |  * Computes the trigonometric sine and cosine values using a combination of table lookup
 14 |  * and linear interpolation.
 15 |  * There are separate functions for Q31 and floating-point data types.
 16 |  * The input to the floating-point version is in degrees while the
 17 |  * fixed-point Q31 have a scaled input with the range
 18 |  * [-1 0.9999] mapping to [-180 +180] degrees.
 19 |  *
 20 |  * The floating point function also allows values that are out of the usual range. When this happens, the function will
 21 |  * take extra time to adjust the input value to the range of [-180 180].
 22 |  *
 23 |  * The result is accurate to 5 digits after the decimal point.
 24 |  *
 25 |  * The implementation is based on table lookup using 360 values together with linear interpolation.
 26 |  * The steps used are:
 27 |  *  -# Calculation of the nearest integer table index.
 28 |  *  -# Compute the fractional portion (fract) of the input.
 29 |  *  -# Fetch the value corresponding to \c index from sine table to \c y0 and also value from \c index+1 to \c y1.
 30 |  *  -# Sine value is computed as  *psinVal = y0 + (fract * (y1 - y0)).
 31 |  *  -# Fetch the value corresponding to \c index from cosine table to \c y0 and also value from \c index+1 to \c y1.
 32 |  *  -# Cosine value is computed as  *pcosVal = y0 + (fract * (y1 - y0)).
 33 |  */
 34 | 
 35 |  /**
 36 |  * @addtogroup SinCos
 37 |  * @{
 38 |  */
 39 | 
 40 | /**
 41 |  * @brief  Floating-point sin_cos function.
 42 |  * @param[in]  theta    input value in degrees
 43 |  * @param[out] *pSinVal points to the processed sine output.
 44 |  * @param[out] *pCosVal points to the processed cos output.
 45 |  * @return none.
 46 |  */
 47 | 
 48 | void xtensa_sin_cos_f32(
 49 |                       float32_t theta,
 50 |                       float32_t * pSinVal,
 51 |                       float32_t * pCosVal)
 52 | {
 53 |     float32_t fract, in;                             /* Temporary variables for input, output */
 54 |     uint16_t indexS, indexC;                         /* Index variable */
 55 |     float32_t f1, f2, d1, d2;                        /* Two nearest output values */
 56 |     float32_t findex, Dn, Df, temp;
 57 | 
 58 |     /* input x is in degrees */
 59 |     /* Scale the input, divide input by 360, for cosine add 0.25 (pi/2) to read sine table */
 60 |     in = theta * 0.00277777777778f;
 61 | 
 62 |     if (in < 0.0f)
 63 |     {
 64 |         in = -in;
 65 |     }
 66 | 
 67 |     in = in - (int32_t)in;
 68 | 
 69 |     /* Calculation of index of the table */
 70 |     findex = (float32_t) FAST_MATH_TABLE_SIZE * in;
 71 |     indexS = ((uint16_t)findex) & 0x1ff;
 72 |     indexC = (indexS + (FAST_MATH_TABLE_SIZE / 4)) & 0x1ff;
 73 | 
 74 |     /* fractional value calculation */
 75 |     fract = findex - (float32_t) indexS;
 76 | 
 77 |     /* Read two nearest values of input value from the cos & sin tables */
 78 |     f1 = sinTable_f32[indexC+0];
 79 |     f2 = sinTable_f32[indexC+1];
 80 |     d1 = -sinTable_f32[indexS+0];
 81 |     d2 = -sinTable_f32[indexS+1];
 82 | 
 83 |     temp = (1.0f - fract) * f1 + fract * f2;
 84 | 
 85 |     Dn = 0.0122718463030f; // delta between the two points (fixed), in this case 2*pi/FAST_MATH_TABLE_SIZE
 86 |     Df = f2 - f1;          // delta between the values of the functions
 87 | 
 88 |     temp = Dn *(d1 + d2) - 2 * Df;
 89 |     temp = fract * temp + (3 * Df - (d2 + 2 * d1) * Dn);
 90 |     temp = fract * temp + d1 * Dn;
 91 | 
 92 |     /* Calculation of cosine value */
 93 |     *pCosVal = fract * temp + f1;
 94 | 
 95 |     /* Read two nearest values of input value from the cos & sin tables */
 96 |     f1 = sinTable_f32[indexS+0];
 97 |     f2 = sinTable_f32[indexS+1];
 98 |     d1 = sinTable_f32[indexC+0];
 99 |     d2 = sinTable_f32[indexC+1];
100 | 
101 |     temp = (1.0f - fract) * f1 + fract * f2;
102 | 
103 |     Df = f2 - f1; // delta between the values of the functions
104 |     temp = Dn*(d1 + d2) - 2*Df;
105 |     temp = fract*temp + (3*Df - (d2 + 2*d1)*Dn);
106 |     temp = fract*temp + d1*Dn;
107 | 
108 |     /* Calculation of sine value */
109 |     *pSinVal = fract*temp + f1;
110 | 
111 |     if (theta < 0.0f)
112 |     {
113 |         *pSinVal = -*pSinVal;
114 |     }
115 | }
116 | /**
117 |  * @} end of SinCos group
118 |  */
119 | 


--------------------------------------------------------------------------------
/components/dsp_lib/FastMathFunctions/xtensa_cos_f32.c:
--------------------------------------------------------------------------------
 1 | 
 2 | 
 3 | #include "xtensa_math.h"
 4 | #include "xtensa_common_tables.h"
 5 | /**
 6 |  * @ingroup groupFastMath
 7 |  */
 8 | 
 9 | /**
10 |  * @defgroup cos Cosine
11 |  *
12 |  * Computes the trigonometric cosine function using a combination of table lookup
13 |  * and linear interpolation.  There are separate functions for
14 |  * Q15, Q31, and floating-point data types.
15 |  * The input to the floating-point version is in radians and in the range [0 2*pi) while the
16 |  * fixed-point Q15 and Q31 have a scaled input with the range
17 |  * [0 +0.9999] mapping to [0 2*pi).  The fixed-point range is chosen so that a
18 |  * value of 2*pi wraps around to 0.
19 |  *
20 |  * The implementation is based on table lookup using 256 values together with linear interpolation.
21 |  * The steps used are:
22 |  *  -# Calculation of the nearest integer table index
23 |  *  -# Compute the fractional portion (fract) of the table index.
24 |  *  -# The final result equals (1.0f-fract)*a + fract*b;
25 |  *
26 |  * where
27 |  * 
28 |  *    b=Table[index+0];
29 |  *    c=Table[index+1];
30 |  * 
31 | */ 32 | 33 | /** 34 | * @addtogroup cos 35 | * @{ 36 | */ 37 | 38 | /** 39 | * @brief Fast approximation to the trigonometric cosine function for floating-point data. 40 | * @param[in] x input value in radians. 41 | * @return cos(x). 42 | */ 43 | 44 | float32_t xtensa_cos_f32( 45 | float32_t x) 46 | { 47 | float32_t cosVal, fract, in; /* Temporary variables for input, output */ 48 | uint16_t index; /* Index variable */ 49 | float32_t a, b; /* Two nearest output values */ 50 | int32_t n; 51 | float32_t findex; 52 | 53 | /* input x is in radians */ 54 | /* Scale the input to [0 1] range from [0 2*PI] , divide input by 2*pi, add 0.25 (pi/2) to read sine table */ 55 | in = x * 0.159154943092f + 0.25f; 56 | 57 | /* Calculation of floor value of input */ 58 | n = (int32_t) in; 59 | 60 | /* Make negative values towards -infinity */ 61 | if (in < 0.0f) 62 | { 63 | n--; 64 | } 65 | 66 | /* Map input value to [0 1] */ 67 | in = in - (float32_t) n; 68 | 69 | /* Calculation of index of the table */ 70 | findex = (float32_t) FAST_MATH_TABLE_SIZE * in; 71 | index = ((uint16_t)findex) & 0x1ff; 72 | 73 | /* fractional value calculation */ 74 | fract = findex - (float32_t) index; 75 | 76 | /* Read two nearest values of input value from the cos table */ 77 | a = sinTable_f32[index]; 78 | b = sinTable_f32[index+1]; 79 | 80 | /* Linear interpolation process */ 81 | cosVal = (1.0f-fract)*a + fract*b; 82 | 83 | /* Return the output value */ 84 | return (cosVal); 85 | } 86 | 87 | /** 88 | * @} end of cos group 89 | */ 90 | -------------------------------------------------------------------------------- /components/dsp_lib/FastMathFunctions/xtensa_sin_f32.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "xtensa_math.h" 4 | #include "xtensa_common_tables.h" 5 | #include 6 | 7 | /** 8 | * @ingroup groupFastMath 9 | */ 10 | 11 | /** 12 | * @defgroup sin Sine 13 | * 14 | * Computes the trigonometric sine function using a combination of table lookup 15 | * and linear interpolation. There are separate functions for 16 | * Q15, Q31, and floating-point data types. 17 | * The input to the floating-point version is in radians and in the range [0 2*pi) while the 18 | * fixed-point Q15 and Q31 have a scaled input with the range 19 | * [0 +0.9999] mapping to [0 2*pi). The fixed-point range is chosen so that a 20 | * value of 2*pi wraps around to 0. 21 | * 22 | * The implementation is based on table lookup using 256 values together with linear interpolation. 23 | * The steps used are: 24 | * -# Calculation of the nearest integer table index 25 | * -# Compute the fractional portion (fract) of the table index. 26 | * -# The final result equals (1.0f-fract)*a + fract*b; 27 | * 28 | * where 29 | *
30 |  *    b=Table[index+0];
31 |  *    c=Table[index+1];
32 |  * 
33 | */ 34 | 35 | /** 36 | * @addtogroup sin 37 | * @{ 38 | */ 39 | 40 | /** 41 | * @brief Fast approximation to the trigonometric sine function for floating-point data. 42 | * @param[in] x input value in radians. 43 | * @return sin(x). 44 | */ 45 | 46 | float32_t xtensa_sin_f32( 47 | float32_t x) 48 | { 49 | float32_t sinVal, fract, in; /* Temporary variables for input, output */ 50 | uint16_t index; /* Index variable */ 51 | float32_t a, b; /* Two nearest output values */ 52 | int32_t n; 53 | float32_t findex; 54 | 55 | /* Special case for small negative inputs */ 56 | if ((x < 0.0f) && (x >= -1.9e-7f)) { 57 | return x; 58 | } 59 | 60 | /* input x is in radians */ 61 | /* Scale the input to [0 1] range from [0 2*PI] , divide input by 2*pi */ 62 | in = x * 0.159154943092f; 63 | 64 | /* Calculation of floor value of input */ 65 | n = (int32_t) in; 66 | 67 | /* Make negative values towards -infinity */ 68 | if (x < 0.0f) 69 | { 70 | n--; 71 | } 72 | 73 | /* Map input value to [0 1] */ 74 | in = in - (float32_t) n; 75 | 76 | /* Calculation of index of the table */ 77 | findex = (float32_t) FAST_MATH_TABLE_SIZE * in; 78 | 79 | index = ((uint16_t)findex) & 0x1ff; 80 | 81 | /* fractional value calculation */ 82 | fract = findex - (float32_t) index; 83 | 84 | /* Read two nearest values of input value from the sin table */ 85 | a = sinTable_f32[index]; 86 | b = sinTable_f32[index+1]; 87 | 88 | /* Linear interpolation process */ 89 | sinVal = (1.0f-fract)*a + fract*b; 90 | 91 | /* Return the output value */ 92 | return (sinVal); 93 | } 94 | 95 | /** 96 | * @} end of sin group 97 | */ 98 | -------------------------------------------------------------------------------- /components/dsp_lib/FilteringFunctions/xtensa_biquad_cascade_df1_init_f32.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "xtensa_math.h" 4 | 5 | /** 6 | * @ingroup groupFilters 7 | */ 8 | 9 | /** 10 | * @addtogroup BiquadCascadeDF1 11 | * @{ 12 | */ 13 | 14 | /** 15 | * @details 16 | * @brief Initialization function for the floating-point Biquad cascade filter. 17 | * @param[in,out] *S points to an instance of the floating-point Biquad cascade structure. 18 | * @param[in] numStages number of 2nd order stages in the filter. 19 | * @param[in] *pCoeffs points to the filter coefficients array. 20 | * @param[in] *pState points to the state array. 21 | * @return none 22 | * 23 | * 24 | * Coefficient and State Ordering: 25 | * 26 | * \par 27 | * The coefficients are stored in the array pCoeffs in the following order: 28 | *
29 |  *     {b10, b11, b12, a11, a12, b20, b21, b22, a21, a22, ...}
30 |  * 
31 | * 32 | * \par 33 | * where b1x and a1x are the coefficients for the first stage, 34 | * b2x and a2x are the coefficients for the second stage, 35 | * and so on. The pCoeffs array contains a total of 5*numStages values. 36 | * 37 | * \par 38 | * The pState is a pointer to state array. 39 | * Each Biquad stage has 4 state variables x[n-1], x[n-2], y[n-1], and y[n-2]. 40 | * The state variables are arranged in the pState array as: 41 | *
42 |  *     {x[n-1], x[n-2], y[n-1], y[n-2]}
43 |  * 
44 | * The 4 state variables for stage 1 are first, then the 4 state variables for stage 2, and so on. 45 | * The state array has a total length of 4*numStages values. 46 | * The state variables are updated after each block of data is processed; the coefficients are untouched. 47 | * 48 | */ 49 | 50 | void xtensa_biquad_cascade_df1_init_f32( 51 | xtensa_biquad_casd_df1_inst_f32 * S, 52 | uint8_t numStages, 53 | float32_t * pCoeffs, 54 | float32_t * pState) 55 | { 56 | /* Assign filter stages */ 57 | S->numStages = numStages; 58 | 59 | /* Assign coefficient pointer */ 60 | S->pCoeffs = pCoeffs; 61 | 62 | /* Clear state buffer and size is always 4 * numStages */ 63 | memset(pState, 0, (4U * (uint32_t) numStages) * sizeof(float32_t)); 64 | 65 | /* Assign state pointer */ 66 | S->pState = pState; 67 | } 68 | 69 | /** 70 | * @} end of BiquadCascadeDF1 group 71 | */ 72 | -------------------------------------------------------------------------------- /components/dsp_lib/FilteringFunctions/xtensa_biquad_cascade_df2T_init_f32.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_biquad_cascade_df2T_init_f32.c 4 | * Description: Initialization function for floating-point transposed direct form II Biquad cascade filter 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "xtensa_math.h" 30 | 31 | /** 32 | * @ingroup groupFilters 33 | */ 34 | 35 | /** 36 | * @addtogroup BiquadCascadeDF2T 37 | * @{ 38 | */ 39 | 40 | /** 41 | * @brief Initialization function for the floating-point transposed direct form II Biquad cascade filter. 42 | * @param[in,out] *S points to an instance of the filter data structure. 43 | * @param[in] numStages number of 2nd order stages in the filter. 44 | * @param[in] *pCoeffs points to the filter coefficients. 45 | * @param[in] *pState points to the state buffer. 46 | * @return none 47 | * 48 | * Coefficient and State Ordering: 49 | * \par 50 | * The coefficients are stored in the array pCoeffs in the following order: 51 | *
52 |  *     {b10, b11, b12, a11, a12, b20, b21, b22, a21, a22, ...}
53 |  * 
54 | * 55 | * \par 56 | * where b1x and a1x are the coefficients for the first stage, 57 | * b2x and a2x are the coefficients for the second stage, 58 | * and so on. The pCoeffs array contains a total of 5*numStages values. 59 | * 60 | * \par 61 | * The pState is a pointer to state array. 62 | * Each Biquad stage has 2 state variables d1, and d2. 63 | * The 2 state variables for stage 1 are first, then the 2 state variables for stage 2, and so on. 64 | * The state array has a total length of 2*numStages values. 65 | * The state variables are updated after each block of data is processed; the coefficients are untouched. 66 | */ 67 | 68 | void xtensa_biquad_cascade_df2T_init_f32( 69 | xtensa_biquad_cascade_df2T_instance_f32 * S, 70 | uint8_t numStages, 71 | float32_t * pCoeffs, 72 | float32_t * pState) 73 | { 74 | /* Assign filter stages */ 75 | S->numStages = numStages; 76 | 77 | /* Assign coefficient pointer */ 78 | S->pCoeffs = pCoeffs; 79 | 80 | /* Clear state buffer and size is always 2 * numStages */ 81 | memset(pState, 0, (2U * (uint32_t) numStages) * sizeof(float32_t)); 82 | 83 | /* Assign state pointer */ 84 | S->pState = pState; 85 | } 86 | 87 | /** 88 | * @} end of BiquadCascadeDF2T group 89 | */ 90 | -------------------------------------------------------------------------------- /components/dsp_lib/FilteringFunctions/xtensa_biquad_cascade_stereo_df2T_init_f32.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_biquad_cascade_stereo_df2T_init_f32.c 4 | * Description: Initialization function for floating-point transposed direct form II Biquad cascade filter 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "xtensa_math.h" 30 | 31 | /** 32 | * @ingroup groupFilters 33 | */ 34 | 35 | /** 36 | * @addtogroup BiquadCascadeDF2T 37 | * @{ 38 | */ 39 | 40 | /** 41 | * @brief Initialization function for the floating-point transposed direct form II Biquad cascade filter. 42 | * @param[in,out] *S points to an instance of the filter data structure. 43 | * @param[in] numStages number of 2nd order stages in the filter. 44 | * @param[in] *pCoeffs points to the filter coefficients. 45 | * @param[in] *pState points to the state buffer. 46 | * @return none 47 | * 48 | * Coefficient and State Ordering: 49 | * \par 50 | * The coefficients are stored in the array pCoeffs in the following order: 51 | *
52 |  *     {b10, b11, b12, a11, a12, b20, b21, b22, a21, a22, ...}
53 |  * 
54 | * 55 | * \par 56 | * where b1x and a1x are the coefficients for the first stage, 57 | * b2x and a2x are the coefficients for the second stage, 58 | * and so on. The pCoeffs array contains a total of 5*numStages values. 59 | * 60 | * \par 61 | * The pState is a pointer to state array. 62 | * Each Biquad stage has 2 state variables d1, and d2 for each channel. 63 | * The 2 state variables for stage 1 are first, then the 2 state variables for stage 2, and so on. 64 | * The state array has a total length of 2*numStages values. 65 | * The state variables are updated after each block of data is processed; the coefficients are untouched. 66 | */ 67 | 68 | void xtensa_biquad_cascade_stereo_df2T_init_f32( 69 | xtensa_biquad_cascade_stereo_df2T_instance_f32 * S, 70 | uint8_t numStages, 71 | float32_t * pCoeffs, 72 | float32_t * pState) 73 | { 74 | /* Assign filter stages */ 75 | S->numStages = numStages; 76 | 77 | /* Assign coefficient pointer */ 78 | S->pCoeffs = pCoeffs; 79 | 80 | /* Clear state buffer and size is always 4 * numStages */ 81 | memset(pState, 0, (4U * (uint32_t) numStages) * sizeof(float32_t)); 82 | 83 | /* Assign state pointer */ 84 | S->pState = pState; 85 | } 86 | 87 | /** 88 | * @} end of BiquadCascadeDF2T group 89 | */ 90 | -------------------------------------------------------------------------------- /components/dsp_lib/FilteringFunctions/xtensa_conv_f32.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_conv_f32.c 4 | * Description: Convolution of floating-point sequences 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "xtensa_math.h" 30 | 31 | /** 32 | * @ingroup groupFilters 33 | */ 34 | 35 | /** 36 | * @defgroup Conv Convolution 37 | * 38 | * Convolution is a mathematical operation that operates on two finite length vectors to generate a finite length output vector. 39 | * Convolution is similar to correlation and is frequently used in filtering and data analysis. 40 | * The CMSIS DSP library contains functions for convolving Q7, Q15, Q31, and floating-point data types. 41 | * The library also provides fast versions of the Q15 and Q31 functions on Cortex-M4 and Cortex-M3. 42 | * 43 | * \par Algorithm 44 | * Let a[n] and b[n] be sequences of length srcALen and srcBLen samples respectively. 45 | * Then the convolution 46 | * 47 | *
 48 |  *                   c[n] = a[n] * b[n]
 49 |  * 
50 | * 51 | * \par 52 | * is defined as 53 | * \image html ConvolutionEquation.gif 54 | * \par 55 | * Note that c[n] is of length srcALen + srcBLen - 1 and is defined over the interval n=0, 1, 2, ..., srcALen + srcBLen - 2. 56 | * pSrcA points to the first input vector of length srcALen and 57 | * pSrcB points to the second input vector of length srcBLen. 58 | * The output result is written to pDst and the calling function must allocate srcALen+srcBLen-1 words for the result. 59 | * 60 | * \par 61 | * Conceptually, when two signals a[n] and b[n] are convolved, 62 | * the signal b[n] slides over a[n]. 63 | * For each offset \c n, the overlapping portions of a[n] and b[n] are multiplied and summed together. 64 | * 65 | * \par 66 | * Note that convolution is a commutative operation: 67 | * 68 | *
 69 |  *                   a[n] * b[n] = b[n] * a[n].
 70 |  * 
71 | * 72 | * \par 73 | * This means that switching the A and B arguments to the convolution functions has no effect. 74 | * 75 | * Fixed-Point Behavior 76 | * 77 | * \par 78 | * Convolution requires summing up a large number of intermediate products. 79 | * As such, the Q7, Q15, and Q31 functions run a risk of overflow and saturation. 80 | * Refer to the function specific documentation below for further details of the particular algorithm used. 81 | * 82 | * 83 | * Fast Versions 84 | * 85 | * \par 86 | * Fast versions are supported for Q31 and Q15. Cycles for Fast versions are less compared to Q31 and Q15 of conv and the design requires 87 | * the input signals should be scaled down to avoid intermediate overflows. 88 | * 89 | * 90 | * Opt Versions 91 | * 92 | * \par 93 | * Opt versions are supported for Q15 and Q7. Design uses internal scratch buffer for getting good optimisation. 94 | * These versions are optimised in cycles and consumes more memory(Scratch memory) compared to Q15 and Q7 versions 95 | */ 96 | 97 | /** 98 | * @addtogroup Conv 99 | * @{ 100 | */ 101 | 102 | /** 103 | * @brief Convolution of floating-point sequences. 104 | * @param[in] *pSrcA points to the first input sequence. 105 | * @param[in] srcALen length of the first input sequence. 106 | * @param[in] *pSrcB points to the second input sequence. 107 | * @param[in] srcBLen length of the second input sequence. 108 | * @param[out] *pDst points to the location where the output result is written. Length srcALen+srcBLen-1. 109 | * @return none. 110 | */ 111 | 112 | void xtensa_conv_f32( 113 | float32_t * pSrcA, 114 | uint32_t srcALen, 115 | float32_t * pSrcB, 116 | uint32_t srcBLen, 117 | float32_t * pDst) 118 | { 119 | 120 | 121 | 122 | 123 | float32_t *pIn1 = pSrcA; /* inputA pointer */ 124 | float32_t *pIn2 = pSrcB; /* inputB pointer */ 125 | float32_t sum; /* Accumulator */ 126 | uint32_t i, j; /* loop counters */ 127 | 128 | /* Loop to calculate convolution for output length number of times */ 129 | for (i = 0U; i < ((srcALen + srcBLen) - 1U); i++) 130 | { 131 | /* Initialize sum with zero to carry out MAC operations */ 132 | sum = 0.0f; 133 | 134 | /* Loop to perform MAC operations according to convolution equation */ 135 | for (j = 0U; j <= i; j++) 136 | { 137 | /* Check the array limitations */ 138 | if ((((i - j) < srcBLen) && (j < srcALen))) 139 | { 140 | /* z[i] += x[i-j] * y[j] */ 141 | sum += pIn1[j] * pIn2[i - j]; 142 | } 143 | } 144 | /* Store the output in the destination buffer */ 145 | pDst[i] = sum; 146 | } 147 | 148 | 149 | } 150 | 151 | /** 152 | * @} end of Conv group 153 | */ 154 | -------------------------------------------------------------------------------- /components/dsp_lib/FilteringFunctions/xtensa_conv_partial_f32.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_conv_partial_f32.c 4 | * Description: Partial convolution of floating-point sequences 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 XTENSA Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "xtensa_math.h" 30 | 31 | /** 32 | * @ingroup groupFilters 33 | */ 34 | 35 | /** 36 | * @defgroup PartialConv Partial Convolution 37 | * 38 | * Partial Convolution is equivalent to Convolution except that a subset of the output samples is generated. 39 | * Each function has two additional arguments. 40 | * firstIndex specifies the starting index of the subset of output samples. 41 | * numPoints is the number of output samples to compute. 42 | * The function computes the output in the range 43 | * [firstIndex, ..., firstIndex+numPoints-1]. 44 | * The output array pDst contains numPoints values. 45 | * 46 | * The allowable range of output indices is [0 srcALen+srcBLen-2]. 47 | * If the requested subset does not fall in this range then the functions return XTENSA_MATH_ARGUMENT_ERROR. 48 | * Otherwise the functions return XTENSA_MATH_SUCCESS. 49 | * \note Refer xtensa_conv_f32() for details on fixed point behavior. 50 | * 51 | * 52 | * Fast Versions 53 | * 54 | * \par 55 | * Fast versions are supported for Q31 and Q15 of partial convolution. Cycles for Fast versions are less compared to Q31 and Q15 of partial conv and the design requires 56 | * the input signals should be scaled down to avoid intermediate overflows. 57 | * 58 | * 59 | * Opt Versions 60 | * 61 | * \par 62 | * Opt versions are supported for Q15 and Q7. Design uses internal scratch buffer for getting good optimisation. 63 | * These versions are optimised in cycles and consumes more memory(Scratch memory) compared to Q15 and Q7 versions of partial convolution 64 | */ 65 | 66 | /** 67 | * @addtogroup PartialConv 68 | * @{ 69 | */ 70 | 71 | /** 72 | * @brief Partial convolution of floating-point sequences. 73 | * @param[in] *pSrcA points to the first input sequence. 74 | * @param[in] srcALen length of the first input sequence. 75 | * @param[in] *pSrcB points to the second input sequence. 76 | * @param[in] srcBLen length of the second input sequence. 77 | * @param[out] *pDst points to the location where the output result is written. 78 | * @param[in] firstIndex is the first output sample to start with. 79 | * @param[in] numPoints is the number of output points to be computed. 80 | * @return Returns either XTENSA_MATH_SUCCESS if the function completed correctly or XTENSA_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2]. 81 | */ 82 | 83 | xtensa_status xtensa_conv_partial_f32( 84 | float32_t * pSrcA, 85 | uint32_t srcALen, 86 | float32_t * pSrcB, 87 | uint32_t srcBLen, 88 | float32_t * pDst, 89 | uint32_t firstIndex, 90 | uint32_t numPoints) 91 | { 92 | 93 | 94 | 95 | 96 | float32_t *pIn1 = pSrcA; /* inputA pointer */ 97 | float32_t *pIn2 = pSrcB; /* inputB pointer */ 98 | float32_t sum; /* Accumulator */ 99 | uint32_t i, j; /* loop counters */ 100 | xtensa_status status; /* status of Partial convolution */ 101 | 102 | /* Check for range of output samples to be calculated */ 103 | if ((firstIndex + numPoints) > ((srcALen + (srcBLen - 1U)))) 104 | { 105 | /* Set status as XTENSA_ARGUMENT_ERROR */ 106 | status = XTENSA_MATH_ARGUMENT_ERROR; 107 | } 108 | else 109 | { 110 | /* Loop to calculate convolution for output length number of values */ 111 | for (i = firstIndex; i <= (firstIndex + numPoints - 1); i++) 112 | { 113 | /* Initialize sum with zero to carry on MAC operations */ 114 | sum = 0.0f; 115 | 116 | /* Loop to perform MAC operations according to convolution equation */ 117 | for (j = 0U; j <= i; j++) 118 | { 119 | /* Check the array limitations for inputs */ 120 | if ((((i - j) < srcBLen) && (j < srcALen))) 121 | { 122 | /* z[i] += x[i-j] * y[j] */ 123 | sum += pIn1[j] * pIn2[i - j]; 124 | } 125 | } 126 | /* Store the output in the destination buffer */ 127 | pDst[i] = sum; 128 | } 129 | /* set status as XTENSA_SUCCESS as there are no argument errors */ 130 | status = XTENSA_MATH_SUCCESS; 131 | } 132 | return (status); 133 | 134 | } 135 | 136 | /** 137 | * @} end of PartialConv group 138 | */ 139 | -------------------------------------------------------------------------------- /components/dsp_lib/FilteringFunctions/xtensa_fir_decimate_init_f32.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_fir_decimate_init_f32.c 4 | * Description: Floating-point FIR Decimator initialization function 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "xtensa_math.h" 30 | 31 | /** 32 | * @ingroup groupFilters 33 | */ 34 | 35 | /** 36 | * @addtogroup FIR_decimate 37 | * @{ 38 | */ 39 | 40 | /** 41 | * @brief Initialization function for the floating-point FIR decimator. 42 | * @param[in,out] *S points to an instance of the floating-point FIR decimator structure. 43 | * @param[in] numTaps number of coefficients in the filter. 44 | * @param[in] M decimation factor. 45 | * @param[in] *pCoeffs points to the filter coefficients. 46 | * @param[in] *pState points to the state buffer. 47 | * @param[in] blockSize number of input samples to process per call. 48 | * @return The function returns ARM_MATH_SUCCESS if initialization was successful or ARM_MATH_LENGTH_ERROR if 49 | * blockSize is not a multiple of M. 50 | * 51 | * Description: 52 | * \par 53 | * pCoeffs points to the array of filter coefficients stored in time reversed order: 54 | *
 55 |  *    {b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]}
 56 |  * 
57 | * \par 58 | * pState points to the array of state variables. 59 | * pState is of length numTaps+blockSize-1 words where blockSize is the number of input samples passed to xtensa_fir_decimate_f32(). 60 | * M is the decimation factor. 61 | */ 62 | 63 | xtensa_status xtensa_fir_decimate_init_f32( 64 | xtensa_fir_decimate_instance_f32 * S, 65 | uint16_t numTaps, 66 | uint8_t M, 67 | float32_t * pCoeffs, 68 | float32_t * pState, 69 | uint32_t blockSize) 70 | { 71 | xtensa_status status; 72 | 73 | /* The size of the input block must be a multiple of the decimation factor */ 74 | if ((blockSize % M) != 0U) 75 | { 76 | /* Set status as ARM_MATH_LENGTH_ERROR */ 77 | status = XTENSA_MATH_LENGTH_ERROR; 78 | } 79 | else 80 | { 81 | /* Assign filter taps */ 82 | S->numTaps = numTaps; 83 | 84 | /* Assign coefficient pointer */ 85 | S->pCoeffs = pCoeffs; 86 | 87 | /* Clear state buffer and size is always (blockSize + numTaps - 1) */ 88 | memset(pState, 0, (numTaps + (blockSize - 1U)) * sizeof(float32_t)); 89 | 90 | /* Assign state pointer */ 91 | S->pState = pState; 92 | 93 | /* Assign Decimation Factor */ 94 | S->M = M; 95 | 96 | status = XTENSA_MATH_SUCCESS; 97 | } 98 | 99 | return (status); 100 | 101 | } 102 | 103 | /** 104 | * @} end of FIR_decimate group 105 | */ 106 | -------------------------------------------------------------------------------- /components/dsp_lib/FilteringFunctions/xtensa_fir_init_f32.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_fir_init_f32.c 4 | * Description: Floating-point FIR filter initialization function 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "xtensa_math.h" 30 | 31 | /** 32 | * @ingroup groupFilters 33 | */ 34 | 35 | /** 36 | * @addtogroup FIR 37 | * @{ 38 | */ 39 | 40 | /** 41 | * @details 42 | * 43 | * @param[in,out] *S points to an instance of the floating-point FIR filter structure. 44 | * @param[in] numTaps Number of filter coefficients in the filter. 45 | * @param[in] *pCoeffs points to the filter coefficients buffer. 46 | * @param[in] *pState points to the state buffer. 47 | * @param[in] blockSize number of samples that are processed per call. 48 | * @return none. 49 | * 50 | * Description: 51 | * \par 52 | * pCoeffs points to the array of filter coefficients stored in time reversed order: 53 | *
54 |  *    {b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]}
55 |  * 
56 | * \par 57 | * pState points to the array of state variables. 58 | * pState is of length numTaps+blockSize-1 samples, where blockSize is the number of input samples processed by each call to xtensa_fir_f32(). 59 | */ 60 | 61 | void xtensa_fir_init_f32( 62 | xtensa_fir_instance_f32 * S, 63 | uint16_t numTaps, 64 | float32_t * pCoeffs, 65 | float32_t * pState, 66 | uint32_t blockSize) 67 | { 68 | /* Assign filter taps */ 69 | S->numTaps = numTaps; 70 | 71 | /* Assign coefficient pointer */ 72 | S->pCoeffs = pCoeffs; 73 | 74 | /* Clear state buffer and the size of state buffer is (blockSize + numTaps - 1) */ 75 | memset(pState, 0, (numTaps + (blockSize - 1U)) * sizeof(float32_t)); 76 | 77 | /* Assign state pointer */ 78 | S->pState = pState; 79 | 80 | } 81 | 82 | /** 83 | * @} end of FIR group 84 | */ 85 | -------------------------------------------------------------------------------- /components/dsp_lib/FilteringFunctions/xtensa_fir_interpolate_init_f32.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_fir_interpolate_init_f32.c 4 | * Description: Floating-point FIR interpolator initialization function 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 XTENSA Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "xtensa_math.h" 30 | 31 | /** 32 | * @ingroup groupFilters 33 | */ 34 | 35 | /** 36 | * @addtogroup FIR_Interpolate 37 | * @{ 38 | */ 39 | 40 | /** 41 | * @brief Initialization function for the floating-point FIR interpolator. 42 | * @param[in,out] *S points to an instance of the floating-point FIR interpolator structure. 43 | * @param[in] L upsample factor. 44 | * @param[in] numTaps number of filter coefficients in the filter. 45 | * @param[in] *pCoeffs points to the filter coefficient buffer. 46 | * @param[in] *pState points to the state buffer. 47 | * @param[in] blockSize number of input samples to process per call. 48 | * @return The function returns XTENSA_MATH_SUCCESS if initialization was successful or XTENSA_MATH_LENGTH_ERROR if 49 | * the filter length numTaps is not a multiple of the interpolation factor L. 50 | * 51 | * Description: 52 | * \par 53 | * pCoeffs points to the array of filter coefficients stored in time reversed order: 54 | *
 55 |  *    {b[numTaps-1], b[numTaps-2], b[numTaps-2], ..., b[1], b[0]}
 56 |  * 
57 | * The length of the filter numTaps must be a multiple of the interpolation factor L. 58 | * \par 59 | * pState points to the array of state variables. 60 | * pState is of length (numTaps/L)+blockSize-1 words 61 | * where blockSize is the number of input samples processed by each call to xtensa_fir_interpolate_f32(). 62 | */ 63 | 64 | xtensa_status xtensa_fir_interpolate_init_f32( 65 | xtensa_fir_interpolate_instance_f32 * S, 66 | uint8_t L, 67 | uint16_t numTaps, 68 | float32_t * pCoeffs, 69 | float32_t * pState, 70 | uint32_t blockSize) 71 | { 72 | xtensa_status status; 73 | 74 | /* The filter length must be a multiple of the interpolation factor */ 75 | if ((numTaps % L) != 0U) 76 | { 77 | /* Set status as XTENSA_MATH_LENGTH_ERROR */ 78 | status = XTENSA_MATH_LENGTH_ERROR; 79 | } 80 | else 81 | { 82 | 83 | /* Assign coefficient pointer */ 84 | S->pCoeffs = pCoeffs; 85 | 86 | /* Assign Interpolation factor */ 87 | S->L = L; 88 | 89 | /* Assign polyPhaseLength */ 90 | S->phaseLength = numTaps / L; 91 | 92 | /* Clear state buffer and size of state array is always phaseLength + blockSize - 1 */ 93 | memset(pState, 0, 94 | (blockSize + 95 | ((uint32_t) S->phaseLength - 1U)) * sizeof(float32_t)); 96 | 97 | /* Assign state pointer */ 98 | S->pState = pState; 99 | 100 | status = XTENSA_MATH_SUCCESS; 101 | } 102 | 103 | return (status); 104 | 105 | } 106 | 107 | /** 108 | * @} end of FIR_Interpolate group 109 | */ 110 | -------------------------------------------------------------------------------- /components/dsp_lib/FilteringFunctions/xtensa_fir_lattice_init_f32.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_fir_lattice_init_f32.c 4 | * Description: Floating-point FIR Lattice filter initialization function 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "xtensa_math.h" 30 | 31 | /** 32 | * @ingroup groupFilters 33 | */ 34 | 35 | /** 36 | * @addtogroup FIR_Lattice 37 | * @{ 38 | */ 39 | 40 | /** 41 | * @brief Initialization function for the floating-point FIR lattice filter. 42 | * @param[in] *S points to an instance of the floating-point FIR lattice structure. 43 | * @param[in] numStages number of filter stages. 44 | * @param[in] *pCoeffs points to the coefficient buffer. The array is of length numStages. 45 | * @param[in] *pState points to the state buffer. The array is of length numStages. 46 | * @return none. 47 | */ 48 | 49 | void xtensa_fir_lattice_init_f32( 50 | xtensa_fir_lattice_instance_f32 * S, 51 | uint16_t numStages, 52 | float32_t * pCoeffs, 53 | float32_t * pState) 54 | { 55 | /* Assign filter taps */ 56 | S->numStages = numStages; 57 | 58 | /* Assign coefficient pointer */ 59 | S->pCoeffs = pCoeffs; 60 | 61 | /* Clear state buffer and size is always numStages */ 62 | memset(pState, 0, (numStages) * sizeof(float32_t)); 63 | 64 | /* Assign state pointer */ 65 | S->pState = pState; 66 | 67 | } 68 | 69 | /** 70 | * @} end of FIR_Lattice group 71 | */ 72 | -------------------------------------------------------------------------------- /components/dsp_lib/FilteringFunctions/xtensa_fir_sparse_init_f32.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_fir_sparse_init_f32.c 4 | * Description: Floating-point sparse FIR filter initialization function 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "xtensa_math.h" 30 | 31 | /** 32 | * @ingroup groupFilters 33 | */ 34 | 35 | /** 36 | * @addtogroup FIR_Sparse 37 | * @{ 38 | */ 39 | 40 | /** 41 | * @brief Initialization function for the floating-point sparse FIR filter. 42 | * @param[in,out] *S points to an instance of the floating-point sparse FIR structure. 43 | * @param[in] numTaps number of nonzero coefficients in the filter. 44 | * @param[in] *pCoeffs points to the array of filter coefficients. 45 | * @param[in] *pState points to the state buffer. 46 | * @param[in] *pTapDelay points to the array of offset times. 47 | * @param[in] maxDelay maximum offset time supported. 48 | * @param[in] blockSize number of samples that will be processed per block. 49 | * @return none 50 | * 51 | * Description: 52 | * \par 53 | * pCoeffs holds the filter coefficients and has length numTaps. 54 | * pState holds the filter's state variables and must be of length 55 | * maxDelay + blockSize, where maxDelay 56 | * is the maximum number of delay line values. 57 | * blockSize is the 58 | * number of samples processed by the xtensa_fir_sparse_f32() function. 59 | */ 60 | 61 | void xtensa_fir_sparse_init_f32( 62 | xtensa_fir_sparse_instance_f32 * S, 63 | uint16_t numTaps, 64 | float32_t * pCoeffs, 65 | float32_t * pState, 66 | int32_t * pTapDelay, 67 | uint16_t maxDelay, 68 | uint32_t blockSize) 69 | { 70 | /* Assign filter taps */ 71 | S->numTaps = numTaps; 72 | 73 | /* Assign coefficient pointer */ 74 | S->pCoeffs = pCoeffs; 75 | 76 | /* Assign TapDelay pointer */ 77 | S->pTapDelay = pTapDelay; 78 | 79 | /* Assign MaxDelay */ 80 | S->maxDelay = maxDelay; 81 | 82 | /* reset the stateIndex to 0 */ 83 | S->stateIndex = 0U; 84 | 85 | /* Clear state buffer and size is always maxDelay + blockSize */ 86 | memset(pState, 0, (maxDelay + blockSize) * sizeof(float32_t)); 87 | 88 | /* Assign state pointer */ 89 | S->pState = pState; 90 | 91 | } 92 | 93 | /** 94 | * @} end of FIR_Sparse group 95 | */ 96 | -------------------------------------------------------------------------------- /components/dsp_lib/FilteringFunctions/xtensa_iir_lattice_init_f32.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_iir_lattice_init_f32.c 4 | * Description: Floating-point IIR lattice filter initialization function 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "xtensa_math.h" 30 | 31 | /** 32 | * @ingroup groupFilters 33 | */ 34 | 35 | /** 36 | * @addtogroup IIR_Lattice 37 | * @{ 38 | */ 39 | 40 | /** 41 | * @brief Initialization function for the floating-point IIR lattice filter. 42 | * @param[in] *S points to an instance of the floating-point IIR lattice structure. 43 | * @param[in] numStages number of stages in the filter. 44 | * @param[in] *pkCoeffs points to the reflection coefficient buffer. The array is of length numStages. 45 | * @param[in] *pvCoeffs points to the ladder coefficient buffer. The array is of length numStages+1. 46 | * @param[in] *pState points to the state buffer. The array is of length numStages+blockSize. 47 | * @param[in] blockSize number of samples to process. 48 | * @return none. 49 | */ 50 | 51 | void xtensa_iir_lattice_init_f32( 52 | xtensa_iir_lattice_instance_f32 * S, 53 | uint16_t numStages, 54 | float32_t * pkCoeffs, 55 | float32_t * pvCoeffs, 56 | float32_t * pState, 57 | uint32_t blockSize) 58 | { 59 | /* Assign filter taps */ 60 | S->numStages = numStages; 61 | 62 | /* Assign reflection coefficient pointer */ 63 | S->pkCoeffs = pkCoeffs; 64 | 65 | /* Assign ladder coefficient pointer */ 66 | S->pvCoeffs = pvCoeffs; 67 | 68 | /* Clear state buffer and size is always blockSize + numStages */ 69 | memset(pState, 0, (numStages + blockSize) * sizeof(float32_t)); 70 | 71 | /* Assign state pointer */ 72 | S->pState = pState; 73 | 74 | 75 | } 76 | 77 | /** 78 | * @} end of IIR_Lattice group 79 | */ 80 | -------------------------------------------------------------------------------- /components/dsp_lib/FilteringFunctions/xtensa_lms_init_f32.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_lms_init_f32.c 4 | * Description: Floating-point LMS filter initialization function 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "xtensa_math.h" 30 | 31 | /** 32 | * @addtogroup LMS 33 | * @{ 34 | */ 35 | 36 | /** 37 | * @brief Initialization function for floating-point LMS filter. 38 | * @param[in] *S points to an instance of the floating-point LMS filter structure. 39 | * @param[in] numTaps number of filter coefficients. 40 | * @param[in] *pCoeffs points to the coefficient buffer. 41 | * @param[in] *pState points to state buffer. 42 | * @param[in] mu step size that controls filter coefficient updates. 43 | * @param[in] blockSize number of samples to process. 44 | * @return none. 45 | */ 46 | 47 | /** 48 | * \par Description: 49 | * pCoeffs points to the array of filter coefficients stored in time reversed order: 50 | *
51 |  *    {b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]}
52 |  * 
53 | * The initial filter coefficients serve as a starting point for the adaptive filter. 54 | * pState points to an array of length numTaps+blockSize-1 samples, where blockSize is the number of input samples processed by each call to xtensa_lms_f32(). 55 | */ 56 | 57 | void xtensa_lms_init_f32( 58 | xtensa_lms_instance_f32 * S, 59 | uint16_t numTaps, 60 | float32_t * pCoeffs, 61 | float32_t * pState, 62 | float32_t mu, 63 | uint32_t blockSize) 64 | { 65 | /* Assign filter taps */ 66 | S->numTaps = numTaps; 67 | 68 | /* Assign coefficient pointer */ 69 | S->pCoeffs = pCoeffs; 70 | 71 | /* Clear state buffer and size is always blockSize + numTaps */ 72 | memset(pState, 0, (numTaps + (blockSize - 1)) * sizeof(float32_t)); 73 | 74 | /* Assign state pointer */ 75 | S->pState = pState; 76 | 77 | /* Assign Step size value */ 78 | S->mu = mu; 79 | } 80 | 81 | /** 82 | * @} end of LMS group 83 | */ 84 | -------------------------------------------------------------------------------- /components/dsp_lib/FilteringFunctions/xtensa_lms_norm_init_f32.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_lms_norm_init_f32.c 4 | * Description: Floating-point NLMS filter initialization function 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "xtensa_math.h" 30 | 31 | /** 32 | * @ingroup groupFilters 33 | */ 34 | 35 | /** 36 | * @addtogroup LMS_NORM 37 | * @{ 38 | */ 39 | 40 | /** 41 | * @brief Initialization function for floating-point normalized LMS filter. 42 | * @param[in] *S points to an instance of the floating-point LMS filter structure. 43 | * @param[in] numTaps number of filter coefficients. 44 | * @param[in] *pCoeffs points to coefficient buffer. 45 | * @param[in] *pState points to state buffer. 46 | * @param[in] mu step size that controls filter coefficient updates. 47 | * @param[in] blockSize number of samples to process. 48 | * @return none. 49 | * 50 | * \par Description: 51 | * pCoeffs points to the array of filter coefficients stored in time reversed order: 52 | *
53 |  *    {b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]}
54 |  * 
55 | * The initial filter coefficients serve as a starting point for the adaptive filter. 56 | * pState points to an array of length numTaps+blockSize-1 samples, 57 | * where blockSize is the number of input samples processed by each call to xtensa_lms_norm_f32(). 58 | */ 59 | 60 | void xtensa_lms_norm_init_f32( 61 | xtensa_lms_norm_instance_f32 * S, 62 | uint16_t numTaps, 63 | float32_t * pCoeffs, 64 | float32_t * pState, 65 | float32_t mu, 66 | uint32_t blockSize) 67 | { 68 | /* Assign filter taps */ 69 | S->numTaps = numTaps; 70 | 71 | /* Assign coefficient pointer */ 72 | S->pCoeffs = pCoeffs; 73 | 74 | /* Clear state buffer and size is always blockSize + numTaps - 1 */ 75 | memset(pState, 0, (numTaps + (blockSize - 1U)) * sizeof(float32_t)); 76 | 77 | /* Assign state pointer */ 78 | S->pState = pState; 79 | 80 | /* Assign Step size value */ 81 | S->mu = mu; 82 | 83 | /* Initialise Energy to zero */ 84 | S->energy = 0.0f; 85 | 86 | /* Initialise x0 to zero */ 87 | S->x0 = 0.0f; 88 | 89 | } 90 | 91 | /** 92 | * @} end of LMS_NORM group 93 | */ 94 | -------------------------------------------------------------------------------- /components/dsp_lib/Include/xtensa_common_tables.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_common_tables.h 4 | * Description: Extern declaration for common tables 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 XTENSA Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #ifndef _XTENSA_COMMON_TABLES_H 30 | #define _XTENSA_COMMON_TABLES_H 31 | 32 | #include "xtensa_math.h" 33 | 34 | extern const uint16_t xtensaBitRevTable[1024]; 35 | extern const float32_t twiddleCoef_16[32]; 36 | extern const float32_t twiddleCoef_32[64]; 37 | extern const float32_t twiddleCoef_64[128]; 38 | extern const float32_t twiddleCoef_128[256]; 39 | extern const float32_t twiddleCoef_256[512]; 40 | extern const float32_t twiddleCoef_512[1024]; 41 | extern const float32_t twiddleCoef_1024[2048]; 42 | extern const float32_t twiddleCoef_2048[4096]; 43 | extern const float32_t twiddleCoef_4096[8192]; 44 | #define twiddleCoef twiddleCoef_4096 45 | extern const float32_t twiddleCoef_rfft_32[32]; 46 | extern const float32_t twiddleCoef_rfft_64[64]; 47 | extern const float32_t twiddleCoef_rfft_128[128]; 48 | extern const float32_t twiddleCoef_rfft_256[256]; 49 | extern const float32_t twiddleCoef_rfft_512[512]; 50 | extern const float32_t twiddleCoef_rfft_1024[1024]; 51 | extern const float32_t twiddleCoef_rfft_2048[2048]; 52 | extern const float32_t twiddleCoef_rfft_4096[4096]; 53 | 54 | /* floating-point bit reversal tables */ 55 | #define XTENSABITREVINDEXTABLE_16_TABLE_LENGTH ((uint16_t)20) 56 | #define XTENSABITREVINDEXTABLE_32_TABLE_LENGTH ((uint16_t)48) 57 | #define XTENSABITREVINDEXTABLE_64_TABLE_LENGTH ((uint16_t)56) 58 | #define XTENSABITREVINDEXTABLE_128_TABLE_LENGTH ((uint16_t)208) 59 | #define XTENSABITREVINDEXTABLE_256_TABLE_LENGTH ((uint16_t)440) 60 | #define XTENSABITREVINDEXTABLE_512_TABLE_LENGTH ((uint16_t)448) 61 | #define XTENSABITREVINDEXTABLE_1024_TABLE_LENGTH ((uint16_t)1800) 62 | #define XTENSABITREVINDEXTABLE_2048_TABLE_LENGTH ((uint16_t)3808) 63 | #define XTENSABITREVINDEXTABLE_4096_TABLE_LENGTH ((uint16_t)4032) 64 | 65 | extern const uint16_t xtensaBitRevIndexTable16[XTENSABITREVINDEXTABLE_16_TABLE_LENGTH]; 66 | extern const uint16_t xtensaBitRevIndexTable32[XTENSABITREVINDEXTABLE_32_TABLE_LENGTH]; 67 | extern const uint16_t xtensaBitRevIndexTable64[XTENSABITREVINDEXTABLE_64_TABLE_LENGTH]; 68 | extern const uint16_t xtensaBitRevIndexTable128[XTENSABITREVINDEXTABLE_128_TABLE_LENGTH]; 69 | extern const uint16_t xtensaBitRevIndexTable256[XTENSABITREVINDEXTABLE_256_TABLE_LENGTH]; 70 | extern const uint16_t xtensaBitRevIndexTable512[XTENSABITREVINDEXTABLE_512_TABLE_LENGTH]; 71 | extern const uint16_t xtensaBitRevIndexTable1024[XTENSABITREVINDEXTABLE_1024_TABLE_LENGTH]; 72 | extern const uint16_t xtensaBitRevIndexTable2048[XTENSABITREVINDEXTABLE_2048_TABLE_LENGTH]; 73 | extern const uint16_t xtensaBitRevIndexTable4096[XTENSABITREVINDEXTABLE_4096_TABLE_LENGTH]; 74 | 75 | /* fixed-point bit reversal tables */ 76 | #define XTENSABITREVINDEXTABLE_FIXED_16_TABLE_LENGTH ((uint16_t)12) 77 | #define XTENSABITREVINDEXTABLE_FIXED_32_TABLE_LENGTH ((uint16_t)24) 78 | #define XTENSABITREVINDEXTABLE_FIXED_64_TABLE_LENGTH ((uint16_t)56) 79 | #define XTENSABITREVINDEXTABLE_FIXED_128_TABLE_LENGTH ((uint16_t)112) 80 | #define XTENSABITREVINDEXTABLE_FIXED_256_TABLE_LENGTH ((uint16_t)240) 81 | #define XTENSABITREVINDEXTABLE_FIXED_512_TABLE_LENGTH ((uint16_t)480) 82 | #define XTENSABITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH ((uint16_t)992) 83 | #define XTENSABITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH ((uint16_t)1984) 84 | #define XTENSABITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH ((uint16_t)4032) 85 | 86 | extern const uint16_t xtensaBitRevIndexTable_fixed_16[XTENSABITREVINDEXTABLE_FIXED_16_TABLE_LENGTH]; 87 | extern const uint16_t xtensaBitRevIndexTable_fixed_32[XTENSABITREVINDEXTABLE_FIXED_32_TABLE_LENGTH]; 88 | extern const uint16_t xtensaBitRevIndexTable_fixed_64[XTENSABITREVINDEXTABLE_FIXED_64_TABLE_LENGTH]; 89 | extern const uint16_t xtensaBitRevIndexTable_fixed_128[XTENSABITREVINDEXTABLE_FIXED_128_TABLE_LENGTH]; 90 | extern const uint16_t xtensaBitRevIndexTable_fixed_256[XTENSABITREVINDEXTABLE_FIXED_256_TABLE_LENGTH]; 91 | extern const uint16_t xtensaBitRevIndexTable_fixed_512[XTENSABITREVINDEXTABLE_FIXED_512_TABLE_LENGTH]; 92 | extern const uint16_t xtensaBitRevIndexTable_fixed_1024[XTENSABITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH]; 93 | extern const uint16_t xtensaBitRevIndexTable_fixed_2048[XTENSABITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH]; 94 | extern const uint16_t xtensaBitRevIndexTable_fixed_4096[XTENSABITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH]; 95 | 96 | /* Tables for Fast Math Sine and Cosine */ 97 | extern const float32_t sinTable_f32[FAST_MATH_TABLE_SIZE + 1]; 98 | 99 | #endif /* XTENSA_COMMON_TABLES_H */ 100 | -------------------------------------------------------------------------------- /components/dsp_lib/Include/xtensa_const_structs.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_const_structs.h 4 | * Description: Constant structs that are initialized for user convenience. 5 | * For example, some can be given as arguments to the xtensa_cfft_f32() function. 6 | * 7 | * $Date: 27. January 2017 8 | * $Revision: V.1.5.1 9 | * 10 | * Target Processor: Cortex-M cores 11 | * -------------------------------------------------------------------- */ 12 | /* 13 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 14 | * 15 | * SPDX-License-Identifier: Apache-2.0 16 | * 17 | * Licensed under the Apache License, Version 2.0 (the License); you may 18 | * not use this file except in compliance with the License. 19 | * You may obtain a copy of the License at 20 | * 21 | * www.apache.org/licenses/LICENSE-2.0 22 | * 23 | * Unless required by applicable law or agreed to in writing, software 24 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 25 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 26 | * See the License for the specific language governing permissions and 27 | * limitations under the License. 28 | */ 29 | 30 | #ifndef _XTENSA_CONST_STRUCTS_H 31 | #define _XTENSA_CONST_STRUCTS_H 32 | 33 | #include "xtensa_math.h" 34 | #include "xtensa_common_tables.h" 35 | 36 | extern const xtensa_cfft_instance_f32 xtensa_cfft_sR_f32_len16; 37 | extern const xtensa_cfft_instance_f32 xtensa_cfft_sR_f32_len32; 38 | extern const xtensa_cfft_instance_f32 xtensa_cfft_sR_f32_len64; 39 | extern const xtensa_cfft_instance_f32 xtensa_cfft_sR_f32_len128; 40 | extern const xtensa_cfft_instance_f32 xtensa_cfft_sR_f32_len256; 41 | extern const xtensa_cfft_instance_f32 xtensa_cfft_sR_f32_len512; 42 | extern const xtensa_cfft_instance_f32 xtensa_cfft_sR_f32_len1024; 43 | extern const xtensa_cfft_instance_f32 xtensa_cfft_sR_f32_len2048; 44 | extern const xtensa_cfft_instance_f32 xtensa_cfft_sR_f32_len4096; 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /components/dsp_lib/MatrixFunctions/arm_mat_add_f32.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_mat_add_f32.c 4 | * Description: Floating-point matrix addition 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 XTENSA Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "xtensa_math.h" 30 | 31 | /** 32 | * @ingroup groupMatrix 33 | */ 34 | 35 | /** 36 | * @defgroup MatrixAdd Matrix Addition 37 | * 38 | * Adds two matrices. 39 | * \image html MatrixAddition.gif "Addition of two 3 x 3 matrices" 40 | * 41 | * The functions check to make sure that 42 | * pSrcA, pSrcB, and pDst have the same 43 | * number of rows and columns. 44 | */ 45 | 46 | /** 47 | * @addtogroup MatrixAdd 48 | * @{ 49 | */ 50 | 51 | 52 | /** 53 | * @brief Floating-point matrix addition. 54 | * @param[in] *pSrcA points to the first input matrix structure 55 | * @param[in] *pSrcB points to the second input matrix structure 56 | * @param[out] *pDst points to output matrix structure 57 | * @return The function returns either 58 | * XTENSA_MATH_SIZE_MISMATCH or XTENSA_MATH_SUCCESS based on the outcome of size checking. 59 | */ 60 | 61 | xtensa_status xtensa_mat_add_f32( 62 | const xtensa_matrix_instance_f32 * pSrcA, 63 | const xtensa_matrix_instance_f32 * pSrcB, 64 | xtensa_matrix_instance_f32 * pDst) 65 | { 66 | float32_t *pIn1 = pSrcA->pData; /* input data matrix pointer A */ 67 | float32_t *pIn2 = pSrcB->pData; /* input data matrix pointer B */ 68 | float32_t *pOut = pDst->pData; /* output data matrix pointer */ 69 | 70 | 71 | 72 | uint32_t numSamples; /* total number of elements in the matrix */ 73 | uint32_t blkCnt; /* loop counters */ 74 | xtensa_status status; /* status of matrix addition */ 75 | 76 | #ifdef XTENSA_MATH_MATRIX_CHECK 77 | /* Check for matrix mismatch condition */ 78 | if ((pSrcA->numRows != pSrcB->numRows) || 79 | (pSrcA->numCols != pSrcB->numCols) || 80 | (pSrcA->numRows != pDst->numRows) || (pSrcA->numCols != pDst->numCols)) 81 | { 82 | /* Set status as XTENSA_MATH_SIZE_MISMATCH */ 83 | status = XTENSA_MATH_SIZE_MISMATCH; 84 | } 85 | else 86 | #endif 87 | { 88 | 89 | /* Total number of samples in the input matrix */ 90 | numSamples = (uint32_t) pSrcA->numRows * pSrcA->numCols; 91 | 92 | 93 | 94 | /* Initialize blkCnt with number of samples */ 95 | blkCnt = numSamples; 96 | 97 | 98 | while (blkCnt > 0U) 99 | { 100 | /* C(m,n) = A(m,n) + B(m,n) */ 101 | /* Add and then store the results in the destination buffer. */ 102 | *pOut++ = (*pIn1++) + (*pIn2++); 103 | 104 | /* Decrement the loop counter */ 105 | blkCnt--; 106 | } 107 | 108 | /* set status as XTENSA_MATH_SUCCESS */ 109 | status = XTENSA_MATH_SUCCESS; 110 | 111 | } 112 | 113 | /* Return to application */ 114 | return (status); 115 | } 116 | 117 | /** 118 | * @} end of MatrixAdd group 119 | */ 120 | -------------------------------------------------------------------------------- /components/dsp_lib/MatrixFunctions/arm_mat_init_f32.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_mat_init_f32.c 4 | * Description: Floating-point matrix initialization 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "xtensa_math.h" 30 | 31 | /** 32 | * @ingroup groupMatrix 33 | */ 34 | 35 | /** 36 | * @defgroup MatrixInit Matrix Initialization 37 | * 38 | * Initializes the underlying matrix data structure. 39 | * The functions set the numRows, 40 | * numCols, and pData fields 41 | * of the matrix data structure. 42 | */ 43 | 44 | /** 45 | * @addtogroup MatrixInit 46 | * @{ 47 | */ 48 | 49 | /** 50 | * @brief Floating-point matrix initialization. 51 | * @param[in,out] *S points to an instance of the floating-point matrix structure. 52 | * @param[in] nRows number of rows in the matrix. 53 | * @param[in] nColumns number of columns in the matrix. 54 | * @param[in] *pData points to the matrix data array. 55 | * @return none 56 | */ 57 | 58 | void xtensa_mat_init_f32( 59 | xtensa_matrix_instance_f32 * S, 60 | uint16_t nRows, 61 | uint16_t nColumns, 62 | float32_t * pData) 63 | { 64 | /* Assign Number of Rows */ 65 | S->numRows = nRows; 66 | 67 | /* Assign Number of Columns */ 68 | S->numCols = nColumns; 69 | 70 | /* Assign Data pointer */ 71 | S->pData = pData; 72 | } 73 | 74 | /** 75 | * @} end of MatrixInit group 76 | */ 77 | -------------------------------------------------------------------------------- /components/dsp_lib/MatrixFunctions/arm_mat_mult_f32.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_mat_mult_f32.c 4 | * Description: Floating-point matrix multiplication 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 XTENSA Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "xtensa_math.h" 30 | 31 | /** 32 | * @ingroup groupMatrix 33 | */ 34 | 35 | /** 36 | * @defgroup MatrixMult Matrix Multiplication 37 | * 38 | * Multiplies two matrices. 39 | * 40 | * \image html MatrixMultiplication.gif "Multiplication of two 3 x 3 matrices" 41 | 42 | * Matrix multiplication is only defined if the number of columns of the 43 | * first matrix equals the number of rows of the second matrix. 44 | * Multiplying an M x N matrix with an N x P matrix results 45 | * in an M x P matrix. 46 | * When matrix size checking is enabled, the functions check: (1) that the inner dimensions of 47 | * pSrcA and pSrcB are equal; and (2) that the size of the output 48 | * matrix equals the outer dimensions of pSrcA and pSrcB. 49 | */ 50 | 51 | 52 | /** 53 | * @addtogroup MatrixMult 54 | * @{ 55 | */ 56 | 57 | /** 58 | * @brief Floating-point matrix multiplication. 59 | * @param[in] *pSrcA points to the first input matrix structure 60 | * @param[in] *pSrcB points to the second input matrix structure 61 | * @param[out] *pDst points to output matrix structure 62 | * @return The function returns either 63 | * XTENSA_MATH_SIZE_MISMATCH or XTENSA_MATH_SUCCESS based on the outcome of size checking. 64 | */ 65 | 66 | xtensa_status xtensa_mat_mult_f32( 67 | const xtensa_matrix_instance_f32 * pSrcA, 68 | const xtensa_matrix_instance_f32 * pSrcB, 69 | xtensa_matrix_instance_f32 * pDst) 70 | { 71 | float32_t *pIn1 = pSrcA->pData; /* input data matrix pointer A */ 72 | float32_t *pIn2 = pSrcB->pData; /* input data matrix pointer B */ 73 | float32_t *pInA = pSrcA->pData; /* input data matrix pointer A */ 74 | float32_t *pOut = pDst->pData; /* output data matrix pointer */ 75 | float32_t *px; /* Temporary output data matrix pointer */ 76 | float32_t sum; /* Accumulator */ 77 | uint16_t numRowsA = pSrcA->numRows; /* number of rows of input matrix A */ 78 | uint16_t numColsB = pSrcB->numCols; /* number of columns of input matrix B */ 79 | uint16_t numColsA = pSrcA->numCols; /* number of columns of input matrix A */ 80 | 81 | 82 | 83 | float32_t *pInB = pSrcB->pData; /* input data matrix pointer B */ 84 | uint16_t col, i = 0U, row = numRowsA, colCnt; /* loop counters */ 85 | xtensa_status status; /* status of matrix multiplication */ 86 | 87 | #ifdef XTENSA_MATH_MATRIX_CHECK 88 | 89 | /* Check for matrix mismatch condition */ 90 | if ((pSrcA->numCols != pSrcB->numRows) || 91 | (pSrcA->numRows != pDst->numRows) || (pSrcB->numCols != pDst->numCols)) 92 | { 93 | 94 | /* Set status as XTENSA_MATH_SIZE_MISMATCH */ 95 | status = XTENSA_MATH_SIZE_MISMATCH; 96 | } 97 | else 98 | #endif /* #ifdef XTENSA_MATH_MATRIX_CHECK */ 99 | 100 | { 101 | /* The following loop performs the dot-product of each row in pInA with each column in pInB */ 102 | /* row loop */ 103 | do 104 | { 105 | /* Output pointer is set to starting address of the row being processed */ 106 | px = pOut + i; 107 | 108 | /* For every row wise process, the column loop counter is to be initiated */ 109 | col = numColsB; 110 | 111 | /* For every row wise process, the pIn2 pointer is set 112 | ** to the starting address of the pSrcB data */ 113 | pIn2 = pSrcB->pData; 114 | 115 | /* column loop */ 116 | do 117 | { 118 | /* Set the variable sum, that acts as accumulator, to zero */ 119 | sum = 0.0f; 120 | 121 | /* Initialize the pointer pIn1 to point to the starting address of the row being processed */ 122 | pIn1 = pInA; 123 | 124 | /* Matrix A columns number of MAC operations are to be performed */ 125 | colCnt = numColsA; 126 | 127 | while (colCnt > 0U) 128 | { 129 | /* c(m,n) = a(1,1)*b(1,1) + a(1,2) * b(2,1) + .... + a(m,p)*b(p,n) */ 130 | sum += *pIn1++ * (*pIn2); 131 | pIn2 += numColsB; 132 | 133 | /* Decrement the loop counter */ 134 | colCnt--; 135 | } 136 | 137 | /* Store the result in the destination buffer */ 138 | *px++ = sum; 139 | 140 | /* Decrement the column loop counter */ 141 | col--; 142 | 143 | /* Update the pointer pIn2 to point to the starting address of the next column */ 144 | pIn2 = pInB + (numColsB - col); 145 | 146 | } while (col > 0U); 147 | 148 | 149 | /* Update the pointer pInA to point to the starting address of the next row */ 150 | i = i + numColsB; 151 | pInA = pInA + numColsA; 152 | 153 | /* Decrement the row loop counter */ 154 | row--; 155 | 156 | } while (row > 0U); 157 | /* Set status as XTENSA_MATH_SUCCESS */ 158 | status = XTENSA_MATH_SUCCESS; 159 | } 160 | 161 | /* Return to application */ 162 | return (status); 163 | } 164 | 165 | /** 166 | * @} end of MatrixMult group 167 | */ 168 | -------------------------------------------------------------------------------- /components/dsp_lib/MatrixFunctions/arm_mat_scale_f32.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_mat_scale_f32.c 4 | * Description: Multiplies a floating-point matrix by a scalar 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 XTENSA Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "xtensa_math.h" 30 | 31 | /** 32 | * @ingroup groupMatrix 33 | */ 34 | 35 | /** 36 | * @defgroup MatrixScale Matrix Scale 37 | * 38 | * Multiplies a matrix by a scalar. This is accomplished by multiplying each element in the 39 | * matrix by the scalar. For example: 40 | * \image html MatrixScale.gif "Matrix Scaling of a 3 x 3 matrix" 41 | * 42 | * The function checks to make sure that the input and output matrices are of the same size. 43 | * 44 | * In the fixed-point Q15 and Q31 functions, scale is represented by 45 | * a fractional multiplication scaleFract and an arithmetic shift shift. 46 | * The shift allows the gain of the scaling operation to exceed 1.0. 47 | * The overall scale factor applied to the fixed-point data is 48 | *
 49 |  *     scale = scaleFract * 2^shift.
 50 |  * 
51 | */ 52 | 53 | /** 54 | * @addtogroup MatrixScale 55 | * @{ 56 | */ 57 | 58 | /** 59 | * @brief Floating-point matrix scaling. 60 | * @param[in] *pSrc points to input matrix structure 61 | * @param[in] scale scale factor to be applied 62 | * @param[out] *pDst points to output matrix structure 63 | * @return The function returns either XTENSA_MATH_SIZE_MISMATCH 64 | * or XTENSA_MATH_SUCCESS based on the outcome of size checking. 65 | * 66 | */ 67 | 68 | xtensa_status xtensa_mat_scale_f32( 69 | const xtensa_matrix_instance_f32 * pSrc, 70 | float32_t scale, 71 | xtensa_matrix_instance_f32 * pDst) 72 | { 73 | float32_t *pIn = pSrc->pData; /* input data matrix pointer */ 74 | float32_t *pOut = pDst->pData; /* output data matrix pointer */ 75 | uint32_t numSamples; /* total number of elements in the matrix */ 76 | uint32_t blkCnt; /* loop counters */ 77 | xtensa_status status; /* status of matrix scaling */ 78 | 79 | 80 | 81 | #ifdef XTENSA_MATH_MATRIX_CHECK 82 | /* Check for matrix mismatch condition */ 83 | if ((pSrc->numRows != pDst->numRows) || (pSrc->numCols != pDst->numCols)) 84 | { 85 | /* Set status as XTENSA_MATH_SIZE_MISMATCH */ 86 | status = XTENSA_MATH_SIZE_MISMATCH; 87 | } 88 | else 89 | #endif /* #ifdef XTENSA_MATH_MATRIX_CHECK */ 90 | { 91 | /* Total number of samples in the input matrix */ 92 | numSamples = (uint32_t) pSrc->numRows * pSrc->numCols; 93 | 94 | 95 | /* Initialize blkCnt with number of samples */ 96 | blkCnt = numSamples; 97 | 98 | 99 | while (blkCnt > 0U) 100 | { 101 | /* C(m,n) = A(m,n) * scale */ 102 | /* The results are stored in the destination buffer. */ 103 | *pOut++ = (*pIn++) * scale; 104 | 105 | /* Decrement the loop counter */ 106 | blkCnt--; 107 | } 108 | 109 | /* Set status as XTENSA_MATH_SUCCESS */ 110 | status = XTENSA_MATH_SUCCESS; 111 | } 112 | 113 | /* Return to application */ 114 | return (status); 115 | } 116 | 117 | /** 118 | * @} end of MatrixScale group 119 | */ 120 | -------------------------------------------------------------------------------- /components/dsp_lib/MatrixFunctions/arm_mat_sub_f32.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_mat_sub_f32.c 4 | * Description: Floating-point matrix subtraction 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 XTENSA Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "xtensa_math.h" 30 | 31 | /** 32 | * @ingroup groupMatrix 33 | */ 34 | 35 | /** 36 | * @defgroup MatrixSub Matrix Subtraction 37 | * 38 | * Subtract two matrices. 39 | * \image html MatrixSubtraction.gif "Subraction of two 3 x 3 matrices" 40 | * 41 | * The functions check to make sure that 42 | * pSrcA, pSrcB, and pDst have the same 43 | * number of rows and columns. 44 | */ 45 | 46 | /** 47 | * @addtogroup MatrixSub 48 | * @{ 49 | */ 50 | 51 | /** 52 | * @brief Floating-point matrix subtraction 53 | * @param[in] *pSrcA points to the first input matrix structure 54 | * @param[in] *pSrcB points to the second input matrix structure 55 | * @param[out] *pDst points to output matrix structure 56 | * @return The function returns either 57 | * XTENSA_MATH_SIZE_MISMATCH or XTENSA_MATH_SUCCESS based on the outcome of size checking. 58 | */ 59 | 60 | xtensa_status xtensa_mat_sub_f32( 61 | const xtensa_matrix_instance_f32 * pSrcA, 62 | const xtensa_matrix_instance_f32 * pSrcB, 63 | xtensa_matrix_instance_f32 * pDst) 64 | { 65 | float32_t *pIn1 = pSrcA->pData; /* input data matrix pointer A */ 66 | float32_t *pIn2 = pSrcB->pData; /* input data matrix pointer B */ 67 | float32_t *pOut = pDst->pData; /* output data matrix pointer */ 68 | 69 | 70 | uint32_t numSamples; /* total number of elements in the matrix */ 71 | uint32_t blkCnt; /* loop counters */ 72 | xtensa_status status; /* status of matrix subtraction */ 73 | 74 | #ifdef XTENSA_MATH_MATRIX_CHECK 75 | /* Check for matrix mismatch condition */ 76 | if ((pSrcA->numRows != pSrcB->numRows) || 77 | (pSrcA->numCols != pSrcB->numCols) || 78 | (pSrcA->numRows != pDst->numRows) || (pSrcA->numCols != pDst->numCols)) 79 | { 80 | /* Set status as XTENSA_MATH_SIZE_MISMATCH */ 81 | status = XTENSA_MATH_SIZE_MISMATCH; 82 | } 83 | else 84 | #endif /* #ifdef XTENSA_MATH_MATRIX_CHECK */ 85 | { 86 | /* Total number of samples in the input matrix */ 87 | numSamples = (uint32_t) pSrcA->numRows * pSrcA->numCols; 88 | 89 | 90 | 91 | /* Initialize blkCnt with number of samples */ 92 | blkCnt = numSamples; 93 | 94 | 95 | while (blkCnt > 0U) 96 | { 97 | /* C(m,n) = A(m,n) - B(m,n) */ 98 | /* Subtract and then store the results in the destination buffer. */ 99 | *pOut++ = (*pIn1++) - (*pIn2++); 100 | 101 | /* Decrement the loop counter */ 102 | blkCnt--; 103 | } 104 | 105 | /* Set status as XTENSA_MATH_SUCCESS */ 106 | status = XTENSA_MATH_SUCCESS; 107 | } 108 | 109 | /* Return to application */ 110 | return (status); 111 | } 112 | 113 | /** 114 | * @} end of MatrixSub group 115 | */ 116 | -------------------------------------------------------------------------------- /components/dsp_lib/MatrixFunctions/arm_mat_trans_f32.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_mat_trans_f32.c 4 | * Description: Floating-point matrix transpose 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 XTENSA Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | /** 30 | * @defgroup MatrixTrans Matrix Transpose 31 | * 32 | * Tranposes a matrix. 33 | * Transposing an M x N matrix flips it around the center diagonal and results in an N x M matrix. 34 | * \image html MatrixTranspose.gif "Transpose of a 3 x 3 matrix" 35 | */ 36 | 37 | #include "xtensa_math.h" 38 | 39 | /** 40 | * @ingroup groupMatrix 41 | */ 42 | 43 | /** 44 | * @addtogroup MatrixTrans 45 | * @{ 46 | */ 47 | 48 | /** 49 | * @brief Floating-point matrix transpose. 50 | * @param[in] *pSrc points to the input matrix 51 | * @param[out] *pDst points to the output matrix 52 | * @return The function returns either XTENSA_MATH_SIZE_MISMATCH 53 | * or XTENSA_MATH_SUCCESS based on the outcome of size checking. 54 | */ 55 | 56 | 57 | xtensa_status xtensa_mat_trans_f32( 58 | const xtensa_matrix_instance_f32 * pSrc, 59 | xtensa_matrix_instance_f32 * pDst) 60 | { 61 | float32_t *pIn = pSrc->pData; /* input data matrix pointer */ 62 | float32_t *pOut = pDst->pData; /* output data matrix pointer */ 63 | float32_t *px; /* Temporary output data matrix pointer */ 64 | uint16_t nRows = pSrc->numRows; /* number of rows */ 65 | uint16_t nColumns = pSrc->numCols; /* number of columns */ 66 | 67 | 68 | 69 | uint16_t col, i = 0U, row = nRows; /* loop counters */ 70 | xtensa_status status; /* status of matrix transpose */ 71 | 72 | 73 | #ifdef XTENSA_MATH_MATRIX_CHECK 74 | 75 | /* Check for matrix mismatch condition */ 76 | if ((pSrc->numRows != pDst->numCols) || (pSrc->numCols != pDst->numRows)) 77 | { 78 | /* Set status as XTENSA_MATH_SIZE_MISMATCH */ 79 | status = XTENSA_MATH_SIZE_MISMATCH; 80 | } 81 | else 82 | #endif /* #ifdef XTENSA_MATH_MATRIX_CHECK */ 83 | 84 | { 85 | /* Matrix transpose by exchanging the rows with columns */ 86 | /* row loop */ 87 | do 88 | { 89 | /* The pointer px is set to starting address of the column being processed */ 90 | px = pOut + i; 91 | 92 | /* Initialize column loop counter */ 93 | col = nColumns; 94 | 95 | while (col > 0U) 96 | { 97 | /* Read and store the input element in the destination */ 98 | *px = *pIn++; 99 | 100 | /* Update the pointer px to point to the next row of the transposed matrix */ 101 | px += nRows; 102 | 103 | /* Decrement the column loop counter */ 104 | col--; 105 | } 106 | 107 | 108 | i++; 109 | 110 | /* Decrement the row loop counter */ 111 | row--; 112 | 113 | } while (row > 0U); /* row loop end */ 114 | 115 | /* Set status as XTENSA_MATH_SUCCESS */ 116 | status = XTENSA_MATH_SUCCESS; 117 | } 118 | 119 | /* Return to application */ 120 | return (status); 121 | } 122 | 123 | /** 124 | * @} end of MatrixTrans group 125 | */ 126 | -------------------------------------------------------------------------------- /components/dsp_lib/StatisticsFunctions/xtensa_max_f32.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_max_f32.c 4 | * Description: Maximum value of a floating-point vector 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "xtensa_math.h" 30 | 31 | /** 32 | * @ingroup groupStats 33 | */ 34 | 35 | /** 36 | * @defgroup Max Maximum 37 | * 38 | * Computes the maximum value of an array of data. 39 | * The function returns both the maximum value and its position within the array. 40 | * There are separate functions for floating-point, Q31, Q15, and Q7 data types. 41 | */ 42 | 43 | /** 44 | * @addtogroup Max 45 | * @{ 46 | */ 47 | 48 | 49 | /** 50 | * @brief Maximum value of a floating-point vector. 51 | * @param[in] *pSrc points to the input vector 52 | * @param[in] blockSize length of the input vector 53 | * @param[out] *pResult maximum value returned here 54 | * @param[out] *pIndex index of maximum value returned here 55 | * @return none. 56 | */ 57 | 58 | void xtensa_max_f32( 59 | float32_t * pSrc, 60 | uint32_t blockSize, 61 | float32_t * pResult, 62 | uint32_t * pIndex) 63 | { 64 | 65 | 66 | float32_t maxVal1, out; /* Temporary variables to store the output value. */ 67 | uint32_t blkCnt, outIndex; /* loop counter */ 68 | 69 | /* Initialise the index value to zero. */ 70 | outIndex = 0U; 71 | /* Load first input value that act as reference value for comparision */ 72 | out = *pSrc++; 73 | 74 | blkCnt = (blockSize - 1U); 75 | 76 | 77 | while (blkCnt > 0U) 78 | { 79 | /* Initialize maxVal to the next consecutive values one by one */ 80 | maxVal1 = *pSrc++; 81 | 82 | /* compare for the maximum value */ 83 | if (out < maxVal1) 84 | { 85 | /* Update the maximum value and it's index */ 86 | out = maxVal1; 87 | outIndex = blockSize - blkCnt; 88 | } 89 | 90 | /* Decrement the loop counter */ 91 | blkCnt--; 92 | } 93 | 94 | /* Store the maximum value and it's index into destination pointers */ 95 | *pResult = out; 96 | *pIndex = outIndex; 97 | } 98 | 99 | /** 100 | * @} end of Max group 101 | */ 102 | -------------------------------------------------------------------------------- /components/dsp_lib/StatisticsFunctions/xtensa_mean_f32.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_mean_f32.c 4 | * Description: Mean value of a floating-point vector 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "xtensa_math.h" 30 | 31 | /** 32 | * @ingroup groupStats 33 | */ 34 | 35 | /** 36 | * @defgroup mean Mean 37 | * 38 | * Calculates the mean of the input vector. Mean is defined as the average of the elements in the vector. 39 | * The underlying algorithm is used: 40 | * 41 | *
42 |  * 	Result = (pSrc[0] + pSrc[1] + pSrc[2] + ... + pSrc[blockSize-1]) / blockSize;
43 |  * 
44 | * 45 | * There are separate functions for floating-point, Q31, Q15, and Q7 data types. 46 | */ 47 | 48 | /** 49 | * @addtogroup mean 50 | * @{ 51 | */ 52 | 53 | 54 | /** 55 | * @brief Mean value of a floating-point vector. 56 | * @param[in] *pSrc points to the input vector 57 | * @param[in] blockSize length of the input vector 58 | * @param[out] *pResult mean value returned here 59 | * @return none. 60 | */ 61 | 62 | void xtensa_mean_f32( 63 | float32_t * pSrc, 64 | uint32_t blockSize, 65 | float32_t * pResult) 66 | { 67 | float32_t sum = 0.0f; /* Temporary result storage */ 68 | uint32_t blkCnt; /* loop counter */ 69 | 70 | 71 | 72 | /* Loop over blockSize number of values */ 73 | blkCnt = blockSize; 74 | 75 | 76 | while (blkCnt > 0U) 77 | { 78 | /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) */ 79 | sum += *pSrc++; 80 | 81 | /* Decrement the loop counter */ 82 | blkCnt--; 83 | } 84 | 85 | /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) / blockSize */ 86 | /* Store the result to the destination */ 87 | *pResult = sum / (float32_t) blockSize; 88 | } 89 | 90 | /** 91 | * @} end of mean group 92 | */ 93 | -------------------------------------------------------------------------------- /components/dsp_lib/StatisticsFunctions/xtensa_min_f32.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_min_f32.c 4 | * Description: Minimum value of a floating-point vector 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "xtensa_math.h" 30 | 31 | /** 32 | * @ingroup groupStats 33 | */ 34 | 35 | /** 36 | * @defgroup Min Minimum 37 | * 38 | * Computes the minimum value of an array of data. 39 | * The function returns both the minimum value and its position within the array. 40 | * There are separate functions for floating-point, Q31, Q15, and Q7 data types. 41 | */ 42 | 43 | /** 44 | * @addtogroup Min 45 | * @{ 46 | */ 47 | 48 | 49 | /** 50 | * @brief Minimum value of a floating-point vector. 51 | * @param[in] *pSrc points to the input vector 52 | * @param[in] blockSize length of the input vector 53 | * @param[out] *pResult minimum value returned here 54 | * @param[out] *pIndex index of minimum value returned here 55 | * @return none. 56 | */ 57 | 58 | void xtensa_min_f32( 59 | float32_t * pSrc, 60 | uint32_t blockSize, 61 | float32_t * pResult, 62 | uint32_t * pIndex) 63 | { 64 | 65 | 66 | float32_t minVal1, out; /* Temporary variables to store the output value. */ 67 | uint32_t blkCnt, outIndex; /* loop counter */ 68 | 69 | /* Initialise the index value to zero. */ 70 | outIndex = 0U; 71 | /* Load first input value that act as reference value for comparision */ 72 | out = *pSrc++; 73 | 74 | blkCnt = (blockSize - 1U); 75 | 76 | 77 | while (blkCnt > 0U) 78 | { 79 | /* Initialize minVal to the next consecutive values one by one */ 80 | minVal1 = *pSrc++; 81 | 82 | /* compare for the minimum value */ 83 | if (out > minVal1) 84 | { 85 | /* Update the minimum value and it's index */ 86 | out = minVal1; 87 | outIndex = blockSize - blkCnt; 88 | } 89 | 90 | /* Decrement the loop counter */ 91 | blkCnt--; 92 | } 93 | 94 | /* Store the minimum value and it's index into destination pointers */ 95 | *pResult = out; 96 | *pIndex = outIndex; 97 | } 98 | 99 | /** 100 | * @} end of Min group 101 | */ 102 | -------------------------------------------------------------------------------- /components/dsp_lib/StatisticsFunctions/xtensa_power_f32.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_power_f32.c 4 | * Description: Sum of the squares of the elements of a floating-point vector 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "xtensa_math.h" 30 | 31 | /** 32 | * @ingroup groupStats 33 | */ 34 | 35 | /** 36 | * @defgroup power Power 37 | * 38 | * Calculates the sum of the squares of the elements in the input vector. 39 | * The underlying algorithm is used: 40 | * 41 | *
42 |  * 	Result = pSrc[0] * pSrc[0] + pSrc[1] * pSrc[1] + pSrc[2] * pSrc[2] + ... + pSrc[blockSize-1] * pSrc[blockSize-1];
43 |  * 
44 | * 45 | * There are separate functions for floating point, Q31, Q15, and Q7 data types. 46 | */ 47 | 48 | /** 49 | * @addtogroup power 50 | * @{ 51 | */ 52 | 53 | 54 | /** 55 | * @brief Sum of the squares of the elements of a floating-point vector. 56 | * @param[in] *pSrc points to the input vector 57 | * @param[in] blockSize length of the input vector 58 | * @param[out] *pResult sum of the squares value returned here 59 | * @return none. 60 | * 61 | */ 62 | 63 | 64 | void xtensa_power_f32( 65 | float32_t * pSrc, 66 | uint32_t blockSize, 67 | float32_t * pResult) 68 | { 69 | float32_t sum = 0.0f; /* accumulator */ 70 | float32_t in; /* Temporary variable to store input value */ 71 | uint32_t blkCnt; /* loop counter */ 72 | 73 | 74 | 75 | /* Loop over blockSize number of values */ 76 | blkCnt = blockSize; 77 | 78 | 79 | 80 | while (blkCnt > 0U) 81 | { 82 | /* C = A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + ... + A[blockSize-1] * A[blockSize-1] */ 83 | /* compute power and then store the result in a temporary variable, sum. */ 84 | in = *pSrc++; 85 | sum += in * in; 86 | 87 | /* Decrement the loop counter */ 88 | blkCnt--; 89 | } 90 | 91 | /* Store the result to the destination */ 92 | *pResult = sum; 93 | } 94 | 95 | /** 96 | * @} end of power group 97 | */ 98 | -------------------------------------------------------------------------------- /components/dsp_lib/StatisticsFunctions/xtensa_rms_f32.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_rms_f32.c 4 | * Description: Root mean square value of an array of F32 type 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "xtensa_math.h" 30 | 31 | /** 32 | * @ingroup groupStats 33 | */ 34 | 35 | /** 36 | * @defgroup RMS Root mean square (RMS) 37 | * 38 | * 39 | * Calculates the Root Mean Sqaure of the elements in the input vector. 40 | * The underlying algorithm is used: 41 | * 42 | *
43 |  * 	Result = sqrt(((pSrc[0] * pSrc[0] + pSrc[1] * pSrc[1] + ... + pSrc[blockSize-1] * pSrc[blockSize-1]) / blockSize));
44 |  * 
45 | * 46 | * There are separate functions for floating point, Q31, and Q15 data types. 47 | */ 48 | 49 | /** 50 | * @addtogroup RMS 51 | * @{ 52 | */ 53 | 54 | 55 | /** 56 | * @brief Root Mean Square of the elements of a floating-point vector. 57 | * @param[in] *pSrc points to the input vector 58 | * @param[in] blockSize length of the input vector 59 | * @param[out] *pResult rms value returned here 60 | * @return none. 61 | * 62 | */ 63 | 64 | void xtensa_rms_f32( 65 | float32_t * pSrc, 66 | uint32_t blockSize, 67 | float32_t * pResult) 68 | { 69 | float32_t sum = 0.0f; /* Accumulator */ 70 | float32_t in; /* Tempoprary variable to store input value */ 71 | uint32_t blkCnt; /* loop counter */ 72 | 73 | 74 | 75 | /* Loop over blockSize number of values */ 76 | blkCnt = blockSize; 77 | 78 | 79 | while (blkCnt > 0U) 80 | { 81 | /* C = A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + ... + A[blockSize-1] * A[blockSize-1] */ 82 | /* Compute sum of the squares and then store the results in a temporary variable, sum */ 83 | in = *pSrc++; 84 | sum += in * in; 85 | 86 | /* Decrement the loop counter */ 87 | blkCnt--; 88 | } 89 | 90 | /* Compute Rms and store the result in the destination */ 91 | xtensa_sqrt_f32(sum / (float32_t) blockSize, pResult); 92 | } 93 | 94 | /** 95 | * @} end of RMS group 96 | */ 97 | -------------------------------------------------------------------------------- /components/dsp_lib/StatisticsFunctions/xtensa_std_f32.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_std_f32.c 4 | * Description: Standard deviation of the elements of a floating-point vector 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "xtensa_math.h" 30 | 31 | /** 32 | * @ingroup groupStats 33 | */ 34 | 35 | /** 36 | * @defgroup STD Standard deviation 37 | * 38 | * Calculates the standard deviation of the elements in the input vector. 39 | * The underlying algorithm is used: 40 | * 41 | *
 42 |  *   Result = sqrt((sumOfSquares - sum2 / blockSize) / (blockSize - 1))
 43 |  *
 44 |  *     where, sumOfSquares = pSrc[0] * pSrc[0] + pSrc[1] * pSrc[1] + ... + pSrc[blockSize-1] * pSrc[blockSize-1]
 45 |  *
 46 |  *                     sum = pSrc[0] + pSrc[1] + pSrc[2] + ... + pSrc[blockSize-1]
 47 |  * 
48 | * 49 | * There are separate functions for floating point, Q31, and Q15 data types. 50 | */ 51 | 52 | /** 53 | * @addtogroup STD 54 | * @{ 55 | */ 56 | 57 | 58 | /** 59 | * @brief Standard deviation of the elements of a floating-point vector. 60 | * @param[in] *pSrc points to the input vector 61 | * @param[in] blockSize length of the input vector 62 | * @param[out] *pResult standard deviation value returned here 63 | * @return none. 64 | */ 65 | 66 | void xtensa_std_f32( 67 | float32_t * pSrc, 68 | uint32_t blockSize, 69 | float32_t * pResult) 70 | { 71 | float32_t sum = 0.0f; /* Temporary result storage */ 72 | float32_t sumOfSquares = 0.0f; /* Sum of squares */ 73 | float32_t in; /* input value */ 74 | uint32_t blkCnt; /* loop counter */ 75 | 76 | float32_t squareOfSum; /* Square of Sum */ 77 | float32_t var; /* Temporary varaince storage */ 78 | 79 | 80 | if (blockSize == 1U) 81 | { 82 | *pResult = 0; 83 | return; 84 | } 85 | 86 | 87 | 88 | /* Loop over blockSize number of values */ 89 | blkCnt = blockSize; 90 | 91 | while (blkCnt > 0U) 92 | { 93 | /* C = (A[0] * A[0] + A[1] * A[1] + ... + A[blockSize-1] * A[blockSize-1]) */ 94 | /* Compute Sum of squares of the input samples 95 | * and then store the result in a temporary variable, sumOfSquares. */ 96 | in = *pSrc++; 97 | sumOfSquares += in * in; 98 | 99 | /* C = (A[0] + A[1] + ... + A[blockSize-1]) */ 100 | /* Compute Sum of the input samples 101 | * and then store the result in a temporary variable, sum. */ 102 | sum += in; 103 | 104 | /* Decrement the loop counter */ 105 | blkCnt--; 106 | } 107 | 108 | /* Compute the square of sum */ 109 | squareOfSum = ((sum * sum) / (float32_t) blockSize); 110 | 111 | /* Compute the variance */ 112 | var = ((sumOfSquares - squareOfSum) / (float32_t) (blockSize - 1.0f)); 113 | 114 | /* Compute standard deviation and then store the result to the destination */ 115 | xtensa_sqrt_f32(var, pResult); 116 | 117 | } 118 | 119 | /** 120 | * @} end of STD group 121 | */ 122 | -------------------------------------------------------------------------------- /components/dsp_lib/StatisticsFunctions/xtensa_var_f32.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_var_f32.c 4 | * Description: Variance of the elements of a floating-point vector 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "xtensa_math.h" 30 | 31 | /** 32 | * @ingroup groupStats 33 | */ 34 | 35 | /** 36 | * @defgroup variance Variance 37 | * 38 | * Calculates the variance of the elements in the input vector. 39 | * The underlying algorithm used is the direct method sometimes referred to as the two-pass method: 40 | * 41 | *
 42 |  *   Result = sum(element - meanOfElements)^2) / numElement - 1
 43 |  *
 44 |  *     where, meanOfElements = ( pSrc[0] * pSrc[0] + pSrc[1] * pSrc[1] + ... + pSrc[blockSize-1] ) / blockSize
 45 |  *
 46 |  * 
47 | * 48 | * There are separate functions for floating point, Q31, and Q15 data types. 49 | */ 50 | 51 | /** 52 | * @addtogroup variance 53 | * @{ 54 | */ 55 | 56 | 57 | /** 58 | * @brief Variance of the elements of a floating-point vector. 59 | * @param[in] *pSrc points to the input vector 60 | * @param[in] blockSize length of the input vector 61 | * @param[out] *pResult variance value returned here 62 | * @return none. 63 | */ 64 | 65 | void xtensa_var_f32( 66 | float32_t * pSrc, 67 | uint32_t blockSize, 68 | float32_t * pResult) 69 | { 70 | float32_t fMean, fValue; 71 | uint32_t blkCnt; /* loop counter */ 72 | float32_t * pInput = pSrc; 73 | float32_t sum = 0.0f; 74 | float32_t fSum = 0.0f; 75 | #if defined(ARM_MATH_DSP) 76 | float32_t in1, in2, in3, in4; 77 | #endif 78 | 79 | if (blockSize <= 1U) 80 | { 81 | *pResult = 0; 82 | return; 83 | } 84 | 85 | 86 | 87 | /* Loop over blockSize number of values */ 88 | blkCnt = blockSize; 89 | 90 | 91 | 92 | while (blkCnt > 0U) 93 | { 94 | /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) */ 95 | sum += *pInput++; 96 | 97 | /* Decrement the loop counter */ 98 | blkCnt--; 99 | } 100 | 101 | /* C = (A[0] + A[1] + A[2] + ... + A[blockSize-1]) / blockSize */ 102 | fMean = sum / (float32_t) blockSize; 103 | 104 | pInput = pSrc; 105 | 106 | 107 | 108 | /* Loop over blockSize number of values */ 109 | blkCnt = blockSize; 110 | 111 | 112 | while (blkCnt > 0U) 113 | { 114 | fValue = *pInput++ - fMean; 115 | fSum += fValue * fValue; 116 | 117 | /* Decrement the loop counter */ 118 | blkCnt--; 119 | } 120 | 121 | /* Variance */ 122 | *pResult = fSum / (float32_t)(blockSize - 1.0f); 123 | } 124 | 125 | /** 126 | * @} end of variance group 127 | */ 128 | -------------------------------------------------------------------------------- /components/dsp_lib/TransformFunctions/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whyengineer/esp32-lin/6fa39f4cd5f7782b3a2a052767f0fb06be2378ff/components/dsp_lib/TransformFunctions/.DS_Store -------------------------------------------------------------------------------- /components/dsp_lib/TransformFunctions/xtensa_bitreversal.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_bitreversal.c 4 | * Description: Bitreversal functions 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "xtensa_math.h" 30 | #include "xtensa_common_tables.h" 31 | 32 | /* 33 | * @brief In-place bit reversal function. 34 | * @param[in, out] *pSrc points to the in-place buffer of floating-point data type. 35 | * @param[in] fftSize length of the FFT. 36 | * @param[in] bitRevFactor bit reversal modifier that supports different size FFTs with the same bit reversal table. 37 | * @param[in] *pBitRevTab points to the bit reversal table. 38 | * @return none. 39 | */ 40 | 41 | void xtensa_bitreversal_f32( 42 | float32_t * pSrc, 43 | uint16_t fftSize, 44 | uint16_t bitRevFactor, 45 | uint16_t * pBitRevTab) 46 | { 47 | uint16_t fftLenBy2, fftLenBy2p1; 48 | uint16_t i, j; 49 | float32_t in; 50 | 51 | /* Initializations */ 52 | j = 0U; 53 | fftLenBy2 = fftSize >> 1U; 54 | fftLenBy2p1 = (fftSize >> 1U) + 1U; 55 | 56 | /* Bit Reversal Implementation */ 57 | for (i = 0U; i <= (fftLenBy2 - 2U); i += 2U) 58 | { 59 | if (i < j) 60 | { 61 | /* pSrc[i] <-> pSrc[j]; */ 62 | in = pSrc[2U * i]; 63 | pSrc[2U * i] = pSrc[2U * j]; 64 | pSrc[2U * j] = in; 65 | 66 | /* pSrc[i+1U] <-> pSrc[j+1U] */ 67 | in = pSrc[(2U * i) + 1U]; 68 | pSrc[(2U * i) + 1U] = pSrc[(2U * j) + 1U]; 69 | pSrc[(2U * j) + 1U] = in; 70 | 71 | /* pSrc[i+fftLenBy2p1] <-> pSrc[j+fftLenBy2p1] */ 72 | in = pSrc[2U * (i + fftLenBy2p1)]; 73 | pSrc[2U * (i + fftLenBy2p1)] = pSrc[2U * (j + fftLenBy2p1)]; 74 | pSrc[2U * (j + fftLenBy2p1)] = in; 75 | 76 | /* pSrc[i+fftLenBy2p1+1U] <-> pSrc[j+fftLenBy2p1+1U] */ 77 | in = pSrc[(2U * (i + fftLenBy2p1)) + 1U]; 78 | pSrc[(2U * (i + fftLenBy2p1)) + 1U] = 79 | pSrc[(2U * (j + fftLenBy2p1)) + 1U]; 80 | pSrc[(2U * (j + fftLenBy2p1)) + 1U] = in; 81 | 82 | } 83 | 84 | /* pSrc[i+1U] <-> pSrc[j+1U] */ 85 | in = pSrc[2U * (i + 1U)]; 86 | pSrc[2U * (i + 1U)] = pSrc[2U * (j + fftLenBy2)]; 87 | pSrc[2U * (j + fftLenBy2)] = in; 88 | 89 | /* pSrc[i+2U] <-> pSrc[j+2U] */ 90 | in = pSrc[(2U * (i + 1U)) + 1U]; 91 | pSrc[(2U * (i + 1U)) + 1U] = pSrc[(2U * (j + fftLenBy2)) + 1U]; 92 | pSrc[(2U * (j + fftLenBy2)) + 1U] = in; 93 | 94 | /* Reading the index for the bit reversal */ 95 | j = *pBitRevTab; 96 | 97 | /* Updating the bit reversal index depending on the fft length */ 98 | pBitRevTab += bitRevFactor; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /components/dsp_lib/TransformFunctions/xtensa_bitreversal2.c: -------------------------------------------------------------------------------- 1 | #include "xtensa_math.h" 2 | /* 3 | arm_bitreversal_32 PROC 4 | ADDS r3,r1,#1 5 | PUSH {r4-r6} 6 | ADDS r1,r2,#0 7 | LSRS r3,r3,#1 8 | arm_bitreversal_32_0 LABEL 9 | LDRH r2,[r1,#2] 10 | LDRH r6,[r1,#0] 11 | ADD r2,r0,r2 12 | ADD r6,r0,r6 13 | LDR r5,[r2,#0] 14 | LDR r4,[r6,#0] 15 | STR r5,[r6,#0] 16 | STR r4,[r2,#0] 17 | LDR r5,[r2,#4] 18 | LDR r4,[r6,#4] 19 | STR r5,[r6,#4] 20 | STR r4,[r2,#4] 21 | ADDS r1,r1,#4 22 | SUBS r3,r3,#1 23 | BNE arm_bitreversal_32_0 24 | POP {r4-r6} 25 | BX lr 26 | ENDP 27 | 28 | */ 29 | void xtensa_bitreversal_32(uint32_t *pSrc, const uint16_t bitRevLen, const uint16_t *pBitRevTab) 30 | { 31 | uint32_t r3 = (bitRevLen + 1) / 2; 32 | uint32_t *r2, *r6; 33 | uint32_t r4, r5; 34 | while(r3--) 35 | { 36 | r2 = (uint32_t *)((uint32_t)pSrc + pBitRevTab[0]); 37 | r6 = (uint32_t *)((uint32_t)pSrc + pBitRevTab[1]); 38 | 39 | r5 = r2[0]; 40 | r4 = r6[0]; 41 | r6[0] = r5; 42 | r2[0] = r4; 43 | 44 | r5 = r2[1]; 45 | r4 = r6[1]; 46 | r6[1] = r5; 47 | r2[1] = r4; 48 | 49 | pBitRevTab += 2; 50 | } 51 | } -------------------------------------------------------------------------------- /components/dsp_lib/TransformFunctions/xtensa_cfft_radix4_init_f32.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_cfft_radix4_init_f32.c 4 | * Description: Radix-4 Decimation in Frequency Floating-point CFFT & CIFFT Initialization function 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 XTENSA Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "xtensa_math.h" 30 | #include "xtensa_common_tables.h" 31 | 32 | /** 33 | * @ingroup groupTransforms 34 | */ 35 | 36 | /** 37 | * @addtogroup ComplexFFT 38 | * @{ 39 | */ 40 | 41 | /** 42 | * @brief Initialization function for the floating-point CFFT/CIFFT. 43 | * @deprecated Do not use this function. It has been superceded by \ref xtensa_cfft_f32 and will be removed 44 | * in the future. 45 | * @param[in,out] *S points to an instance of the floating-point CFFT/CIFFT structure. 46 | * @param[in] fftLen length of the FFT. 47 | * @param[in] ifftFlag flag that selects forward (ifftFlag=0) or inverse (ifftFlag=1) transform. 48 | * @param[in] bitReverseFlag flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. 49 | * @return The function returns XTENSA_MATH_SUCCESS if initialization is successful or XTENSA_MATH_ARGUMENT_ERROR if fftLen is not a supported value. 50 | * 51 | * \par Description: 52 | * \par 53 | * The parameter ifftFlag controls whether a forward or inverse transform is computed. 54 | * Set(=1) ifftFlag for calculation of CIFFT otherwise CFFT is calculated 55 | * \par 56 | * The parameter bitReverseFlag controls whether output is in normal order or bit reversed order. 57 | * Set(=1) bitReverseFlag for output to be in normal order otherwise output is in bit reversed order. 58 | * \par 59 | * The parameter fftLen Specifies length of CFFT/CIFFT process. Supported FFT Lengths are 16, 64, 256, 1024. 60 | * \par 61 | * This Function also initializes Twiddle factor table pointer and Bit reversal table pointer. 62 | */ 63 | 64 | xtensa_status xtensa_cfft_radix4_init_f32( 65 | xtensa_cfft_radix4_instance_f32 * S, 66 | uint16_t fftLen, 67 | uint8_t ifftFlag, 68 | uint8_t bitReverseFlag) 69 | { 70 | /* Initialise the default xtensa status */ 71 | xtensa_status status = XTENSA_MATH_SUCCESS; 72 | 73 | /* Initialise the FFT length */ 74 | S->fftLen = fftLen; 75 | 76 | /* Initialise the Twiddle coefficient pointer */ 77 | S->pTwiddle = (float32_t *) twiddleCoef; 78 | 79 | /* Initialise the Flag for selection of CFFT or CIFFT */ 80 | S->ifftFlag = ifftFlag; 81 | 82 | /* Initialise the Flag for calculation Bit reversal or not */ 83 | S->bitReverseFlag = bitReverseFlag; 84 | 85 | /* Initializations of structure parameters depending on the FFT length */ 86 | switch (S->fftLen) 87 | { 88 | 89 | case 4096U: 90 | /* Initializations of structure parameters for 4096 point FFT */ 91 | 92 | /* Initialise the twiddle coef modifier value */ 93 | S->twidCoefModifier = 1U; 94 | /* Initialise the bit reversal table modifier */ 95 | S->bitRevFactor = 1U; 96 | /* Initialise the bit reversal table pointer */ 97 | S->pBitRevTable = (uint16_t *) xtensaBitRevTable; 98 | /* Initialise the 1/fftLen Value */ 99 | S->onebyfftLen = 0.000244140625; 100 | break; 101 | 102 | case 1024U: 103 | /* Initializations of structure parameters for 1024 point FFT */ 104 | 105 | /* Initialise the twiddle coef modifier value */ 106 | S->twidCoefModifier = 4U; 107 | /* Initialise the bit reversal table modifier */ 108 | S->bitRevFactor = 4U; 109 | /* Initialise the bit reversal table pointer */ 110 | S->pBitRevTable = (uint16_t *) & xtensaBitRevTable[3]; 111 | /* Initialise the 1/fftLen Value */ 112 | S->onebyfftLen = 0.0009765625f; 113 | break; 114 | 115 | 116 | case 256U: 117 | /* Initializations of structure parameters for 256 point FFT */ 118 | S->twidCoefModifier = 16U; 119 | S->bitRevFactor = 16U; 120 | S->pBitRevTable = (uint16_t *) & xtensaBitRevTable[15]; 121 | S->onebyfftLen = 0.00390625f; 122 | break; 123 | 124 | case 64U: 125 | /* Initializations of structure parameters for 64 point FFT */ 126 | S->twidCoefModifier = 64U; 127 | S->bitRevFactor = 64U; 128 | S->pBitRevTable = (uint16_t *) & xtensaBitRevTable[63]; 129 | S->onebyfftLen = 0.015625f; 130 | break; 131 | 132 | case 16U: 133 | /* Initializations of structure parameters for 16 point FFT */ 134 | S->twidCoefModifier = 256U; 135 | S->bitRevFactor = 256U; 136 | S->pBitRevTable = (uint16_t *) & xtensaBitRevTable[255]; 137 | S->onebyfftLen = 0.0625f; 138 | break; 139 | 140 | 141 | default: 142 | /* Reporting argument error if fftSize is not valid value */ 143 | status = XTENSA_MATH_ARGUMENT_ERROR; 144 | break; 145 | } 146 | 147 | return (status); 148 | } 149 | 150 | /** 151 | * @} end of ComplexFFT group 152 | */ 153 | -------------------------------------------------------------------------------- /components/dsp_lib/TransformFunctions/xtensa_rfft_fast_init_f32.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: xtensa_cfft_init_f32.c 4 | * Description: Split Radix Decimation in Frequency CFFT Floating point processing function 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 XTENSA Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "xtensa_math.h" 30 | #include "xtensa_common_tables.h" 31 | 32 | /** 33 | * @ingroup groupTransforms 34 | */ 35 | 36 | /** 37 | * @addtogroup RealFFT 38 | * @{ 39 | */ 40 | 41 | /** 42 | * @brief Initialization function for the floating-point real FFT. 43 | * @param[in,out] *S points to an xtensa_rfft_fast_instance_f32 structure. 44 | * @param[in] fftLen length of the Real Sequence. 45 | * @return The function returns XTENSA_MATH_SUCCESS if initialization is successful or XTENSA_MATH_ARGUMENT_ERROR if fftLen is not a supported value. 46 | * 47 | * \par Description: 48 | * \par 49 | * The parameter fftLen Specifies length of RFFT/CIFFT process. Supported FFT Lengths are 32, 64, 128, 256, 512, 1024, 2048, 4096. 50 | * \par 51 | * This Function also initializes Twiddle factor table pointer and Bit reversal table pointer. 52 | */ 53 | xtensa_status xtensa_rfft_fast_init_f32( 54 | xtensa_rfft_fast_instance_f32 * S, 55 | uint16_t fftLen) 56 | { 57 | xtensa_cfft_instance_f32 * Sint; 58 | /* Initialise the default xtensa status */ 59 | xtensa_status status = XTENSA_MATH_SUCCESS; 60 | /* Initialise the FFT length */ 61 | Sint = &(S->Sint); 62 | Sint->fftLen = fftLen/2; 63 | S->fftLenRFFT = fftLen; 64 | 65 | /* Initializations of structure parameters depending on the FFT length */ 66 | switch (Sint->fftLen) 67 | { 68 | case 2048U: 69 | /* Initializations of structure parameters for 2048 point FFT */ 70 | /* Initialise the bit reversal table length */ 71 | Sint->bitRevLength = XTENSABITREVINDEXTABLE_2048_TABLE_LENGTH; 72 | /* Initialise the bit reversal table pointer */ 73 | Sint->pBitRevTable = (uint16_t *)xtensaBitRevIndexTable2048; 74 | /* Initialise the Twiddle coefficient pointers */ 75 | Sint->pTwiddle = (float32_t *) twiddleCoef_2048; 76 | S->pTwiddleRFFT = (float32_t *) twiddleCoef_rfft_4096; 77 | break; 78 | case 1024U: 79 | Sint->bitRevLength = XTENSABITREVINDEXTABLE_1024_TABLE_LENGTH; 80 | Sint->pBitRevTable = (uint16_t *)xtensaBitRevIndexTable1024; 81 | Sint->pTwiddle = (float32_t *) twiddleCoef_1024; 82 | S->pTwiddleRFFT = (float32_t *) twiddleCoef_rfft_2048; 83 | break; 84 | case 512U: 85 | Sint->bitRevLength = XTENSABITREVINDEXTABLE_512_TABLE_LENGTH; 86 | Sint->pBitRevTable = (uint16_t *)xtensaBitRevIndexTable512; 87 | Sint->pTwiddle = (float32_t *) twiddleCoef_512; 88 | S->pTwiddleRFFT = (float32_t *) twiddleCoef_rfft_1024; 89 | break; 90 | case 256U: 91 | Sint->bitRevLength = XTENSABITREVINDEXTABLE_256_TABLE_LENGTH; 92 | Sint->pBitRevTable = (uint16_t *)xtensaBitRevIndexTable256; 93 | Sint->pTwiddle = (float32_t *) twiddleCoef_256; 94 | S->pTwiddleRFFT = (float32_t *) twiddleCoef_rfft_512; 95 | break; 96 | case 128U: 97 | Sint->bitRevLength = XTENSABITREVINDEXTABLE_128_TABLE_LENGTH; 98 | Sint->pBitRevTable = (uint16_t *)xtensaBitRevIndexTable128; 99 | Sint->pTwiddle = (float32_t *) twiddleCoef_128; 100 | S->pTwiddleRFFT = (float32_t *) twiddleCoef_rfft_256; 101 | break; 102 | case 64U: 103 | Sint->bitRevLength = XTENSABITREVINDEXTABLE_64_TABLE_LENGTH; 104 | Sint->pBitRevTable = (uint16_t *)xtensaBitRevIndexTable64; 105 | Sint->pTwiddle = (float32_t *) twiddleCoef_64; 106 | S->pTwiddleRFFT = (float32_t *) twiddleCoef_rfft_128; 107 | break; 108 | case 32U: 109 | Sint->bitRevLength = XTENSABITREVINDEXTABLE_32_TABLE_LENGTH; 110 | Sint->pBitRevTable = (uint16_t *)xtensaBitRevIndexTable32; 111 | Sint->pTwiddle = (float32_t *) twiddleCoef_32; 112 | S->pTwiddleRFFT = (float32_t *) twiddleCoef_rfft_64; 113 | break; 114 | case 16U: 115 | Sint->bitRevLength = XTENSABITREVINDEXTABLE_16_TABLE_LENGTH; 116 | Sint->pBitRevTable = (uint16_t *)xtensaBitRevIndexTable16; 117 | Sint->pTwiddle = (float32_t *) twiddleCoef_16; 118 | S->pTwiddleRFFT = (float32_t *) twiddleCoef_rfft_32; 119 | break; 120 | default: 121 | /* Reporting argument error if fftSize is not valid value */ 122 | status = XTENSA_MATH_ARGUMENT_ERROR; 123 | break; 124 | } 125 | 126 | return (status); 127 | } 128 | 129 | /** 130 | * @} end of RealFFT group 131 | */ 132 | -------------------------------------------------------------------------------- /components/dsp_lib/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_SRCDIRS:=BasicMathFunctions CommonTables ComplexMathFunctions ControllerFunctions \ 2 | FastMathFunctions FilteringFunctions MartixFunctions StatisticsFunctions SupportFunctions \ 3 | TransformFunctions 4 | CFLAGS += -D ARM_MATH_CM4 5 | -------------------------------------------------------------------------------- /components/helix/component.mk: -------------------------------------------------------------------------------- 1 | 2 | ifdef CONFIG_AUDIO_HELIX 3 | CFLAGS += -DARM -DCONFIG_AUDIO_HELIX 4 | COMPONENT_ADD_INCLUDEDIRS := include 5 | COMPONENT_SRCDIRS:=src 6 | ./src/subband.o ./src/scalfact.o ./src/dqchan.o ./src/huffman.o: CFLAGS += -Wno-unused-but-set-variable 7 | endif 8 | -------------------------------------------------------------------------------- /components/helix/include/mp3common.h: -------------------------------------------------------------------------------- 1 | /* ***** BEGIN LICENSE BLOCK ***** 2 | * Version: RCSL 1.0/RPSL 1.0 3 | * 4 | * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 5 | * 6 | * The contents of this file, and the files included with this file, are 7 | * subject to the current version of the RealNetworks Public Source License 8 | * Version 1.0 (the "RPSL") available at 9 | * http://www.helixcommunity.org/content/rpsl unless you have licensed 10 | * the file under the RealNetworks Community Source License Version 1.0 11 | * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 12 | * in which case the RCSL will apply. You may also obtain the license terms 13 | * directly from RealNetworks. You may not use this file except in 14 | * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 15 | * applicable to this file, the RCSL. Please see the applicable RPSL or 16 | * RCSL for the rights, obligations and limitations governing use of the 17 | * contents of the file. 18 | * 19 | * This file is part of the Helix DNA Technology. RealNetworks is the 20 | * developer of the Original Code and owns the copyrights in the portions 21 | * it created. 22 | * 23 | * This file, and the files included with this file, is distributed and made 24 | * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 25 | * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 26 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 27 | * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 28 | * 29 | * Technology Compatibility Kit Test Suite(s) Location: 30 | * http://www.helixcommunity.org/content/tck 31 | * 32 | * Contributor(s): 33 | * 34 | * ***** END LICENSE BLOCK ***** */ 35 | 36 | /************************************************************************************** 37 | * Fixed-point MP3 decoder 38 | * Jon Recker (jrecker@real.com), Ken Cooke (kenc@real.com) 39 | * June 2003 40 | * 41 | * mp3common.h - implementation-independent API's, datatypes, and definitions 42 | **************************************************************************************/ 43 | 44 | #ifndef _MP3COMMON_H 45 | #define _MP3COMMON_H 46 | 47 | #include "mp3dec.h" 48 | #include "statname.h" /* do name-mangling for static linking */ 49 | 50 | #define MAX_SCFBD 4 /* max scalefactor bands per channel */ 51 | #define NGRANS_MPEG1 2 52 | #define NGRANS_MPEG2 1 53 | 54 | /* 11-bit syncword if MPEG 2.5 extensions are enabled */ 55 | #define SYNCWORDH 0xff 56 | #define SYNCWORDL 0xe0 57 | 58 | /* 12-bit syncword if MPEG 1,2 only are supported 59 | * #define SYNCWORDH 0xff 60 | * #define SYNCWORDL 0xf0 61 | */ 62 | 63 | typedef struct _MP3DecInfo { 64 | /* pointers to platform-specific data structures */ 65 | void *FrameHeaderPS; 66 | void *SideInfoPS; 67 | void *ScaleFactorInfoPS; 68 | void *HuffmanInfoPS; 69 | void *DequantInfoPS; 70 | void *IMDCTInfoPS; 71 | void *SubbandInfoPS; 72 | 73 | /* buffer which must be large enough to hold largest possible main_data section */ 74 | unsigned char mainBuf[MAINBUF_SIZE]; 75 | 76 | /* special info for "free" bitrate files */ 77 | int freeBitrateFlag; 78 | int freeBitrateSlots; 79 | 80 | /* user-accessible info */ 81 | int bitrate; 82 | int nChans; 83 | int samprate; 84 | int nGrans; /* granules per frame */ 85 | int nGranSamps; /* samples per granule */ 86 | int nSlots; 87 | int layer; 88 | MPEGVersion version; 89 | 90 | int mainDataBegin; 91 | int mainDataBytes; 92 | 93 | int part23Length[MAX_NGRAN][MAX_NCHAN]; 94 | 95 | } MP3DecInfo; 96 | 97 | typedef struct _SFBandTable { 98 | short l[23]; 99 | short s[14]; 100 | } SFBandTable; 101 | 102 | /* decoder functions which must be implemented for each platform */ 103 | MP3DecInfo *AllocateBuffers(void); 104 | void FreeBuffers(MP3DecInfo *mp3DecInfo); 105 | int CheckPadBit(MP3DecInfo *mp3DecInfo); 106 | int UnpackFrameHeader(MP3DecInfo *mp3DecInfo, unsigned char *buf); 107 | int UnpackSideInfo(MP3DecInfo *mp3DecInfo, unsigned char *buf); 108 | int DecodeHuffman(MP3DecInfo *mp3DecInfo, unsigned char *buf, int *bitOffset, int huffBlockBits, int gr, int ch); 109 | int Dequantize(MP3DecInfo *mp3DecInfo, int gr); 110 | int IMDCT(MP3DecInfo *mp3DecInfo, int gr, int ch); 111 | int UnpackScaleFactors(MP3DecInfo *mp3DecInfo, unsigned char *buf, int *bitOffset, int bitsAvail, int gr, int ch); 112 | int Subband(MP3DecInfo *mp3DecInfo, short *pcmBuf); 113 | 114 | /* mp3tabs.c - global ROM tables */ 115 | extern const int samplerateTab[3][3]; 116 | extern const short bitrateTab[3][3][15]; 117 | extern const short samplesPerFrameTab[3][3]; 118 | extern const short bitsPerSlotTab[3]; 119 | extern const short sideBytesTab[3][2]; 120 | extern const short slotTab[3][3][15]; 121 | extern const SFBandTable sfBandTable[3][3]; 122 | 123 | #endif /* _MP3COMMON_H */ 124 | -------------------------------------------------------------------------------- /components/helix/include/mp3dec.h: -------------------------------------------------------------------------------- 1 | /* ***** BEGIN LICENSE BLOCK ***** 2 | * Version: RCSL 1.0/RPSL 1.0 3 | * 4 | * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 5 | * 6 | * The contents of this file, and the files included with this file, are 7 | * subject to the current version of the RealNetworks Public Source License 8 | * Version 1.0 (the "RPSL") available at 9 | * http://www.helixcommunity.org/content/rpsl unless you have licensed 10 | * the file under the RealNetworks Community Source License Version 1.0 11 | * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 12 | * in which case the RCSL will apply. You may also obtain the license terms 13 | * directly from RealNetworks. You may not use this file except in 14 | * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 15 | * applicable to this file, the RCSL. Please see the applicable RPSL or 16 | * RCSL for the rights, obligations and limitations governing use of the 17 | * contents of the file. 18 | * 19 | * This file is part of the Helix DNA Technology. RealNetworks is the 20 | * developer of the Original Code and owns the copyrights in the portions 21 | * it created. 22 | * 23 | * This file, and the files included with this file, is distributed and made 24 | * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 25 | * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 26 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 27 | * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 28 | * 29 | * Technology Compatibility Kit Test Suite(s) Location: 30 | * http://www.helixcommunity.org/content/tck 31 | * 32 | * Contributor(s): 33 | * 34 | * ***** END LICENSE BLOCK ***** */ 35 | 36 | /************************************************************************************** 37 | * Fixed-point MP3 decoder 38 | * Jon Recker (jrecker@real.com), Ken Cooke (kenc@real.com) 39 | * June 2003 40 | * 41 | * mp3dec.h - public C API for MP3 decoder 42 | **************************************************************************************/ 43 | 44 | #ifndef _MP3DEC_H 45 | #define _MP3DEC_H 46 | 47 | #ifdef CONFIG_AUDIO_HELIX 48 | 49 | #if defined(_WIN32) && !defined(_WIN32_WCE) 50 | # 51 | #elif defined(_WIN32) && defined(_WIN32_WCE) && defined(ARM) 52 | # 53 | #elif defined(_WIN32) && defined(WINCE_EMULATOR) 54 | # 55 | #elif defined(ARM_ADS) 56 | # 57 | #elif defined(_SYMBIAN) && defined(__WINS__) /* Symbian emulator for Ix86 */ 58 | # 59 | #elif defined(__GNUC__) && defined(ARM) 60 | # 61 | #elif defined(__GNUC__) && defined(MIPS) 62 | # 63 | #elif defined(__GNUC__) && defined(__i386__) 64 | # 65 | #elif defined(_OPENWAVE_SIMULATOR) || defined(_OPENWAVE_ARMULATOR) 66 | # 67 | #elif defined(__GNUC__) //add by yongjian.ma 68 | #else 69 | #error No platform defined. See valid options in mp3dec.h 70 | #endif 71 | 72 | #ifdef __cplusplus 73 | extern "C" { 74 | #endif 75 | 76 | /* determining MAINBUF_SIZE: 77 | * max mainDataBegin = (2^9 - 1) bytes (since 9-bit offset) = 511 78 | * max nSlots (concatenated with mainDataBegin bytes from before) = 1440 - 9 - 4 + 1 = 1428 79 | * 511 + 1428 = 1939, round up to 1940 (4-byte align) 80 | */ 81 | #define MAINBUF_SIZE 1940 82 | 83 | #define MAX_NGRAN 2 /* max granules */ 84 | #define MAX_NCHAN 2 /* max channels */ 85 | #define MAX_NSAMP 576 /* max samples per channel, per granule */ 86 | 87 | /* map to 0,1,2 to make table indexing easier */ 88 | typedef enum { 89 | MPEG1 = 0, 90 | MPEG2 = 1, 91 | MPEG25 = 2 92 | } MPEGVersion; 93 | 94 | typedef void *HMP3Decoder; 95 | 96 | enum { 97 | ERR_MP3_NONE = 0, 98 | ERR_MP3_INDATA_UNDERFLOW = -1, 99 | ERR_MP3_MAINDATA_UNDERFLOW = -2, 100 | ERR_MP3_FREE_BITRATE_SYNC = -3, 101 | ERR_MP3_OUT_OF_MEMORY = -4, 102 | ERR_MP3_NULL_POINTER = -5, 103 | ERR_MP3_INVALID_FRAMEHEADER = -6, 104 | ERR_MP3_INVALID_SIDEINFO = -7, 105 | ERR_MP3_INVALID_SCALEFACT = -8, 106 | ERR_MP3_INVALID_HUFFCODES = -9, 107 | ERR_MP3_INVALID_DEQUANTIZE = -10, 108 | ERR_MP3_INVALID_IMDCT = -11, 109 | ERR_MP3_INVALID_SUBBAND = -12, 110 | 111 | ERR_UNKNOWN = -9999 112 | }; 113 | 114 | typedef struct _MP3FrameInfo { 115 | int bitrate; 116 | int nChans; 117 | int samprate; 118 | int bitsPerSample; 119 | int outputSamps; 120 | int layer; 121 | int version; 122 | } MP3FrameInfo; 123 | 124 | /* public API */ 125 | HMP3Decoder MP3InitDecoder(void); 126 | void MP3FreeDecoder(HMP3Decoder hMP3Decoder); 127 | int MP3Decode(HMP3Decoder hMP3Decoder, unsigned char **inbuf, int *bytesLeft, short *outbuf, int useSize); 128 | 129 | void MP3GetLastFrameInfo(HMP3Decoder hMP3Decoder, MP3FrameInfo *mp3FrameInfo); 130 | int MP3GetNextFrameInfo(HMP3Decoder hMP3Decoder, MP3FrameInfo *mp3FrameInfo, unsigned char *buf); 131 | int MP3FindSyncWord(unsigned char *buf, int nBytes); 132 | 133 | #ifdef __cplusplus 134 | } 135 | #endif 136 | 137 | 138 | #else 139 | #error "helix is not enabled" 140 | #endif 141 | 142 | 143 | 144 | 145 | #endif /* _MP3DEC_H */ 146 | -------------------------------------------------------------------------------- /components/helix/include/mpadecobjfixpt.h: -------------------------------------------------------------------------------- 1 | /* ***** BEGIN LICENSE BLOCK ***** 2 | * Version: RCSL 1.0/RPSL 1.0 3 | * 4 | * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 5 | * 6 | * The contents of this file, and the files included with this file, are 7 | * subject to the current version of the RealNetworks Public Source License 8 | * Version 1.0 (the "RPSL") available at 9 | * http://www.helixcommunity.org/content/rpsl unless you have licensed 10 | * the file under the RealNetworks Community Source License Version 1.0 11 | * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 12 | * in which case the RCSL will apply. You may also obtain the license terms 13 | * directly from RealNetworks. You may not use this file except in 14 | * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 15 | * applicable to this file, the RCSL. Please see the applicable RPSL or 16 | * RCSL for the rights, obligations and limitations governing use of the 17 | * contents of the file. 18 | * 19 | * This file is part of the Helix DNA Technology. RealNetworks is the 20 | * developer of the Original Code and owns the copyrights in the portions 21 | * it created. 22 | * 23 | * This file, and the files included with this file, is distributed and made 24 | * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 25 | * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 26 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 27 | * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 28 | * 29 | * Technology Compatibility Kit Test Suite(s) Location: 30 | * http://www.helixcommunity.org/content/tck 31 | * 32 | * Contributor(s): 33 | * 34 | * ***** END LICENSE BLOCK ***** */ 35 | 36 | #ifndef _MPADECOBJFIXPT_H_ 37 | #define _MPADECOBJFIXPT_H_ 38 | 39 | #include "mp3dec.h" /* public C API for new MP3 decoder */ 40 | 41 | class CMpaDecObj 42 | { 43 | public: 44 | CMpaDecObj(); 45 | ~CMpaDecObj(); 46 | 47 | /////////////////////////////////////////////////////////////////////////// 48 | // Function: Init_n 49 | // Purpose: Initialize the mp3 decoder. 50 | // Parameters: pSync a pointer to a syncword 51 | // ulSize the size of the buffer pSync points to 52 | // bUseSize this tells the decoder to use the input frame 53 | // size on the decode instead of calculating 54 | // the frame size. This is necessary when 55 | // our formatted mp3 data (main_data_begin always 56 | // equal to 0). 57 | // 58 | // Returns: returns 1 on success, 0 on failure 59 | /////////////////////////////////////////////////////////////////////////// 60 | int Init_n(unsigned char *pSync, 61 | unsigned long ulSize, 62 | unsigned char bUseSize=0); 63 | 64 | /////////////////////////////////////////////////////////////////////////// 65 | // Function: DecodeFrame_v 66 | // Purpose: Decodes one mp3 frame 67 | // Parameters: pSource pointer to an mp3 frame (at a syncword) 68 | // pulSize size of the buffer pSource points to. It will 69 | // contain the number of mp3 bytes decoded upon 70 | // return. 71 | // pPCM pointer to a buffer to decode into 72 | // pulPCMSize size of the PCM buffer. It will contain the 73 | // number of PCM bytes prodced upon return. 74 | /////////////////////////////////////////////////////////////////////////// 75 | void DecodeFrame_v(unsigned char *pSource, 76 | unsigned long *pulSize, 77 | unsigned char *pPCM, 78 | unsigned long *pulPCMSize); 79 | 80 | // overloaded new version that returns error code in errCode 81 | void DecodeFrame_v(unsigned char *pSource, 82 | unsigned long *pulSize, 83 | unsigned char *pPCM, 84 | unsigned long *pulPCMSize, 85 | int *errCode); 86 | 87 | void GetPCMInfo_v(unsigned long &ulSampRate, 88 | int &nChannels, 89 | int &nBitsPerSample); 90 | 91 | // return number of samples per frame, PER CHANNEL (renderer multiplies this result by nChannels) 92 | int GetSamplesPerFrame_n(); 93 | 94 | void SetTrustPackets(unsigned char bTrust) { m_bTrustPackets = bTrust; } 95 | 96 | private: 97 | void * m_pDec; // generic void ptr 98 | 99 | void * m_pDecL1; // not implemented (could use old Xing mpadecl1.cpp) 100 | void * m_pDecL2; // not implemented (could use old Xing mpadecl2.cpp) 101 | HMP3Decoder m_pDecL3; 102 | 103 | MP3FrameInfo m_lastMP3FrameInfo; 104 | unsigned char m_bUseFrameSize; 105 | unsigned char m_bTrustPackets; 106 | }; 107 | 108 | #endif /* _MPADECOBJFIXPT_H_ */ 109 | -------------------------------------------------------------------------------- /components/helix/include/statname.h: -------------------------------------------------------------------------------- 1 | /* ***** BEGIN LICENSE BLOCK ***** 2 | * Version: RCSL 1.0/RPSL 1.0 3 | * 4 | * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 5 | * 6 | * The contents of this file, and the files included with this file, are 7 | * subject to the current version of the RealNetworks Public Source License 8 | * Version 1.0 (the "RPSL") available at 9 | * http://www.helixcommunity.org/content/rpsl unless you have licensed 10 | * the file under the RealNetworks Community Source License Version 1.0 11 | * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 12 | * in which case the RCSL will apply. You may also obtain the license terms 13 | * directly from RealNetworks. You may not use this file except in 14 | * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 15 | * applicable to this file, the RCSL. Please see the applicable RPSL or 16 | * RCSL for the rights, obligations and limitations governing use of the 17 | * contents of the file. 18 | * 19 | * This file is part of the Helix DNA Technology. RealNetworks is the 20 | * developer of the Original Code and owns the copyrights in the portions 21 | * it created. 22 | * 23 | * This file, and the files included with this file, is distributed and made 24 | * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 25 | * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 26 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 27 | * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 28 | * 29 | * Technology Compatibility Kit Test Suite(s) Location: 30 | * http://www.helixcommunity.org/content/tck 31 | * 32 | * Contributor(s): 33 | * 34 | * ***** END LICENSE BLOCK ***** */ 35 | 36 | /************************************************************************************** 37 | * Fixed-point MP3 decoder 38 | * Jon Recker (jrecker@real.com), Ken Cooke (kenc@real.com) 39 | * June 2003 40 | * 41 | * statname.h - name mangling macros for static linking 42 | **************************************************************************************/ 43 | 44 | #ifndef _STATNAME_H 45 | #define _STATNAME_H 46 | 47 | /* define STAT_PREFIX to a unique name for static linking 48 | * all the C functions and global variables will be mangled by the preprocessor 49 | * e.g. void FFT(int *fftbuf) becomes void cook_FFT(int *fftbuf) 50 | */ 51 | #define STAT_PREFIX xmp3 52 | 53 | #define STATCC1(x,y,z) STATCC2(x,y,z) 54 | #define STATCC2(x,y,z) x##y##z 55 | 56 | #ifdef STAT_PREFIX 57 | #define STATNAME(func) STATCC1(STAT_PREFIX, _, func) 58 | #else 59 | #define STATNAME(func) func 60 | #endif 61 | 62 | /* these symbols are common to all implementations */ 63 | #define CheckPadBit STATNAME(CheckPadBit) 64 | #define UnpackFrameHeader STATNAME(UnpackFrameHeader) 65 | #define UnpackSideInfo STATNAME(UnpackSideInfo) 66 | #define AllocateBuffers STATNAME(AllocateBuffers) 67 | #define FreeBuffers STATNAME(FreeBuffers) 68 | #define DecodeHuffman STATNAME(DecodeHuffman) 69 | #define Dequantize STATNAME(Dequantize) 70 | #define IMDCT STATNAME(IMDCT) 71 | #define UnpackScaleFactors STATNAME(UnpackScaleFactors) 72 | #define Subband STATNAME(Subband) 73 | 74 | #define samplerateTab STATNAME(samplerateTab) 75 | #define bitrateTab STATNAME(bitrateTab) 76 | #define samplesPerFrameTab STATNAME(samplesPerFrameTab) 77 | #define bitsPerSlotTab STATNAME(bitsPerSlotTab) 78 | #define sideBytesTab STATNAME(sideBytesTab) 79 | #define slotTab STATNAME(slotTab) 80 | #define sfBandTable STATNAME(sfBandTable) 81 | 82 | /* in your implementation's top-level include file (e.g. real\coder.h) you should 83 | * add new #define sym STATNAME(sym) lines for all the 84 | * additional global functions or variables which your 85 | * implementation uses 86 | */ 87 | 88 | #endif /* _STATNAME_H */ 89 | -------------------------------------------------------------------------------- /components/helix/src/subband.c: -------------------------------------------------------------------------------- 1 | /* ***** BEGIN LICENSE BLOCK ***** 2 | * Version: RCSL 1.0/RPSL 1.0 3 | * 4 | * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 5 | * 6 | * The contents of this file, and the files included with this file, are 7 | * subject to the current version of the RealNetworks Public Source License 8 | * Version 1.0 (the "RPSL") available at 9 | * http://www.helixcommunity.org/content/rpsl unless you have licensed 10 | * the file under the RealNetworks Community Source License Version 1.0 11 | * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 12 | * in which case the RCSL will apply. You may also obtain the license terms 13 | * directly from RealNetworks. You may not use this file except in 14 | * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 15 | * applicable to this file, the RCSL. Please see the applicable RPSL or 16 | * RCSL for the rights, obligations and limitations governing use of the 17 | * contents of the file. 18 | * 19 | * This file is part of the Helix DNA Technology. RealNetworks is the 20 | * developer of the Original Code and owns the copyrights in the portions 21 | * it created. 22 | * 23 | * This file, and the files included with this file, is distributed and made 24 | * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 25 | * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 26 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 27 | * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 28 | * 29 | * Technology Compatibility Kit Test Suite(s) Location: 30 | * http://www.helixcommunity.org/content/tck 31 | * 32 | * Contributor(s): 33 | * 34 | * ***** END LICENSE BLOCK ***** */ 35 | 36 | /************************************************************************************** 37 | * Fixed-point MP3 decoder 38 | * Jon Recker (jrecker@real.com), Ken Cooke (kenc@real.com) 39 | * June 2003 40 | * February 2010 Lucio Di Jasio (lucio@dijasio.com) modified for batch transfer to output 41 | * July 2010 Priyabrata Sinha removed redundant code related to audio codec and profiling 42 | * 43 | * subband.c - subband transform (synthesis filterbank implemented via 32-point DCT 44 | * followed by polyphase filter) 45 | **************************************************************************************/ 46 | 47 | #include "coder.h" 48 | #include "assembly.h" 49 | 50 | /************************************************************************************** 51 | * Function: Subband 52 | * 53 | * Description: do subband transform on all the blocks in one granule, all channels 54 | * 55 | * Inputs: filled MP3DecInfo structure, after calling IMDCT for all channels 56 | * vbuf[ch] and vindex[ch] must be preserved between calls 57 | * 58 | * Outputs: decoded PCM data, interleaved LRLRLR... if stereo 59 | * 60 | * Return: 0 on success, -1 if null input pointers 61 | **************************************************************************************/ 62 | int Subband(MP3DecInfo *mp3DecInfo, short *pcmBuf) 63 | { 64 | int b; 65 | HuffmanInfo *hi; 66 | IMDCTInfo *mi; 67 | SubbandInfo *sbi; 68 | 69 | /* validate pointers */ 70 | if (!mp3DecInfo || !mp3DecInfo->HuffmanInfoPS || !mp3DecInfo->IMDCTInfoPS || !mp3DecInfo->SubbandInfoPS) 71 | return -1; 72 | 73 | hi = (HuffmanInfo *)mp3DecInfo->HuffmanInfoPS; 74 | mi = (IMDCTInfo *)(mp3DecInfo->IMDCTInfoPS); 75 | sbi = (SubbandInfo*)(mp3DecInfo->SubbandInfoPS); 76 | 77 | if (mp3DecInfo->nChans == 2) { 78 | /* stereo */ 79 | for (b = 0; b < BLOCK_SIZE; b++) { 80 | FDCT32(mi->outBuf[0][b], sbi->vbuf + 0*32, sbi->vindex, (b & 0x01), mi->gb[0]); 81 | FDCT32(mi->outBuf[1][b], sbi->vbuf + 1*32, sbi->vindex, (b & 0x01), mi->gb[1]); 82 | PolyphaseStereo(pcmBuf, sbi->vbuf + sbi->vindex + VBUF_LENGTH * (b & 0x01), polyCoef); 83 | sbi->vindex = (sbi->vindex - (b & 0x01)) & 7; 84 | pcmBuf += (2 * NBANDS); 85 | } 86 | } else { 87 | /* mono */ 88 | for (b = 0; b < BLOCK_SIZE; b++) { 89 | FDCT32(mi->outBuf[0][b], sbi->vbuf + 0*32, sbi->vindex, (b & 0x01), mi->gb[0]); 90 | PolyphaseMono(pcmBuf, sbi->vbuf + sbi->vindex + VBUF_LENGTH * (b & 0x01), polyCoef); 91 | sbi->vindex = (sbi->vindex - (b & 0x01)) & 7; 92 | pcmBuf += NBANDS; 93 | } 94 | } 95 | 96 | return 0; 97 | } 98 | 99 | 100 | -------------------------------------------------------------------------------- /components/ringb/component.mk: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /components/ringb/include/ringbuf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2018 5 | * 6 | * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | 25 | #ifndef _RINGBUF_H__ 26 | #define _RINGBUF_H__ 27 | 28 | #include "freertos/FreeRTOS.h" 29 | #include "freertos/task.h" 30 | #include "freertos/semphr.h" 31 | #include "freertos/queue.h" 32 | #include 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #define RB_OK (ESP_OK) 39 | #define RB_FAIL (ESP_FAIL) 40 | #define RB_DONE (-2) 41 | #define RB_ABORT (-3) 42 | #define RB_TIMEOUT (-4) 43 | 44 | typedef struct ringbuf *ringbuf_handle_t; 45 | 46 | /** 47 | * @brief Create ringbuffer with total size = size * block_size 48 | * 49 | * @param[in] size The size 50 | * @param[in] block_size The block size 51 | * 52 | * @return ringbuf_handle_t 53 | */ 54 | ringbuf_handle_t rb_create(int size, int block_size); 55 | 56 | /** 57 | * @brief Cleanup and free all memory created by ringbuf_handle_t 58 | * 59 | * @param[in] rb The Ringbuffer handle 60 | * 61 | * @return 62 | * - ESP_OK 63 | * - ESP_FAIL 64 | */ 65 | esp_err_t rb_destroy(ringbuf_handle_t rb); 66 | 67 | /** 68 | * @brief Abort waiting until there is space for reading or writing of the ringbuffer 69 | * 70 | * @param[in] rb The Ringbuffer handle 71 | * 72 | * @return 73 | * - ESP_OK 74 | * - ESP_FAIL 75 | */ 76 | esp_err_t rb_abort(ringbuf_handle_t rb); 77 | 78 | /** 79 | * @brief Reset ringbuffer, clear all values as initial state 80 | * 81 | * @param[in] rb The Ringbuffer handle 82 | * 83 | * @return 84 | * - ESP_OK 85 | * - ESP_FAIL 86 | */ 87 | esp_err_t rb_reset(ringbuf_handle_t rb); 88 | 89 | /** 90 | * @brief Get total bytes available of Ringbuffer 91 | * 92 | * @param[in] rb The Ringbuffer handle 93 | * 94 | * @return total bytes available 95 | */ 96 | int rb_bytes_available(ringbuf_handle_t rb); 97 | 98 | /** 99 | * @brief Get the number of bytes that have filled the ringbuffer 100 | * 101 | * @param[in] rb The Ringbuffer handle 102 | * 103 | * @return The number of bytes that have filled the ringbuffer 104 | */ 105 | int rb_bytes_filled(ringbuf_handle_t rb); 106 | 107 | /** 108 | * @brief Get total size of Ringbuffer (in bytes) 109 | * 110 | * @param[in] rb The Ringbuffer handle 111 | * 112 | * @return total size of Ringbuffer 113 | */ 114 | int rb_get_size(ringbuf_handle_t rb); 115 | 116 | /** 117 | * @brief Read from Ringbuffer to `buf` with len and wait `tick_to_wait` ticks until enough bytes to read 118 | * if the ringbuffer bytes available is less than `len` 119 | * 120 | * @param[in] rb The Ringbuffer handle 121 | * @param buf The buffer pointer to read out data 122 | * @param[in] len The length request 123 | * @param[in] ticks_to_wait The ticks to wait 124 | * 125 | * @return Number of bytes read 126 | */ 127 | int rb_read(ringbuf_handle_t rb, char *buf, int len, TickType_t ticks_to_wait); 128 | 129 | /** 130 | * @brief Write to Ringbuffer from `buf` with `len` and wait `tick_to_wait` ticks until enough space to write 131 | * if the ringbuffer space available is less than `len` 132 | * 133 | * @param[in] rb The Ringbuffer handle 134 | * @param buf The buffer 135 | * @param[in] len The length 136 | * @param[in] ticks_to_wait The ticks to wait 137 | * 138 | * @return Number of bytes written 139 | */ 140 | int rb_write(ringbuf_handle_t rb, char *buf, int len, TickType_t ticks_to_wait); 141 | 142 | /** 143 | * @brief Get total size of ringbuffer 144 | * 145 | * @param[in] rb The Ringbuffer handle 146 | * 147 | * @return Total size of ringbuffer (in block byte(s)) 148 | */ 149 | int rb_size_get(ringbuf_handle_t rb); 150 | 151 | /** 152 | * @brief Set status of writing to ringbuffer is done 153 | * 154 | * @param[in] rb The Ringbuffer handle 155 | * 156 | * @return 157 | * - ESP_OK 158 | * - ESP_FAIL 159 | */ 160 | esp_err_t rb_done_write(ringbuf_handle_t rb); 161 | #ifdef __cplusplus 162 | } 163 | #endif 164 | 165 | #endif -------------------------------------------------------------------------------- /components/util/component.mk: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /components/util/include/util.h: -------------------------------------------------------------------------------- 1 | #ifndef UTIL_H 2 | #define UTIL_H 3 | 4 | 5 | 6 | typedef struct 7 | { 8 | char rld[4]; //riff 标志符号 9 | int rLen; // 10 | char wld[4]; //格式类型(wave) 11 | char fld[4]; //"fmt" 12 | 13 | int fLen; //sizeof(wave format matex) 14 | 15 | short wFormatTag; //编码格式 16 | short wChannels; //声道数 17 | int nSamplesPersec; //采样频率 18 | int nAvgBitsPerSample;//WAVE文件采样大小 19 | short wBlockAlign; //块对齐 20 | short wBitsPerSample; //WAVE文件采样大小 21 | 22 | char dld[4]; //”data“ 23 | int wSampleLength; //音频数据的大小 24 | }wav_header_t; 25 | 26 | #endif -------------------------------------------------------------------------------- /example/dsp_test/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whyengineer/esp32-lin/6fa39f4cd5f7782b3a2a052767f0fb06be2378ff/example/dsp_test/.DS_Store -------------------------------------------------------------------------------- /example/dsp_test/Makefile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME := ESP32-LIN-PLAY-MP3 2 | 3 | NOW_PATH:=$(shell pwd) 4 | LIN_PATH:=$(dir $(patsubst %/,%,$(dir $(NOW_PATH)))) 5 | export LIN_PATH 6 | include $(LIN_PATH)project.mk 7 | -------------------------------------------------------------------------------- /example/dsp_test/README.md: -------------------------------------------------------------------------------- 1 | # DSP Library test 2 | 3 | * Fir 4 | * RFFT 5 | * IRFFT 6 | 7 | the dsp_ref.py output the reference result 8 | -------------------------------------------------------------------------------- /example/dsp_test/dsp_ref.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | import math 3 | import numpy 4 | from scipy.signal import kaiserord, lfilter, firwin, freqz 5 | from scipy.fftpack import fft,ifft,dct 6 | import matplotlib.pyplot as plt 7 | import time 8 | 9 | 10 | 11 | N=64 12 | #sin cos 13 | print("sin(0.1)=%f"% math.sin(0.1)) 14 | print("cos(2.0)=%f"% math.cos(2.0)) 15 | #------------------------------------------------ 16 | # FIR. 17 | #------------------------------------------------ 18 | x=[1.1016856340840009,1.3819116564898124,1.2902960763808005,1.0566626343732346, 19 | 0.9442254510513154,0.9579868821695956,1.046306253339488,1.2410366852938386, 20 | 1.4436282176750759,1.3874515506551908,1.0378805602935988,0.7756155443385301, 21 | 0.9178050511383941,1.2537702552749763,1.3426204627941956,1.117610065929717, 22 | 0.8800604905211858,0.8012517778630224,0.7821389128510301,0.7711632039505969, 23 | 0.8501510692896972,0.951564312477108,0.8436661347816815,0.5268377902750552, 24 | 0.33441324855963317,0.4608704807237677,0.660838911589431,0.6315802275119023, 25 | 0.4503064294285132,0.3690546542314113,0.3830365542353578,0.32286699253190193, 26 | 0.23477111445056748,0.30990336758188164,0.4885556520187167,0.49487230610275945, 27 | 0.29017088466245566,0.15479252877059746,0.24169920785325388,0.3670607943691402, 28 | 0.36701157780354643,0.3520189111198753,0.42271529556318366,0.4225052367712395, 29 | 0.23092439222513883,0.06926710273608785,0.1994021343386783,0.4723172130423151, 30 | 0.5111771910438687,0.2622959422441363,0.03179207010391415,0.00435686084990973, 31 | 0.060746245121383116,0.09208186182560787,0.14769880330463428,0.18278609616995745, 32 | 0.004175541124054452,-0.36016119316009115,-0.5430364808518742,-0.33032288155563755, 33 | -0.031070289589745434,-0.0789812885502211,-0.444599870929681,-0.7399276026332652] 34 | 35 | taps=[-0.00028361,-0.00075393,-0.00109268,-0.0006769,0.00102914,0.00391172,\ 36 | 0.00678037,0.0074884,0.00382395,-0.00503141,-0.0171363,-0.02737452,\ 37 | -0.02859017,-0.01418401,0.01873238,0.0670341,0.12139937,0.16869521,\ 38 | 0.19622892,0.19622892,0.16869521,0.12139937,0.0670341,0.01873238,\ 39 | -0.01418401,-0.02859017,-0.0273745,-0.0171363,-0.00503141,0.00382395,\ 40 | 0.0074884,0.00678037,0.00391172,0.00102914,-0.0006769,-0.00109268,\ 41 | -0.00075393,-0.00028361] 42 | 43 | # Use lfilter to filter x with the FIR filter. 44 | 45 | filtered_x = lfilter(taps, 1.0, x) 46 | print("FIR Result:",filtered_x,end="\r\n**************\r\n") 47 | 48 | #------------------------------------------------ 49 | # FFT 50 | #------------------------------------------------ 51 | ffted_x=numpy.fft.rfft(x) 52 | print("RFFT Length:",len(ffted_x)) 53 | print("FFT Result:",ffted_x,end="\r\n**************\r\n") 54 | print("Complex Magnitude Module:",numpy.abs(ffted_x),end="\r\n***************\r\n") 55 | #------------------------------------------------ 56 | # IFFT 57 | #------------------------------------------------ 58 | iffted_x=numpy.fft.irfft(ffted_x) 59 | print("IFFT Result:",iffted_x,end="\r\n**************\r\n") 60 | #------------------------------------------------ 61 | # DCT2 and DCT4 62 | #------------------------------------------------ 63 | dcted_x=dct(x) 64 | print("DCT2 Result:",dcted_x,end="\r\n**************\r\n") 65 | #caculate dct4 from dct2 66 | #y4(k)=y2(k)-y4(k-1) 67 | #y4(-1)=y4(0) 68 | dct4ed_x=[None]*64 69 | dct4ed_x[0]=dcted_x[0]/2 70 | for i in range(1,N): 71 | dct4ed_x[i]=dcted_x[i]-dct4ed_x[i-1] 72 | print("DCT4 Result:",dct4ed_x,end="\r\n**************\r\n") 73 | #------------------------------------------------ 74 | # Martix 75 | #------------------------------------------------ 76 | m= numpy.matrix('1 2; 3 4') 77 | print("Source Martix:",m,end="\r\n**************\r\n") 78 | print("Inverse Martix:",m.getI(),end="\r\n**************\r\n") 79 | print("Transpose Martix:",m.T,end="\r\n**************\r\n") -------------------------------------------------------------------------------- /example/dsp_test/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main Makefile. This is basically the same as a component makefile. 3 | # 4 | 5 | -------------------------------------------------------------------------------- /example/dsp_test/main/dsp_test.c: -------------------------------------------------------------------------------- 1 | /* Play mp3 file by audio pipeline 2 | 3 | This example code is in the Public Domain (or CC0 licensed, at your option.) 4 | 5 | Unless required by applicable law or agreed to in writing, this 6 | software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 7 | CONDITIONS OF ANY KIND, either express or implied. 8 | */ 9 | 10 | #include 11 | #include 12 | #include "freertos/FreeRTOS.h" 13 | #include "freertos/task.h" 14 | 15 | #include "esp_log.h" 16 | #include "xtensa_math.h" 17 | 18 | static const char *TAG = "DSP"; 19 | 20 | static float cof[38]={-0.00028361,-0.00075393,-0.00109268,-0.0006769,0.00102914,0.00391172,\ 21 | 0.00678037,0.0074884,0.00382395,-0.00503141,-0.0171363,-0.02737452,\ 22 | -0.02859017,-0.01418401,0.01873238,0.0670341,0.12139937,0.16869521,\ 23 | 0.19622892,0.19622892,0.16869521,0.12139937,0.0670341,0.01873238,\ 24 | -0.01418401,-0.02859017,-0.0273745,-0.0171363,-0.00503141,0.00382395,\ 25 | 0.0074884,0.00678037,0.00391172,0.00102914,-0.0006769,-0.00109268,\ 26 | -0.00075393,-0.00028361}; 27 | 28 | static float x[64]={1.1016856340840009,1.3819116564898124,1.2902960763808005,1.0566626343732346, 29 | 0.9442254510513154,0.9579868821695956,1.046306253339488,1.2410366852938386, 30 | 1.4436282176750759,1.3874515506551908,1.0378805602935988,0.7756155443385301, 31 | 0.9178050511383941,1.2537702552749763,1.3426204627941956,1.117610065929717, 32 | 0.8800604905211858,0.8012517778630224,0.7821389128510301,0.7711632039505969, 33 | 0.8501510692896972,0.951564312477108,0.8436661347816815,0.5268377902750552, 34 | 0.33441324855963317,0.4608704807237677,0.660838911589431,0.6315802275119023, 35 | 0.4503064294285132,0.3690546542314113,0.3830365542353578,0.32286699253190193, 36 | 0.23477111445056748,0.30990336758188164,0.4885556520187167,0.49487230610275945, 37 | 0.29017088466245566,0.15479252877059746,0.24169920785325388,0.3670607943691402, 38 | 0.36701157780354643,0.3520189111198753,0.42271529556318366,0.4225052367712395, 39 | 0.23092439222513883,0.06926710273608785,0.1994021343386783,0.4723172130423151, 40 | 0.5111771910438687,0.2622959422441363,0.03179207010391415,0.00435686084990973, 41 | 0.060746245121383116,0.09208186182560787,0.14769880330463428,0.18278609616995745, 42 | 0.004175541124054452,-0.36016119316009115,-0.5430364808518742,-0.33032288155563755, 43 | -0.031070289589745434,-0.0789812885502211,-0.444599870929681,-0.7399276026332652}; 44 | 45 | 46 | void calculate(){ 47 | float res[64]={0.0}; 48 | float state[64+37]={0.0}; 49 | int i; 50 | /****** fir *******/ 51 | xtensa_fir_instance_f32 fir; 52 | //float* state=malloc(sizeof(float32_t)*(38+64-1)); 53 | xtensa_fir_init_f32(&fir,38,cof,state,64); 54 | xtensa_fir_f32(&fir,x,res,64); 55 | ESP_LOGI(TAG,"FIR Result:") 56 | for(i=0;i<64;i=i+4){ 57 | ESP_LOGI(TAG,"[%f,%f,%f,%f]",res[i],res[i+1],res[i+2],res[i+3]); 58 | } 59 | /****** rfft ******/ 60 | xtensa_rfft_fast_instance_f32 rfft; 61 | xtensa_rfft_fast_init_f32(&rfft,64); 62 | xtensa_rfft_fast_f32(&rfft,x,res,0); 63 | ESP_LOGI(TAG,"RFFT Result:") 64 | for(i=0;i<64;i=i+4){ 65 | ESP_LOGI(TAG,"[%f,%f,%f,%f]",res[i],res[i+1],res[i+2],res[i+3]); 66 | } 67 | #if 1 68 | float mag[33]={0}; 69 | configASSERT(mag!=NULL); 70 | xtensa_cmplx_mag_f32(res,mag,64); 71 | mag[0]=res[0]; 72 | mag[32]=res[1]; 73 | ESP_LOGI(TAG,"RFFT Magnitude Result:") 74 | for(int i=0;i<32;i=i+4){ 75 | ESP_LOGI(TAG,"[%f,%f,%f,%f]",mag[i],mag[i+1],mag[i+2],mag[i+3]); 76 | } 77 | ESP_LOGI(TAG,"[%f]",mag[32]); 78 | #endif 79 | xtensa_rfft_fast_instance_f32 rifft; 80 | xtensa_rfft_fast_init_f32(&rifft,64); 81 | float ifft_res[64]; 82 | xtensa_rfft_fast_f32(&rifft,res,ifft_res,1); 83 | ESP_LOGI(TAG,"IRFFT Result:") 84 | for(i=0;i<64;i=i+4){ 85 | ESP_LOGI(TAG,"[%f,%f,%f,%f]",ifft_res[i],ifft_res[i+1],ifft_res[i+2],ifft_res[i+3]); 86 | } 87 | vTaskSuspend(NULL); 88 | } 89 | void app_main(void) 90 | { 91 | //add and mul 92 | float x[2]={0.333,1.2}; 93 | float y[2]={32.1,1000.2}; 94 | float res[2]={0}; 95 | xtensa_add_f32(x,y,res,2); 96 | ESP_LOGI(TAG,"%f + %f =%f",x[0],y[0],res[0]); 97 | ESP_LOGI(TAG,"%f + %f =%f",x[1],y[1],res[1]); 98 | //sin and cos 99 | res[0]=xtensa_sin_f32(0.1); 100 | ESP_LOGI(TAG,"sin(%f)=%f",0.1,res[0]); 101 | res[0]=xtensa_cos_f32(2.0); 102 | ESP_LOGI(TAG,"cos(%f)=%f",2.0,res[0]); 103 | //fir 104 | 105 | 106 | xTaskCreate(calculate,"cal",1024*3,NULL,3,NULL); 107 | vTaskSuspend(NULL); 108 | 109 | } 110 | -------------------------------------------------------------------------------- /example/hello_world/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whyengineer/esp32-lin/6fa39f4cd5f7782b3a2a052767f0fb06be2378ff/example/hello_world/.DS_Store -------------------------------------------------------------------------------- /example/hello_world/Makefile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME := ESP32-LIN-PLAY-MP3 2 | 3 | NOW_PATH:=$(shell pwd) 4 | LIN_PATH:=$(dir $(patsubst %/,%,$(dir $(NOW_PATH)))) 5 | export LIN_PATH 6 | include $(LIN_PATH)project.mk 7 | -------------------------------------------------------------------------------- /example/hello_world/README.md: -------------------------------------------------------------------------------- 1 | # DSP Library test 2 | 3 | * Fir 4 | * RFFT 5 | * IRFFT 6 | 7 | the dsp_ref.py output the reference result 8 | -------------------------------------------------------------------------------- /example/hello_world/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main Makefile. This is basically the same as a component makefile. 3 | # 4 | 5 | -------------------------------------------------------------------------------- /example/hello_world/main/main.c: -------------------------------------------------------------------------------- 1 | /* Play mp3 file by audio pipeline 2 | 3 | This example code is in the Public Domain (or CC0 licensed, at your option.) 4 | 5 | Unless required by applicable law or agreed to in writing, this 6 | software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 7 | CONDITIONS OF ANY KIND, either express or implied. 8 | */ 9 | 10 | #include 11 | #include 12 | #include "freertos/FreeRTOS.h" 13 | #include "freertos/task.h" 14 | 15 | #include "esp_log.h" 16 | #include "bsp.h" 17 | 18 | #define TAG "main" 19 | 20 | void app_main(void) 21 | { 22 | bsp_init(); 23 | bsp_event_t bsp_e; 24 | while(1){ 25 | 26 | bsp_event_get(&bsp_e,portMAX_DELAY); 27 | ESP_LOGI(TAG,"key_event:%d,vol:%d,sd:%d",bsp_e.key_e,bsp_e.vol,bsp_e.sd); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /example/play_mp3/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whyengineer/esp32-lin/6fa39f4cd5f7782b3a2a052767f0fb06be2378ff/example/play_mp3/.DS_Store -------------------------------------------------------------------------------- /example/play_mp3/Makefile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME := ESP32-LIN-PLAY-MP3 2 | 3 | NOW_PATH:=$(shell pwd) 4 | LIN_PATH:=$(dir $(patsubst %/,%,$(dir $(NOW_PATH)))) 5 | export LIN_PATH 6 | include $(LIN_PATH)project.mk 7 | -------------------------------------------------------------------------------- /example/play_mp3/README.md: -------------------------------------------------------------------------------- 1 | # DSP Library test 2 | 3 | * Fir 4 | * RFFT 5 | * IRFFT 6 | 7 | the dsp_ref.py output the reference result 8 | -------------------------------------------------------------------------------- /example/play_mp3/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main Makefile. This is basically the same as a component makefile. 3 | # 4 | 5 | -------------------------------------------------------------------------------- /example/play_mp3/main/main.c: -------------------------------------------------------------------------------- 1 | /* Play mp3 file by audio pipeline 2 | 3 | This example code is in the Public Domain (or CC0 licensed, at your option.) 4 | 5 | Unless required by applicable law or agreed to in writing, this 6 | software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 7 | CONDITIONS OF ANY KIND, either express or implied. 8 | */ 9 | 10 | #include 11 | #include 12 | #include "freertos/FreeRTOS.h" 13 | #include "freertos/task.h" 14 | 15 | #include "esp_log.h" 16 | #include "bsp.h" 17 | #include "util.h" 18 | #include "mp3dec.h" 19 | 20 | 21 | #define TAG "main" 22 | 23 | static void play_task(){ 24 | while(1){ 25 | HMP3Decoder hMP3Decoder; 26 | MP3FrameInfo mp3FrameInfo; 27 | unsigned char *readBuf=malloc(MAINBUF_SIZE); 28 | if(readBuf==NULL){ 29 | ESP_LOGE(TAG,"readBuf malloc failed"); 30 | return; 31 | } 32 | short *output=malloc(1153*4); 33 | if(output==NULL){ 34 | free(readBuf); 35 | ESP_LOGE(TAG,"outBuf malloc failed"); 36 | } 37 | hMP3Decoder = MP3InitDecoder(); 38 | if (hMP3Decoder == 0){ 39 | free(readBuf); 40 | free(output); 41 | ESP_LOGE(TAG,"memory is not enough.."); 42 | } 43 | 44 | int samplerate=0; 45 | i2s_zero_dma_buffer(0); 46 | FILE *mp3File=fopen("/sdcard/music1.mp3","rb"); 47 | if(mp3File==NULL){ 48 | MP3FreeDecoder(hMP3Decoder); 49 | free(readBuf); 50 | free(output); 51 | ESP_LOGE(TAG,"open file failed"); 52 | } 53 | char tag[10]; 54 | int tag_len = 0; 55 | int read_bytes = fread(tag, 1, 10, mp3File); 56 | if(read_bytes == 10) 57 | { 58 | if (memcmp(tag,"ID3",3) == 0) 59 | { 60 | tag_len = ((tag[6] & 0x7F)<< 21)|((tag[7] & 0x7F) << 14) | ((tag[8] & 0x7F) << 7) | (tag[9] & 0x7F); 61 | // ESP_LOGI(TAG,"tag_len: %d %x %x %x %x", tag_len,tag[6],tag[7],tag[8],tag[9]); 62 | fseek(mp3File, tag_len - 10, SEEK_SET); 63 | } 64 | else 65 | { 66 | fseek(mp3File, 0, SEEK_SET); 67 | } 68 | } 69 | unsigned char* input = &readBuf[0]; 70 | int bytesLeft = 0; 71 | int outOfData = 0; 72 | unsigned char* readPtr = readBuf; 73 | while (1) 74 | { 75 | 76 | if (bytesLeft < MAINBUF_SIZE) 77 | { 78 | memmove(readBuf, readPtr, bytesLeft); 79 | int br = fread(readBuf + bytesLeft, 1, MAINBUF_SIZE - bytesLeft, mp3File); 80 | if ((br == 0)&&(bytesLeft==0)) break; 81 | 82 | bytesLeft = bytesLeft + br; 83 | readPtr = readBuf; 84 | } 85 | int offset = MP3FindSyncWord(readPtr, bytesLeft); 86 | if (offset < 0) 87 | { 88 | ESP_LOGE(TAG,"MP3FindSyncWord not find"); 89 | bytesLeft=0; 90 | continue; 91 | } 92 | else 93 | { 94 | readPtr += offset; //data start point 95 | bytesLeft -= offset; //in buffer 96 | int errs = MP3Decode(hMP3Decoder, &readPtr, &bytesLeft, output, 0); 97 | if (errs != 0) 98 | { 99 | ESP_LOGE(TAG,"MP3Decode failed ,code is %d ",errs); 100 | break; 101 | } 102 | MP3GetLastFrameInfo(hMP3Decoder, &mp3FrameInfo); 103 | if(samplerate!=mp3FrameInfo.samprate) 104 | { 105 | samplerate=mp3FrameInfo.samprate; 106 | //hal_i2s_init(0,samplerate,16,mp3FrameInfo.nChans); 107 | //i2s_set_clk(0,samplerate,16,mp3FrameInfo.nChans); 108 | hal_i2s_deinit(0); 109 | hal_i2s_init(0,samplerate,mp3FrameInfo.bitsPerSample,mp3FrameInfo.nChans); 110 | //wm8978_samplerate_set(samplerate); 111 | ESP_LOGI(TAG,"mp3file info---bitrate=%d,layer=%d,nChans=%d,samprate=%d,outputSamps=%d",mp3FrameInfo.bitrate,mp3FrameInfo.layer,mp3FrameInfo.nChans,mp3FrameInfo.samprate,mp3FrameInfo.outputSamps); 112 | } 113 | hal_i2s_write(0,(char*)output,mp3FrameInfo.outputSamps*2, 1000 / portTICK_RATE_MS); 114 | } 115 | 116 | } 117 | i2s_zero_dma_buffer(0); 118 | //i2s_driver_uninstall(0); 119 | MP3FreeDecoder(hMP3Decoder); 120 | free(readBuf); 121 | free(output); 122 | fclose(mp3File); 123 | } 124 | } 125 | void app_main(void) 126 | { 127 | bsp_init(); 128 | bsp_event_t bsp_e; 129 | xTaskCreate(play_task, "play_task", 4096, NULL, 9, NULL);//low priority 130 | while(1){ 131 | 132 | bsp_event_get(&bsp_e,portMAX_DELAY); 133 | ESP_LOGI(TAG,"key_event:%d,vol:%d,sd:%d",bsp_e.key_e,bsp_e.vol,bsp_e.sd); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /example/play_wav/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whyengineer/esp32-lin/6fa39f4cd5f7782b3a2a052767f0fb06be2378ff/example/play_wav/.DS_Store -------------------------------------------------------------------------------- /example/play_wav/Makefile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME := ESP32-LIN-PLAY-MP3 2 | 3 | NOW_PATH:=$(shell pwd) 4 | LIN_PATH:=$(dir $(patsubst %/,%,$(dir $(NOW_PATH)))) 5 | export LIN_PATH 6 | include $(LIN_PATH)project.mk 7 | -------------------------------------------------------------------------------- /example/play_wav/README.md: -------------------------------------------------------------------------------- 1 | # DSP Library test 2 | 3 | * Fir 4 | * RFFT 5 | * IRFFT 6 | 7 | the dsp_ref.py output the reference result 8 | -------------------------------------------------------------------------------- /example/play_wav/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main Makefile. This is basically the same as a component makefile. 3 | # 4 | 5 | -------------------------------------------------------------------------------- /example/play_wav/main/main.c: -------------------------------------------------------------------------------- 1 | /* Play mp3 file by audio pipeline 2 | 3 | This example code is in the Public Domain (or CC0 licensed, at your option.) 4 | 5 | Unless required by applicable law or agreed to in writing, this 6 | software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 7 | CONDITIONS OF ANY KIND, either express or implied. 8 | */ 9 | 10 | #include 11 | #include 12 | #include "freertos/FreeRTOS.h" 13 | #include "freertos/task.h" 14 | 15 | #include "esp_log.h" 16 | #include "bsp.h" 17 | #include "util.h" 18 | 19 | #define TAG "main" 20 | 21 | static void play_task(){ 22 | while(1){ 23 | wav_header_t wav_head; 24 | FILE *f= fopen("/sdcard/music1.wav", "r"); 25 | if (f == NULL) { 26 | ESP_LOGE(TAG,"Failed to open file"); 27 | return; 28 | } 29 | int rlen=fread(&wav_head,1,sizeof(wav_head),f); 30 | if(rlen!=sizeof(wav_head)){ 31 | ESP_LOGE(TAG,"read faliled"); 32 | return; 33 | } 34 | int channels = wav_head.wChannels; 35 | int frequency = wav_head.nSamplesPersec; 36 | int bit = wav_head.wBitsPerSample; 37 | int datalen= wav_head.wSampleLength; 38 | (void)datalen; 39 | ESP_LOGI(TAG,"channels:%d,frequency:%d,bit:%d\n",channels,frequency,bit); 40 | hal_i2s_deinit(0); 41 | hal_i2s_init(0,frequency,bit,channels); 42 | char* samples_data = malloc(1024); 43 | do{ 44 | rlen=fread(samples_data,1,1024,f); 45 | //datalen-=rlen; 46 | hal_i2s_write(0,samples_data,rlen,5000); 47 | }while(rlen>0); 48 | fclose(f); 49 | free(samples_data); 50 | f=NULL; 51 | } 52 | } 53 | void app_main(void) 54 | { 55 | bsp_init(); 56 | bsp_event_t bsp_e; 57 | xTaskCreate(play_task, "play_task", 4096, NULL, 9, NULL);//low priority 58 | while(1){ 59 | 60 | bsp_event_get(&bsp_e,portMAX_DELAY); 61 | ESP_LOGI(TAG,"key_event:%d,vol:%d,sd:%d",bsp_e.key_e,bsp_e.vol,bsp_e.sd); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /project.mk: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | EXTRA_COMPONENT_DIRS += $(LIN_PATH)components/ 6 | 7 | include $(IDF_PATH)/make/project.mk 8 | 9 | --------------------------------------------------------------------------------