|
21 | 21 |
|
22 | 22 | #include <sof/audio/buffer.h> |
23 | 23 | #include <sof/audio/format.h> |
| 24 | +#include <sof/math/a_law.h> |
24 | 25 | #include <rtos/bit.h> |
25 | 26 | #include <sof/common.h> |
26 | 27 | #include <sof/compiler_attributes.h> |
@@ -93,6 +94,66 @@ static int pcm_convert_s32_to_u8(const struct audio_stream *source, |
93 | 94 | } |
94 | 95 | #endif /* CONFIG_PCM_CONVERTER_FORMAT_U8 && CONFIG_PCM_CONVERTER_FORMAT_S32LE */ |
95 | 96 |
|
| 97 | +#if CONFIG_PCM_CONVERTER_FORMAT_A_LAW && CONFIG_PCM_CONVERTER_FORMAT_S32LE |
| 98 | +static int pcm_convert_alaw_to_s32(const struct audio_stream *source, |
| 99 | + uint32_t ioffset, struct audio_stream *sink, |
| 100 | + uint32_t ooffset, uint32_t samples, uint32_t chmap) |
| 101 | +{ |
| 102 | + const uint8_t *src = audio_stream_get_rptr(source); |
| 103 | + int32_t *dst = audio_stream_get_wptr(sink); |
| 104 | + uint32_t processed; |
| 105 | + uint32_t nmax, i, n; |
| 106 | + |
| 107 | + src += ioffset; |
| 108 | + dst += ooffset; |
| 109 | + for (processed = 0; processed < samples; processed += n) { |
| 110 | + src = audio_stream_wrap(source, (void *)src); |
| 111 | + dst = audio_stream_wrap(sink, dst); |
| 112 | + n = samples - processed; |
| 113 | + nmax = audio_stream_bytes_without_wrap(source, src) >> BYTES_TO_U8_SAMPLES; |
| 114 | + n = MIN(n, nmax); |
| 115 | + nmax = audio_stream_bytes_without_wrap(sink, dst) >> BYTES_TO_S32_SAMPLES; |
| 116 | + n = MIN(n, nmax); |
| 117 | + for (i = 0; i < n; i++) { |
| 118 | + *dst = sofm_a_law_decode(*src) << 16; |
| 119 | + src++; |
| 120 | + dst++; |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + return samples; |
| 125 | +} |
| 126 | + |
| 127 | +static int pcm_convert_s32_to_alaw(const struct audio_stream *source, |
| 128 | + uint32_t ioffset, struct audio_stream *sink, |
| 129 | + uint32_t ooffset, uint32_t samples, uint32_t chmap) |
| 130 | +{ |
| 131 | + const int32_t *src = audio_stream_get_rptr(source); |
| 132 | + uint8_t *dst = audio_stream_get_wptr(sink); |
| 133 | + uint32_t processed; |
| 134 | + uint32_t nmax, i, n; |
| 135 | + |
| 136 | + src += ioffset; |
| 137 | + dst += ooffset; |
| 138 | + for (processed = 0; processed < samples; processed += n) { |
| 139 | + src = audio_stream_wrap(source, (void *)src); |
| 140 | + dst = audio_stream_wrap(sink, dst); |
| 141 | + n = samples - processed; |
| 142 | + nmax = audio_stream_bytes_without_wrap(source, src) >> BYTES_TO_S32_SAMPLES; |
| 143 | + n = MIN(n, nmax); |
| 144 | + nmax = audio_stream_bytes_without_wrap(sink, dst) >> BYTES_TO_U8_SAMPLES; |
| 145 | + n = MIN(n, nmax); |
| 146 | + for (i = 0; i < n; i++) { |
| 147 | + *dst = sofm_a_law_encode(*src >> 16); |
| 148 | + src++; |
| 149 | + dst++; |
| 150 | + } |
| 151 | + } |
| 152 | + |
| 153 | + return samples; |
| 154 | +} |
| 155 | +#endif /* CONFIG_PCM_CONVERTER_FORMAT_A_LAW && CONFIG_PCM_CONVERTER_FORMAT_S32LE */ |
| 156 | + |
96 | 157 | #if CONFIG_PCM_CONVERTER_FORMAT_S16LE && CONFIG_PCM_CONVERTER_FORMAT_S24LE |
97 | 158 |
|
98 | 159 | static int pcm_convert_s16_to_s24(const struct audio_stream *source, |
@@ -555,6 +616,13 @@ const struct pcm_func_map pcm_func_map[] = { |
555 | 616 | { SOF_IPC_FRAME_U8, SOF_IPC_FRAME_S32_LE, pcm_convert_u8_to_s32 }, |
556 | 617 | { SOF_IPC_FRAME_S32_LE, SOF_IPC_FRAME_U8, pcm_convert_s32_to_u8 }, |
557 | 618 | #endif /* CONFIG_PCM_CONVERTER_FORMAT_U8 && CONFIG_PCM_CONVERTER_FORMAT_S32LE */ |
| 619 | +#if CONFIG_PCM_CONVERTER_FORMAT_A_LAW |
| 620 | + { SOF_IPC_FRAME_A_LAW, SOF_IPC_FRAME_A_LAW, just_copy }, |
| 621 | +#endif /* CONFIG_PCM_CONVERTER_FORMAT_A_LAW */ |
| 622 | +#if CONFIG_PCM_CONVERTER_FORMAT_A_LAW && CONFIG_PCM_CONVERTER_FORMAT_S32LE |
| 623 | + { SOF_IPC_FRAME_A_LAW, SOF_IPC_FRAME_S32_LE, pcm_convert_alaw_to_s32 }, |
| 624 | + { SOF_IPC_FRAME_S32_LE, SOF_IPC_FRAME_A_LAW, pcm_convert_s32_to_alaw }, |
| 625 | +#endif /* CONFIG_PCM_CONVERTER_FORMAT_A_LAW && CONFIG_PCM_CONVERTER_FORMAT_S32LE */ |
558 | 626 | #if CONFIG_PCM_CONVERTER_FORMAT_S16LE |
559 | 627 | { SOF_IPC_FRAME_S16_LE, SOF_IPC_FRAME_S16_LE, just_copy }, |
560 | 628 | #endif /* CONFIG_PCM_CONVERTER_FORMAT_S16LE */ |
|
0 commit comments