1/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
5
6#ifndef CRAS_DSP_MODULE_H_
7#define CRAS_DSP_MODULE_H_
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
13#include "cras_dsp_ini.h"
14
15/* Holds the functions we can use on a dsp module. */
16struct dsp_module {
17	/* Opaque data used by the implementation of this module */
18	void *data;
19
20	/* Initializes the module for a given sampling rate. To change
21	 * the sampling rate, deinstantiate() must be called before
22	 * calling instantiate again.
23	 * Args:
24	 *    sample_rate - The sampling rate for the audio data, like 44100.
25	 * Returns:
26	 *    0 if the initialization is successful. -1 otherwise.
27	 */
28	int (*instantiate)(struct dsp_module *mod, unsigned long sample_rate);
29
30	/* Assigns the memory location for a port of this module.
31	 * Args:
32	 *    port - The index of the port.
33	 *    data_location - The memory address of the data for this port.
34	 */
35	void (*connect_port)(struct dsp_module *mod, unsigned long port,
36			     float *data_location);
37
38	/* Returns the buffering delay of this module. This should be called
39	 * only after all input control ports have been connected.
40	 * Returns:
41	 *     The buffering delay in frames. The value returned should only be
42	 * based on the sampling rate and the input control ports values and not
43	 * the audio data itself.
44	 */
45	int (*get_delay)(struct dsp_module *mod);
46
47	/* Processes a block of samples using this module. The memory
48	 * location for the input and output data are assigned by the
49	 * connect_port() call.
50	 * Args:
51	 *    sample_count - The number of samples to be processed.
52	 */
53	void (*run)(struct dsp_module *mod, unsigned long sample_count);
54
55	/* Free resources used by the module. This module can be used
56	 * again by calling instantiate() */
57	void (*deinstantiate)(struct dsp_module *mod);
58
59	/* Frees all resources used by this module. After calling
60	 * free_module(), this struct dsp_module cannot be used
61	 * anymore.
62	 */
63	void (*free_module)(struct dsp_module *mod);
64
65	/* Returns special properties of this module, see the enum
66	 * below for details */
67	int (*get_properties)(struct dsp_module *mod);
68
69	/* Dumps the information about current state of this module */
70	void (*dump)(struct dsp_module *mod, struct dumper *d);
71};
72
73enum {
74	MODULE_INPLACE_BROKEN = 1  /* See ladspa.h for explanation */
75};
76
77struct dsp_module *cras_dsp_module_load_ladspa(struct plugin *plugin);
78struct dsp_module *cras_dsp_module_load_builtin(struct plugin *plugin);
79
80#ifdef __cplusplus
81} /* extern "C" */
82#endif
83
84#endif /* CRAS_DSP_MODULE_H_ */
85