Skip to content

Commit fe83dd7

Browse files
committed
Audio: PCM Converter: Add support for 8-bit S8 format
This patch adds to PCM converter the support to convert between S8 and S32_LE formats. Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
1 parent 46e12d7 commit fe83dd7

File tree

5 files changed

+90
-0
lines changed

5 files changed

+90
-0
lines changed

app/boards/intel_adsp/Kconfig.defconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ config FORMAT_MU_LAW
2929
config FORMAT_U8
3030
default y
3131

32+
config FORMAT_S8
33+
default y
34+
3235
config PCM_CONVERTER_FORMAT_A_LAW
3336
default y
3437

@@ -59,5 +62,8 @@ config PCM_CONVERTER_FORMAT_S24_C32_AND_S24_C24
5962
config PCM_CONVERTER_FORMAT_U8
6063
default y
6164

65+
config PCM_CONVERTER_FORMAT_S8
66+
default y
67+
6268
config PIPELINE_2_0
6369
default y

src/audio/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ config FORMAT_U8
168168
help
169169
Support unsigned 8 bit processing data format
170170

171+
config FORMAT_S8
172+
bool "Support S8"
173+
help
174+
Support signed 8 bit processing data format
175+
171176
config FORMAT_A_LAW
172177
bool "Support A-law"
173178
help
@@ -224,6 +229,11 @@ config PCM_CONVERTER_FORMAT_U8
224229
help
225230
Support 8 bit processing data format without sign
226231

232+
config PCM_CONVERTER_FORMAT_S8
233+
bool "Support S8"
234+
help
235+
Support signed 8 bit processing data format
236+
227237
config PCM_CONVERTER_FORMAT_A_LAW
228238
bool "Support A-law"
229239
select MATH_A_LAW_CODEC

src/audio/pcm_converter/pcm_converter_generic.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,66 @@ static int pcm_convert_s32_to_u8(const struct audio_stream *source,
9595
}
9696
#endif /* CONFIG_PCM_CONVERTER_FORMAT_U8 && CONFIG_PCM_CONVERTER_FORMAT_S32LE */
9797

