forked from thesofproject/sof
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwaves.c
More file actions
870 lines (725 loc) · 24.6 KB
/
waves.c
File metadata and controls
870 lines (725 loc) · 24.6 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
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2020 Waves Audio Ltd. All rights reserved.
//
// Author: Oleksandr Strelchenko <oleksandr.strelchenko@waves.com>
//
#include <rtos/init.h>
#include <sof/audio/module_adapter/module/generic.h>
#include <sof/debug/debug.h>
#include <sof/compiler_attributes.h>
#include <sof/audio/MaxxEffect/Initialize/MaxxEffect_Initialize.h>
#include <sof/audio/MaxxEffect/Process/MaxxEffect_Process.h>
#include <sof/audio/MaxxEffect/Process/MaxxEffect_Reset.h>
#include <sof/audio/MaxxEffect/Control/RPC/MaxxEffect_RPC_Server.h>
#include <sof/audio/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;
struct module_config setup_cfg;
};
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 processing_module *mod)
{
struct comp_dev *dev = mod->dev;
struct module_data *codec = &mod->priv;
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 *)module_allocate_memory(mod,
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_dbg(dev, "waves_effect_allocate() allocated %d bytes for effect",
waves_codec->effect_size);
return 0;
}
/* checks if sink/source parameters fit MaxxEffect */
static int waves_effect_check(struct comp_dev *dev)
{
struct comp_buffer *sink = list_first_item(&dev->bsink_list, struct comp_buffer,
source_list);
struct comp_buffer *source = list_first_item(&dev->bsource_list, struct comp_buffer,
sink_list);
const struct audio_stream *src_fmt = &source->stream;
const struct audio_stream *snk_fmt = &sink->stream;
/* Init sink & source buffers */
comp_dbg(dev, "waves_effect_check() start");
/* todo use fallback to comp_verify_params when ready */
/* resampling not supported */
if (audio_stream_get_rate(src_fmt) != audio_stream_get_rate(snk_fmt)) {
comp_err(dev, "waves_effect_check() source %d sink %d rate mismatch",
audio_stream_get_rate(src_fmt), audio_stream_get_rate(snk_fmt));
return -EINVAL;
}
/* upmix/downmix not supported */
if (audio_stream_get_channels(src_fmt) != audio_stream_get_channels(snk_fmt)) {
comp_err(dev, "waves_effect_check() source %d sink %d channels mismatch",
audio_stream_get_channels(src_fmt), audio_stream_get_channels(snk_fmt));
return -EINVAL;
}
/* different frame format not supported */
if (audio_stream_get_frm_fmt(src_fmt) != audio_stream_get_frm_fmt(snk_fmt)) {
comp_err(dev, "waves_effect_check() source %d sink %d sample format mismatch",
audio_stream_get_frm_fmt(src_fmt), audio_stream_get_frm_fmt(snk_fmt));
return -EINVAL;
}
/* different interleaving is not supported */
if (audio_stream_get_buffer_fmt(src_fmt) != audio_stream_get_buffer_fmt(snk_fmt)) {
comp_err(dev, "waves_effect_check() source %d sink %d buffer format mismatch");
return -EINVAL;
}
if (!format_is_supported(audio_stream_get_frm_fmt(src_fmt))) {
comp_err(dev, "waves_effect_check() float samples not supported");
return -EINVAL;
}
if (!layout_is_supported(audio_stream_get_buffer_fmt(src_fmt))) {
comp_err(dev, "waves_effect_check() non interleaved format not supported");
return -EINVAL;
}
if (!rate_is_supported(audio_stream_get_rate(src_fmt))) {
comp_err(dev, "waves_effect_check() rate %d not supported",
audio_stream_get_rate(src_fmt));
return -EINVAL;
}
if (audio_stream_get_channels(src_fmt) != 2) {
comp_err(dev, "waves_effect_check() channels %d not supported",
audio_stream_get_channels(src_fmt));
return -EINVAL;
}
comp_dbg(dev, "waves_effect_check() done");
return 0;
}
/* initializes MaxxEffect based on stream parameters */
static int waves_effect_init(struct processing_module *mod)
{
struct comp_dev *dev = mod->dev;
struct comp_buffer *source = list_first_item(&dev->bsource_list, struct comp_buffer,
sink_list);
struct module_data *codec = &mod->priv;
struct waves_codec_data *waves_codec = codec->private;
const struct audio_stream *src_fmt = &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(audio_stream_get_frm_fmt(src_fmt));
if (sample_format < 0) {
comp_err(dev, "waves_effect_init() sof sample format %d not supported",
audio_stream_get_frm_fmt(src_fmt));
return -EINVAL;
}
buffer_format = layout_convert_sof_to_me(audio_stream_get_buffer_fmt(src_fmt));
if (buffer_format < 0) {
comp_err(dev, "waves_effect_init() sof buffer format %d not supported",
audio_stream_get_buffer_fmt(src_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->i_buffer = 0;
waves_codec->o_buffer = 0;
waves_codec->i_format.sampleRate = audio_stream_get_rate(src_fmt);
waves_codec->i_format.numChannels = audio_stream_get_channels(src_fmt);
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;
/* Prepare a buffer for 1 period worth of data
* dev->pipeline->period stands for the scheduling period in us
*/
waves_codec->buffer_samples = audio_stream_get_rate(src_fmt) * dev->pipeline->period /
1000000;
waves_codec->buffer_bytes = waves_codec->buffer_samples *
audio_stream_get_channels(src_fmt) * 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 processing_module *mod)
{
struct comp_dev *dev = mod->dev;
struct module_data *codec = &mod->priv;
struct waves_codec_data *waves_codec = codec->private;
int ret;
void *i_buffer = NULL, *o_buffer = NULL;
comp_dbg(dev, "waves_effect_buffers() start");
i_buffer = module_allocate_memory(mod, 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 = module_allocate_memory(mod, 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;
codec->mpd.in_buff = waves_codec->i_buffer;
codec->mpd.in_buff_size = waves_codec->buffer_bytes;
codec->mpd.out_buff = waves_codec->o_buffer;
codec->mpd.out_buff_size = waves_codec->buffer_bytes;
comp_dbg(dev, "waves_effect_buffers() in_buff_size %d, out_buff_size %d",
codec->mpd.in_buff_size, codec->mpd.out_buff_size);
comp_dbg(dev, "waves_effect_buffers() done");
return 0;
err:
if (i_buffer)
module_free_memory(mod, i_buffer);
if (o_buffer)
module_free_memory(mod, o_buffer);
return ret;
}
/* get MaxxEffect revision */
static int waves_effect_revision(struct processing_module *mod)
{
struct module_data *codec = &mod->priv;
struct waves_codec_data *waves_codec = codec->private;
struct comp_dev *dev = mod->dev;
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 processing_module *mod, void *data, uint32_t size)
{
struct module_data *codec = &mod->priv;
struct waves_codec_data *waves_codec = codec->private;
struct comp_dev *dev = mod->dev;
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 processing_module *mod)
{
struct comp_dev *dev = mod->dev;
struct module_data *codec = &mod->priv;
struct waves_codec_data *waves_codec = codec->private;
struct module_param *param;
struct module_config *cfg;
uint32_t index;
uint32_t param_number = 0;
int ret = 0;
comp_info(dev, "waves_codec_configure() start");
cfg = &codec->cfg;
/* use setup config if no runtime config available */
if (!cfg->avail)
cfg = &waves_codec->setup_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, avail %d, size %d",
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 module_param
* there migh be more than one struct module_param inside cfg->data, glued back to back
*/
for (index = 0; index < cfg->size && (!ret); param_number++) {
uint32_t param_data_size;
param = (struct module_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(mod, param->data, param_data_size);
break;
case PARAM_REVISION:
ret = waves_effect_revision(mod);
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 processing_module *mod)
{
struct comp_dev *dev = mod->dev;
int ret;
comp_dbg(dev, "waves_effect_setup_config() start");
ret = waves_effect_config(mod);
if (ret < 0) {
comp_err(dev, "waves_effect_setup_config(): fail to apply config");
return ret;
}
comp_dbg(dev, "waves_effect_setup_config() done");
return 0;
}
static int waves_codec_init(struct processing_module *mod)
{
struct comp_dev *dev = mod->dev;
struct module_data *codec = &mod->priv;
struct waves_codec_data *waves_codec;
int ret = 0;
void *response = NULL;
comp_dbg(dev, "waves_codec_init() start");
waves_codec = module_allocate_memory(mod, 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(mod);
if (ret) {
module_free_memory(mod, waves_codec);
codec->private = NULL;
}
}
if (ret) {
comp_err(dev, "waves_codec_init() failed %d", ret);
return ret;
}
waves_codec->setup_cfg.avail = false;
/* copy the setup config only for the first init */
if (codec->state == MODULE_DISABLED && codec->cfg.avail) {
struct module_config *setup_cfg = &waves_codec->setup_cfg;
/* allocate memory for set up config */
setup_cfg->data = module_allocate_memory(mod, codec->cfg.size, 16);
if (!setup_cfg->data) {
comp_err(dev, "waves_codec_init(): failed to alloc setup config");
module_free_memory(mod, waves_codec);
return -ENOMEM;
}
/* copy the setup config */
setup_cfg->size = codec->cfg.size;
ret = memcpy_s(setup_cfg->data, setup_cfg->size,
codec->cfg.init_data, setup_cfg->size);
if (ret) {
comp_err(dev, "waves_codec_init(): failed to copy setup config %d", ret);
module_free_memory(mod, setup_cfg->data);
module_free_memory(mod, waves_codec);
return ret;
}
setup_cfg->avail = true;
}
ret = MaxxEffect_GetMessageMaxSize(waves_codec->effect, &waves_codec->request_max_bytes,
&waves_codec->response_max_bytes);
if (ret) {
comp_err(dev, "waves_codec_init() MaxxEffect_GetMessageMaxSize returned %d", ret);
return -EINVAL;
}
response = module_allocate_memory(mod, waves_codec->response_max_bytes, 16);
if (!response) {
comp_err(dev, "waves_codec_init() failed to allocate %d bytes for response",
waves_codec->response_max_bytes);
return -ENOMEM;
}
waves_codec->response = response;
comp_dbg(dev, "waves_codec_init() done");
return ret;
}
static int waves_codec_prepare(struct processing_module *mod,
struct sof_source **sources, int num_of_sources,
struct sof_sink **sinks, int num_of_sinks)
{
struct comp_dev *dev = mod->dev;
int ret;
comp_dbg(dev, "waves_codec_prepare() start");
ret = waves_effect_check(dev);
if (!ret)
ret = waves_effect_init(mod);
if (!ret)
ret = waves_effect_buffers(mod);
if (!ret)
ret = waves_effect_setup_config(mod);
if (ret)
comp_err(dev, "waves_codec_prepare() failed %d", ret);
comp_dbg(dev, "waves_codec_prepare() done");
return ret;
}
static int waves_codec_init_process(struct processing_module *mod)
{
struct module_data *codec = &mod->priv;
struct comp_dev *dev = mod->dev;
comp_dbg(dev, "waves_codec_init_process()");
codec->mpd.produced = 0;
codec->mpd.consumed = 0;
codec->mpd.init_done = 1;
return 0;
}
static int
waves_codec_process(struct processing_module *mod,
struct input_stream_buffer *input_buffers, int num_input_buffers,
struct output_stream_buffer *output_buffers, int num_output_buffers)
{
int ret;
struct comp_dev *dev = mod->dev;
struct module_data *codec = &mod->priv;
struct waves_codec_data *waves_codec = codec->private;
/* Proceed only if we have enough data to fill the module buffer completely */
if (input_buffers[0].size < codec->mpd.in_buff_size) {
comp_dbg(dev, "waves_codec_process(): not enough data to process");
return -ENODATA;
}
if (!codec->mpd.init_done)
waves_codec_init_process(mod);
memcpy_s(codec->mpd.in_buff, codec->mpd.in_buff_size,
input_buffers[0].data, codec->mpd.in_buff_size);
codec->mpd.avail = codec->mpd.in_buff_size;
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 mpd, check them anyways
*/
if (codec->mpd.avail != waves_codec->buffer_bytes) {
comp_warn(dev, "waves_codec_process() input buffer %d is not full %d",
codec->mpd.avail, waves_codec->buffer_bytes);
num_input_samples = codec->mpd.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->mpd.produced = waves_codec->o_stream.numAvailableSamples *
waves_codec->o_format.numChannels * waves_codec->sample_size_in_bytes;
codec->mpd.consumed = codec->mpd.produced;
input_buffers[0].consumed = codec->mpd.consumed;
ret = 0;
/* copy the produced samples into the output buffer */
memcpy_s(output_buffers[0].data, codec->mpd.produced, codec->mpd.out_buff,
codec->mpd.produced);
output_buffers[0].size = codec->mpd.produced;
}
if (ret)
comp_err(dev, "waves_codec_process() failed %d", ret);
comp_dbg(dev, "waves_codec_process() done");
return ret;
}
static int waves_codec_apply_config(struct processing_module *mod)
{
int ret;
struct comp_dev *dev = mod->dev;
comp_dbg(dev, "waves_codec_apply_config() start");
ret = waves_effect_config(mod);
if (ret)
comp_err(dev, "waves_codec_apply_config() failed %d", ret);
comp_dbg(dev, "waves_codec_apply_config() done");
return ret;
}
static int waves_codec_reset(struct processing_module *mod)
{
MaxxStatus_t status;
int ret = 0;
struct comp_dev *dev = mod->dev;
struct module_data *codec = &mod->priv;
struct waves_codec_data *waves_codec = codec->private;
comp_info(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);
if (codec->mpd.in_buff)
module_free_memory(mod, codec->mpd.in_buff);
if (codec->mpd.out_buff)
module_free_memory(mod, codec->mpd.out_buff);
comp_dbg(dev, "waves_codec_reset() done");
return ret;
}
static int waves_codec_free(struct processing_module *mod)
{
module_free_all_memory(mod);
comp_dbg(mod->dev, "waves_codec_free()");
return 0;
}
static int
waves_codec_set_configuration(struct processing_module *mod, uint32_t config_id,
enum module_cfg_fragment_position pos, uint32_t data_offset_size,
const uint8_t *fragment, size_t fragment_size, uint8_t *response,
size_t response_size)
{
struct module_data *md = &mod->priv;
struct comp_dev *dev = mod->dev;
int ret;
ret = module_set_configuration(mod, config_id, pos, data_offset_size, fragment,
fragment_size, response, response_size);
if (ret < 0)
return ret;
/* return if more fragments are expected or if the module is not prepared */
if ((pos != MODULE_CFG_FRAGMENT_LAST && pos != MODULE_CFG_FRAGMENT_SINGLE) ||
md->state < MODULE_INITIALIZED)
return 0;
/* whole configuration received, apply it now */
ret = waves_codec_apply_config(mod);
if (ret) {
comp_err(dev, "waves_codec_set_configuration(): error %x: runtime config apply failed",
ret);
return ret;
}
comp_dbg(dev, "waves_codec_set_configuration(): config applied");
return 0;
}
static const struct module_interface waves_interface = {
.init = waves_codec_init,
.prepare = waves_codec_prepare,
.process_raw_data = waves_codec_process,
.set_configuration = waves_codec_set_configuration,
.reset = waves_codec_reset,
.free = waves_codec_free
};
DECLARE_MODULE_ADAPTER(waves_interface, waves_uuid, waves_tr);
SOF_MODULE_INIT(waves, sys_comp_module_waves_interface_init);