forked from thesofproject/sof
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwaves.c
More file actions
777 lines (641 loc) · 21 KB
/
waves.c
File metadata and controls
777 lines (641 loc) · 21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2020 Waves Audio Ltd. All rights reserved.
//
// Author: Oleksandr Strelchenko <oleksandr.strelchenko@waves.com>
//
#include <sof/audio/module_adapter/codec/generic.h>
#include <sof/audio/module_adapter/codec/waves.h>
#include <sof/debug/debug.h>
#include <sof/compiler_attributes.h>
#include "MaxxEffect/MaxxEffect.h"
#include "MaxxEffect/MaxxStream.h"
#include "MaxxEffect/MaxxStatus.h"
#include "MaxxEffect/Initialize/MaxxEffect_Initialize.h"
#include "MaxxEffect/Process/MaxxEffect_Process.h"
#include "MaxxEffect/Process/MaxxEffect_Reset.h"
#include "MaxxEffect/Control/RPC/MaxxEffect_RPC_Server.h"
#include "MaxxEffect/Control/Direct/MaxxEffect_Revision.h"
#define MAX_CONFIG_SIZE_BYTES (8192)
#define NUM_IO_STREAMS (1)
/* d944281a-afe9-4695-a043-d7f62b89538e*/
DECLARE_SOF_RT_UUID("waves_codec", waves_uuid, 0xd944281a, 0xafe9, 0x4695,
0xa0, 0x43, 0xd7, 0xf6, 0x2b, 0x89, 0x53, 0x8e);
DECLARE_TR_CTX(waves_tr, SOF_UUID(waves_uuid), LOG_LEVEL_INFO);
struct waves_codec_data {
uint32_t sample_rate;
uint32_t buffer_bytes;
uint32_t buffer_samples;
uint32_t sample_size_in_bytes;
uint64_t reserved;
MaxxEffect_t *effect;
uint32_t effect_size;
MaxxStreamFormat_t i_format;
MaxxStreamFormat_t o_format;
MaxxStream_t i_stream;
MaxxStream_t o_stream;
MaxxBuffer_t i_buffer;
MaxxBuffer_t o_buffer;
uint32_t response_max_bytes;
uint32_t request_max_bytes;
void *response;
};
enum waves_codec_params {
PARAM_NOP = 0,
PARAM_MESSAGE = 1,
PARAM_REVISION = 2
};
/* convert MaxxBuffer_Format_t to number of bytes it requires */
static int32_t sample_format_convert_to_bytes(MaxxBuffer_Format_t format)
{
int32_t res;
switch (format) {
case MAXX_BUFFER_FORMAT_Q1_15:
res = sizeof(uint16_t);
break;
case MAXX_BUFFER_FORMAT_Q1_23:
res = 3; /* 3 bytes */
break;
case MAXX_BUFFER_FORMAT_Q9_23:
COMPILER_FALLTHROUGH
case MAXX_BUFFER_FORMAT_Q1_31:
COMPILER_FALLTHROUGH
case MAXX_BUFFER_FORMAT_Q5_27:
res = sizeof(uint32_t);
break;
case MAXX_BUFFER_FORMAT_FLOAT:
res = sizeof(float);
break;
default:
res = -EINVAL;
break;
}
return res;
}
/* convert enum sof_ipc_frame to MaxxBuffer_Format_t */
static MaxxBuffer_Format_t format_convert_sof_to_me(enum sof_ipc_frame format)
{
MaxxBuffer_Format_t res;
switch (format) {
case SOF_IPC_FRAME_S16_LE:
res = MAXX_BUFFER_FORMAT_Q1_15;
break;
case SOF_IPC_FRAME_S24_4LE:
res = MAXX_BUFFER_FORMAT_Q9_23;
break;
case SOF_IPC_FRAME_S32_LE:
res = MAXX_BUFFER_FORMAT_Q1_31;
break;
case SOF_IPC_FRAME_FLOAT:
res = MAXX_BUFFER_FORMAT_FLOAT;
break;
default:
res = -EINVAL;
break;
}
return res;
}
/* convert sof frame format to MaxxBuffer_Layout_t */
static MaxxBuffer_Layout_t layout_convert_sof_to_me(uint32_t layout)
{
MaxxBuffer_Layout_t res;
switch (layout) {
case SOF_IPC_BUFFER_INTERLEAVED:
res = MAXX_BUFFER_LAYOUT_INTERLEAVED;
break;
case SOF_IPC_BUFFER_NONINTERLEAVED:
res = MAXX_BUFFER_LAYOUT_DEINTERLEAVED;
break;
default:
res = -EINVAL;
break;
}
return res;
}
/* check if sample format supported by codec */
static bool format_is_supported(enum sof_ipc_frame format)
{
bool supported;
switch (format) {
case SOF_IPC_FRAME_S16_LE:
COMPILER_FALLTHROUGH
case SOF_IPC_FRAME_S24_4LE:
COMPILER_FALLTHROUGH
case SOF_IPC_FRAME_S32_LE:
supported = true;
break;
case SOF_IPC_FRAME_FLOAT:
COMPILER_FALLTHROUGH
default:
supported = false;
break;
}
return supported;
}
/* check if buffer layout supported by codec */
static bool layout_is_supported(uint32_t layout)
{
bool supported;
switch (layout) {
case SOF_IPC_BUFFER_INTERLEAVED:
supported = true;
break;
case SOF_IPC_BUFFER_NONINTERLEAVED:
COMPILER_FALLTHROUGH
default:
supported = false;
break;
}
return supported;
}
/* check if sample rate supported by codec */
static bool rate_is_supported(uint32_t rate)
{
bool supported;
switch (rate) {
case 44100:
COMPILER_FALLTHROUGH
case 48000:
supported = true;
break;
default:
supported = false;
break;
}
return supported;
}
/* allocate memory for MaxxEffect object */
static int waves_effect_allocate(struct comp_dev *dev)
{
struct codec_data *codec = comp_get_codec(dev);
struct waves_codec_data *waves_codec = codec->private;
MaxxStatus_t status;
comp_dbg(dev, "waves_effect_allocate() start");
status = MaxxEffect_GetEffectSize(&waves_codec->effect_size);
if (status) {
comp_err(dev, "waves_effect_allocate() MaxxEffect_GetEffectSize returned %d",
status);
return -EINVAL;
}
waves_codec->effect = (MaxxEffect_t *)codec_allocate_memory(dev,
waves_codec->effect_size, 16);
if (!waves_codec->effect) {
comp_err(dev, "waves_effect_allocate() failed to allocate %d bytes for effect",
waves_codec->effect_size);
return -ENOMEM;
}
comp_info(dev, "waves_codec_init() allocated %d bytes for effect",
waves_codec->effect_size);
comp_dbg(dev, "waves_codec_init() done");
return 0;
}
/* checks if sink/source parameters fit MaxxEffect */
static int waves_effect_check(struct comp_dev *dev)
{
struct comp_data *component = comp_get_drvdata(dev);
const struct audio_stream *src_fmt = &component->ca_source->stream;
const struct audio_stream *snk_fmt = &component->ca_sink->stream;
comp_dbg(dev, "waves_effect_check() start");
/* todo use fallback to comp_verify_params when ready */
/* resampling not supported */
if (src_fmt->rate != snk_fmt->rate) {
comp_err(dev, "waves_effect_check() source %d sink %d rate mismatch",
src_fmt->rate, snk_fmt->rate);
return -EINVAL;
}
/* upmix/downmix not supported */
if (src_fmt->channels != snk_fmt->channels) {
comp_err(dev, "waves_effect_check() source %d sink %d channels mismatch",
src_fmt->channels, snk_fmt->channels);
return -EINVAL;
}
/* different frame format not supported */
if (src_fmt->frame_fmt != snk_fmt->frame_fmt) {
comp_err(dev, "waves_effect_check() source %d sink %d sample format mismatch",
src_fmt->frame_fmt, snk_fmt->frame_fmt);
return -EINVAL;
}
/* different interleaving is not supported */
if (component->ca_source->buffer_fmt != component->ca_sink->buffer_fmt) {
comp_err(dev, "waves_effect_check() source %d sink %d buffer format mismatch");
return -EINVAL;
}
if (!format_is_supported(src_fmt->frame_fmt)) {
comp_err(dev, "waves_effect_check() float samples not supported");
return -EINVAL;
}
if (!layout_is_supported(component->ca_source->buffer_fmt)) {
comp_err(dev, "waves_effect_check() non interleaved format not supported");
return -EINVAL;
}
if (!rate_is_supported(src_fmt->rate)) {
comp_err(dev, "waves_effect_check() rate %d not supported", src_fmt->rate);
return -EINVAL;
}
if (src_fmt->channels != 2) {
comp_err(dev, "waves_effect_check() channels %d not supported", src_fmt->channels);
return -EINVAL;
}
comp_dbg(dev, "waves_effect_check() done");
return 0;
}
/* initializes MaxxEffect based on stream parameters */
static int waves_effect_init(struct comp_dev *dev)
{
struct codec_data *codec = comp_get_codec(dev);
struct waves_codec_data *waves_codec = codec->private;
struct comp_data *component = comp_get_drvdata(dev);
const struct audio_stream *src_fmt = &component->ca_source->stream;
MaxxStatus_t status;
MaxxBuffer_Format_t sample_format;
MaxxBuffer_Layout_t buffer_format;
int32_t sample_bytes;
MaxxStreamFormat_t *i_formats[NUM_IO_STREAMS] = { &waves_codec->i_format };
MaxxStreamFormat_t *o_formats[NUM_IO_STREAMS] = { &waves_codec->o_format };
comp_dbg(dev, "waves_effect_init() start");
sample_format = format_convert_sof_to_me(src_fmt->frame_fmt);
if (sample_format < 0) {
comp_err(dev, "waves_effect_init() sof sample format %d not supported",
src_fmt->frame_fmt);
return -EINVAL;
}
buffer_format = layout_convert_sof_to_me(component->ca_source->buffer_fmt);
if (buffer_format < 0) {
comp_err(dev, "waves_effect_init() sof buffer format %d not supported",
component->ca_source->buffer_fmt);
return -EINVAL;
}
sample_bytes = sample_format_convert_to_bytes(sample_format);
if (sample_bytes < 0) {
comp_err(dev, "waves_effect_init() sample_format %d not supported",
sample_format);
return -EINVAL;
}
waves_codec->request_max_bytes = 0;
waves_codec->response_max_bytes = 0;
waves_codec->response = 0;
waves_codec->i_buffer = 0;
waves_codec->o_buffer = 0;
waves_codec->i_format.sampleRate = src_fmt->rate;
waves_codec->i_format.numChannels = src_fmt->channels;
waves_codec->i_format.samplesFormat = sample_format;
waves_codec->i_format.samplesLayout = buffer_format;
waves_codec->o_format = waves_codec->i_format;
waves_codec->sample_size_in_bytes = sample_bytes;
waves_codec->buffer_samples = (src_fmt->rate * 2) / 1000; /* 2 ms io buffers */
waves_codec->buffer_bytes = waves_codec->buffer_samples * src_fmt->channels *
waves_codec->sample_size_in_bytes;
// trace allows printing only up-to 4 words at a time
// logging all the information in two calls
comp_info(dev, "waves_effect_init() rate %d, channels %d", waves_codec->i_format.sampleRate,
waves_codec->i_format.numChannels);
comp_info(dev, "waves_effect_init() format %d, layout %d, frame %d",
waves_codec->i_format.samplesFormat, waves_codec->i_format.samplesLayout,
waves_codec->buffer_samples);
status = MaxxEffect_Initialize(waves_codec->effect, i_formats, 1, o_formats, 1);
if (status) {
comp_err(dev, "waves_effect_init() MaxxEffect_Initialize returned %d", status);
return -EINVAL;
}
comp_dbg(dev, "waves_effect_init() done");
return 0;
}
/* allocate additional buffers for MaxxEffect */
static int waves_effect_buffers(struct comp_dev *dev)
{
struct codec_data *codec = comp_get_codec(dev);
struct waves_codec_data *waves_codec = codec->private;
MaxxStatus_t status;
int ret;
void *i_buffer = NULL, *o_buffer = NULL, *response = NULL;
comp_dbg(dev, "waves_effect_buffers() start");
status = MaxxEffect_GetMessageMaxSize(waves_codec->effect, &waves_codec->request_max_bytes,
&waves_codec->response_max_bytes);
if (status) {
comp_err(dev, "waves_effect_buffers() MaxxEffect_GetMessageMaxSize returned %d",
status);
ret = -EINVAL;
goto err;
}
response = codec_allocate_memory(dev, waves_codec->response_max_bytes, 16);
if (!response) {
comp_err(dev, "waves_effect_buffers() failed to allocate %d bytes for response",
waves_codec->response_max_bytes);
ret = -ENOMEM;
goto err;
}
i_buffer = codec_allocate_memory(dev, waves_codec->buffer_bytes, 16);
if (!i_buffer) {
comp_err(dev, "waves_effect_buffers() failed to allocate %d bytes for i_buffer",
waves_codec->buffer_bytes);
ret = -ENOMEM;
goto err;
}
o_buffer = codec_allocate_memory(dev, waves_codec->buffer_bytes, 16);
if (!o_buffer) {
comp_err(dev, "waves_effect_buffers() failed to allocate %d bytes for o_buffer",
waves_codec->buffer_bytes);
ret = -ENOMEM;
goto err;
}
waves_codec->i_buffer = i_buffer;
waves_codec->o_buffer = o_buffer;
waves_codec->response = response;
codec->cpd.in_buff = waves_codec->i_buffer;
codec->cpd.in_buff_size = waves_codec->buffer_bytes;
codec->cpd.out_buff = waves_codec->o_buffer;
codec->cpd.out_buff_size = waves_codec->buffer_bytes;
comp_info(dev, "waves_effect_buffers() size response %d, i_buffer %d, o_buffer %d",
waves_codec->response_max_bytes, waves_codec->buffer_bytes,
waves_codec->buffer_bytes);
comp_dbg(dev, "waves_effect_buffers() done");
return 0;
err:
if (i_buffer)
codec_free_memory(dev, i_buffer);
if (o_buffer)
codec_free_memory(dev, o_buffer);
if (response)
codec_free_memory(dev, response);
return ret;
}
/* get MaxxEffect revision */
static int waves_effect_revision(struct comp_dev *dev)
{
struct codec_data *codec = comp_get_codec(dev);
struct waves_codec_data *waves_codec = codec->private;
const char *revision = NULL;
uint32_t revision_len;
MaxxStatus_t status;
comp_info(dev, "waves_effect_revision() start");
status = MaxxEffect_Revision_Get(waves_codec->effect, &revision, &revision_len);
if (status) {
comp_err(dev, "waves_effect_revision() MaxxEffect_Revision_Get returned %d",
status);
return -EINVAL;
}
#if CONFIG_TRACEV
if (revision_len) {
const uint32_t *ptr = (uint32_t *)revision;
uint32_t len = revision_len / sizeof(uint32_t);
uint32_t idx = 0;
/* get requests from codec_adapter are not supported
* printing strings is not supported
* so dumping revision string to trace log as ascii values
* if simply write a for loop here then depending on trace filtering settings
* some parts of revision might not be printed - this is highly unwanted
*/
dump_hex(ptr, idx, len);
dump_hex(ptr, idx, len);
dump_hex(ptr, idx, len);
dump_hex(ptr, idx, len);
dump_hex(ptr, idx, len);
dump_hex(ptr, idx, len);
dump_hex(ptr, idx, len);
dump_hex(ptr, idx, len);
dump_hex(ptr, idx, len);
dump_hex(ptr, idx, len);
}
#endif
comp_info(dev, "waves_effect_revision() done");
return 0;
}
/* apply MaxxEffect message */
static int waves_effect_message(struct comp_dev *dev, void *data, uint32_t size)
{
struct codec_data *codec = comp_get_codec(dev);
struct waves_codec_data *waves_codec = codec->private;
MaxxStatus_t status;
uint32_t response_size = 0;
comp_info(dev, "waves_effect_message() start data %p size %d", data, size);
status = MaxxEffect_Message(waves_codec->effect, data, size,
waves_codec->response, &response_size);
if (status) {
comp_err(dev, "waves_effect_message() MaxxEffect_Message returned %d", status);
return -EINVAL;
}
#if CONFIG_TRACEV
/* at time of writing codec adapter does not support getting something from codec
* so response is stored to internal structure and dumped into trace messages
*/
if (response_size) {
uint32_t idx;
uint32_t len = response_size / sizeof(uint32_t);
const uint32_t *ptr = (uint32_t *)waves_codec->response;
for (idx = 0; idx < len; )
dump_hex(ptr, idx, len);
}
#endif
return 0;
}
/* apply codec config */
static int waves_effect_config(struct comp_dev *dev, enum codec_cfg_type type)
{
struct codec_config *cfg;
struct codec_data *codec = comp_get_codec(dev);
struct codec_param *param;
uint32_t index;
uint32_t param_number = 0;
int ret = 0;
comp_info(dev, "waves_codec_configure() start type %d", type);
cfg = (type == CODEC_CFG_SETUP) ? &codec->s_cfg : &codec->r_cfg;
comp_info(dev, "waves_codec_configure() config %p, size %d, avail %d",
cfg->data, cfg->size, cfg->avail);
if (!cfg->avail || !cfg->size) {
comp_err(dev, "waves_codec_configure() no config for type %d, avail %d, size %d",
type, cfg->avail, cfg->size);
return -EINVAL;
}
if (cfg->size > MAX_CONFIG_SIZE_BYTES) {
comp_err(dev, "waves_codec_configure() provided config is too big, size %d",
cfg->size);
return -EINVAL;
}
/* incoming data in cfg->data is arranged according to struct codec_param
* there migh be more than one struct codec_param inside cfg->data, glued back to back
*/
for (index = 0; index < cfg->size && (!ret); param_number++) {
uint32_t param_data_size;
param = (struct codec_param *)((char *)cfg->data + index);
param_data_size = param->size - sizeof(param->size) - sizeof(param->id);
comp_info(dev, "waves_codec_configure() param num %d id %d size %d",
param_number, param->id, param->size);
switch (param->id) {
case PARAM_NOP:
comp_info(dev, "waves_codec_configure() NOP");
break;
case PARAM_MESSAGE:
ret = waves_effect_message(dev, param->data, param_data_size);
break;
case PARAM_REVISION:
ret = waves_effect_revision(dev);
break;
default:
ret = -EINVAL;
break;
}
index += param->size;
}
if (ret)
comp_err(dev, "waves_codec_configure() failed %d", ret);
comp_dbg(dev, "waves_codec_configure() done");
return ret;
}
/* apply setup config */
static int waves_effect_setup_config(struct comp_dev *dev)
{
struct codec_data *codec = comp_get_codec(dev);
int ret;
comp_dbg(dev, "waves_effect_setup_config() start");
if (!codec->s_cfg.avail && !codec->s_cfg.size) {
comp_err(dev, "waves_effect_startup_config() setup config is not provided");
return -EINVAL;
}
if (!codec->s_cfg.avail) {
comp_warn(dev, "waves_effect_startup_config() using old setup config");
codec->s_cfg.avail = true;
}
ret = waves_effect_config(dev, CODEC_CFG_SETUP);
codec->s_cfg.avail = false;
comp_dbg(dev, "waves_effect_setup_config() done");
return ret;
}
int waves_codec_init(struct comp_dev *dev)
{
struct codec_data *codec = comp_get_codec(dev);
struct waves_codec_data *waves_codec;
int ret = 0;
comp_dbg(dev, "waves_codec_init() start");
waves_codec = codec_allocate_memory(dev, sizeof(struct waves_codec_data), 16);
if (!waves_codec) {
comp_err(dev, "waves_codec_init() failed to allocate %d bytes for waves_codec_data",
sizeof(struct waves_codec_data));
ret = -ENOMEM;
} else {
memset(waves_codec, 0, sizeof(struct waves_codec_data));
codec->private = waves_codec;
ret = waves_effect_allocate(dev);
if (ret) {
codec_free_memory(dev, waves_codec);
codec->private = NULL;
}
}
if (ret)
comp_err(dev, "waves_codec_init() failed %d", ret);
comp_dbg(dev, "waves_codec_init() done");
return ret;
}
int waves_codec_prepare(struct comp_dev *dev)
{
int ret;
comp_dbg(dev, "waves_codec_prepare() start");
ret = waves_effect_check(dev);
if (!ret)
ret = waves_effect_init(dev);
if (!ret)
ret = waves_effect_buffers(dev);
if (!ret)
ret = waves_effect_setup_config(dev);
if (ret)
comp_err(dev, "waves_codec_prepare() failed %d", ret);
comp_dbg(dev, "waves_codec_prepare() done");
return ret;
}
int waves_codec_init_process(struct comp_dev *dev)
{
struct codec_data *codec = comp_get_codec(dev);
comp_dbg(dev, "waves_codec_init_process()");
codec->cpd.produced = 0;
codec->cpd.consumed = 0;
codec->cpd.init_done = 1;
return 0;
}
int waves_codec_process(struct comp_dev *dev)
{
int ret;
struct codec_data *codec = comp_get_codec(dev);
struct waves_codec_data *waves_codec = codec->private;
comp_dbg(dev, "waves_codec_process() start");
MaxxStream_t *i_streams[NUM_IO_STREAMS] = { &waves_codec->i_stream };
MaxxStream_t *o_streams[NUM_IO_STREAMS] = { &waves_codec->o_stream };
MaxxStatus_t status;
uint32_t num_input_samples = waves_codec->buffer_samples;
/* here input buffer should always be filled up as requested
* since no one updates it`s size except code in prepare.
* on the other hand there is available/produced counters in cpd, check them anyways
*/
if (codec->cpd.avail != waves_codec->buffer_bytes) {
comp_warn(dev, "waves_codec_process() input buffer %d is not full %d",
codec->cpd.avail, waves_codec->buffer_bytes);
num_input_samples = codec->cpd.avail /
(waves_codec->sample_size_in_bytes * waves_codec->i_format.numChannels);
}
waves_codec->i_stream.buffersArray = &waves_codec->i_buffer;
waves_codec->i_stream.numAvailableSamples = num_input_samples;
waves_codec->i_stream.numProcessedSamples = 0;
waves_codec->i_stream.maxNumSamples = waves_codec->buffer_samples;
waves_codec->o_stream.buffersArray = &waves_codec->o_buffer;
waves_codec->o_stream.numAvailableSamples = 0;
waves_codec->o_stream.numProcessedSamples = 0;
waves_codec->o_stream.maxNumSamples = waves_codec->buffer_samples;
status = MaxxEffect_Process(waves_codec->effect, i_streams, o_streams);
if (status) {
comp_err(dev, "waves_codec_process() MaxxEffect_Process returned %d", status);
ret = -EINVAL;
} else {
codec->cpd.produced = waves_codec->o_stream.numAvailableSamples *
waves_codec->o_format.numChannels * waves_codec->sample_size_in_bytes;
codec->cpd.consumed = codec->cpd.produced;
ret = 0;
}
if (ret)
comp_err(dev, "waves_codec_process() failed %d", ret);
comp_dbg(dev, "waves_codec_process() done");
return ret;
}
int waves_codec_apply_config(struct comp_dev *dev)
{
int ret;
comp_dbg(dev, "waves_codec_apply_config() start");
ret = waves_effect_config(dev, CODEC_CFG_RUNTIME);
if (ret)
comp_err(dev, "waves_codec_apply_config() failed %d", ret);
comp_dbg(dev, "waves_codec_apply_config() done");
return ret;
}
int waves_codec_reset(struct comp_dev *dev)
{
MaxxStatus_t status;
int ret = 0;
struct codec_data *codec = comp_get_codec(dev);
struct waves_codec_data *waves_codec = codec->private;
comp_dbg(dev, "waves_codec_reset() start");
status = MaxxEffect_Reset(waves_codec->effect);
if (status) {
comp_err(dev, "waves_codec_reset() MaxxEffect_Reset returned %d", status);
ret = -EINVAL;
}
if (ret)
comp_err(dev, "waves_codec_reset() failed %d", ret);
comp_dbg(dev, "waves_codec_reset() done");
return ret;
}
int waves_codec_free(struct comp_dev *dev)
{
/* codec is using codec_adapter method codec_allocate_memory for all allocations
* codec_adapter will free it all on component free call
* nothing to do here
*/
comp_dbg(dev, "waves_codec_free()");
return 0;
}
static struct codec_interface waves_interface = {
.init = waves_codec_init,
.prepare = waves_codec_prepare,
.init_process = waves_codec_init_process,
.process = waves_codec_process,
.apply_config = waves_codec_apply_config,
.reset = waves_codec_reset,
.free = waves_codec_free
};
DECLARE_CODEC_ADAPTER(waves_interface, waves_uuid, waves_tr);