|
22 | 22 | #include <sof/audio/buffer.h> |
23 | 23 | #include <sof/audio/format.h> |
24 | 24 | #include <sof/math/a_law.h> |
| 25 | +#include <sof/math/mu_law.h> |
25 | 26 | #include <rtos/bit.h> |
26 | 27 | #include <sof/common.h> |
27 | 28 | #include <sof/compiler_attributes.h> |
@@ -154,6 +155,66 @@ static int pcm_convert_s32_to_alaw(const struct audio_stream *source, |
154 | 155 | } |
155 | 156 | #endif /* CONFIG_PCM_CONVERTER_FORMAT_A_LAW && CONFIG_PCM_CONVERTER_FORMAT_S32LE */ |
156 | 157 |
|
| 158 | +#if CONFIG_PCM_CONVERTER_FORMAT_MU_LAW && CONFIG_PCM_CONVERTER_FORMAT_S32LE |
| 159 | +static int pcm_convert_mulaw_to_s32(const struct audio_stream *source, |
| 160 | + uint32_t ioffset, struct audio_stream *sink, |
| 161 | + uint32_t ooffset, uint32_t samples, uint32_t chmap) |
| 162 | +{ |
| 163 | + const uint8_t *src = audio_stream_get_rptr(source); |
| 164 | + int32_t *dst = audio_stream_get_wptr(sink); |
| 165 | + uint32_t processed; |
| 166 | + uint32_t nmax, i, n; |
| 167 | + |
| 168 | + src += ioffset; |
| 169 | + dst += ooffset; |
| 170 | + for (processed = 0; processed < samples; processed += n) { |
| 171 | + src = audio_stream_wrap(source, (void *)src); |
| 172 | + dst = audio_stream_wrap(sink, dst); |
| 173 | + n = samples - processed; |
| 174 | + nmax = audio_stream_bytes_without_wrap(source, src) >> BYTES_TO_U8_SAMPLES; |
| 175 | + n = MIN(n, nmax); |
| 176 | + nmax = audio_stream_bytes_without_wrap(sink, dst) >> BYTES_TO_S32_SAMPLES; |
| 177 | + n = MIN(n, nmax); |
| 178 | + for (i = 0; i < n; i++) { |
| 179 | + *dst = sofm_mu_law_decode(*src) << 16; |
| 180 | + src++; |
| 181 | + dst++; |
| 182 | + } |
| 183 | + } |
| 184 | + |
| 185 | + return samples; |
| 186 | +} |
| 187 | + |
| 188 | +static int pcm_convert_s32_to_mulaw(const struct audio_stream *source, |
| 189 | + uint32_t ioffset, struct audio_stream *sink, |
| 190 | + uint32_t ooffset, uint32_t samples, uint32_t chmap) |
| 191 | +{ |
| 192 | + const int32_t *src = audio_stream_get_rptr(source); |
| 193 | + uint8_t *dst = audio_stream_get_wptr(sink); |
| 194 | + uint32_t processed; |
| 195 | + uint32_t nmax, i, n; |
| 196 | + |
| 197 | + src += ioffset; |
| 198 | + dst += ooffset; |
| 199 | + for (processed = 0; processed < samples; processed += n) { |
| 200 | + src = audio_stream_wrap(source, (void *)src); |
| 201 | + dst = audio_stream_wrap(sink, dst); |
| 202 | + n = samples - processed; |
| 203 | + nmax = audio_stream_bytes_without_wrap(source, src) >> BYTES_TO_S32_SAMPLES; |
| 204 | + n = MIN(n, nmax); |
| 205 | + nmax = audio_stream_bytes_without_wrap(sink, dst) >> BYTES_TO_U8_SAMPLES; |
| 206 | + n = MIN(n, nmax); |
| 207 | + for (i = 0; i < n; i++) { |
| 208 | + *dst = sofm_mu_law_encode(*src >> 16); |
| 209 | + src++; |
| 210 | + dst++; |
| 211 | + } |
| 212 | + } |
| 213 | + |
| 214 | + return samples; |
| 215 | +} |
| 216 | +#endif /* CONFIG_PCM_CONVERTER_FORMAT_MU_LAW && CONFIG_PCM_CONVERTER_FORMAT_S32LE */ |
| 217 | + |
157 | 218 | #if CONFIG_PCM_CONVERTER_FORMAT_S16LE && CONFIG_PCM_CONVERTER_FORMAT_S24LE |
158 | 219 |
|
159 | 220 | static int pcm_convert_s16_to_s24(const struct audio_stream *source, |
@@ -623,6 +684,13 @@ const struct pcm_func_map pcm_func_map[] = { |
623 | 684 | { SOF_IPC_FRAME_A_LAW, SOF_IPC_FRAME_S32_LE, pcm_convert_alaw_to_s32 }, |
624 | 685 | { SOF_IPC_FRAME_S32_LE, SOF_IPC_FRAME_A_LAW, pcm_convert_s32_to_alaw }, |
625 | 686 | #endif /* CONFIG_PCM_CONVERTER_FORMAT_A_LAW && CONFIG_PCM_CONVERTER_FORMAT_S32LE */ |
| 687 | +#if CONFIG_PCM_CONVERTER_FORMAT_MU_LAW |
| 688 | + { SOF_IPC_FRAME_MU_LAW, SOF_IPC_FRAME_MU_LAW, just_copy }, |
| 689 | +#endif /* CONFIG_PCM_CONVERTER_FORMAT_MU_LAW */ |
| 690 | +#if CONFIG_PCM_CONVERTER_FORMAT_MU_LAW && CONFIG_PCM_CONVERTER_FORMAT_S32LE |
| 691 | + { SOF_IPC_FRAME_MU_LAW, SOF_IPC_FRAME_S32_LE, pcm_convert_mulaw_to_s32 }, |
| 692 | + { SOF_IPC_FRAME_S32_LE, SOF_IPC_FRAME_MU_LAW, pcm_convert_s32_to_mulaw }, |
| 693 | +#endif /* CONFIG_PCM_CONVERTER_FORMAT_A_LAW && CONFIG_PCM_CONVERTER_FORMAT_S32LE */ |
626 | 694 | #if CONFIG_PCM_CONVERTER_FORMAT_S16LE |
627 | 695 | { SOF_IPC_FRAME_S16_LE, SOF_IPC_FRAME_S16_LE, just_copy }, |
628 | 696 | #endif /* CONFIG_PCM_CONVERTER_FORMAT_S16LE */ |
|
0 commit comments