RetroArch/audio/ext/rarch_dsp.h

130 lines
3.6 KiB
C
Raw Normal View History

2011-05-13 19:05:28 +00:00
/////
2012-04-21 21:13:50 +00:00
// API header for external RetroArch DSP plugins.
2011-05-13 19:05:28 +00:00
//
//
2012-04-21 21:25:32 +00:00
#ifndef __RARCH_DSP_PLUGIN_H
#define __RARCH_DSP_PLUGIN_H
2011-05-13 19:05:28 +00:00
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _WIN32
2012-04-21 21:25:32 +00:00
#ifdef RARCH_DLL_IMPORT
#define RARCH_API_EXPORT __declspec(dllimport)
2011-05-13 19:05:28 +00:00
#else
2012-04-21 21:25:32 +00:00
#define RARCH_API_EXPORT __declspec(dllexport)
2011-05-13 19:05:28 +00:00
#endif
2012-04-21 21:25:32 +00:00
#define RARCH_API_CALLTYPE __cdecl
2011-05-13 19:05:28 +00:00
#else
2012-04-21 21:25:32 +00:00
#define RARCH_API_EXPORT
#define RARCH_API_CALLTYPE
2011-05-13 19:05:28 +00:00
#endif
2012-04-21 21:25:32 +00:00
#ifndef RARCH_FALSE
#define RARCH_FALSE 0
#endif
2012-04-21 21:25:32 +00:00
#ifndef RARCH_TRUE
#define RARCH_TRUE 1
#endif
2011-05-13 19:05:28 +00:00
2012-04-21 21:25:32 +00:00
#define RARCH_DSP_API_VERSION 3
2011-05-13 19:19:05 +00:00
2012-04-21 21:25:32 +00:00
typedef struct rarch_dsp_info
2011-05-13 19:05:28 +00:00
{
// Input sample rate that the DSP plugin receives. This is generally ~32kHz.
// Some small variance is allowed due to syncing behavior.
float input_rate;
2011-05-13 19:19:05 +00:00
2012-04-21 21:13:50 +00:00
// RetroArch requests that the DSP plugin resamples the
2011-05-13 19:05:28 +00:00
// input to a certain frequency.
//
// However, the plugin might ignore this
2012-04-21 21:25:32 +00:00
// using the resample field in rarch_dsp_output_t (see below).
2011-05-13 19:05:28 +00:00
float output_rate;
2012-04-21 21:25:32 +00:00
} rarch_dsp_info_t;
2011-05-13 19:05:28 +00:00
2012-04-21 21:25:32 +00:00
typedef struct rarch_dsp_output
2011-05-13 19:05:28 +00:00
{
// The DSP plugin has to provide the buffering for the output samples.
// This is for performance reasons to avoid redundant copying of data.
// The samples are laid out in interleaving order: LRLRLRLR
// The range of the samples are [-1.0, 1.0].
// This range cannot be exceeded without horrible audio glitches.
const float *samples;
2011-05-13 19:19:05 +00:00
2011-05-13 19:05:28 +00:00
// Frames which the DSP plugin outputted for the current process.
// One frame is here defined as a combined sample of
// left and right channels.
// (I.e. 44.1kHz, 16bit stereo will have
// 88.2k samples/sec and 44.1k frames/sec.)
unsigned frames;
// If true, the DSP plugin did not resample the input audio,
// and requests resampling to the proper frequency to be
// performed outside the plugin.
// If false,
2011-05-13 20:05:16 +00:00
// it is assumed that the output has the same sample rate as given
// in output_rate.
2011-05-13 19:05:28 +00:00
int should_resample;
2012-04-21 21:25:32 +00:00
} rarch_dsp_output_t;
2011-05-13 19:05:28 +00:00
2012-04-21 21:25:32 +00:00
typedef struct rarch_dsp_input
2011-05-13 19:05:28 +00:00
{
// Input data for the DSP. The samples are interleaved in order: LRLRLRLR
const float *samples;
2011-05-13 19:19:05 +00:00
2011-05-13 19:05:28 +00:00
// Number of frames for input data.
// One frame is here defined as a combined sample of
// left and right channels.
// (I.e. 44.1kHz, 16bit stereo will have
// 88.2k samples/sec and 44.1k frames/sec.)
unsigned frames;
2012-04-21 21:25:32 +00:00
} rarch_dsp_input_t;
2011-05-13 19:05:28 +00:00
2012-04-21 21:25:32 +00:00
typedef struct rarch_dsp_plugin
2011-05-13 19:05:28 +00:00
{
// Creates a handle of the plugin. Returns NULL if failed.
2012-04-21 21:25:32 +00:00
void *(*init)(const rarch_dsp_info_t *info);
2011-05-13 19:05:28 +00:00
// Processes input data.
// The plugin is allowed to return variable sizes for output data.
2012-04-21 21:25:32 +00:00
void (*process)(void *data, rarch_dsp_output_t *output,
const rarch_dsp_input_t *input);
2011-05-13 19:05:28 +00:00
2011-08-13 02:09:08 +00:00
// Frees the handle.
2011-05-13 19:05:28 +00:00
void (*free)(void *data);
2011-05-13 19:19:05 +00:00
// API version used to compile the plugin.
// Used to detect mismatches in API.
2012-04-21 21:25:32 +00:00
// Must be set to RARCH_DSP_API_VERSION on compile.
2011-05-13 19:19:05 +00:00
int api_version;
// Signal plugin that it may open a configuring window or
// something similiar. The behavior of this function
// is thus plugin dependent. Implementing this is optional,
// and can be set to NULL.
void (*config)(void *data);
// Human readable identification string.
const char *ident;
2011-08-13 02:09:08 +00:00
// Called every frame, allows creating a GUI main loop in the main thread.
// GUI events can be processed here in a non-blocking fashion.
// Can be set to NULL to ignore it.
void (*events)(void *data);
2012-04-21 21:25:32 +00:00
} rarch_dsp_plugin_t;
2011-05-13 19:05:28 +00:00
2012-04-21 21:13:50 +00:00
// Called by RetroArch at startup to get the callback struct.
2011-05-14 18:53:38 +00:00
// This is NOT dynamically allocated!
2012-04-21 21:25:32 +00:00
RARCH_API_EXPORT const rarch_dsp_plugin_t* RARCH_API_CALLTYPE
rarch_dsp_plugin_init(void);
2011-05-13 19:05:28 +00:00
#ifdef __cplusplus
}
#endif
#endif