Skip to content

Commit 7fc8b6c

Browse files
koffesgreg-fer
authored andcommitted
lib: tone: Tone module moved
Tone module moved from applications/nrf5340_audio Signed-off-by: Kristoffer Rist Skøien <kristoffer.skoien@nordicsemi.no> Co-authored-by: Grzegorz Ferenc <Grzegorz.Ferenc@nordicsemi.no>
1 parent d942784 commit 7fc8b6c

File tree

16 files changed

+122
-54
lines changed

16 files changed

+122
-54
lines changed

CODEOWNERS

+2
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ Kconfig* @tejlmand
122122
/lib/qos/ @simensrostad
123123
/lib/pcm_mix/ @koffes @alexsven @erikrobstad @rick1082 @gWacey
124124
/lib/contin_array/ @koffes @alexsven @erikrobstad @rick1082 @gWacey
125+
/lib/tone/ @koffes @alexsven @erikrobstad @rick1082 @gWacey
125126
/modules/ @tejlmand
126127
/modules/mcuboot/ @de-nordic @nordicjm
127128
/modules/cjson/ @simensrostad @plskeggs @sigvartmh
@@ -245,6 +246,7 @@ Kconfig* @tejlmand
245246
/tests/lib/nrf_modem_lib/ @lemrey @MirkoCovizzi
246247
/tests/lib/nrf_modem_lib/nrf91_sockets/ @MirkoCovizzi
247248
/tests/lib/ram_pwrdn/ @Damian-Nordic
249+
/tests/lib/tone/ @koffes @alexsven @erikrobstad @rick1082 @gWacey
248250
/tests/modules/lib/zcbor/ @oyvindronningstad
249251
/tests/modules/mcuboot/direct_xip/ @hakonfam
250252
/tests/modules/mcuboot/external_flash/ @hakonfam @sigvartmh

applications/nrf5340_audio/Kconfig.defaults

+4
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ config PCM_MIX
7777
bool
7878
default y
7979

80+
config TONE
81+
bool
82+
default y
83+
8084
# Enable NRFX_CLOCK for ACLK control
8185
config NRFX_CLOCK
8286
bool

applications/nrf5340_audio/src/utils/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ target_sources(app PRIVATE
1010
${CMAKE_CURRENT_SOURCE_DIR}/data_fifo.c
1111
${CMAKE_CURRENT_SOURCE_DIR}/error_handler.c
1212
${CMAKE_CURRENT_SOURCE_DIR}/pcm_stream_channel_modifier.c
13-
${CMAKE_CURRENT_SOURCE_DIR}/tone.c
1413
${CMAKE_CURRENT_SOURCE_DIR}/uicr.c
1514
)

applications/nrf5340_audio/src/utils/tone.h

-32
This file was deleted.

doc/nrf/libraries/others/tone.rst

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.. _lib_tone:
2+
3+
Tone generator
4+
##############
5+
6+
.. contents::
7+
:local:
8+
:depth: 2
9+
10+
The tone generator library creates an array of pulse-code modulation (PCM) data of a one-period sine tone, with a given tone frequency and sampling frequency.
11+
For more information, see `API documentation`_.
12+
13+
Configuration
14+
*************
15+
16+
To enable the library, set the :kconfig:option:`CONFIG_TONE` Kconfig option to ``y`` in the project configuration file :file:`prj.conf`.
17+
18+
API documentation
19+
*****************
20+
21+
| Header file: :file:`include/tone.h`
22+
| Source file: :file:`lib/tone/tone.c`
23+
24+
.. doxygengroup:: tone_gen
25+
:project: nrf
26+
:members:

include/tone.h

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2020 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/** @file
8+
* @brief Tone generator header.
9+
*/
10+
11+
#ifndef __TONE_H__
12+
#define __TONE_H__
13+
14+
/**
15+
* @defgroup tone_gen Tone generator
16+
* @{
17+
* @brief Library for generating PCM-based period tones.
18+
*
19+
*/
20+
21+
#include <stdint.h>
22+
#include <stddef.h>
23+
24+
/**
25+
* @brief Generates one full pulse-code modulation (PCM) period of a tone with the
26+
* given parameters.
27+
*
28+
* @param tone User provided buffer. Must be large enough to hold
29+
* the generated PCM tone, depending on settings.
30+
* @param tone_size Resulting tone size.
31+
* @param tone_freq_hz The desired tone frequency in the range [100..10000] Hz.
32+
* @param smpl_freq_hz Sampling frequency.
33+
* @param amplitude Amplitude in the range [0..1].
34+
*
35+
* @retval 0 Tone generated.
36+
* @retval -ENXIO If tone or tone_size is NULL.
37+
* @retval -EINVAL If smpl_freq_hz == 0 or tone_freq_hz is out of range.
38+
* @retval -EPERM If amplitude is out of range.
39+
*/
40+
int tone_gen(int16_t *tone, size_t *tone_size, uint16_t tone_freq_hz, uint32_t smpl_freq_hz,
41+
float amplitude);
42+
43+
/**
44+
* @}
45+
*/
46+
47+
#endif /* __TONE_H__ */

lib/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ add_subdirectory_ifdef(CONFIG_IDENTITY_KEY identity_key)
4242
add_subdirectory_ifdef(CONFIG_SFLOAT sfloat)
4343
add_subdirectory_ifdef(CONFIG_CONTIN_ARRAY contin_array)
4444
add_subdirectory_ifdef(CONFIG_PCM_MIX pcm_mix)
45+
add_subdirectory_ifdef(CONFIG_TONE tone)

lib/Kconfig

+1
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@ rsource "identity_key/Kconfig"
4343
rsource "sfloat/Kconfig"
4444
rsource "contin_array/Kconfig"
4545
rsource "pcm_mix/Kconfig"
46+
rsource "tone/Kconfig"
4647

4748
endmenu

lib/tone/CMakeLists.txt

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#
2+
# Copyright (c) 2023 Nordic Semiconductor
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
zephyr_library()
8+
zephyr_library_sources(
9+
tone.c
10+
)

lib/tone/Kconfig

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright (c) 2023 Nordic Semiconductor
2+
#
3+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
4+
#
5+
6+
menuconfig TONE
7+
bool "TONE - Sinus creation library"
8+
help
9+
Library for creating tones
10+
11+
if TONE
12+
13+
module = TONE
14+
module-str = tone
15+
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"
16+
17+
endif #TONE
File renamed without changes.

tests/lib/tone/CMakeLists.txt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#
2+
# Copyright (c) 2023 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
cmake_minimum_required(VERSION 3.20.0)
8+
9+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
10+
project(tone)
11+
12+
FILE(GLOB app_sources src/*.c)
13+
target_sources(app PRIVATE ${app_sources})

tests/nrf5340_audio/tone/prj.conf tests/lib/tone/prj.conf

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ CONFIG_NEWLIB_LIBC=y
44
CONFIG_CMSIS_DSP_FASTMATH=y
55
CONFIG_CMSIS_DSP_TABLES=y
66
CONFIG_MAIN_STACK_SIZE=8192
7+
CONFIG_TONE=y
File renamed without changes.
File renamed without changes.

tests/nrf5340_audio/tone/CMakeLists.txt

-21
This file was deleted.

0 commit comments

Comments
 (0)