ESP-IDF Firmware
Firmware architecture and call graph
Loading...
Searching...
No Matches
dsps_cplx_gen.c
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#include "dsps_cplx_gen.h"
8
9esp_err_t dsps_cplx_gen_ansi(cplx_sig_t *cplx_gen, void *output, int32_t len)
10{
11 // angle frequency is already cplx_gen->freq
12 const int sin_to_cos = cplx_gen->lut_len / 4;
13 float ph = cplx_gen->phase;
14 const float fr = cplx_gen->freq;
15 int sin_pos, cos_pos;
16
17 for (int i = 0 ; i < len; i++) {
18
19 if (ph < 0) {
20 ph += 1.0;
21 }
22 if (ph >= 1.0) {
23 ph -= 1.0;
24 }
25
26 sin_pos = (int)(ph * (cplx_gen->lut_len));
27 cos_pos = (sin_pos + sin_to_cos) & (cplx_gen->lut_len - 1);
28
29 if (cplx_gen->d_type == S16_FIXED) {
30 ((int16_t *)output)[i * 2 + 0] = ((int16_t *)cplx_gen->lut)[cos_pos];
31 ((int16_t *)output)[i * 2 + 1] = ((int16_t *)cplx_gen->lut)[sin_pos];
32 } else {
33 ((float *)output)[i * 2 + 0] = ((float *)cplx_gen->lut)[cos_pos];
34 ((float *)output)[i * 2 + 1] = ((float *)cplx_gen->lut)[sin_pos];
35 }
36 ph += fr;
37 }
38
39 return ESP_OK;
40}
esp_err_t dsps_cplx_gen_ansi(cplx_sig_t *cplx_gen, void *output, int32_t len)
The function generates a complex signal.
struct cplx_sig_s cplx_sig_t
Data struct of the complex signal generator.
@ S16_FIXED
int esp_err_t
Definition esp_err.h:21
#define ESP_OK
Definition esp_err.h:23
int32_t lut_len
out_d_type d_type