nRF Connect SDK API 0.1.0
Loading...
Searching...
No Matches
sw_codec_select.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
7#ifndef _SW_CODEC_SELECT_H_
8#define _SW_CODEC_SELECT_H_
9
10#include <zephyr/kernel.h>
11#include "channel_assignment.h"
12
13#if (CONFIG_SW_CODEC_LC3)
14#define LC3_MAX_FRAME_SIZE_MS 10
15#define LC3_ENC_MONO_FRAME_SIZE (CONFIG_LC3_BITRATE_MAX * LC3_MAX_FRAME_SIZE_MS / (8 * 1000))
16
17#define LC3_PCM_NUM_BYTES_MONO \
18 (CONFIG_AUDIO_SAMPLE_RATE_HZ * CONFIG_AUDIO_BIT_DEPTH_OCTETS * LC3_MAX_FRAME_SIZE_MS / 1000)
19#define LC3_ENC_TIME_US 3000
20#define LC3_DEC_TIME_US 1500
21#else
22#define LC3_ENC_MONO_FRAME_SIZE 0
23#define LC3_PCM_NUM_BYTES_MONO 0
24#define LC3_ENC_TIME_US 0
25#define LC3_DEC_TIME_US 0
26#endif /* CONFIG_SW_CODEC_LC3 */
27
28/* Max will be used when multiple codecs are supported */
29#define ENC_MAX_FRAME_SIZE MAX(LC3_ENC_MONO_FRAME_SIZE, 0)
30#define ENC_TIME_US MAX(LC3_ENC_TIME_US, 0)
31#define DEC_TIME_US MAX(LC3_DEC_TIME_US, 0)
32#define PCM_NUM_BYTES_MONO MAX(LC3_PCM_NUM_BYTES_MONO, 0)
33#define PCM_NUM_BYTES_STEREO (PCM_NUM_BYTES_MONO * 2)
34
37 SW_CODEC_LC3, /* Low Complexity Communication Codec */
38};
39
43};
44
46 bool enabled;
49 uint8_t num_ch;
52};
53
55 bool enabled;
56 enum sw_codec_channel_mode channel_mode; /* Mono or stereo. */
57 uint8_t num_ch; /* Number of decoder channels. */
58 enum audio_channel audio_ch; /* Used to choose which channel to use. */
60};
61
66 enum sw_codec_select sw_codec; /* sw_codec to be used, e.g. LC3, etc. */
67 struct sw_codec_decoder decoder; /* Struct containing settings for decoder. */
68 struct sw_codec_encoder encoder; /* Struct containing settings for encoder. */
69 bool initialized; /* Status of codec. */
70};
71
79
93int sw_codec_encode(void *pcm_data, size_t pcm_size, uint8_t **encoded_data, size_t *encoded_size);
94
106int sw_codec_decode(uint8_t const *const encoded_data, size_t encoded_size, bool bad_frame,
107 void **pcm_data, size_t *pcm_size);
108
118int sw_codec_uninit(struct sw_codec_config sw_codec_cfg);
119
129int sw_codec_init(struct sw_codec_config sw_codec_cfg);
130
131#endif /* _SW_CODEC_SELECT_H_ */
audio_channel
Audio channel assignment values.
Definition: audio_defines.h:20
Audio channel assignment.
struct sw_codec_decoder decoder
Definition: sw_codec_select.h:67
struct sw_codec_encoder encoder
Definition: sw_codec_select.h:68
enum sw_codec_select sw_codec
Definition: sw_codec_select.h:66
bool initialized
Definition: sw_codec_select.h:69
Sw_codec configuration structure.
Definition: sw_codec_select.h:65
uint8_t num_ch
Definition: sw_codec_select.h:57
enum audio_channel audio_ch
Definition: sw_codec_select.h:58
bool enabled
Definition: sw_codec_select.h:55
enum sw_codec_channel_mode channel_mode
Definition: sw_codec_select.h:56
uint32_t sample_rate_hz
Definition: sw_codec_select.h:59
Definition: sw_codec_select.h:54
uint8_t num_ch
Definition: sw_codec_select.h:49
int bitrate
Definition: sw_codec_select.h:47
bool enabled
Definition: sw_codec_select.h:46
uint32_t sample_rate_hz
Definition: sw_codec_select.h:51
enum sw_codec_channel_mode channel_mode
Definition: sw_codec_select.h:48
enum audio_channel audio_ch
Definition: sw_codec_select.h:50
Definition: sw_codec_select.h:45
int sw_codec_init(struct sw_codec_config sw_codec_cfg)
Initialize the software codec and statically or dynamically allocate memory to be used,...
sw_codec_channel_mode
Definition: sw_codec_select.h:40
@ SW_CODEC_STEREO
Definition: sw_codec_select.h:42
@ SW_CODEC_MONO
Definition: sw_codec_select.h:41
int sw_codec_decode(uint8_t const *const encoded_data, size_t encoded_size, bool bad_frame, void **pcm_data, size_t *pcm_size)
Decode encoded data and output PCM data.
bool sw_codec_is_initialized(void)
Check if the software codec is initialized.
int sw_codec_uninit(struct sw_codec_config sw_codec_cfg)
Uninitialize the software codec and free the allocated space.
sw_codec_select
Definition: sw_codec_select.h:35
@ SW_CODEC_LC3
Definition: sw_codec_select.h:37
@ SW_CODEC_NONE
Definition: sw_codec_select.h:36
int sw_codec_encode(void *pcm_data, size_t pcm_size, uint8_t **encoded_data, size_t *encoded_size)
Encode PCM data and output encoded data.