98+
#if CONFIG_PCM_CONVERTER_FORMAT_S8 && CONFIG_PCM_CONVERTER_FORMAT_S32LE
99+
static int pcm_convert_s8_to_s32(const struct audio_stream *source,
100+
uint32_t ioffset, struct audio_stream *sink,
101+
uint32_t ooffset, uint32_t samples, uint32_t chmap)
102+
{
103+
int8_t *src = audio_stream_get_rptr(source);
104+
int32_t *dst = audio_stream_get_wptr(sink);
105+
uint32_t processed;
106+
uint32_t nmax, i, n;
107+
108+
src += ioffset;
109+
dst += ooffset;
110+
for (processed = 0; processed < samples; processed += n) {
111+
src = audio_stream_wrap(source, src);
112+
dst = audio_stream_wrap(sink, dst);
113+
n = samples - processed;
114+
nmax = audio_stream_bytes_without_wrap(source, src) >> BYTES_TO_U8_SAMPLES;
115+
n = MIN(n, nmax);
116+
nmax = audio_stream_bytes_without_wrap(sink, dst) >> BYTES_TO_S32_SAMPLES;
117+
n = MIN(n, nmax);
118+
for (i = 0; i < n; i++) {
119+
*dst = *src << 24;
120+
src++;
121+
dst++;
122+
}
123+
}
124+
125+
return samples;
126+
}
127+
128+
static int pcm_convert_s32_to_s8(const struct audio_stream *source,
129+
uint32_t ioffset, struct audio_stream *sink,
130+
uint32_t ooffset, uint32_t samples, uint32_t chmap)
131+
{
132+
int32_t *src = audio_stream_get_rptr(source);
133+
int8_t *dst = audio_stream_get_wptr(sink);
134+
uint32_t processed;
135+
uint32_t nmax, i, n;
136+
137+
src += ioffset;
138+
dst += ooffset;
139+
for (processed = 0; processed < samples; processed += n) {
140+
src = audio_stream_wrap(source, src);
141+
dst = audio_stream_wrap(sink, dst);
142+
n = samples - processed;
143+
nmax = audio_stream_bytes_without_wrap(source, src) >> BYTES_TO_S32_SAMPLES;
144+
n = MIN(n, nmax);
145+
nmax = audio_stream_bytes_without_wrap(sink, dst) >> BYTES_TO_U8_SAMPLES;
146+
n = MIN(n, nmax);
147+
for (i = 0; i < n; i++) {
148+
*dst = sat_int8(Q_SHIFT_RND(*src, 24, 0));
149+
src++;
150+
dst++;
151+
}
152+
}
153+
154+
return samples;
155+
}
156+
#endif /* CONFIG_PCM_CONVERTER_FORMAT_S8 && CONFIG_PCM_CONVERTER_FORMAT_S32LE */
157+
98158
#if CONFIG_PCM_CONVERTER_FORMAT_A_LAW && CONFIG_PCM_CONVERTER_FORMAT_S32LE
99159
static int pcm_convert_alaw_to_s32(const struct audio_stream *source,
100160
uint32_t ioffset, struct audio_stream *sink,
@@ -677,6 +737,13 @@ const struct pcm_func_map pcm_func_map[] = {
677737
{ SOF_IPC_FRAME_U8, SOF_IPC_FRAME_S32_LE, pcm_convert_u8_to_s32 },
678738
{ SOF_IPC_FRAME_S32_LE, SOF_IPC_FRAME_U8, pcm_convert_s32_to_u8 },
679739
#endif /* CONFIG_PCM_CONVERTER_FORMAT_U8 && CONFIG_PCM_CONVERTER_FORMAT_S32LE */
740+
#if CONFIG_PCM_CONVERTER_FORMAT_S8
741+
{ SOF_IPC_FRAME_S8, SOF_IPC_FRAME_S8, just_copy },
742+
#endif /* CONFIG_PCM_CONVERTER_FORMAT_S8 */
743+
#if CONFIG_PCM_CONVERTER_FORMAT_S8 && CONFIG_PCM_CONVERTER_FORMAT_S32LE
744+
{ SOF_IPC_FRAME_S8, SOF_IPC_FRAME_S32_LE, pcm_convert_s8_to_s32 },
745+
{ SOF_IPC_FRAME_S32_LE, SOF_IPC_FRAME_S8, pcm_convert_s32_to_s8 },
746+
#endif /* CONFIG_PCM_CONVERTER_FORMAT_S8 && CONFIG_PCM_CONVERTER_FORMAT_S32LE */
680747
#if CONFIG_PCM_CONVERTER_FORMAT_A_LAW
681748
{ SOF_IPC_FRAME_A_LAW, SOF_IPC_FRAME_A_LAW, just_copy },
682749
#endif /* CONFIG_PCM_CONVERTER_FORMAT_A_LAW */

src/include/module/ipc/stream.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ enum sof_ipc_frame {
2525
SOF_IPC_FRAME_S16_4LE, /* 16-bit in 32-bit container */
2626
SOF_IPC_FRAME_A_LAW,
2727
SOF_IPC_FRAME_MU_LAW,
28+
SOF_IPC_FRAME_S8,
2829
SOF_IPC_FRAME_INVALID, /* keep last */
2930
};
3031

src/include/sof/audio/audio_stream.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,12 @@ static inline int audio_stream_fmt_conversion(enum ipc4_bit_depth depth,
10361036
*valid_fmt = SOF_IPC_FRAME_S24_3LE;
10371037
ret = 0;
10381038
#endif
1039+
} else if (depth == 8 && valid == 8) {
1040+
#ifdef CONFIG_FORMAT_S8
1041+
*frame_fmt = SOF_IPC_FRAME_S8;
1042+
*valid_fmt = SOF_IPC_FRAME_S8;
1043+
ret = 0;
1044+
#endif /* CONFIG_FORMAT_S8 */
10391045
} else {
10401046
/* IPC4_DEPTH_16BIT (16) <---> SOF_IPC_FRAME_S16_LE (0)
10411047
* IPC4_DEPTH_24BIT (24) <---> SOF_IPC_FRAME_S24_4LE (1)

0 commit comments

Comments
 (0)