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_H_ 7 #define CRAS_DSP_H_ 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 #include "cras_dsp_pipeline.h" 14 15 struct cras_dsp_context; 16 17 /* Starts the dsp subsystem. It starts a thread internally to load the 18 * plugins. This should be called before other functions. 19 * Args: 20 * filename - The ini file where the dsp plugin graph should be read from. 21 */ 22 void cras_dsp_init(const char *filename); 23 24 /* Stops the dsp subsystem. */ 25 void cras_dsp_stop(); 26 27 /* Creates a dsp context. The context holds a pipeline and its 28 * parameters. To use the pipeline in the context, first use 29 * cras_dsp_load_pipeline() to load it and then use 30 * cras_dsp_get_pipeline() to lock it for access. 31 * Args: 32 * sample_rate - The sampling rate of the pipeline. 33 * purpose - The purpose of the pipeline, "playback" or "capture". 34 * Returns: 35 * A pointer to the dsp context. 36 */ 37 struct cras_dsp_context *cras_dsp_context_new(int sample_rate, 38 const char *purpose); 39 40 /* Frees a dsp context. */ 41 void cras_dsp_context_free(struct cras_dsp_context *ctx); 42 43 /* Sets a configuration string variable in the context. */ 44 void cras_dsp_set_variable_string(struct cras_dsp_context *ctx, const char *key, 45 const char *value); 46 47 /* Sets a configuration boolean variable in the context. */ 48 void cras_dsp_set_variable_boolean(struct cras_dsp_context *ctx, const char *key, 49 char value); 50 51 /* Loads the pipeline to the context. This should be called again when 52 * new values of configuration variables may change the plugin 53 * graph. The actual loading happens in another thread to avoid 54 * blocking the audio thread. */ 55 void cras_dsp_load_pipeline(struct cras_dsp_context *ctx); 56 57 /* Locks the pipeline in the context for access. Returns NULL if the 58 * pipeline is still being loaded or cannot be loaded. */ 59 struct pipeline *cras_dsp_get_pipeline(struct cras_dsp_context *ctx); 60 61 /* Releases the pipeline in the context. This must be called in pair 62 * with cras_dsp_get_pipeline() once the client finishes using the 63 * pipeline. This should be called in the same thread as 64 * cras_dsp_get_pipeline() was called. */ 65 void cras_dsp_put_pipeline(struct cras_dsp_context *ctx); 66 67 /* Re-reads the ini file and reloads all pipelines in the system. */ 68 void cras_dsp_reload_ini(); 69 70 /* Dump current dsp information to syslog. */ 71 void cras_dsp_dump_info(); 72 73 /* Number of channels output. */ 74 unsigned int cras_dsp_num_output_channels(const struct cras_dsp_context *ctx); 75 76 /* Number of channels input. */ 77 unsigned int cras_dsp_num_input_channels(const struct cras_dsp_context *ctx); 78 79 #ifdef __cplusplus 80 } /* extern "C" */ 81 #endif 82 83 #endif /* CRAS_DSP_H_ */ 84