1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2012-2019 Intel Corporation. All rights reserved.
4  */
5 
6 /*
7  * @brief    API header containing sample rate converter struct and interface
8  *           functions.
9  *
10  * @mainpage Hifi3 Implementation of the Intel TSD Sample Rate Converter
11  *
12  * The sample rate converter is based on the so-called Farrow structure.
13  * It supports multi-channel operation, and the PCM samples can be
14  * represented by int16_t or int32_t values.
15  *
16  * The sample rate converter can be applied for transmit and receive
17  * use cases.  To support both directions, the sample rate converter
18  * offers two modes of operation: push-mode and pull-mode.
19  * <p>
20  * @image html Push_mode-Pull_mode-Use_case_150dpi.png
21  * "Push-mode vs. pull-mode operation"
22  * @image rtf  Push_mode-Pull_mode-Use_case_150dpi.png
23  * </p>
24  * If the sample rate converter operates in push-mode, the caller can
25  * specify how many input frames shall be processed with each call of
26  * this function.  Depending on the current conversion ratio, the
27  * number of output frames might vary from call to call. Therefore,
28  * the push-mode sample rate converter is usually combined with a ring
29  * buffer at its output. The push-mode operation is performed by the
30  * functions process_push16() and process_push32().
31  *
32  * If the sample rate converter operates in pull-mode, the caller can
33  * specify how many output frames shall be generated with each call of
34  * this function.  Depending on the current conversion ratio, the
35  * number of input frames might vary from call to call. Therefore, the
36  * pull-mode sample rate converter is usually combined with a ring
37  * buffer at its input. The pull-mode operation is performed by the
38  * functions process_pull16() and process_pull32().
39  */
40 
41 #ifndef IAS_SRC_FARROW_H
42 #define IAS_SRC_FARROW_H
43 
44 #include <sof/audio/component.h>
45 #include <stdbool.h>
46 #include <stddef.h>
47 #include <stdint.h>
48 
49 /*
50  * @brief FIR filter is max 128 taps and delay lines per channel are
51  * max 256 samples long.
52  */
53 #define ASRC_MAX_FILTER_LENGTH	128
54 
55 /*
56  * @brief Define whether the input and output buffers shall be
57  * interleaved or not.
58  */
59 enum asrc_io_format {
60 	ASRC_IOF_DEINTERLEAVED, /*<! Non-interleaved, i.e. individual buffers */
61 				/*<! for each channel. */
62 	ASRC_IOF_INTERLEAVED    /*<! Interleaved buffers. */
63 };
64 
65 /*
66  * @brief Define whether the sample rate converter shall use a linear
67  * buffer or a ring buffer on its secondary side.
68  *
69  * The secondary side corresponds to the output, if the sample rate
70  * converter is a push mode device.  The secondary side corresponds to
71  * the input, if the sample rate converter is a pull mode device.
72  */
73 enum asrc_buffer_mode {
74 	ASRC_BM_CIRCULAR,	/*!< The buffer at the secondary side is */
75 				/*!< used as ring buffer. */
76 	ASRC_BM_LINEAR		/*!< The buffer at the secondary side is used */
77 				/*!< as linear buffer. */
78 };
79 
80 /*
81  * @brief Define how the ASRC controller (drift estimator) shall
82  * update the conversion ratio.
83  */
84 enum asrc_control_mode {
85 	ASRC_CM_FEEDBACK,	/*!< The controller specifies a factor that */
86 				/*!< is applied  to the fs ratio. */
87 				/*!< This has to be done by means of the */
88 				/*!< function update_drift(). */
89 	ASRC_CM_FIXED		/*!< The controller specifies a fixed number */
90 				/*!< of samples that shall be processed on */
91 				/*!< the secondary side during the following */
92 				/*!< control cycle. This has to be done by */
93 				/*!< means of the function update_fs_ratio(). */
94 };
95 
96 /*
97  * @brief Define whether the ASRC will be used in push-mode or in
98  * pull-mode.
99  */
100 enum asrc_operation_mode {
101 	ASRC_OM_PUSH,	/*!< ASRC will be used in push-mode; functions */
102 			/*!< process_push16() or process_push32() */
103 	ASRC_OM_PULL	/*!< ASRC will be used in pull-mode; functions */
104 			/*!< process_pull16() or process_pull32() */
105 };
106 
107 /*
108  * @brief Error code
109  */
110 enum asrc_error_code {
111 	ASRC_EC_OK = 0,				/*!< Operation successful. */
112 	ASRC_EC_INIT_FAILED = -1,		/*!< Initialization of the component failed. */
113 	ASRC_EC_UPDATE_FS_FAILED = -2,		/*!< Control mode is set to CM_FIXED and update */
114 						/*!< drift is not called in time. */
115 	ASRC_EC_INVALID_POINTER = -3,		/*!< Couldn't allocate memory. Bad pointer. */
116 	ASRC_EC_INVALID_BUFFER_POINTER = -4,	/*!< Internal buffer pointers are invalid. */
117 	ASRC_EC_INVALID_SAMPLE_RATE = -5,	/*!< Sample rate is not supported. */
118 	ASRC_EC_INVALID_CONVERSION_RATIO = -6,	/*!< Conversion ratio is not supported. */
119 	ASRC_EC_INVALID_BIT_DEPTH = -7,		/*!< Bit depth is not supported. Choose either */
120 						/*!< 16 or 32 bit. */
121 	ASRC_EC_INVALID_NUM_CHANNELS = -8,	/*!< Nummber of channels must be larger */
122 						/*!< than zero. */
123 	ASRC_EC_INVALID_BUFFER_LENGTH = -9,	/*!< Buffer length must be larger than one. */
124 	ASRC_EC_INVALID_FRAME_SIZE = -10,	/*!< Invalid frame size: must be greater than 0 */
125 						/*!< for primary side and secondary side. */
126 	ASRC_EC_INVALID_CLOCK_SKEW = -11,	/*!< The clock drift is out of bounds. */
127 	ASRC_EC_INVALID_CONTROL_MODE = -12,	/*!< Call update_fs_ratio() for feedback, and */
128 						/*!< update_drift() for fixed control mode. */
129 	ASRC_EC_FAILED_PUSH_MODE = -13,		/*!< Push mode operation failed. */
130 	ASRC_EC_FAILED_PULL_MODE = -14,		/*!< Pull mode operation failed. */
131 	ASRC_EC_INVALID_FILTER_LENGTH = -15,    /*!< Length exceeds max. */
132 };
133 
134 /*
135  * asrc_farrow: Struct which stores all the setup parameters and
136  * pointers.  An instance of this struct has to be passed to all
137  * setter and processing functions.
138  */
139 struct asrc_farrow {
140 	/* IO + ring_buffer data */
141 	int num_channels;	/*!< Number of channels processed */
142 				/*!< simultaneously */
143 	int buffer_length;	/*!< Length of the ring buffer for each */
144 				/*!< channel */
145 	int buffer_write_position;	/*!< Position of the ring buffer */
146 					/*!< to which will be written next */
147 	int32_t **ring_buffers32;	/*!< Pointer to the pointers to the */
148 					/*!< 32 bit ring buffers for each */
149 					/*!< channel */
150 	int16_t **ring_buffers16;	/*!< Pointer to the pointers to the */
151 					/*!< 16 bit ring buffers for each */
152 					/*!< channel */
153 
154 	/* + IO ring_buffer status */
155 	enum asrc_buffer_mode io_buffer_mode; /*!< Mode in which IO buffers */
156 					      /*!< are operated */
157 	int io_buffer_idx;	/*!< Index for accessing the IO ring buffer */
158 	int io_buffer_length;	/*!< Size of the IO ring buffer */
159 
160 	/* FILTER + filter parameters */
161 	int filter_length;	/*!< Length of the impulse response */
162 	int num_filters;	/*!< Total number of filters used */
163 
164 	/* + filter coefficients */
165 	const int32_t *polyphase_filters; /*!< Pointer to the filter */
166 					  /*!< coefficients */
167 	int32_t *impulse_response; /*!< Pointer to the impulse response */
168 				   /*!< for generating one output sample */
169 
170 	/* PROGRAM + general */
171 	bool is_initialised;	/*!< Flag is set to true after */
172 				/*!< initialise_asrc function */
173 	bool is_updated;        /*!< Flag is set to true after call to */
174 				/*!< update_fs_ratio */
175 	enum asrc_io_format input_format; /*!< Format in which the input */
176 					  /*!< data arrives (interleaved / */
177 					  /*!< deinterleaved) */
178 	enum asrc_io_format output_format; /*!< Format in which the output */
179 					   /*!< data is written (interleaved */
180 					   /*!< or deinterleaved) */
181 	int bit_depth; /*!< Bit depth of input and output signal */
182 	enum asrc_control_mode control_mode; /*!< Operation mode of the */
183 					     /*!< src's controller */
184 	enum asrc_operation_mode operation_mode; /*!< Operation mode of the */
185 						 /*!< src itself */
186 
187 	/* + state machine */
188 	int fs_prim;		/*!< Primary sampling rate */
189 	int fs_sec;		/*!< Secondary sampling rate */
190 	uint32_t fs_ratio;	/*!< Conversion ratio: Input_rate/Output_rate */
191 				/*!< (5q27) */
192 	uint32_t fs_ratio_inv;	/*!< Reciprocal conversion ratio for */
193 				/*!< synchronous pull mode (5q27) */
194 	uint32_t time_value;	/*!< Relative position between two input */
195 				/*!< samples (5q27) */
196 	uint32_t time_value_pull; /*!< Time value used for synchronised */
197 				  /*!< pull mode (5q27) */
198 	int prim_num_frames;	/*!< Counts number of samples on */
199 				/*!< primary side */
200 	int prim_num_frames_targ;	/*!< Target number of samples on */
201 					/*!< primary side during one control */
202 					/*!< loop */
203 	int sec_num_frames;	/*!< Counts number of samples on */
204 				/*!< secondary side */
205 	int sec_num_frames_targ;	/*!< Target number of samples on */
206 					/*!< secondary side during one */
207 					/*!< control loop */
208 
209 	/* + function pointer */
210 	void (*calc_ir)(struct asrc_farrow *src_obj);	/*!< Pointer */
211 	/*!< to the function which calculates the impulse response */
212 };
213 
214 /*
215  * @brief ASRC component struct storing the configuration.
216  */
217 
218 /*
219  * @brief Returns the required size in bytes to be allocated for the
220  * ASRC struct and buffers.
221  *
222  * This function should be called before creating and initialising an
223  * instance of ias_src_farrow.  It lies on the user to allocate the
224  * required memory and let the ias_src_farrow instance point to the
225  * beginning.
226  *
227  * @returns    Error code.
228  * @param[out] required_size The required size in bytes that has to be
229  *                           allocated by the application.
230  * @param[in]  num_channels  The number of channels the ASRC shall be used for.
231  * @param[in]  bit_depth     The wordlength that will be used for representing
232  *                           the PCM samples, must be 16 or 32.
233  */
234 enum asrc_error_code asrc_get_required_size(struct comp_dev *dev,
235 					    int *required_size,
236 					    int num_channels,
237 					    int bit_depth);
238 
239 /*
240  * @brief Initialises the ias_src_farrow instance.
241  *
242  * This function should be called immediately after memory allocation.
243  * Requires a pointer to the instance to be initialised.
244  *
245  * @param[in] src_obj        Pointer to the ias_src_farrow.
246  * @param[in] num_channels   Number of channels that should be processed.
247  * @param[in] fs_prim        Primary signal sampling rate.
248  * @param[in] fs_sec         Secondary signal sampling rate.
249  * @param[in] input_format   Configures how input data will be read.
250  *                           Choose 'interleaved' for interleaved input data
251  *                           or 'deinterleaved' instead.
252  * @param[in] output_format  Configures how output data will be written.
253  *                           Choose 'interleaved' for interleaved input data
254  *                           or 'deinterleaved' instead.
255  * @param[in] buffer_mode    Choose linear or circular; this defines whether a
256  *			     linear buffer or a ring buffer shall be used at
257  *                           the secondary side.
258  * @param[in] buffer_length  Length of the I/O buffer
259  * @param[in] bit_depth      Bit depth of input and output signal. Valid
260  *                           values are 16 and 32!
261  * @param[in] control_mode   Choose the kind of controller used to operate the
262  *                           ASRC.
263  *                           Select 'feedback' if the controller returns a
264  *                           factor applied to the fs ratio.
265  *                           Select 'fixed' if the controller returns a fixed
266  *                           number of samples to be generated
267  *                           in the following control cycle.
268  * @param[in] operation_mode Choose 'push' or 'pull', depending on the mode
269  *                           you want your ASRC to operate in.
270  */
271 enum asrc_error_code asrc_initialise(struct comp_dev *dev,
272 				     struct asrc_farrow *src_obj,
273 				     int num_channels,
274 				     int32_t fs_prim,
275 				     int32_t fs_sec,
276 				     enum asrc_io_format input_format,
277 				     enum asrc_io_format output_format,
278 				     enum asrc_buffer_mode buffer_mode,
279 				     int buffer_length,
280 				     int bit_depth,
281 				     enum asrc_control_mode control_mode,
282 				     enum asrc_operation_mode operation_mode);
283 
284 /*
285  * @brief Process the sample rate converter for one frame; the frame
286  *        consists of @p input_num_frames samples within @p num_channels
287  *        channels.
288  *
289  * This function represents the push-mode implementation of the sample
290  * rate converter.  This means that the caller can specify how many
291  * input samples shall be processed with each call of this
292  * function. The function returns by means of the output parameter @p
293  * output_num_frames how many output frames have been generated.
294  *
295  * @param[in] src_obj            Pointer to the ias_src_farrow instance.
296  * @param[in] input_buffers      Pointer to the pointers to the 16 bit input
297  *                               data arrays.  Should contain <tt>
298  *                               input_buffer_size *
299  *                               ias_src_farrow.m_num_channels </tt>
300  *                               samples.  Data can be stored in
301  *                               interleaved or deinterleaved format,
302  *                               this should also be correctly
303  *                               configured in the @p src_obj.
304  * @param[in, out] input_num_frames
305  *				 Number of samples in each channel of input
306  *                               data (NOT the number of total samples).
307  * @param[out] output_buffers    Pointer to the pointers to the 16 bit
308  *                               buffers the generated samples should
309  *                               be stored in.  Written in interleaved
310  *                               or deinterleaved format, depending on
311  *                               the configuration in @p src_obj.
312  * @param[out] output_num_frames Number of samples written to the output
313  *                               buffer for each channel.
314  * @param[out] write_index       If I/O buffer mode is set to BM_CIRCULAR,
315  *                               this parameter returns the position
316  *                               within the output_buffers, where the
317  *                               next call of this function would write
318  *                               to. In other words: when this
319  *                               function returns, the output buffer
320  *                               provides the most recent samples up to
321  *                               positions < @p write_index.
322  * @param[in] read_index         If I/O buffer mode is set to BM_CIRCULAR,
323  *                               this parameter must specify until
324  *                               which position the application has
325  *                               already read samples from the
326  *                               output_buffers (the parameter must
327  *                               specify the next position, which has
328  *                               not been read so far).  The sample
329  *                               rate converter only writes samples to
330  *                               positions < @p read_index in order to
331  *                               avoid that unconsumed samples are
332  *                               overwritten.
333  */
334 enum asrc_error_code asrc_process_push16(struct comp_dev *dev,
335 					 struct asrc_farrow *src_obj,
336 					 int16_t **__restrict input_buffers,
337 					 int *input_num_frames,
338 					 int16_t **__restrict output_buffers,
339 					 int *output_num_frames,
340 					 int *write_index,
341 					 int read_index);
342 
343 /*
344  * @brief Process the sample rate converter for one frame; the frame
345  *        consists of @p input_num_frames samples within @p num_channels
346  *        channels.
347  *
348  * This function represents the push-mode implementation of the sample
349  * rate converter.  This means that the caller can specify how many
350  * input samples shall be processed with each call of this
351  * function. The function returns by means of the output parameter @p
352  * output_num_frames how many output frames have been generated.
353  *
354  * @param[in] src_obj             Pointer to the ias_src_farrow instance.
355  * @param[in] input_buffers       Pointer to the pointers to the 32 bit input
356  *                                data arrays. Should contain <tt>
357  *                                input_buffer_size *
358  *                                ias_src_farrow.m_num_channels </tt>
359  *                                samples.Data can be stored in
360  *                                interleaved or deinterleaved format,
361  *                                this should also be correctly
362  *                                configured in the @p src_obj.
363  * @param[in, out] input_num_frames
364  *				  Number of samples in each channel of
365  *                                input data (NOT the number of total samples).
366  * @param[out] output_buffers     Pointer to the pointers to the 32 bit
367  *                                buffers the generated samples should
368  *                                be stored in.  Written in interleaved
369  *                                or deinterleaved format, depending on
370  *                                the configuration in @p src_obj.
371  * @param[out] output_num_frames  Number of samples written to the output
372  *                                buffer for each channel.
373  * @param[out] write_index        If I/O buffer mode is set to BM_CIRCULAR,
374  *                                this parameter returns the position
375  *                                within the output_buffers, where the
376  *                                next call of this function would write
377  *                                to.  In other words: when this
378  *                                function returns, the output buffer
379  *                                provides the most recent samples up to
380  *                                positions < @p write_index.
381  * @param[in] read_index          If I/O buffer mode is set to BM_CIRCULAR,
382  *                                this parameter must specify until
383  *                                which position the application has
384  *                                already read samples from the
385  *                                output_buffers (the parameter must
386  *                                specify the next position, which has
387  *                                not been read so far).  The sample
388  *                                rate converter only writes samples to
389  *                                positions < @p read_index in order to
390  *                                avoid that unconsumed samples are
391  *                                overwritten.
392  */
393 enum asrc_error_code asrc_process_push32(struct comp_dev *dev,
394 					 struct asrc_farrow *src_obj,
395 					 int32_t **__restrict input_buffers,
396 					 int *input_num_frames,
397 					 int32_t **__restrict output_buffers,
398 					 int *output_num_frames,
399 					 int *write_index,
400 					 int read_index);
401 
402 /*
403  * @brief Process the sample rate converter and generate one frame of
404  *        @p num_output_samples samples within @p num_channels channels.
405  *
406  * This function represents the pull-mode implementation of the sample
407  * rate converter.  This means that the caller can specify how many
408  * output samples shall be generated with each call of this
409  * function. The function returns by means of the output parameter @p
410  * input_num_frames how many input frames have been consumed.
411  *
412  * @param[in] src_obj           Pointer to the ias_src_farrow instance.
413  *
414  * @param[in] input_buffers     Pointer to the pointers to the 16 bit input
415  *                              data arrays.  Should contain <tt>
416  *                              input_buffer_size *
417  *                              ias_src_farrow.m_num_channels </tt>
418  *                              samples.  Data can be stored in
419  *                              interleaved or deinterleaved format,
420  *                              this should also be correctly
421  *                              configured in the @p src_obj.
422  * @param[out] input_num_frames Number of samples in each channel that
423  *                              have been consumed from the input buffers.
424  * @param[out] output_buffers   Pointer to the pointers to the 16 bit
425  *                              buffers the generated samples should
426  *                              be stored in.  Written in interleaved
427  *                              or deinterleaved format, depending on
428  *                              the configuration in @p src_obj.  No
429  *                              support for output ring buffers yet.
430  * @param[in, out] output_num_frames
431  *				Number of samples that shall be written
432  *                              to the output buffer for each channel.
433  * @param[in] write_index       Index within the input ring buffer, must
434  *                              point to the next frame, which has not
435  *                              been written by the application so
436  *                              far. The sample rate converter only
437  *                              reads frames from before this
438  *                              position. If I/O buffer mode is set to
439  *                              BM_LINEAR, the @p write_index is
440  *                              equivalent to the number of frames
441  *                              provided by the application within the
442  *                              input buffer.
443  * @param[in,out] read_index    If I/O buffer mode is set to BM_CIRCULAR,
444  *                              this parameter specifies the index
445  *                              within the input ring buffer where the
446  *                              sample rate converter shall start
447  *                              reading frames from.  When the
448  *                              function returns, this parameter
449  *                              returns the index of the next frame,
450  *                              which has not been read so far.  If
451  *                              I/O buffer mode is set to BM_LINEAR,
452  *                              the function starts reading always
453  *                              from the beginning of the input
454  *                              buffer, so this parameter is ignored.
455  *                              When the function returns, this
456  *                              parameter returns the number of frames
457  *                              that have been read.
458  */
459 enum asrc_error_code asrc_process_pull16(struct comp_dev *dev,
460 					 struct asrc_farrow *src_obj,
461 					 int16_t **__restrict input_buffers,
462 					 int *input_num_frames,
463 					 int16_t **__restrict output_buffers,
464 					 int *output_num_frames,
465 					 int write_index,
466 					 int *read_index);
467 
468 /*
469  * @brief Process the sample rate converter and generate one frame of
470  *        @p num_output_samples samples within @p num_channels channels.
471  *
472  * This function represents the pull-mode implementation of the sample
473  * rate converter.  This means that the caller can specify how many
474  * output samples shall be generated with each call of this
475  * function. The function returns by means of the output parameter @p
476  * input_num_frames how many input frames have been consumed.
477  *
478  * @param[in] src_obj           Pointer to the ias_src_farrow instance.
479  * @param[in] input_buffers     Pointer to the pointers to the 32 bit input
480  *                              data arrays.  Should contain <tt>
481  *                              input_buffer_size *
482  *                              ias_src_farrow.m_num_channels </tt>
483  *                              samples.  Data can be stored in
484  *                              interleaved or deinterleaved format,
485  *                              this should also be correctly
486  *                              configured in the @p src_obj.
487  * @param[out] input_num_frames Number of samples in each channel that
488  *                              have been consumed from the input buffers.
489  * @param[out] output_buffers   Pointer to the pointers to the 32 bit
490  *                              buffers the generated samples should
491  *                              be stored in.  Written in interleaved
492  *                              or deinterleaved format, depending on
493  *                              the configuration in @p src_obj.  No
494  *                              support for output ring buffers yet.
495  * @param[in, out] output_num_frames
496  *				Number of samples that shall be written
497  *                              to the output buffer for each channel.
498  * @param[in] write_index       Index within the input ring buffer, must
499  *                              point to the next frame, which has not
500  *                              been written by the application so
501  *                              far. The sample rate converter only
502  *                              reads frames from before this
503  *                              position. If I/O buffer mode is set to
504  *                              BM_LINEAR, the @p write_index is
505  *                              equivalent to the number of frames
506  *                              provided by the application within the
507  *                              input buffer.
508  * @param[in,out] read_index    If I/O buffer mode is set to BM_CIRCULAR,
509  *                              this parameter specifies the index
510  *                              within the input ring buffer where the
511  *                              sample rate converter shall start
512  *                              reading frames from.  When the
513  *                              function returns, this parameter
514  *                              returns the index of the next frame,
515  *                              which has not been read so far.  If
516  *                              I/O buffer mode is set to BM_LINEAR,
517  *                              the function starts reading always
518  *                              from the beginning of the input
519  *                              buffer, so this parameter is ignored.
520  *                              When the function returns, this
521  *                              parameter returns the number of frames
522  *                              that have been read.
523  */
524 enum asrc_error_code asrc_process_pull32(struct comp_dev *dev,
525 					 struct asrc_farrow *src_obj,
526 					 int32_t **__restrict input_buffers,
527 					 int *input_num_frames,
528 					 int32_t **__restrict output_buffers,
529 					 int *output_num_frames,
530 					 int write_index,
531 					 int *read_index);
532 
533 /*
534  * @brief Updates the clock drift
535  *
536  * Compensate the drift in primary and secondary clock sources by
537  * applying the clock skew to the fs ratio. Only call this function if
538  * the controller mode is set to 'feedback'.
539  *
540  * @param[in] src_obj    Pointer to the ias_src_farrow instance.
541  * @param[in] clock_skew Allows compensation of the clock drift.
542  *                       Value should be passed as 2q30 fixed point value.
543  *                       For synchrounous operation pass (1 << 30).
544  */
545 enum asrc_error_code asrc_update_drift(struct comp_dev *dev,
546 				       struct asrc_farrow *src_obj,
547 				       uint32_t clock_skew);
548 
549 /*
550  * @brief Updates the fs ratio
551  *
552  * Ensure generation/consumption of a certain number of samples on
553  * primary and secondary side.  This function should be called just
554  * after the controller function AND only if the controller mode is
555  * set to 'fixed'.  In push mode @p secondary_num_frames samples will be
556  * generated out of @p primary_num_frames samples per channel.  In pull
557  * mode @p primary_num_frames samples will be generated out of @p
558  * secondary_num_frames samples per channel.
559  *
560  * @param[in] src_obj              Pointer to the ias_src_farrow instance.
561  * @param[in] primary_num_frames   Number of samples per channel counted
562  *                                 in one controller loop on the
563  *                                 primary (ALSA) side
564  * @param[in] secondary_num_frames Number of samples per channel counted
565  *                                 in one controller loop on the
566  *                                 secondary (SSP) side
567  */
568 enum asrc_error_code asrc_update_fs_ratio(struct comp_dev *dev,
569 					  struct asrc_farrow *src_obj,
570 					  int primary_num_frames,
571 					  int secondary_num_frames);
572 
573 /*
574  * @brief Changes the input and output sampling rate.
575  *
576  * Configures the src for given sampling rates.
577  * Shouldn't be called on the fly because the buffers get flushed when called.
578  * Release buffers BEFORE call this function and allocate them again after function returns.
579  *
580  * Available sample rates [Hz] are:
581  * 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000.
582  *
583  * @param[in] src_obj  Pointer to the ias_src_farrow instance.
584  * @param[in] fs_prim  Primary sampling rate.
585  * @param[in] fs_sec   Secondary sampling rate.
586  */
587 enum asrc_error_code asrc_set_fs_ratio(struct comp_dev *dev,
588 				       struct asrc_farrow *src_obj,
589 				       int32_t fs_prim, int32_t fs_sec);
590 
591 /*
592  * @brief Changes how input data will be read.
593  *
594  * Choose either 'interleaved' or 'deinterleaved' of the @e format enum.
595  *
596  * @param[in] src_obj      Pointer to the ias_src_farrow instance.
597  * @param[in] input_format Format parameter.
598  */
599 enum asrc_error_code asrc_set_input_format(struct comp_dev *dev,
600 					   struct asrc_farrow *src_obj,
601 					   enum asrc_io_format input_format);
602 
603 /*
604  * @brief Changes how output data will be written.
605  *
606  * Choose either 'interleaved' or 'deinterleaved' of the @e format enum.
607  *
608  * @param[in] src_obj        Pointer to the ias_src_farrow instance.
609  * @param[in] output_format  Format parameter.
610  */
611 enum asrc_error_code asrc_set_output_format(struct comp_dev *dev,
612 					    struct asrc_farrow *src_obj,
613 					    enum asrc_io_format output_format);
614 
615 /*
616  * Write value of 16 bit input buffers to the channels of the ring buffer
617  */
618 void asrc_write_to_ring_buffer16(struct asrc_farrow *src_obj,
619 				 int16_t **input_buffers,
620 				 int index_input_frame);
621 
622 /*
623  * Write value of 32 bit input buffers to the channels of the ring buffer
624  */
625 void asrc_write_to_ring_buffer32(struct asrc_farrow *src_obj,
626 				 int32_t **input_buffers,
627 				 int index_input_frame);
628 
629 /*
630  * Filter the 32 bit ring buffer values with impulse_response
631  */
632 void asrc_fir_filter16(struct asrc_farrow *src_obj,
633 		       int16_t **output_buffers,
634 		       int index_output_frame);
635 
636 /*
637  * Filter the 32 bit ring buffer values with impulse_response
638  */
639 void asrc_fir_filter32(struct asrc_farrow *src_obj,
640 		       int32_t **output_buffers,
641 		       int index_output_frame);
642 
643 /*
644  * Calculates the impulse response. This impulse response is then
645  * applied to the buffered signal, in order to generate the output.
646  * There are four versions, from whom one is pointed to by the
647  * ias_src_farrow struct.  This depends on the number of polyphase
648  * filters given for the current conversion ratio.
649  */
650 void asrc_calc_impulse_response_n4(struct asrc_farrow *src_obj);
651 void asrc_calc_impulse_response_n5(struct asrc_farrow *src_obj);
652 void asrc_calc_impulse_response_n6(struct asrc_farrow *src_obj);
653 void asrc_calc_impulse_response_n7(struct asrc_farrow *src_obj);
654 
655 #endif /* IAS_SRC_FARROW_H */
656