Tone generator

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. For more information, see API documentation.

Configuration

To enable the library, set the CONFIG_TONE Kconfig option to y in the project configuration file prj.conf.

API documentation

Header file: include/tone.h
Source file: lib/tone/tone.c
group tone_gen

Library for generating PCM-based period tones.

Functions

int tone_gen(int16_t *tone, size_t *tone_size, uint16_t tone_freq_hz, uint32_t smpl_freq_hz, float amplitude)

Generates one full pulse-code modulation (PCM) period of a tone with the given parameters.

Parameters:
  • tone – User provided buffer. Must be large enough to hold the generated PCM tone, depending on settings.

  • tone_size – Resulting tone size.

  • tone_freq_hz – The desired tone frequency in the range [100..10000] Hz.

  • smpl_freq_hz – Sampling frequency.

  • amplitude – Amplitude in the range [0..1].

Return values:
  • 0 – Tone generated.

  • -ENXIO – If tone or tone_size is NULL.

  • -EINVAL – If smpl_freq_hz == 0 or tone_freq_hz is out of range.

  • -EPERM – If amplitude is out of range.