Skip to content

Commit 551bb2d

Browse files
dbalutalgirdwood
authored andcommitted
codec: Add dummy codec implementation
This is useful to test codec adapter component and generic codec code. Our dummy codec has 1 input buffer and 1 output buffer and in its initial implementation just copies input to output without any processing on the data. Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
1 parent 7531d6b commit 551bb2d

File tree

5 files changed

+130
-0
lines changed

5 files changed

+130
-0
lines changed

src/audio/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,14 @@ config CADENCE_CODEC
336336
Select for codecs which conforms to the Cadence API.
337337
This will cause codec adapter component to include header
338338
files specific to CADENCE base codecs.
339+
340+
config DUMMY_CODEC
341+
bool "Dummy codec"
342+
default n
343+
help
344+
Select for a dummy API codec implementation.
345+
This will cause codec adapter component to include header
346+
files specific to DUMMY base codecs.
339347
endif
340348
endmenu # "Audio components"
341349

src/audio/codec_adapter/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ add_local_sources(sof codec_adapter.c codec/generic.c)
44
if(CONFIG_CADENCE_CODEC)
55
add_local_sources(sof codec/cadence.c)
66
endif()
7+
8+
if(CONFIG_DUMMY_CODEC)
9+
add_local_sources(sof codec/dummy.c)
10+
endif()
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
//
3+
// Copyright 2020 NXP
4+
//
5+
// Author: Daniel Baluta <daniel.baluta@nxp.com>
6+
//
7+
// Dummy codec implementation to demonstrate Codec Adapter API
8+
9+
#include <sof/audio/codec_adapter/codec/generic.h>
10+
#include <sof/audio/codec_adapter/codec/dummy.h>
11+
12+
int dummy_codec_init(struct comp_dev *dev)
13+
{
14+
comp_info(dev, "dummy_codec_init() start");
15+
return 0;
16+
}
17+
18+
int dummy_codec_prepare(struct comp_dev *dev)
19+
{
20+
struct codec_data *codec = comp_get_codec(dev);
21+
struct comp_data *cd = comp_get_drvdata(dev);
22+
23+
comp_info(dev, "dummy_codec_process()");
24+
25+
codec->cpd.in_buff = rballoc(0, SOF_MEM_CAPS_RAM, cd->period_bytes);
26+
if (!codec->cpd.in_buff) {
27+
comp_err(dev, "dummy_codec_prepare(): Failed to alloc in_buff");
28+
return -ENOMEM;
29+
}
30+
codec->cpd.in_buff_size = cd->period_bytes;
31+
32+
codec->cpd.out_buff = rballoc(0, SOF_MEM_CAPS_RAM, cd->period_bytes);
33+
if (!codec->cpd.out_buff) {
34+
comp_err(dev, "dummy_codec_prepare(): Failed to alloc out_buff");
35+
rfree(codec->cpd.in_buff);
36+
return -ENOMEM;
37+
}
38+
codec->cpd.out_buff_size = cd->period_bytes;
39+
40+
return 0;
41+
}
42+
43+
int dummy_codec_process(struct comp_dev *dev)
44+
{
45+
struct codec_data *codec = comp_get_codec(dev);
46+
struct comp_data *cd = comp_get_drvdata(dev);
47+
48+
comp_dbg(dev, "dummy_codec_process()");
49+
50+
memcpy_s(codec->cpd.out_buff, codec->cpd.out_buff_size,
51+
codec->cpd.in_buff, codec->cpd.in_buff_size);
52+
codec->cpd.produced = cd->period_bytes;
53+
54+
return 0;
55+
}
56+
57+
int dummy_codec_apply_config(struct comp_dev *dev)
58+
{
59+
comp_info(dev, "dummy_codec_apply_config()");
60+
61+
/* nothing to do */
62+
return 0;
63+
}
64+
65+
int dummy_codec_reset(struct comp_dev *dev)
66+
{
67+
comp_info(dev, "dummy_codec_reset()");
68+
69+
/* nothing to do */
70+
return 0;
71+
}
72+
73+
int dummy_codec_free(struct comp_dev *dev)
74+
{
75+
struct codec_data *codec = comp_get_codec(dev);
76+
77+
comp_info(dev, "dummy_codec_free()");
78+
79+
rfree(codec->cpd.in_buff);
80+
rfree(codec->cpd.out_buff);
81+
82+
return 0;
83+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* SPDX-License-Identifier: BSD-3-Clause
2+
*
3+
* Copyright 2020 NXP
4+
*
5+
* Author: Daniel Baluta <daniel.baluta@nxp.com>
6+
*/
7+
8+
#ifndef __SOF_AUDIO_DUMMY_CODEC__
9+
#define __SOF_AUDIO_DUMMY_CODEC__
10+
11+
int dummy_codec_init(struct comp_dev *dev);
12+
int dummy_codec_prepare(struct comp_dev *dev);
13+
int dummy_codec_process(struct comp_dev *dev);
14+
int dummy_codec_apply_config(struct comp_dev *dev);
15+
int dummy_codec_reset(struct comp_dev *dev);
16+
int dummy_codec_free(struct comp_dev *dev);
17+
18+
#endif /* __SOF_AUDIO_DUMMY_CODEC__ */

src/include/sof/audio/codec_adapter/interfaces.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515
#include <sof/audio/codec_adapter/codec/cadence.h>
1616
#endif /* CONFIG_CADENCE_CODEC */
1717

18+
#if CONFIG_DUMMY_CODEC
19+
#include <sof/audio/codec_adapter/codec/dummy.h>
20+
#endif
21+
1822
#define CADENCE_ID 0xCADE01
23+
#define DUMMY_ID 0xD03311
1924

2025
/*****************************************************************************/
2126
/* Linked codecs interfaces */
@@ -32,6 +37,18 @@ static struct codec_interface interfaces[] = {
3237
.free = cadence_codec_free
3338
},
3439
#endif /* CONFIG_CADENCE_CODEC */
40+
41+
#ifdef CONFIG_DUMMY_CODEC
42+
{
43+
.id = DUMMY_ID, /** dummy interface */
44+
.init = dummy_codec_init,
45+
.prepare = dummy_codec_prepare,
46+
.process = dummy_codec_process,
47+
.apply_config = dummy_codec_apply_config,
48+
.reset = dummy_codec_reset,
49+
.free = dummy_codec_free
50+
},
51+
#endif /* CONFIG_DUMMY_CODEC */
3552
};
3653

3754
#endif /* __SOF_AUDIO_CODEC_INTERFACES__ */

0 commit comments

Comments
 (0)