Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017, Intel Corporation |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * * Neither the name of the Intel Corporation nor the |
| 13 | * names of its contributors may be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 26 | * POSSIBILITY OF SUCH DAMAGE. |
| 27 | * |
| 28 | * Author: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com> |
| 29 | * Liam Girdwood <liam.r.girdwood@linux.intel.com> |
| 30 | * Keyon Jie <yang.jie@linux.intel.com> |
| 31 | */ |
| 32 | |
| 33 | #include <stdint.h> |
| 34 | #include <stddef.h> |
| 35 | #include <errno.h> |
| 36 | #include <reef/reef.h> |
| 37 | #include <reef/lock.h> |
| 38 | #include <reef/list.h> |
| 39 | #include <reef/stream.h> |
| 40 | #include <reef/alloc.h> |
| 41 | #include <reef/work.h> |
| 42 | #include <reef/clock.h> |
| 43 | #include <reef/audio/component.h> |
| 44 | #include <reef/audio/pipeline.h> |
Liam Girdwood | 1764152 | 2017-06-09 17:27:02 +0100 | [diff] [blame] | 45 | #include <uapi/ipc.h> |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 46 | #include "src_core.h" |
| 47 | |
| 48 | #ifdef MODULE_TEST |
| 49 | #include <stdio.h> |
| 50 | #endif |
| 51 | |
| 52 | #define trace_src(__e) trace_event(TRACE_CLASS_SRC, __e) |
| 53 | #define tracev_src(__e) tracev_event(TRACE_CLASS_SRC, __e) |
| 54 | #define trace_src_error(__e) trace_error(TRACE_CLASS_SRC, __e) |
| 55 | |
| 56 | /* src component private data */ |
| 57 | struct comp_data { |
Seppo Ingalsuo | 4b007cb | 2017-10-20 18:45:30 +0300 | [diff] [blame] | 58 | struct polyphase_src src; |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 59 | struct src_param param; |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 60 | int32_t *delay_lines; |
Liam Girdwood | 3488cce | 2017-08-10 11:59:08 +0100 | [diff] [blame] | 61 | uint32_t sink_rate; |
| 62 | uint32_t source_rate; |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 63 | int32_t *sbuf_w_ptr; |
| 64 | int32_t *sbuf_r_ptr; |
| 65 | int sbuf_avail; |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 66 | void (* src_func)(struct comp_dev *dev, |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 67 | struct comp_buffer *source, |
| 68 | struct comp_buffer *sink, |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 69 | size_t *consumed, |
| 70 | size_t *produced); |
Seppo Ingalsuo | 4b007cb | 2017-10-20 18:45:30 +0300 | [diff] [blame] | 71 | void (* polyphase_func)(struct src_stage_prm *s); |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 72 | }; |
| 73 | |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 74 | /* Fallback function */ |
Seppo Ingalsuo | 4b007cb | 2017-10-20 18:45:30 +0300 | [diff] [blame] | 75 | static void src_fallback(struct comp_dev *dev, struct comp_buffer *source, |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 76 | struct comp_buffer *sink, size_t *bytes_read, size_t *bytes_written) |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 77 | { |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 78 | *bytes_read = 0; |
| 79 | *bytes_written = 0; |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /* Normal 2 stage SRC */ |
| 83 | static void src_2s_s32_default(struct comp_dev *dev, |
| 84 | struct comp_buffer *source, struct comp_buffer *sink, |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 85 | size_t *bytes_read, size_t *bytes_written) |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 86 | { |
Pierre-Louis Bossart | 4ccf81d | 2017-09-25 14:52:09 -0500 | [diff] [blame] | 87 | struct src_stage_prm s1; |
| 88 | struct src_stage_prm s2; |
Seppo Ingalsuo | 4b007cb | 2017-10-20 18:45:30 +0300 | [diff] [blame] | 89 | int s1_blk_in; |
| 90 | int s1_blk_out; |
| 91 | int s2_blk_in; |
| 92 | int s2_blk_out; |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 93 | struct comp_data *cd = comp_get_drvdata(dev); |
| 94 | int32_t *dest = (int32_t *) sink->w_ptr; |
| 95 | int32_t *src = (int32_t *) source->r_ptr; |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 96 | int32_t *sbuf_end_addr = &cd->delay_lines[cd->param.sbuf_length]; |
| 97 | int32_t sbuf_size = cd->param.sbuf_length * sizeof(int32_t); |
Seppo Ingalsuo | 4b007cb | 2017-10-20 18:45:30 +0300 | [diff] [blame] | 98 | int nch = dev->params.channels; |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 99 | int sbuf_free = cd->param.sbuf_length - cd->sbuf_avail; |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 100 | int n_read = 0; |
| 101 | int n_written = 0; |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 102 | int n1 = 0; |
| 103 | int n2 = 0; |
Seppo Ingalsuo | 4b007cb | 2017-10-20 18:45:30 +0300 | [diff] [blame] | 104 | int avail_b = source->avail; |
| 105 | int free_b = sink->free; |
| 106 | int sz = sizeof(int32_t); |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 107 | |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 108 | s1.x_end_addr = source->end_addr; |
Liam Girdwood | 4450924 | 2017-09-07 15:34:42 +0100 | [diff] [blame] | 109 | s1.x_size = source->size; |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 110 | s1.y_end_addr = sbuf_end_addr; |
| 111 | s1.y_size = sbuf_size; |
Seppo Ingalsuo | 4b007cb | 2017-10-20 18:45:30 +0300 | [diff] [blame] | 112 | s1.state = &cd->src.state1; |
| 113 | s1.stage = cd->src.stage1; |
| 114 | s1.x_rptr = src; |
| 115 | s1.y_wptr = cd->sbuf_w_ptr; |
| 116 | s1.nch = nch; |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 117 | |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 118 | s2.x_end_addr = sbuf_end_addr; |
| 119 | s2.x_size = sbuf_size; |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 120 | s2.y_end_addr = sink->end_addr; |
Liam Girdwood | 4450924 | 2017-09-07 15:34:42 +0100 | [diff] [blame] | 121 | s2.y_size = sink->size; |
Seppo Ingalsuo | 4b007cb | 2017-10-20 18:45:30 +0300 | [diff] [blame] | 122 | s2.state = &cd->src.state2; |
| 123 | s2.stage = cd->src.stage2; |
| 124 | s2.x_rptr = cd->sbuf_r_ptr; |
| 125 | s2.y_wptr = dest; |
| 126 | s2.nch = nch; |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 127 | |
Seppo Ingalsuo | 4b007cb | 2017-10-20 18:45:30 +0300 | [diff] [blame] | 128 | |
| 129 | /* Test if 1st stage can be run with default block length to reach |
| 130 | * the period length or just under it. |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 131 | */ |
Seppo Ingalsuo | 4b007cb | 2017-10-20 18:45:30 +0300 | [diff] [blame] | 132 | s1.times = cd->param.stage1_times; |
| 133 | s1_blk_in = s1.times * cd->src.stage1->blk_in * nch; |
| 134 | s1_blk_out = s1.times * cd->src.stage1->blk_out * nch; |
| 135 | if ((avail_b >= s1_blk_in * sz) && (sbuf_free >= s1_blk_out)) { |
| 136 | cd->polyphase_func(&s1); |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 137 | |
Seppo Ingalsuo | 4b007cb | 2017-10-20 18:45:30 +0300 | [diff] [blame] | 138 | cd->sbuf_w_ptr = s1.y_wptr; |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 139 | cd->sbuf_avail += s1_blk_out; |
Seppo Ingalsuo | 4b007cb | 2017-10-20 18:45:30 +0300 | [diff] [blame] | 140 | n_read += s1_blk_in; |
| 141 | avail_b -= s1_blk_in * sz; |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 142 | sbuf_free -= s1_blk_out; |
Seppo Ingalsuo | 4b007cb | 2017-10-20 18:45:30 +0300 | [diff] [blame] | 143 | n1 = s1.times; |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 144 | } |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 145 | |
Seppo Ingalsuo | 4b007cb | 2017-10-20 18:45:30 +0300 | [diff] [blame] | 146 | /* Run one block at time the remaining data for 1st stage. */ |
| 147 | s1.times = 1; |
| 148 | s1_blk_in = cd->src.stage1->blk_in * nch; |
| 149 | s1_blk_out = cd->src.stage1->blk_out * nch; |
| 150 | while ((n1 < cd->param.stage1_times_max) && (avail_b >= s1_blk_in * sz) |
| 151 | && (sbuf_free >= s1_blk_out)) { |
| 152 | cd->polyphase_func(&s1); |
| 153 | |
| 154 | cd->sbuf_w_ptr = s1.y_wptr; |
| 155 | cd->sbuf_avail += s1_blk_out; |
| 156 | n_read += s1_blk_in; |
| 157 | avail_b -= s1_blk_in * sz; |
| 158 | sbuf_free -= s1_blk_out; |
| 159 | n1 += s1.times; |
| 160 | } |
| 161 | |
| 162 | /* Test if 2nd stage can be run with default block length. */ |
| 163 | s2.times = cd->param.stage2_times; |
| 164 | s2_blk_in = s2.times * cd->src.stage2->blk_in * nch; |
| 165 | s2_blk_out = s2.times * cd->src.stage2->blk_out * nch; |
| 166 | if ((cd->sbuf_avail >= s2_blk_in) && (free_b >= s2_blk_out * sz)) { |
| 167 | cd->polyphase_func(&s2); |
| 168 | |
| 169 | cd->sbuf_r_ptr = s2.x_rptr; |
| 170 | cd->sbuf_avail -= s2_blk_in; |
| 171 | free_b -= s2_blk_out * sz; |
| 172 | n_written += s2_blk_out; |
| 173 | n2 = s2.times; |
| 174 | } |
| 175 | |
| 176 | |
| 177 | /* Run one block at time the remaining 2nd stage output */ |
| 178 | s2.times = 1; |
| 179 | s2_blk_in = cd->src.stage2->blk_in * nch; |
| 180 | s2_blk_out = cd->src.stage2->blk_out * nch; |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 181 | while ((n2 < cd->param.stage2_times_max) |
| 182 | && (cd->sbuf_avail >= s2_blk_in) |
Seppo Ingalsuo | 4b007cb | 2017-10-20 18:45:30 +0300 | [diff] [blame] | 183 | && (free_b >= s2_blk_out * sz)) { |
| 184 | cd->polyphase_func(&s2); |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 185 | |
Seppo Ingalsuo | 4b007cb | 2017-10-20 18:45:30 +0300 | [diff] [blame] | 186 | cd->sbuf_r_ptr = s2.x_rptr; |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 187 | cd->sbuf_avail -= s2_blk_in; |
Seppo Ingalsuo | 4b007cb | 2017-10-20 18:45:30 +0300 | [diff] [blame] | 188 | free_b -= s2_blk_out * sz; |
| 189 | n_written += s2_blk_out; |
| 190 | n2 += s2.times; |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 191 | } |
| 192 | *bytes_read = sizeof(int32_t) * n_read; |
| 193 | *bytes_written = sizeof(int32_t) * n_written; |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /* 1 stage SRC for simple conversions */ |
| 197 | static void src_1s_s32_default(struct comp_dev *dev, |
| 198 | struct comp_buffer *source, struct comp_buffer *sink, |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 199 | size_t *bytes_read, size_t *bytes_written) |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 200 | { |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 201 | struct src_stage_prm s1; |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 202 | struct comp_data *cd = comp_get_drvdata(dev); |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 203 | int nch = dev->params.channels; |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 204 | int n_read = 0; |
| 205 | int n_written = 0; |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 206 | |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 207 | s1.times = cd->param.stage1_times; |
Seppo Ingalsuo | 4b007cb | 2017-10-20 18:45:30 +0300 | [diff] [blame] | 208 | s1.x_rptr = (int32_t *) source->r_ptr; |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 209 | s1.x_end_addr = source->end_addr; |
Liam Girdwood | 4450924 | 2017-09-07 15:34:42 +0100 | [diff] [blame] | 210 | s1.x_size = source->size; |
Seppo Ingalsuo | 4b007cb | 2017-10-20 18:45:30 +0300 | [diff] [blame] | 211 | s1.y_wptr = (int32_t *) sink->w_ptr; |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 212 | s1.y_end_addr = sink->end_addr; |
Liam Girdwood | 4450924 | 2017-09-07 15:34:42 +0100 | [diff] [blame] | 213 | s1.y_size = sink->size; |
Seppo Ingalsuo | 4b007cb | 2017-10-20 18:45:30 +0300 | [diff] [blame] | 214 | s1.state = &cd->src.state1; |
| 215 | s1.stage = cd->src.stage1; |
| 216 | s1.nch = dev->params.channels; |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 217 | |
Seppo Ingalsuo | 4b007cb | 2017-10-20 18:45:30 +0300 | [diff] [blame] | 218 | cd->polyphase_func(&s1); |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 219 | |
Seppo Ingalsuo | 4b007cb | 2017-10-20 18:45:30 +0300 | [diff] [blame] | 220 | n_read += nch * cd->param.blk_in; |
| 221 | n_written += nch * cd->param.blk_out; |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 222 | *bytes_read = n_read * sizeof(int32_t); |
| 223 | *bytes_written = n_written * sizeof(int32_t); |
| 224 | } |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 225 | |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 226 | /* A fast copy function for same in and out rate */ |
| 227 | static void src_copy_s32_default(struct comp_dev *dev, |
| 228 | struct comp_buffer *source, struct comp_buffer *sink, |
| 229 | size_t *bytes_read, size_t *bytes_written) |
| 230 | { |
| 231 | struct comp_data *cd = comp_get_drvdata(dev); |
| 232 | int32_t *src = (int32_t *) source->r_ptr; |
| 233 | int32_t *snk = (int32_t *) sink->w_ptr; |
| 234 | int nch = dev->params.channels; |
| 235 | int frames = cd->param.blk_in; |
| 236 | int n; |
| 237 | int n_wrap_src; |
| 238 | int n_wrap_snk; |
| 239 | int n_wrap_min; |
| 240 | int n_copy; |
| 241 | |
| 242 | n = frames * nch; |
| 243 | while (n > 0) { |
| 244 | n_wrap_src = (int32_t *) source->end_addr - src; |
| 245 | n_wrap_snk = (int32_t *) sink->end_addr - snk; |
| 246 | n_wrap_min = (n_wrap_src < n_wrap_snk) ? n_wrap_src : n_wrap_snk; |
| 247 | n_copy = (n < n_wrap_min) ? n : n_wrap_min; |
| 248 | memcpy(snk, src, n_copy * sizeof(int32_t)); |
| 249 | |
| 250 | /* Update and check both source and destination for wrap */ |
| 251 | n -= n_copy; |
| 252 | src += n_copy; |
| 253 | snk += n_copy; |
| 254 | src_circ_inc_wrap(&src, source->end_addr, source->size); |
| 255 | src_circ_inc_wrap(&snk, sink->end_addr, sink->size); |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 256 | |
| 257 | } |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 258 | *bytes_read = frames * nch * sizeof(int32_t); |
| 259 | *bytes_written = frames * nch * sizeof(int32_t); |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | static struct comp_dev *src_new(struct sof_ipc_comp *comp) |
| 263 | { |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 264 | struct comp_dev *dev; |
Liam Girdwood | 960cf8e | 2017-06-12 11:38:07 +0100 | [diff] [blame] | 265 | struct sof_ipc_comp_src *src; |
Seppo Ingalsuo | 28ef854 | 2017-08-25 18:29:04 +0300 | [diff] [blame] | 266 | struct sof_ipc_comp_src *ipc_src = (struct sof_ipc_comp_src *) comp; |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 267 | struct comp_data *cd; |
| 268 | |
Liam Girdwood | 3488cce | 2017-08-10 11:59:08 +0100 | [diff] [blame] | 269 | trace_src("new"); |
Liam Girdwood | 960cf8e | 2017-06-12 11:38:07 +0100 | [diff] [blame] | 270 | |
Liam Girdwood | b12aa0d | 2017-09-03 22:00:58 +0100 | [diff] [blame] | 271 | /* validate init data - either SRC sink or source rate must be set */ |
| 272 | if (ipc_src->source_rate == 0 && ipc_src->sink_rate == 0) { |
| 273 | trace_src_error("sn1"); |
| 274 | return NULL; |
| 275 | } |
| 276 | |
Liam Girdwood | 3488cce | 2017-08-10 11:59:08 +0100 | [diff] [blame] | 277 | dev = rzalloc(RZONE_RUNTIME, RFLAGS_NONE, |
Liam Girdwood | 1764152 | 2017-06-09 17:27:02 +0100 | [diff] [blame] | 278 | COMP_SIZE(struct sof_ipc_comp_src)); |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 279 | if (dev == NULL) |
| 280 | return NULL; |
| 281 | |
Seppo Ingalsuo | 28ef854 | 2017-08-25 18:29:04 +0300 | [diff] [blame] | 282 | src = (struct sof_ipc_comp_src *) &dev->comp; |
Liam Girdwood | 960cf8e | 2017-06-12 11:38:07 +0100 | [diff] [blame] | 283 | memcpy(src, ipc_src, sizeof(struct sof_ipc_comp_src)); |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 284 | |
Liam Girdwood | 3488cce | 2017-08-10 11:59:08 +0100 | [diff] [blame] | 285 | cd = rzalloc(RZONE_RUNTIME, RFLAGS_NONE, sizeof(*cd)); |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 286 | if (cd == NULL) { |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 287 | rfree(dev); |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 288 | return NULL; |
| 289 | } |
| 290 | |
| 291 | comp_set_drvdata(dev, cd); |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 292 | |
| 293 | cd->delay_lines = NULL; |
| 294 | cd->src_func = src_2s_s32_default; |
Seppo Ingalsuo | 4b007cb | 2017-10-20 18:45:30 +0300 | [diff] [blame] | 295 | cd->polyphase_func = src_polyphase_stage_cir; |
| 296 | src_polyphase_reset(&cd->src); |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 297 | |
Liam Girdwood | be41b68 | 2017-09-21 16:48:18 +0100 | [diff] [blame] | 298 | dev->state = COMP_STATE_READY; |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 299 | return dev; |
| 300 | } |
| 301 | |
| 302 | static void src_free(struct comp_dev *dev) |
| 303 | { |
| 304 | struct comp_data *cd = comp_get_drvdata(dev); |
| 305 | |
Liam Girdwood | 3488cce | 2017-08-10 11:59:08 +0100 | [diff] [blame] | 306 | trace_src("fre"); |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 307 | |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 308 | /* Free dynamically reserved buffers for SRC algorithm */ |
| 309 | if (cd->delay_lines != NULL) |
| 310 | rfree(cd->delay_lines); |
| 311 | |
| 312 | rfree(cd); |
| 313 | rfree(dev); |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | /* set component audio stream parameters */ |
Liam Girdwood | 2cfaebe | 2017-08-21 17:13:52 +0100 | [diff] [blame] | 317 | static int src_params(struct comp_dev *dev) |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 318 | { |
Liam Girdwood | 3488cce | 2017-08-10 11:59:08 +0100 | [diff] [blame] | 319 | struct sof_ipc_stream_params *params = &dev->params; |
| 320 | struct sof_ipc_comp_src *src = COMP_GET_IPC(dev, sof_ipc_comp_src); |
| 321 | struct sof_ipc_comp_config *config = COMP_GET_CONFIG(dev); |
| 322 | struct comp_data *cd = comp_get_drvdata(dev); |
Pierre-Louis Bossart | 4ccf81d | 2017-09-25 14:52:09 -0500 | [diff] [blame] | 323 | struct comp_buffer *sink; |
| 324 | struct comp_buffer *source; |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 325 | size_t delay_lines_size; |
Pierre-Louis Bossart | 4ccf81d | 2017-09-25 14:52:09 -0500 | [diff] [blame] | 326 | uint32_t source_rate; |
| 327 | uint32_t sink_rate; |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 328 | int32_t *buffer_start; |
Pierre-Louis Bossart | 4ccf81d | 2017-09-25 14:52:09 -0500 | [diff] [blame] | 329 | int n = 0; |
Pierre-Louis Bossart | 4ccf81d | 2017-09-25 14:52:09 -0500 | [diff] [blame] | 330 | int err; |
| 331 | int frames_is_for_source; |
Pierre-Louis Bossart | 4ccf81d | 2017-09-25 14:52:09 -0500 | [diff] [blame] | 332 | int q; |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 333 | |
Liam Girdwood | 3488cce | 2017-08-10 11:59:08 +0100 | [diff] [blame] | 334 | trace_src("par"); |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 335 | |
Seppo Ingalsuo | 887628a | 2017-09-14 16:00:05 +0300 | [diff] [blame] | 336 | /* SRC supports S24_4LE and S32_LE formats */ |
| 337 | switch (config->frame_fmt) { |
| 338 | case SOF_IPC_FRAME_S24_4LE: |
Seppo Ingalsuo | 4b007cb | 2017-10-20 18:45:30 +0300 | [diff] [blame] | 339 | cd->polyphase_func = src_polyphase_stage_cir_s24; |
Seppo Ingalsuo | 887628a | 2017-09-14 16:00:05 +0300 | [diff] [blame] | 340 | break; |
| 341 | case SOF_IPC_FRAME_S32_LE: |
Seppo Ingalsuo | 4b007cb | 2017-10-20 18:45:30 +0300 | [diff] [blame] | 342 | cd->polyphase_func = src_polyphase_stage_cir; |
Seppo Ingalsuo | 887628a | 2017-09-14 16:00:05 +0300 | [diff] [blame] | 343 | break; |
| 344 | default: |
Liam Girdwood | b12aa0d | 2017-09-03 22:00:58 +0100 | [diff] [blame] | 345 | trace_src_error("sr0"); |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 346 | return -EINVAL; |
Liam Girdwood | b12aa0d | 2017-09-03 22:00:58 +0100 | [diff] [blame] | 347 | } |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 348 | |
Liam Girdwood | 3488cce | 2017-08-10 11:59:08 +0100 | [diff] [blame] | 349 | /* Calculate source and sink rates, one rate will come from IPC new |
| 350 | * and the other from params. */ |
| 351 | if (src->source_rate == 0) { |
| 352 | /* params rate is source rate */ |
| 353 | source_rate = params->rate; |
| 354 | sink_rate = src->sink_rate; |
| 355 | /* re-write our params with output rate for next component */ |
| 356 | params->rate = sink_rate; |
Seppo Ingalsuo | cb3a64d | 2017-09-06 15:16:12 +0300 | [diff] [blame] | 357 | frames_is_for_source = 0; |
Liam Girdwood | 3488cce | 2017-08-10 11:59:08 +0100 | [diff] [blame] | 358 | } else { |
| 359 | /* params rate is sink rate */ |
| 360 | source_rate = src->source_rate; |
| 361 | sink_rate = params->rate; |
| 362 | /* re-write our params with output rate for next component */ |
| 363 | params->rate = source_rate; |
Seppo Ingalsuo | cb3a64d | 2017-09-06 15:16:12 +0300 | [diff] [blame] | 364 | frames_is_for_source = 1; |
Liam Girdwood | 3488cce | 2017-08-10 11:59:08 +0100 | [diff] [blame] | 365 | } |
Seppo Ingalsuo | 4a00691 | 2017-06-28 19:25:51 +0300 | [diff] [blame] | 366 | |
| 367 | /* Allocate needed memory for delay lines */ |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 368 | err = src_buffer_lengths(&cd->param, source_rate, sink_rate, |
Seppo Ingalsuo | cb3a64d | 2017-09-06 15:16:12 +0300 | [diff] [blame] | 369 | params->channels, dev->frames, frames_is_for_source); |
Liam Girdwood | b12aa0d | 2017-09-03 22:00:58 +0100 | [diff] [blame] | 370 | if (err < 0) { |
| 371 | trace_src_error("sr1"); |
| 372 | trace_value(source_rate); |
| 373 | trace_value(sink_rate); |
| 374 | trace_value(params->channels); |
Seppo Ingalsuo | cb3a64d | 2017-09-06 15:16:12 +0300 | [diff] [blame] | 375 | trace_value(dev->frames); |
Liam Girdwood | b12aa0d | 2017-09-03 22:00:58 +0100 | [diff] [blame] | 376 | return err; |
| 377 | } |
| 378 | |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 379 | delay_lines_size = sizeof(int32_t) * cd->param.total; |
Liam Girdwood | b12aa0d | 2017-09-03 22:00:58 +0100 | [diff] [blame] | 380 | if (delay_lines_size == 0) { |
| 381 | trace_src_error("sr2"); |
| 382 | return -EINVAL; |
| 383 | } |
| 384 | |
Pierre-Louis Bossart | f945809 | 2017-11-09 15:24:07 -0600 | [diff] [blame] | 385 | /* free any existing delay lines. TODO reuse if same size */ |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 386 | if (cd->delay_lines != NULL) |
| 387 | rfree(cd->delay_lines); |
| 388 | |
Liam Girdwood | 22ce806 | 2017-09-03 22:04:26 +0100 | [diff] [blame] | 389 | cd->delay_lines = rballoc(RZONE_RUNTIME, RFLAGS_NONE, delay_lines_size); |
Liam Girdwood | b12aa0d | 2017-09-03 22:00:58 +0100 | [diff] [blame] | 390 | if (cd->delay_lines == NULL) { |
| 391 | trace_src_error("sr3"); |
| 392 | trace_value(delay_lines_size); |
Liam Girdwood | 3488cce | 2017-08-10 11:59:08 +0100 | [diff] [blame] | 393 | return -EINVAL; |
Liam Girdwood | b12aa0d | 2017-09-03 22:00:58 +0100 | [diff] [blame] | 394 | } |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 395 | |
| 396 | /* Clear all delay lines here */ |
| 397 | memset(cd->delay_lines, 0, delay_lines_size); |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 398 | buffer_start = cd->delay_lines + cd->param.sbuf_length; |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 399 | |
Pierre-Louis Bossart | f945809 | 2017-11-09 15:24:07 -0600 | [diff] [blame] | 400 | /* Initialize SRC for actual sample rate */ |
Seppo Ingalsuo | 4b007cb | 2017-10-20 18:45:30 +0300 | [diff] [blame] | 401 | n = src_polyphase_init(&cd->src, &cd->param, buffer_start); |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 402 | |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 403 | /* Reset stage buffer */ |
| 404 | cd->sbuf_r_ptr = cd->delay_lines; |
| 405 | cd->sbuf_w_ptr = cd->delay_lines; |
| 406 | cd->sbuf_avail = 0; |
| 407 | |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 408 | switch (n) { |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 409 | case 0: |
| 410 | cd->src_func = src_copy_s32_default; /* 1:1 fast copy */ |
| 411 | break; |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 412 | case 1: |
| 413 | cd->src_func = src_1s_s32_default; /* Simpler 1 stage SRC */ |
| 414 | break; |
| 415 | case 2: |
| 416 | cd->src_func = src_2s_s32_default; /* Default 2 stage SRC */ |
| 417 | break; |
| 418 | default: |
| 419 | /* This is possibly due to missing coefficients for |
| 420 | * requested rates combination. Sink audio will be |
| 421 | * muted if copy() is run. |
| 422 | */ |
| 423 | trace_src("SFa"); |
Seppo Ingalsuo | 4b007cb | 2017-10-20 18:45:30 +0300 | [diff] [blame] | 424 | cd->src_func = src_fallback; |
Seppo Ingalsuo | 4a00691 | 2017-06-28 19:25:51 +0300 | [diff] [blame] | 425 | return -EINVAL; |
Liam Girdwood | 3488cce | 2017-08-10 11:59:08 +0100 | [diff] [blame] | 426 | break; |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 427 | } |
| 428 | |
Seppo Ingalsuo | 14d10a8 | 2017-09-22 16:08:47 +0300 | [diff] [blame] | 429 | /* Calculate period size based on config. First make sure that |
| 430 | * frame_bytes is set. |
| 431 | */ |
Seppo Ingalsuo | 28ef854 | 2017-08-25 18:29:04 +0300 | [diff] [blame] | 432 | dev->frame_bytes = |
| 433 | dev->params.sample_container_bytes * dev->params.channels; |
Liam Girdwood | 4450924 | 2017-09-07 15:34:42 +0100 | [diff] [blame] | 434 | |
Seppo Ingalsuo | 5416229 | 2017-09-12 13:45:50 +0300 | [diff] [blame] | 435 | /* The downstream buffer must be at least length of blk_out plus |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 436 | * a dev->frames and an integer multiple of dev->frames. The |
Seppo Ingalsuo | 5416229 | 2017-09-12 13:45:50 +0300 | [diff] [blame] | 437 | * buffer_set_size will return an error if the required length would |
| 438 | * be too long. |
| 439 | */ |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 440 | q = src_ceil_divide(cd->param.blk_out, (int) dev->frames) + 1; |
Seppo Ingalsuo | 5416229 | 2017-09-12 13:45:50 +0300 | [diff] [blame] | 441 | |
| 442 | /* Configure downstream buffer */ |
| 443 | sink = list_first_item(&dev->bsink_list, struct comp_buffer, |
| 444 | source_list); |
| 445 | err = buffer_set_size(sink, q * dev->frames * dev->frame_bytes); |
Liam Girdwood | 4450924 | 2017-09-07 15:34:42 +0100 | [diff] [blame] | 446 | if (err < 0) { |
| 447 | trace_src_error("eSz"); |
Seppo Ingalsuo | 887628a | 2017-09-14 16:00:05 +0300 | [diff] [blame] | 448 | trace_value(sink->alloc_size); |
| 449 | trace_value(q * dev->frames * dev->frame_bytes); |
Liam Girdwood | 4450924 | 2017-09-07 15:34:42 +0100 | [diff] [blame] | 450 | return err; |
| 451 | } |
| 452 | |
Seppo Ingalsuo | 5416229 | 2017-09-12 13:45:50 +0300 | [diff] [blame] | 453 | /* Check that source buffer has sufficient size */ |
| 454 | source = list_first_item(&dev->bsource_list, struct comp_buffer, |
| 455 | sink_list); |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 456 | if (source->size < cd->param.blk_in * dev->frame_bytes) { |
Seppo Ingalsuo | 5416229 | 2017-09-12 13:45:50 +0300 | [diff] [blame] | 457 | trace_src_error("eSy"); |
| 458 | return -EINVAL; |
| 459 | } |
| 460 | |
| 461 | |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 462 | return 0; |
| 463 | } |
| 464 | |
Liam Girdwood | 854b2e5 | 2017-09-02 23:14:02 +0100 | [diff] [blame] | 465 | static int src_ctrl_cmd(struct comp_dev *dev, struct sof_ipc_ctrl_data *cdata) |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 466 | { |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 467 | trace_src_error("ec1"); |
| 468 | return -EINVAL; |
Liam Girdwood | 854b2e5 | 2017-09-02 23:14:02 +0100 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | /* used to pass standard and bespoke commands (with data) to component */ |
| 472 | static int src_cmd(struct comp_dev *dev, int cmd, void *data) |
| 473 | { |
| 474 | struct sof_ipc_ctrl_data *cdata = data; |
Ranjani Sridharan | 6200408 | 2017-09-06 22:01:40 +0100 | [diff] [blame] | 475 | int ret = 0; |
Liam Girdwood | 854b2e5 | 2017-09-02 23:14:02 +0100 | [diff] [blame] | 476 | |
Liam Girdwood | be41b68 | 2017-09-21 16:48:18 +0100 | [diff] [blame] | 477 | trace_src("cmd"); |
| 478 | |
| 479 | ret = comp_set_state(dev, cmd); |
| 480 | if (ret < 0) |
| 481 | return ret; |
Liam Girdwood | 854b2e5 | 2017-09-02 23:14:02 +0100 | [diff] [blame] | 482 | |
Pierre-Louis Bossart | b513a45 | 2017-09-25 14:52:12 -0500 | [diff] [blame] | 483 | if (cmd == COMP_CMD_SET_VALUE) |
| 484 | ret = src_ctrl_cmd(dev, cdata); |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 485 | |
Ranjani Sridharan | 6200408 | 2017-09-06 22:01:40 +0100 | [diff] [blame] | 486 | return ret; |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | /* copy and process stream data from source to sink buffers */ |
| 490 | static int src_copy(struct comp_dev *dev) |
| 491 | { |
| 492 | struct comp_data *cd = comp_get_drvdata(dev); |
Pierre-Louis Bossart | 4ccf81d | 2017-09-25 14:52:09 -0500 | [diff] [blame] | 493 | struct comp_buffer *source; |
| 494 | struct comp_buffer *sink; |
| 495 | int need_source; |
| 496 | int need_sink; |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 497 | size_t consumed = 0; |
| 498 | size_t produced = 0; |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 499 | |
Liam Girdwood | ab50527 | 2017-11-13 16:55:30 +0000 | [diff] [blame] | 500 | trace_src("SRC"); |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 501 | |
| 502 | /* src component needs 1 source and 1 sink buffer */ |
| 503 | source = list_first_item(&dev->bsource_list, struct comp_buffer, |
| 504 | sink_list); |
| 505 | sink = list_first_item(&dev->bsink_list, struct comp_buffer, |
| 506 | source_list); |
| 507 | |
Seppo Ingalsuo | cb3a64d | 2017-09-06 15:16:12 +0300 | [diff] [blame] | 508 | /* Calculate needed amount of source buffer and sink buffer |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 509 | * for one SRC run. The blk_in and blk are minimum condition to |
| 510 | * call copy. Copy can consume or produce a slightly larger block |
| 511 | * with the rates where block sizes are not constant. E.g. for |
Pierre-Louis Bossart | f945809 | 2017-11-09 15:24:07 -0600 | [diff] [blame] | 512 | * 1 ms scheduling the blocks can be under or above 1 ms when the |
| 513 | * SRC interval block size constraint prevents exact 1 ms blocks. |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 514 | */ |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 515 | need_source = cd->param.blk_in * dev->frame_bytes; |
| 516 | need_sink = cd->param.blk_out * dev->frame_bytes; |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 517 | |
Liam Girdwood | ab50527 | 2017-11-13 16:55:30 +0000 | [diff] [blame] | 518 | /* make sure source component buffer has enough data available and that |
| 519 | * the sink component buffer has enough free bytes for copy. Also |
| 520 | * check for XRUNs */ |
Seppo Ingalsuo | 83b7560 | 2017-12-05 15:54:57 +0200 | [diff] [blame] | 521 | if (source->avail < need_source) { |
Liam Girdwood | ab50527 | 2017-11-13 16:55:30 +0000 | [diff] [blame] | 522 | trace_src_error("xru"); |
| 523 | return -EIO; /* xrun */ |
| 524 | } |
Seppo Ingalsuo | 83b7560 | 2017-12-05 15:54:57 +0200 | [diff] [blame] | 525 | if (sink->free < need_sink) { |
Liam Girdwood | ab50527 | 2017-11-13 16:55:30 +0000 | [diff] [blame] | 526 | trace_src_error("xro"); |
| 527 | return -EIO; /* xrun */ |
| 528 | } |
| 529 | |
Seppo Ingalsuo | 83b7560 | 2017-12-05 15:54:57 +0200 | [diff] [blame] | 530 | cd->src_func(dev, source, sink, &consumed, &produced); |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 531 | |
Seppo Ingalsuo | 83b7560 | 2017-12-05 15:54:57 +0200 | [diff] [blame] | 532 | /* Calc new free and available if data was processed. These |
| 533 | * functions must not be called with 0 consumed/produced. |
| 534 | */ |
| 535 | if (consumed > 0) |
| 536 | comp_update_buffer_consume(source, consumed); |
Seppo Ingalsuo | 28fafc1 | 2017-10-05 18:57:37 +0300 | [diff] [blame] | 537 | |
Liam Girdwood | e0f65a2 | 2017-12-08 20:34:29 +0000 | [diff] [blame^] | 538 | if (produced > 0) { |
Seppo Ingalsuo | 83b7560 | 2017-12-05 15:54:57 +0200 | [diff] [blame] | 539 | comp_update_buffer_produce(sink, produced); |
Liam Girdwood | e0f65a2 | 2017-12-08 20:34:29 +0000 | [diff] [blame^] | 540 | return cd->param.blk_out; |
| 541 | } |
Seppo Ingalsuo | 83b7560 | 2017-12-05 15:54:57 +0200 | [diff] [blame] | 542 | |
Liam Girdwood | e0f65a2 | 2017-12-08 20:34:29 +0000 | [diff] [blame^] | 543 | /* produced no data */ |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 544 | return 0; |
| 545 | } |
| 546 | |
| 547 | static int src_prepare(struct comp_dev *dev) |
| 548 | { |
Liam Girdwood | b083e58 | 2017-10-12 16:05:44 +0100 | [diff] [blame] | 549 | trace_src("pre"); |
| 550 | |
| 551 | return comp_set_state(dev, COMP_CMD_PREPARE); |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 552 | } |
| 553 | |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 554 | static int src_reset(struct comp_dev *dev) |
| 555 | { |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 556 | struct comp_data *cd = comp_get_drvdata(dev); |
| 557 | |
| 558 | trace_src("SRe"); |
| 559 | |
| 560 | cd->src_func = src_2s_s32_default; |
Seppo Ingalsuo | 4b007cb | 2017-10-20 18:45:30 +0300 | [diff] [blame] | 561 | src_polyphase_reset(&cd->src); |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 562 | |
Liam Girdwood | b083e58 | 2017-10-12 16:05:44 +0100 | [diff] [blame] | 563 | comp_set_state(dev, COMP_CMD_RESET); |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 564 | return 0; |
| 565 | } |
| 566 | |
| 567 | struct comp_driver comp_src = { |
| 568 | .type = SOF_COMP_SRC, |
Seppo Ingalsuo | 4a00691 | 2017-06-28 19:25:51 +0300 | [diff] [blame] | 569 | .ops = { |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 570 | .new = src_new, |
| 571 | .free = src_free, |
| 572 | .params = src_params, |
| 573 | .cmd = src_cmd, |
| 574 | .copy = src_copy, |
| 575 | .prepare = src_prepare, |
| 576 | .reset = src_reset, |
Seppo Ingalsuo | 6a27483 | 2017-06-07 14:17:55 +0300 | [diff] [blame] | 577 | }, |
| 578 | }; |
| 579 | |
| 580 | void sys_comp_src_init(void) |
| 581 | { |
| 582 | comp_register(&comp_src); |
| 583 | } |