forked from nrfconnect/sdk-nrf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpcm_stream_channel_modifier.h
114 lines (102 loc) · 4.11 KB
/
pcm_stream_channel_modifier.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* Copyright (c) 2018 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
/** @file
* @brief PCM Stream Channel Modifier library header.
*/
#ifndef _PCM_STREAM_CHANNEL_MODIFIER_H_
#define _PCM_STREAM_CHANNEL_MODIFIER_H_
/**
* @defgroup pscm PCM Stream Channel Modifier library
* @brief Enables splitting of pulse-code modulation (PCM) streams from stereo to mono
* or combine mono streams to form a stereo stream.
*
* @{
*/
#include <zephyr/kernel.h>
#include <audio_defines.h>
/** @brief Adds a 0 after every sample from *input
* and writes it to *output.
* @note Use to create stereo stream from a mono source where one
* channel is silent.
*
* @param[in] input Pointer to the input buffer.
* @param[in] input_size Number of bytes in input.
* @param[in] channel Channel to contain the audio data.
* @param[in] pcm_bit_depth Bit depth of PCM samples (16, 24, or 32).
* @param[out] output Pointer to the output buffer.
* @param[out] output_size Number of bytes written to the output.
*
* @return 0 if success.
*/
int pscm_zero_pad(void const *const input, size_t input_size, enum audio_channel channel,
uint8_t pcm_bit_depth, void *output, size_t *output_size);
/** @brief Adds a copy of every sample from *input
* and writes it to both channels in *output.
* @note Use to create stereo stream from a mono source where both
* channels are identical.
*
* @param[in] input Pointer to the input buffer.
* @param[in] input_size Number of bytes in input.
* @param[in] pcm_bit_depth Bit depth of PCM samples (16, 24, or 32).
* @param[out] output Pointer to the output buffer.
* @param[out] output_size Number of bytes written to output.
*
* @return 0 if success.
*/
int pscm_copy_pad(void const *const input, size_t input_size, uint8_t pcm_bit_depth, void *output,
size_t *output_size);
/** @brief Combines two mono streams into one stereo stream.
*
* @param[in] input_left Pointer to the input buffer for the left channel.
* @param[in] input_right Pointer to the input buffer for the right channel.
* @param[in] input_size Number of bytes in the input. Same for both channels.
* @param[in] pcm_bit_depth Bit depth of PCM samples (16, 24, or 32).
* @param[out] output Pointer to the output buffer.
* @param[out] output_size Number of bytes written to the output.
*
* @return 0 if success.
*/
int pscm_combine(void const *const input_left, void const *const input_right, size_t input_size,
uint8_t pcm_bit_depth, void *output, size_t *output_size);
/** @brief Removes every second sample from *input
* and writes it to *output.
* @note Use to split stereo audio stream to single channel.
*
* @param[in] input Pointer to the input buffer.
* @param[in] input_size Number of bytes in the input. Must be
* divisible by two.
* @param[in] channel Channel to keep the audio data from.
* @param[in] pcm_bit_depth Bit depth of PCM samples (16, 24, or 32).
* @param[out] output Pointer to the output buffer.
* @param[out] output_size Number of bytes written to the output.
*
* @return 0 if success.
*/
int pscm_one_channel_split(void const *const input, size_t input_size,
enum audio_channel channel, uint8_t pcm_bit_depth, void *output,
size_t *output_size);
/** @brief Splits a stereo stream to two separate mono streams.
* @note Use to split stereo audio stream to two separate channels.
*
* @param[in] input Pointer to the input buffer.
* @param[in] input_size Number of bytes in input. Must be
* divisible by two.
* @param[in] pcm_bit_depth Bit depth of PCM samples (16, 24, or 32).
* @param[out] output_left Pointer to the output buffer containing
* the left channel.
* @param[out] output_right Pointer to the output buffer containing
* the right channel.
* @param[out] output_size Number of bytes written to the output,
* same for both channels.
*
* @return 0 if success.
*/
int pscm_two_channel_split(void const *const input, size_t input_size, uint8_t pcm_bit_depth,
void *output_left, void *output_right, size_t *output_size);
/**
* @}
*/
#endif /* _PCM_STREAM_CHANNEL_MODIFIER_H_ */