diff options
author | anders <anders@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2002-11-12 12:33:56 +0000 |
---|---|---|
committer | anders <anders@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2002-11-12 12:33:56 +0000 |
commit | 66f4e56389d97b61a4a17325201643ef6bd87e37 (patch) | |
tree | 2f8fd12c1e876b7abaeed2d8bf2d34bd0fa37493 /libaf/af_volume.c | |
parent | 54a8a603fb418b675a08c6349dfc720939f6c37a (diff) | |
download | mpv-66f4e56389d97b61a4a17325201643ef6bd87e37.tar.bz2 mpv-66f4e56389d97b61a4a17325201643ef6bd87e37.tar.xz |
New features:
-- Support for runtime cpu detection
-- Stand alone compile of libaf
-- Unlimited number of channels (compiletime switch)
-- Sample format defined by bit-fields
-- New formats: float, A-Law and mu-law
-- Format conversion set in human readable format
i.e. format=4:us_be to set 32 bit unsigned big endian output
-- Format reporting in human readable format
-- Volume control has only one parameter for setting the volume
i.e. volume=-10.0:1:0:1 to set atenuation = -10dB
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@8168 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libaf/af_volume.c')
-rw-r--r-- | libaf/af_volume.c | 75 |
1 files changed, 39 insertions, 36 deletions
diff --git a/libaf/af_volume.c b/libaf/af_volume.c index 432bbd996f..8238f06026 100644 --- a/libaf/af_volume.c +++ b/libaf/af_volume.c @@ -23,31 +23,24 @@ #include <inttypes.h> #include <math.h> -#include "../config.h" -#include "../mp_msg.h" - #include "af.h" // Some limits +#define NCH AF_NCH // Number of channels + #define MIN_S16 -32650 #define MAX_S16 32650 -#define MAX_VOL +20.0 -#define MIN_VOL -60.0 - -// Number of channels -#define NCH 6 - -#include "../libao2/afmt.h" - +#define MAX_VOL +40.0 +#define MIN_VOL -200.0 // Data for specific instances of this filter typedef struct af_volume_s { - double volume[NCH]; // Volume for each channel - double power[NCH]; // Instantaneous power in each channel - double maxpower[NCH]; // Maximum power in each channel - double alpha; // Forgetting factor for power estimate + float volume[NCH]; // Volume for each channel + float power[NCH]; // Instantaneous power in each channel + float maxpower[NCH]; // Maximum power in each channel + float alpha; // Forgetting factor for power estimate int softclip; // Soft clippng on/off int probe; // Probing on/off int onoff; // Volume control on/off @@ -55,29 +48,37 @@ typedef struct af_volume_s /* Convert to gain value from dB. Returns AF_OK if of and AF_ERROR if fail */ -inline int from_dB(double* in, double* out, double k) +inline int from_dB(float* in, float* out, float k) { int i = 0; // Sanity check if(!in || !out) return AF_ERROR; - for(i=0;i<NCH;i++) - out[i]=pow(10.0,clamp(in[i],MIN_VOL,MAX_VOL)/k); + for(i=0;i<NCH;i++){ + if(in[i]<MIN_VOL) + out[i]=0.0; + else + out[i]=pow(10.0,clamp(in[i],MIN_VOL,MAX_VOL)/k); + } return AF_OK; } /* Convert from gain value to dB. Returns AF_OK if of and AF_ERROR if fail */ -inline int to_dB(double* in, double* out, double k) +inline int to_dB(float* in, float* out, float k) { int i = 0; // Sanity check if(!in || !out) return AF_ERROR; - for(i=0;i<NCH;i++) - out[i]=k*log10(clamp(in[i],MIN_VOL,MAX_VOL)); + for(i=0;i<NCH;i++){ + if(in[i] == 0.0) + out[i]=MIN_VOL; + else + out[i]=k*log10(clamp(in[i],MIN_VOL,MAX_VOL)); + } return AF_OK; } @@ -93,11 +94,11 @@ static int control(struct af_instance_s* af, int cmd, void* arg) af->data->rate = ((af_data_t*)arg)->rate; af->data->nch = ((af_data_t*)arg)->nch; - af->data->format = AFMT_S16_LE; + af->data->format = AF_FORMAT_SI | AF_FORMAT_LE; af->data->bps = 2; // Time constant set to 0.1s - s->alpha = (1.0/0.2)/(2.0*M_PI*(double)((af_data_t*)arg)->rate); + s->alpha = (1.0/0.2)/(2.0*M_PI*(float)((af_data_t*)arg)->rate); // Only AFMT_S16_LE is supported for now if(af->data->format != ((af_data_t*)arg)->format || @@ -105,20 +106,22 @@ static int control(struct af_instance_s* af, int cmd, void* arg) return AF_FALSE; return AF_OK; case AF_CONTROL_COMMAND_LINE:{ - double vol[6]={-10.0,-10.0,-10.0,-10.0,-10.0,-10.0}; - sscanf((char*)arg,"%lf:%lf:%lf:%lf:%lf:%lf:%i:%i:%i", - &vol[0], &vol[1], &vol[2], &vol[3], &vol[4], &vol[5], + float v=-10.0; + float vol[6]; + int i; + sscanf((char*)arg,"%f:%i:%i:%i", &v, &(s->softclip), &(s->probe), &(s->onoff)); + for(i=0;i<NCH;i++) vol[i]=v; return from_dB(vol,s->volume,20.0); } case AF_CONTROL_VOLUME_SET: - return from_dB((double*)arg,s->volume,20.0); + return from_dB((float*)arg,s->volume,20.0); case AF_CONTROL_VOLUME_GET: - return to_dB(s->volume,(double*)arg,20.0); + return to_dB(s->volume,(float*)arg,20.0); case AF_CONTROL_VOLUME_PROBE_GET: - return to_dB(s->power,(double*)arg,10.0); + return to_dB(s->power,(float*)arg,10.0); case AF_CONTROL_VOLUME_PROBE_GET_MAX: - return to_dB(s->maxpower,(double*)arg,10.0); + return to_dB(s->maxpower,(float*)arg,10.0); case AF_CONTROL_VOLUME_SOFTCLIP: s->softclip = (int)arg; return AF_OK; @@ -155,13 +158,13 @@ static af_data_t* play(struct af_instance_s* af, af_data_t* data) // Probe the data stream if(s->probe){ for(ch = 0; ch < nch ; ch++){ - double alpha = s->alpha; - double beta = 1 - alpha; - double pow = s->power[ch]; - double maxpow = s->maxpower[ch]; - register double t = 0; + float alpha = s->alpha; + float beta = 1 - alpha; + float pow = s->power[ch]; + float maxpow = s->maxpower[ch]; + register float t = 0; for(i=ch;i<len;i+=nch){ - t = ((double)a[i])/32768.0; + t = ((float)a[i])/32768.0; t *= t; // Check maximum power value if(t>maxpow) |