1111#include <string.h>
1212#include <cmocka.h>
1313
14- #include <sof/audio/audio_stream .h>
14+ #include <sof/common .h>
1515#include <sof/audio/format.h>
16+ #include <sof/audio/audio_stream.h>
1617
1718#include "dcblock.h"
1819
1920#define TEST_CHANNELS 2
2021#define TEST_FRAMES 256
2122
23+ /*
24+ * The dcblock processing functions operate on struct cir_buf_source /
25+ * struct cir_buf_sink circular buffer views. The tests use static, non
26+ * wrapping sample buffers, so the views simply span the whole array.
27+ */
28+ static void cir_buf_src_setup (struct cir_buf_source * s , const void * data , size_t bytes )
29+ {
30+ s -> buf_start = data ;
31+ s -> buf_end = (const char * )data + bytes ;
32+ s -> ptr = data ;
33+ }
34+
35+ static void cir_buf_snk_setup (struct cir_buf_sink * s , void * data , size_t bytes )
36+ {
37+ s -> buf_start = data ;
38+ s -> buf_end = (char * )data + bytes ;
39+ s -> ptr = data ;
40+ }
41+
2242/* Q2.30 coefficient close to 1.0 used for the DC removal test cases. */
2343#define R_COEF_NEAR_ONE 1063004406 /* ~0.99 in Q2.30 */
2444
@@ -41,20 +61,6 @@ static double dcblock_ref(struct ref_state *s, double r, double x)
4161 return y ;
4262}
4363
44- /* Build an audio_stream over a linear (non wrapping) sample buffer. */
45- static void setup_stream (struct audio_stream * stream , void * data ,
46- size_t bytes , enum sof_ipc_frame fmt , int channels )
47- {
48- memset (stream , 0 , sizeof (* stream ));
49- stream -> addr = data ;
50- stream -> end_addr = (char * )data + bytes ;
51- stream -> r_ptr = data ;
52- stream -> w_ptr = data ;
53- stream -> size = bytes ;
54- stream -> runtime_stream_params .frame_fmt = fmt ;
55- stream -> runtime_stream_params .channels = channels ;
56- }
57-
5864/* Fill the source buffer with a per-channel sinusoid plus a DC offset. */
5965static void gen_input (double * ref_in , int channels , int frames , double dc )
6066{
@@ -77,7 +83,8 @@ static void gen_input(double *ref_in, int channels, int frames, double dc)
7783static double run_s32_case (int32_t r_coeff , double dc , double tol_rel )
7884{
7985 struct comp_data cd ;
80- struct audio_stream source , sink ;
86+ struct cir_buf_source csrc ;
87+ struct cir_buf_sink csnk ;
8188 int32_t src [TEST_FRAMES * TEST_CHANNELS ];
8289 int32_t dst [TEST_FRAMES * TEST_CHANNELS ];
8390 double ref_in [TEST_FRAMES * TEST_CHANNELS ];
@@ -89,6 +96,7 @@ static double run_s32_case(int32_t r_coeff, double dc, double tol_rel)
8996 int ch , i ;
9097
9198 memset (& cd , 0 , sizeof (cd ));
99+ cd .channels = TEST_CHANNELS ;
92100 for (ch = 0 ; ch < TEST_CHANNELS ; ch ++ )
93101 cd .R_coeffs [ch ] = r_coeff ;
94102
@@ -98,8 +106,8 @@ static double run_s32_case(int32_t r_coeff, double dc, double tol_rel)
98106 for (i = 0 ; i < TEST_FRAMES * TEST_CHANNELS ; i ++ )
99107 src [i ] = (int32_t )round (ref_in [i ] * 2147483647.0 );
100108
101- setup_stream ( & source , src , sizeof (src ), SOF_IPC_FRAME_S32_LE , TEST_CHANNELS );
102- setup_stream ( & sink , dst , sizeof (dst ), SOF_IPC_FRAME_S32_LE , TEST_CHANNELS );
109+ cir_buf_src_setup ( & csrc , src , sizeof (src ));
110+ cir_buf_snk_setup ( & csnk , dst , sizeof (dst ));
103111
104112 func = dcblock_find_func (SOF_IPC_FRAME_S32_LE );
105113 assert_non_null (func );
@@ -156,22 +164,24 @@ static void test_dcblock_saturation(void **state)
156164 (void )state ;
157165
158166 struct comp_data cd ;
159- struct audio_stream source , sink ;
167+ struct cir_buf_source csrc ;
168+ struct cir_buf_sink csnk ;
160169 int32_t src [TEST_FRAMES * TEST_CHANNELS ];
161170 int32_t dst [TEST_FRAMES * TEST_CHANNELS ];
162171 dcblock_func func ;
163172 int i ;
164173
165174 memset (& cd , 0 , sizeof (cd ));
175+ cd .channels = TEST_CHANNELS ;
166176 for (i = 0 ; i < TEST_CHANNELS ; i ++ )
167177 cd .R_coeffs [i ] = ONE_Q2_30 ;
168178
169179 /* Alternating +full/-full scale is the worst case for the difference. */
170180 for (i = 0 ; i < TEST_FRAMES * TEST_CHANNELS ; i ++ )
171181 src [i ] = (i & 1 ) ? INT32_MAX : INT32_MIN ;
172182
173- setup_stream ( & source , src , sizeof (src ), SOF_IPC_FRAME_S32_LE , TEST_CHANNELS );
174- setup_stream ( & sink , dst , sizeof (dst ), SOF_IPC_FRAME_S32_LE , TEST_CHANNELS );
183+ cir_buf_src_setup ( & csrc , src , sizeof (src ));
184+ cir_buf_snk_setup ( & csnk , dst , sizeof (dst ));
175185
176186 func = dcblock_find_func (SOF_IPC_FRAME_S32_LE );
177187 assert_non_null (func );
@@ -199,7 +209,8 @@ static void test_dcblock_bitexact_s32(void **state)
199209static void run_s16_case (int32_t r_coeff , double dc )
200210{
201211 struct comp_data cd ;
202- struct audio_stream source , sink ;
212+ struct cir_buf_source csrc ;
213+ struct cir_buf_sink csnk ;
203214 int16_t src [TEST_FRAMES * TEST_CHANNELS ];
204215 int16_t dst [TEST_FRAMES * TEST_CHANNELS ];
205216 double ref_in [TEST_FRAMES * TEST_CHANNELS ];
@@ -210,6 +221,7 @@ static void run_s16_case(int32_t r_coeff, double dc)
210221 int ch , i ;
211222
212223 memset (& cd , 0 , sizeof (cd ));
224+ cd .channels = TEST_CHANNELS ;
213225 for (ch = 0 ; ch < TEST_CHANNELS ; ch ++ )
214226 cd .R_coeffs [ch ] = r_coeff ;
215227
@@ -219,8 +231,8 @@ static void run_s16_case(int32_t r_coeff, double dc)
219231 for (i = 0 ; i < TEST_FRAMES * TEST_CHANNELS ; i ++ )
220232 src [i ] = (int16_t )round (ref_in [i ] * 32767.0 );
221233
222- setup_stream ( & source , src , sizeof (src ), SOF_IPC_FRAME_S16_LE , TEST_CHANNELS );
223- setup_stream ( & sink , dst , sizeof (dst ), SOF_IPC_FRAME_S16_LE , TEST_CHANNELS );
234+ cir_buf_src_setup ( & csrc , src , sizeof (src ));
235+ cir_buf_snk_setup ( & csnk , dst , sizeof (dst ));
224236
225237 func = dcblock_find_func (SOF_IPC_FRAME_S16_LE );
226238 assert_non_null (func );
@@ -258,7 +270,8 @@ static void test_dcblock_bitexact_s16(void **state)
258270static void run_s24_case (int32_t r_coeff , double dc )
259271{
260272 struct comp_data cd ;
261- struct audio_stream source , sink ;
273+ struct cir_buf_source csrc ;
274+ struct cir_buf_sink csnk ;
262275 int32_t src [TEST_FRAMES * TEST_CHANNELS ];
263276 int32_t dst [TEST_FRAMES * TEST_CHANNELS ];
264277 double ref_in [TEST_FRAMES * TEST_CHANNELS ];
@@ -269,6 +282,7 @@ static void run_s24_case(int32_t r_coeff, double dc)
269282 int ch , i ;
270283
271284 memset (& cd , 0 , sizeof (cd ));
285+ cd .channels = TEST_CHANNELS ;
272286 for (ch = 0 ; ch < TEST_CHANNELS ; ch ++ )
273287 cd .R_coeffs [ch ] = r_coeff ;
274288
@@ -278,12 +292,12 @@ static void run_s24_case(int32_t r_coeff, double dc)
278292 for (i = 0 ; i < TEST_FRAMES * TEST_CHANNELS ; i ++ )
279293 src [i ] = (int32_t )round (ref_in [i ] * 8388607.0 );
280294
281- setup_stream ( & source , src , sizeof (src ), SOF_IPC_FRAME_S24_4LE , TEST_CHANNELS );
282- setup_stream ( & sink , dst , sizeof (dst ), SOF_IPC_FRAME_S24_4LE , TEST_CHANNELS );
295+ cir_buf_src_setup ( & csrc , src , sizeof (src ));
296+ cir_buf_snk_setup ( & csnk , dst , sizeof (dst ));
283297
284298 func = dcblock_find_func (SOF_IPC_FRAME_S24_4LE );
285299 assert_non_null (func );
286- func (& cd , & source , & sink , TEST_FRAMES );
300+ func (& cd , & csrc , & csnk , TEST_FRAMES );
287301
288302 for (i = 0 ; i < TEST_FRAMES ; i ++ ) {
289303 for (ch = 0 ; ch < TEST_CHANNELS ; ch ++ ) {
0 commit comments