- merge with original master from jorgen
- minimize RAM usage of all components - use both IRAM and DRAM in player component so we can buffer up to 1s on modules without SPI RAM - support fragemented pcm chunks so we can use all available RAM if there isn't a big enough block available but still enough HEAP - reinclude all components from jorgen's master branch - add custom i2s driver to get a precise timing of initial sync - change wrong usage of esp_timer for latency measurement of snapcast protocol - add player component
This commit is contained in:
9
components/esp-dsp/examples/basic_math/CMakeLists.txt
Normal file
9
components/esp-dsp/examples/basic_math/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
# The following lines of boilerplate have to be in your project's
|
||||
# CMakeLists in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
set(EXTRA_COMPONENT_DIRS "../../")
|
||||
set(IDF_EXCLUDE_COMPONENTS test test_app)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(basic_math)
|
||||
16
components/esp-dsp/examples/basic_math/Makefile
Normal file
16
components/esp-dsp/examples/basic_math/Makefile
Normal file
@@ -0,0 +1,16 @@
|
||||
#
|
||||
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
|
||||
# project subdirectory.
|
||||
#
|
||||
|
||||
PROJECT_NAME := basic_math
|
||||
|
||||
# This line has to be included into the make file
|
||||
# to include components that are located somewhere
|
||||
# but not in "component" directory
|
||||
|
||||
EXTRA_COMPONENT_DIRS := $(realpath ../..)
|
||||
EXCLUDE_COMPONENTS := test
|
||||
|
||||
include $(IDF_PATH)/make/project.mk
|
||||
|
||||
83
components/esp-dsp/examples/basic_math/README.md
Normal file
83
components/esp-dsp/examples/basic_math/README.md
Normal file
@@ -0,0 +1,83 @@
|
||||
# Basic Math Example
|
||||
|
||||
(See the README.md file in the upper level 'examples' directory for more information about examples.)
|
||||
|
||||
This example demonstrates how to use basic math functions from esp-dsp library. Example does the following steps:
|
||||
|
||||
1. Initialize the library
|
||||
2. Initialize input signals with 1024 samples
|
||||
3. Apply window to input signal by standard C loop.
|
||||
4. Calculate FFT for 1024 complex samples and show the result
|
||||
5. Show results on the plots
|
||||
6. Apply window to input signal by basic math functions dsps_mul_f32 and dsps_mulc_f32.
|
||||
7. Calculate FFT for 1024 complex samples
|
||||
8. Show results on the plots
|
||||
|
||||
## How to use example
|
||||
|
||||
### Hardware required
|
||||
|
||||
This example does not require any special hardware, and can be run on any common development board.
|
||||
|
||||
### Configure the project
|
||||
|
||||
If using Make based build system, run `make menuconfig` and set serial port under Serial Flasher Options.
|
||||
If using CMake based build system, no configuration is required.
|
||||
Also, under Component Config ---> DSP Library ---> Optimization for ESP32, it's possible to select optimized or ansi implementation to compare.
|
||||
|
||||
### Build and flash
|
||||
|
||||
Build the project and flash it to the board, then run monitor tool to view serial output:
|
||||
|
||||
```
|
||||
make -j4 flash monitor
|
||||
```
|
||||
|
||||
Or, for CMake based build system (replace PORT with serial port name):
|
||||
|
||||
```
|
||||
idf.py -p PORT flash monitor
|
||||
```
|
||||
|
||||
(To exit the serial monitor, type ``Ctrl-]``.)
|
||||
|
||||
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
|
||||
|
||||
## Example output
|
||||
|
||||
Here is an typical example console output.
|
||||
|
||||
```bash
|
||||
I (132) main: *** Start Example. ***
|
||||
I (132) main: *** Multiply tone signal with Hann window by standard C loop. ***
|
||||
I (152) view: Data min[432] = -173.749878, Data max[205] = 23.849705
|
||||
________________________________________________________________
|
||||
0 | |
|
||||
1 | |
|
||||
2 | |
|
||||
3 || |
|
||||
4 | | |
|
||||
5 || | |
|
||||
6 ||| || |
|
||||
7 ||||| |||| |
|
||||
8||||||||||||||| |||||| |
|
||||
9 |||||||||||||||||||||||||
|
||||
0123456789012345678901234567890123456789012345678901234567890123
|
||||
I (162) view: Plot: Length=512, min=-120.000000, max=40.000000
|
||||
I (162) main: *** Multiply tone signal with Hann window by esp-dsp basic math functions. ***
|
||||
I (162) view: Data min[432] = -173.749878, Data max[205] = 23.849705
|
||||
________________________________________________________________
|
||||
0 | |
|
||||
1 | |
|
||||
2 | |
|
||||
3 || |
|
||||
4 | | |
|
||||
5 || | |
|
||||
6 ||| || |
|
||||
7 ||||| |||| |
|
||||
8||||||||||||||| |||||| |
|
||||
9 |||||||||||||||||||||||||
|
||||
0123456789012345678901234567890123456789012345678901234567890123
|
||||
I (172) view: Plot: Length=512, min=-120.000000, max=40.000000
|
||||
I (172) main: *** End Example. ***
|
||||
```
|
||||
@@ -0,0 +1,4 @@
|
||||
set(COMPONENT_SRCS "dsps_math_main.c")
|
||||
set(COMPONENT_ADD_INCLUDEDIRS "")
|
||||
|
||||
register_component()
|
||||
8
components/esp-dsp/examples/basic_math/main/component.mk
Normal file
8
components/esp-dsp/examples/basic_math/main/component.mk
Normal file
@@ -0,0 +1,8 @@
|
||||
#
|
||||
# Main component makefile.
|
||||
#
|
||||
# This Makefile can be left empty. By default, it will take the sources in the
|
||||
# src/ directory, compile them and link them into lib(subdirectory_name).a
|
||||
# in the build directory. This behaviour is entirely configurable,
|
||||
# please read the ESP-IDF documents if you need to do this.
|
||||
#
|
||||
93
components/esp-dsp/examples/basic_math/main/dsps_math_main.c
Normal file
93
components/esp-dsp/examples/basic_math/main/dsps_math_main.c
Normal file
@@ -0,0 +1,93 @@
|
||||
// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_system.h"
|
||||
#include "driver/spi_master.h"
|
||||
#include "soc/gpio_struct.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/uart.h"
|
||||
#include "soc/uart_struct.h"
|
||||
#include <math.h>
|
||||
|
||||
#include "esp_dsp.h"
|
||||
|
||||
static const char *TAG = "main";
|
||||
|
||||
// This example shows how to use FFT from esp-dsp library
|
||||
|
||||
#define N_SAMPLES 1024
|
||||
int N = N_SAMPLES;
|
||||
// Input test array
|
||||
float x1[N_SAMPLES];
|
||||
// Window coefficients
|
||||
float wind[N_SAMPLES];
|
||||
// working complex array
|
||||
float y_cf[N_SAMPLES*2];
|
||||
// Pointers to result arrays
|
||||
float* y1_cf = &y_cf[0];
|
||||
|
||||
static void process_and_show(float* data, int length)
|
||||
{
|
||||
dsps_fft2r_fc32(data, length);
|
||||
// Bit reverse
|
||||
dsps_bit_rev_fc32(data, length);
|
||||
// Convert one complex vector to two complex vectors
|
||||
dsps_cplx2reC_fc32(data, length);
|
||||
|
||||
for (int i = 0 ; i < length/2 ; i++) {
|
||||
data[i] = 10 * log10f((data[i * 2 + 0] * data[i * 2 + 0] + data[i * 2 + 1] * data[i * 2 + 1])/N);
|
||||
}
|
||||
|
||||
// Show power spectrum in 64x10 window from -100 to 0 dB from 0..N/4 samples
|
||||
dsps_view(data, length/2, 64, 10, -120, 40, '|');
|
||||
}
|
||||
|
||||
void app_main()
|
||||
{
|
||||
esp_err_t ret;
|
||||
ESP_LOGI(TAG, "*** Start Example. ***");
|
||||
ret = dsps_fft2r_init_fc32(NULL, CONFIG_DSP_MAX_FFT_SIZE);
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "Not possible to initialize FFT. Error = %i", ret);
|
||||
return;
|
||||
}
|
||||
|
||||
// Generate Hann window
|
||||
dsps_wind_hann_f32(wind, N);
|
||||
|
||||
ESP_LOGI(TAG, "*** Multiply tone signal with Hann window by standard C loop. ***");
|
||||
// Generate input signal
|
||||
dsps_tone_gen_f32(x1, N, 1., 0.2, 0);
|
||||
// Convert two input vectors to one complex vector
|
||||
for (int i=0 ; i< N ; i++)
|
||||
{
|
||||
y_cf[i*2 + 0] = x1[i]*wind[i];
|
||||
y_cf[i*2 + 1] = 0;
|
||||
}
|
||||
process_and_show(y_cf, N);
|
||||
|
||||
ESP_LOGI(TAG, "*** Multiply tone signal with Hann window by esp-dsp basic math functions. ***");
|
||||
// Convert two input vectors to one complex vector with basic functions
|
||||
dsps_mul_f32(x1, wind, y_cf, N, 1, 1, 2); // Multiply input array with window and store as real part
|
||||
dsps_mulc_f32(&y_cf[1], &y_cf[1], N, 0, 2, 2); // Clear imaginary part of the complex signal
|
||||
process_and_show(y_cf, N);
|
||||
ESP_LOGI(TAG, "*** End Example. ***");
|
||||
}
|
||||
Reference in New Issue
Block a user