2009-01-05 12:41:40 +00:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2008-02-22 09:09:46 +00:00
|
|
|
#ifndef MPLAYER_AF_H
|
|
|
|
#define MPLAYER_AF_H
|
2004-06-26 10:05:13 +00:00
|
|
|
|
2002-11-12 12:33:56 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
2009-03-28 20:21:20 +00:00
|
|
|
|
|
|
|
#include "af_format.h"
|
2002-10-16 01:49:40 +00:00
|
|
|
#include "control.h"
|
2009-03-28 20:01:43 +00:00
|
|
|
#include "cpudetect.h"
|
2009-03-28 20:03:08 +00:00
|
|
|
#include "mp_msg.h"
|
2009-03-28 20:01:43 +00:00
|
|
|
|
|
|
|
/* Set the initialization type from mplayers cpudetect */
|
|
|
|
#ifdef AF_INIT_TYPE
|
|
|
|
#undef AF_INIT_TYPE
|
|
|
|
#define AF_INIT_TYPE \
|
|
|
|
((gCpuCaps.has3DNow || gCpuCaps.hasSSE)?AF_INIT_FAST:AF_INIT_SLOW)
|
2009-05-13 02:58:57 +00:00
|
|
|
#endif
|
2002-10-16 01:49:40 +00:00
|
|
|
|
2002-10-01 06:45:08 +00:00
|
|
|
struct af_instance_s;
|
|
|
|
|
2006-11-25 19:57:31 +00:00
|
|
|
// Number of channels
|
|
|
|
#ifndef AF_NCH
|
2009-11-10 00:45:19 +00:00
|
|
|
#define AF_NCH 8
|
2006-11-25 19:57:31 +00:00
|
|
|
#endif
|
|
|
|
|
2002-10-01 06:45:08 +00:00
|
|
|
// Audio data chunk
|
|
|
|
typedef struct af_data_s
|
|
|
|
{
|
|
|
|
void* audio; // data buffer
|
|
|
|
int len; // buffer length
|
|
|
|
int rate; // sample rate
|
|
|
|
int nch; // number of channels
|
|
|
|
int format; // format
|
|
|
|
int bps; // bytes per sample
|
|
|
|
} af_data_t;
|
|
|
|
|
2005-01-08 21:34:06 +00:00
|
|
|
|
2002-11-12 12:33:56 +00:00
|
|
|
// Flags used for defining the behavior of an audio filter
|
2002-10-06 11:26:14 +00:00
|
|
|
#define AF_FLAGS_REENTRANT 0x00000000
|
|
|
|
#define AF_FLAGS_NOT_REENTRANT 0x00000001
|
|
|
|
|
2002-10-01 06:45:08 +00:00
|
|
|
/* Audio filter information not specific for current instance, but for
|
2009-05-13 02:58:57 +00:00
|
|
|
a specific filter */
|
|
|
|
typedef struct af_info_s
|
2002-10-01 06:45:08 +00:00
|
|
|
{
|
|
|
|
const char *info;
|
|
|
|
const char *name;
|
|
|
|
const char *author;
|
|
|
|
const char *comment;
|
2002-10-06 11:26:14 +00:00
|
|
|
const int flags;
|
2002-10-01 06:45:08 +00:00
|
|
|
int (*open)(struct af_instance_s* vf);
|
|
|
|
} af_info_t;
|
|
|
|
|
|
|
|
// Linked list of audio filters
|
|
|
|
typedef struct af_instance_s
|
|
|
|
{
|
|
|
|
af_info_t* info;
|
|
|
|
int (*control)(struct af_instance_s* af, int cmd, void* arg);
|
|
|
|
void (*uninit)(struct af_instance_s* af);
|
|
|
|
af_data_t* (*play)(struct af_instance_s* af, af_data_t* data);
|
|
|
|
void* setup; // setup data for this specific instance and filter
|
|
|
|
af_data_t* data; // configuration for outgoing data stream
|
|
|
|
struct af_instance_s* next;
|
2009-05-13 02:58:57 +00:00
|
|
|
struct af_instance_s* prev;
|
2007-11-01 06:52:50 +00:00
|
|
|
double delay; /* Delay caused by the filter, in units of bytes read without
|
|
|
|
* corresponding output */
|
2007-11-01 06:52:01 +00:00
|
|
|
double mul; /* length multiplier: how much does this instance change
|
2002-10-01 06:45:08 +00:00
|
|
|
the length of the buffer. */
|
|
|
|
}af_instance_t;
|
|
|
|
|
2002-10-16 01:49:40 +00:00
|
|
|
// Initialization flags
|
2002-11-12 12:33:56 +00:00
|
|
|
extern int* af_cpu_speed;
|
|
|
|
|
2002-10-16 01:49:40 +00:00
|
|
|
#define AF_INIT_AUTO 0x00000000
|
|
|
|
#define AF_INIT_SLOW 0x00000001
|
|
|
|
#define AF_INIT_FAST 0x00000002
|
|
|
|
#define AF_INIT_FORCE 0x00000003
|
|
|
|
#define AF_INIT_TYPE_MASK 0x00000003
|
2002-10-01 12:53:30 +00:00
|
|
|
|
2003-01-10 01:01:38 +00:00
|
|
|
#define AF_INIT_INT 0x00000000
|
2003-01-10 01:45:34 +00:00
|
|
|
#define AF_INIT_FLOAT 0x00000004
|
|
|
|
#define AF_INIT_FORMAT_MASK 0x00000004
|
2003-01-10 01:01:38 +00:00
|
|
|
|
2009-05-13 02:58:57 +00:00
|
|
|
// Default init type
|
2002-11-12 12:33:56 +00:00
|
|
|
#ifndef AF_INIT_TYPE
|
2009-01-26 09:29:53 +00:00
|
|
|
#if HAVE_SSE || HAVE_AMD3DNOW
|
2002-11-12 12:33:56 +00:00
|
|
|
#define AF_INIT_TYPE (af_cpu_speed?*af_cpu_speed:AF_INIT_FAST)
|
|
|
|
#else
|
|
|
|
#define AF_INIT_TYPE (af_cpu_speed?*af_cpu_speed:AF_INIT_SLOW)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2002-10-01 12:53:30 +00:00
|
|
|
// Configuration switches
|
|
|
|
typedef struct af_cfg_s{
|
|
|
|
int force; // Initialization type
|
2002-11-12 12:33:56 +00:00
|
|
|
char** list; /* list of names of filters that are added to filter
|
2002-10-01 12:53:30 +00:00
|
|
|
list during first initialization of stream */
|
|
|
|
}af_cfg_t;
|
|
|
|
|
|
|
|
// Current audio stream
|
|
|
|
typedef struct af_stream_s
|
|
|
|
{
|
|
|
|
// The first and last filter in the list
|
|
|
|
af_instance_t* first;
|
|
|
|
af_instance_t* last;
|
|
|
|
// Storage for input and output data formats
|
|
|
|
af_data_t input;
|
|
|
|
af_data_t output;
|
2002-11-12 12:33:56 +00:00
|
|
|
// Configuration for this stream
|
2002-10-01 12:53:30 +00:00
|
|
|
af_cfg_t cfg;
|
|
|
|
}af_stream_t;
|
|
|
|
|
2002-10-01 06:45:08 +00:00
|
|
|
/*********************************************
|
|
|
|
// Return values
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define AF_DETACH 2
|
|
|
|
#define AF_OK 1
|
|
|
|
#define AF_TRUE 1
|
|
|
|
#define AF_FALSE 0
|
|
|
|
#define AF_UNKNOWN -1
|
|
|
|
#define AF_ERROR -2
|
2002-11-12 12:33:56 +00:00
|
|
|
#define AF_FATAL -3
|
2002-10-01 06:45:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2002-10-16 01:49:40 +00:00
|
|
|
/*********************************************
|
2002-10-01 06:45:08 +00:00
|
|
|
// Export functions
|
2002-10-16 01:49:40 +00:00
|
|
|
*/
|
2002-10-01 06:45:08 +00:00
|
|
|
|
2005-10-01 12:55:34 +00:00
|
|
|
/**
|
|
|
|
* \defgroup af_chain Audio filter chain functions
|
|
|
|
* \{
|
|
|
|
* \param s filter chain
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Initialize the stream "s".
|
|
|
|
* \return 0 on success, -1 on failure
|
|
|
|
*
|
|
|
|
* This function creates a new filter list if necessary, according
|
|
|
|
* to the values set in input and output. Input and output should contain
|
|
|
|
* the format of the current movie and the format of the preferred output
|
|
|
|
* respectively.
|
|
|
|
* Filters to convert to the preferred output format are inserted
|
|
|
|
* automatically, except when they are set to 0.
|
|
|
|
* The function is reentrant i.e. if called with an already initialized
|
|
|
|
* stream the stream will be reinitialized.
|
|
|
|
*/
|
2005-06-24 10:50:53 +00:00
|
|
|
int af_init(af_stream_t* s);
|
2002-10-07 10:46:01 +00:00
|
|
|
|
2005-10-01 12:55:34 +00:00
|
|
|
/**
|
|
|
|
* \brief Uninit and remove all filters from audio filter chain
|
|
|
|
*/
|
2002-10-01 12:53:30 +00:00
|
|
|
void af_uninit(af_stream_t* s);
|
2002-10-07 10:46:01 +00:00
|
|
|
|
2005-10-01 12:55:34 +00:00
|
|
|
/**
|
|
|
|
* \brief This function adds the filter "name" to the stream s.
|
|
|
|
* \param name name of filter to add
|
|
|
|
* \return pointer to the new filter, NULL if insert failed
|
|
|
|
*
|
|
|
|
* The filter will be inserted somewhere nice in the
|
|
|
|
* list of filters (i.e. at the beginning unless the
|
|
|
|
* first filter is the format filter (why??).
|
|
|
|
*/
|
2002-10-07 10:46:01 +00:00
|
|
|
af_instance_t* af_add(af_stream_t* s, char* name);
|
|
|
|
|
2005-10-01 12:55:34 +00:00
|
|
|
/**
|
|
|
|
* \brief Uninit and remove the filter "af"
|
|
|
|
* \param af filter to remove
|
|
|
|
*/
|
2002-10-07 10:46:01 +00:00
|
|
|
void af_remove(af_stream_t* s, af_instance_t* af);
|
|
|
|
|
2005-10-01 12:55:34 +00:00
|
|
|
/**
|
|
|
|
* \brief find filter in chain by name
|
|
|
|
* \param name name of the filter to find
|
|
|
|
* \return first filter with right name or NULL if not found
|
2009-05-13 02:58:57 +00:00
|
|
|
*
|
2005-10-01 12:55:34 +00:00
|
|
|
* This function is used for finding already initialized filters
|
|
|
|
*/
|
2002-10-07 10:46:01 +00:00
|
|
|
af_instance_t* af_get(af_stream_t* s, char* name);
|
|
|
|
|
2005-10-01 12:55:34 +00:00
|
|
|
/**
|
|
|
|
* \brief filter data chunk through the filters in the list
|
|
|
|
* \param data data to play
|
|
|
|
* \return resulting data
|
|
|
|
* \ingroup af_chain
|
|
|
|
*/
|
2002-10-01 12:53:30 +00:00
|
|
|
af_data_t* af_play(af_stream_t* s, af_data_t* data);
|
2002-10-07 10:46:01 +00:00
|
|
|
|
2005-10-01 12:55:34 +00:00
|
|
|
/**
|
|
|
|
* \brief send control to all filters, starting with the last until
|
|
|
|
* one accepts the command with AF_OK.
|
|
|
|
* \param cmd filter control command
|
|
|
|
* \param arg argument for filter command
|
|
|
|
* \return the accepting filter or NULL if none was found
|
|
|
|
*/
|
2005-01-01 18:46:56 +00:00
|
|
|
af_instance_t *af_control_any_rev (af_stream_t* s, int cmd, void* arg);
|
2004-06-25 19:02:53 +00:00
|
|
|
|
2005-10-01 12:55:34 +00:00
|
|
|
/**
|
2007-11-01 06:52:19 +00:00
|
|
|
* \brief calculate average ratio of filter output lenth to input length
|
|
|
|
* \return the ratio
|
|
|
|
*/
|
|
|
|
double af_calc_filter_multiplier(af_stream_t* s);
|
2002-10-01 06:45:08 +00:00
|
|
|
|
2005-10-01 12:55:34 +00:00
|
|
|
/**
|
|
|
|
* \brief Calculate the total delay caused by the filters
|
2007-11-01 06:52:50 +00:00
|
|
|
* \return delay in bytes of "missing" output
|
2005-10-01 12:55:34 +00:00
|
|
|
*/
|
2002-10-08 10:20:36 +00:00
|
|
|
double af_calc_delay(af_stream_t* s);
|
2002-10-01 06:45:08 +00:00
|
|
|
|
2005-10-01 12:55:34 +00:00
|
|
|
/** \} */ // end of af_chain group
|
|
|
|
|
2002-10-01 06:45:08 +00:00
|
|
|
// Helper functions and macros used inside the audio filters
|
|
|
|
|
2005-10-01 12:55:34 +00:00
|
|
|
/**
|
|
|
|
* \defgroup af_filter Audio filter helper functions
|
|
|
|
* \{
|
|
|
|
*/
|
|
|
|
|
2002-10-01 06:45:08 +00:00
|
|
|
/* Helper function called by the macro with the same name only to be
|
|
|
|
called from inside filters */
|
|
|
|
int af_resize_local_buffer(af_instance_t* af, af_data_t* data);
|
|
|
|
|
|
|
|
/* Helper function used to calculate the exact buffer length needed
|
2002-10-03 12:02:46 +00:00
|
|
|
when buffers are resized. The returned length is >= than what is
|
|
|
|
needed */
|
2007-11-01 06:52:01 +00:00
|
|
|
int af_lencalc(double mul, af_data_t* data);
|
2002-10-01 06:45:08 +00:00
|
|
|
|
2005-10-01 12:55:34 +00:00
|
|
|
/**
|
|
|
|
* \brief convert dB to gain value
|
|
|
|
* \param n number of values to convert
|
|
|
|
* \param in [in] values in dB, <= -200 will become 0 gain
|
|
|
|
* \param out [out] gain values
|
|
|
|
* \param k input values are divided by this
|
|
|
|
* \param mi minimum dB value, input will be clamped to this
|
|
|
|
* \param ma maximum dB value, input will be clamped to this
|
|
|
|
* \return AF_ERROR on error, AF_OK otherwise
|
|
|
|
*/
|
2002-12-28 13:59:53 +00:00
|
|
|
int af_from_dB(int n, float* in, float* out, float k, float mi, float ma);
|
2005-10-01 12:55:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief convert gain value to dB
|
|
|
|
* \param n number of values to convert
|
|
|
|
* \param in [in] gain values, 0 wil become -200 dB
|
|
|
|
* \param out [out] values in dB
|
|
|
|
* \param k output values will be multiplied by this
|
|
|
|
* \return AF_ERROR on error, AF_OK otherwise
|
|
|
|
*/
|
2002-12-28 13:59:53 +00:00
|
|
|
int af_to_dB(int n, float* in, float* out, float k);
|
2005-10-01 12:55:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief convert milliseconds to sample time
|
|
|
|
* \param n number of values to convert
|
|
|
|
* \param in [in] values in milliseconds
|
|
|
|
* \param out [out] sample time values
|
|
|
|
* \param rate sample rate
|
|
|
|
* \param mi minimum ms value, input will be clamped to this
|
|
|
|
* \param ma maximum ms value, input will be clamped to this
|
|
|
|
* \return AF_ERROR on error, AF_OK otherwise
|
|
|
|
*/
|
2002-12-31 05:42:20 +00:00
|
|
|
int af_from_ms(int n, float* in, int* out, int rate, float mi, float ma);
|
2005-10-01 12:55:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief convert sample time to milliseconds
|
|
|
|
* \param n number of values to convert
|
|
|
|
* \param in [in] sample time values
|
|
|
|
* \param out [out] values in milliseconds
|
|
|
|
* \param rate sample rate
|
|
|
|
* \return AF_ERROR on error, AF_OK otherwise
|
|
|
|
*/
|
2009-05-13 02:58:57 +00:00
|
|
|
int af_to_ms(int n, int* in, float* out, int rate);
|
2005-10-01 12:55:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief test if output format matches
|
|
|
|
* \param af audio filter
|
|
|
|
* \param out needed format, will be overwritten by available
|
|
|
|
* format if they do not match
|
|
|
|
* \return AF_FALSE if formats do not match, AF_OK if they match
|
|
|
|
*
|
|
|
|
* compares the format, bps, rate and nch values of af->data with out
|
|
|
|
*/
|
2002-12-28 13:59:53 +00:00
|
|
|
int af_test_output(struct af_instance_s* af, af_data_t* out);
|
|
|
|
|
2005-10-01 12:55:34 +00:00
|
|
|
/**
|
|
|
|
* \brief soft clipping function using sin()
|
|
|
|
* \param a input value
|
|
|
|
* \return clipped value
|
|
|
|
*/
|
2005-01-31 11:43:08 +00:00
|
|
|
float af_softclip(float a);
|
|
|
|
|
2005-10-01 12:55:34 +00:00
|
|
|
/** \} */ // end of af_filter group, but more functions of this group below
|
|
|
|
|
2004-09-06 22:27:08 +00:00
|
|
|
/** Print a list of all available audio filters */
|
|
|
|
void af_help(void);
|
|
|
|
|
2005-10-01 12:55:34 +00:00
|
|
|
/**
|
|
|
|
* \brief fill the missing parameters in the af_data_t structure
|
|
|
|
* \param data structure to fill
|
|
|
|
* \ingroup af_filter
|
2009-05-13 02:58:57 +00:00
|
|
|
*
|
2005-10-01 12:55:34 +00:00
|
|
|
* Currently only sets bps based on format
|
|
|
|
*/
|
2005-03-01 22:52:02 +00:00
|
|
|
void af_fix_parameters(af_data_t *data);
|
2005-02-25 11:11:07 +00:00
|
|
|
|
2005-10-01 12:55:34 +00:00
|
|
|
/** Memory reallocation macro: if a local buffer is used (i.e. if the
|
2002-10-01 06:45:08 +00:00
|
|
|
filter doesn't operate on the incoming buffer this macro must be
|
2005-10-01 12:55:34 +00:00
|
|
|
called to ensure the buffer is big enough.
|
|
|
|
* \ingroup af_filter
|
|
|
|
*/
|
2002-10-01 06:45:08 +00:00
|
|
|
#define RESIZE_LOCAL_BUFFER(a,d)\
|
2002-10-03 12:44:58 +00:00
|
|
|
((a->data->len < af_lencalc(a->mul,d))?af_resize_local_buffer(a,d):AF_OK)
|
2002-10-01 06:45:08 +00:00
|
|
|
|
2002-10-16 01:49:40 +00:00
|
|
|
/* Some other useful macro definitions*/
|
2002-10-01 06:45:08 +00:00
|
|
|
#ifndef min
|
|
|
|
#define min(a,b)(((a)>(b))?(b):(a))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef max
|
|
|
|
#define max(a,b)(((a)>(b))?(a):(b))
|
|
|
|
#endif
|
|
|
|
|
2002-10-16 01:49:40 +00:00
|
|
|
#ifndef clamp
|
|
|
|
#define clamp(a,min,max) (((a)>(max))?(max):(((a)<(min))?(min):(a)))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef sign
|
2009-05-13 02:58:57 +00:00
|
|
|
#define sign(a) (((a)>0)?(1):(-1))
|
2002-11-03 09:51:02 +00:00
|
|
|
#endif
|
|
|
|
|
2002-11-12 12:33:56 +00:00
|
|
|
#ifndef lrnd
|
|
|
|
#define lrnd(a,b) ((b)((a)>=0.0?(a)+0.5:(a)-0.5))
|
2002-10-16 01:49:40 +00:00
|
|
|
#endif
|
|
|
|
|
2008-02-22 09:09:46 +00:00
|
|
|
#endif /* MPLAYER_AF_H */
|