0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 12:02:23 +02:00

a52 dynamic range compression support by Peter Gansterer

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@12286 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
alex 2004-04-26 08:53:41 +00:00
parent 6f2ea1e2df
commit 4ed4169ec6
4 changed files with 57 additions and 0 deletions

View File

@ -388,6 +388,14 @@ soll. F
.SH "DEMUXER/STREAM-OPTIONEN"
.TP
.B \-a52drc <level>
Gibt die Höhe der Dynamic Range Compression für den AC3 Audio Stream an.
<level> ist ein Fließkommawert im Bereich von 0 bis 1, wobei 0 keine Kompression
und 1 (der Standardwert) volle Kompression bedeutet (laute Passagen werden leiser
und umgekehrt).
Diese Option zeigt nur Wirkung, wenn im AC3 Stream die Rangei Compression i
Information vorhanden ist.
.TP
.B \-aid <id> (siehe auch \-alang)
Gibt die zu verwendende Audiospur an [MPEG: 0\-31 AVI/\:OGM: 1\-99
ASF/\:RM: 0\-127 VOB(AC3): 128\-159 VOB(LPCM): 160\-191]

View File

@ -596,6 +596,14 @@ this option.
.
.SH "DEMUXER/STREAM OPTIONS"
.TP
.B \-a52drc <level>
Select the Dynamic Range Compression level for AC3 audio streams.
<level> is a float value ranging from 0 to 1, where 0 means no compression
and 1 (which is the default) means full compression (make loud passages more
silent and vice versa).
This option only shows an effect if the AC3 stream contains the required range
compression information.
.TP
.B \-aid <id> (also see \-alang option)
Select audio channel [MPEG: 0\-31 AVI/\:OGM: 1\-99 ASF/\:RM: 0\-127
VOB(AC3): 128\-159 VOB(LPCM): 160\-191 MPEG-TS 17\-8190].

View File

@ -134,6 +134,8 @@
{"channels", &audio_output_channels, CONF_TYPE_INT, CONF_RANGE, 1, 6, NULL},
{"format", &audio_output_format, CONF_TYPE_INT, CONF_RANGE, 0, 0x00002000, NULL},
{"a52drc", &a52_drc_level, CONF_TYPE_FLOAT, CONF_RANGE, 0, 1, NULL},
// ------------------------- codec/vfilter options --------------------
// MP3-only: select stereo/left/right
@ -303,6 +305,8 @@ extern int network_ipv4_only_proxy;
#endif
extern float a52_drc_level;
/* defined in libmpdemux: */
extern int hr_mp3_seek;
extern m_option_t demux_rawaudio_opts[];

View File

@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include "config.h"
#ifdef USE_LIBA52
@ -19,6 +20,13 @@ static sample_t * a52_samples;
static a52_state_t a52_state;
static uint32_t a52_flags=0;
#define DRC_NO_ACTION 0
#define DRC_NO_COMPRESSION 1
#define DRC_CALLBACK 2
float a52_drc_level = 1.0;
static int a52_drc_action = DRC_NO_ACTION;
#include "bswap.h"
static ad_info_t info =
@ -95,6 +103,11 @@ int channels=0;
return (flags&A52_LFE) ? (channels+1) : channels;
}
sample_t dynrng_call (sample_t c, void *data) {
// fprintf(stderr, "(%lf, %lf): %lf\n", (double)c, (double)a52_drc_level, (double)pow((double)c, a52_drc_level));
return pow((double)c, a52_drc_level);
}
static int preinit(sh_audio_t *sh)
{
@ -126,6 +139,21 @@ static int init(sh_audio_t *sh_audio)
mp_msg(MSGT_DECAUDIO,MSGL_ERR,"A52 sync failed\n");
return 0;
}
/* Init a52 dynrng */
if (a52_drc_level < 0.001) {
/* level == 0 --> no compression, init library without callback */
a52_drc_action = DRC_NO_COMPRESSION;
} else if (a52_drc_level > 0.999) {
/* level == 1 --> full compression, do nothing at all (library default = full compression) */
a52_drc_action = DRC_NO_ACTION;
} else {
a52_drc_action = DRC_CALLBACK;
}
/* Library init for dynrng has to be done for each frame, see decode_audio() */
/* 'a52 cannot upmix' hotfix:*/
a52_printinfo(sh_audio);
sh_audio->channels=audio_output_channels;
@ -186,6 +214,15 @@ static int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int m
mp_msg(MSGT_DECAUDIO,MSGL_WARN,"a52: error decoding frame\n");
return len;
}
/* handle dynrng */
if (a52_drc_action != DRC_NO_ACTION) {
if (a52_drc_action == DRC_NO_COMPRESSION)
a52_dynrng(&a52_state, NULL, NULL);
else
a52_dynrng(&a52_state, dynrng_call, NULL);
}
len=0;
for (i = 0; i < 6; i++) {
if (a52_block (&a52_state, a52_samples)){