summaryrefslogtreecommitdiff
path: root/libavformat/libmodplug.c
diff options
context:
space:
mode:
authorClément Bœsch <ubitux@gmail.com>2011-10-05 21:02:49 +0200
committerClément Bœsch <ubitux@gmail.com>2011-10-06 08:30:37 +0200
commita763b46298ab70fb0b38aec30c922a6a9ad752e2 (patch)
tree8a79ec388d8e4e685e76868b940af42615229d56 /libavformat/libmodplug.c
parent6638207bce4eabd3f99295c1ab096d2815eff3ce (diff)
libmodplug: support options (noise reduction, reverb, bass boost, ...)
Diffstat (limited to 'libavformat/libmodplug.c')
-rw-r--r--libavformat/libmodplug.c56
1 files changed, 55 insertions, 1 deletions
diff --git a/libavformat/libmodplug.c b/libavformat/libmodplug.c
index 9fc2ec9384..a3c407f192 100644
--- a/libavformat/libmodplug.c
+++ b/libavformat/libmodplug.c
@@ -19,18 +19,48 @@
/**
* @file
* ModPlug demuxer
-* @todo ModPlug options (noise reduction, reverb, bass boost, ...)
* @todo metadata
*/
#include <libmodplug/modplug.h>
+#include "libavutil/opt.h"
#include "avformat.h"
typedef struct ModPlugContext {
+ const AVClass *class;
ModPlugFile *f;
uint8_t buf[5 * 1<<20]; ///< input file content, 5M max
+
+ /* options */
+ int noise_reduction;
+ int reverb_depth;
+ int reverb_delay;
+ int bass_amount;
+ int bass_range;
+ int surround_depth;
+ int surround_delay;
} ModPlugContext;
+#define OFFSET(x) offsetof(ModPlugContext, x)
+#define D AV_OPT_FLAG_DECODING_PARAM
+static const AVOption options[] = {
+ {"noise_reduction", "Enable noise reduction 0(off)-1(on)", OFFSET(noise_reduction), FF_OPT_TYPE_INT, {.dbl = 0}, 0, 1, D},
+ {"reverb_depth", "Reverb level 0(quiet)-100(loud)", OFFSET(reverb_depth), FF_OPT_TYPE_INT, {.dbl = 0}, 0, 100, D},
+ {"reverb_delay", "Reverb delay in ms, usually 40-200ms", OFFSET(reverb_delay), FF_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, D},
+ {"bass_amount", "XBass level 0(quiet)-100(loud)", OFFSET(bass_amount), FF_OPT_TYPE_INT, {.dbl = 0}, 0, 100, D},
+ {"bass_range", "XBass cutoff in Hz 10-100", OFFSET(bass_range), FF_OPT_TYPE_INT, {.dbl = 0}, 0, 100, D},
+ {"surround_depth", "Surround level 0(quiet)-100(heavy)", OFFSET(surround_depth), FF_OPT_TYPE_INT, {.dbl = 0}, 0, 100, D},
+ {"surround_delay", "Surround delay in ms, usually 5-40ms", OFFSET(surround_delay), FF_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, D},
+ {NULL},
+};
+
+#define SET_OPT_IF_REQUESTED(libopt, opt, flag) do { \
+ if (modplug->opt) { \
+ settings.libopt = modplug->opt; \
+ settings.mFlags |= flag; \
+ } \
+} while (0)
+
static int modplug_read_header(AVFormatContext *s, AVFormatParameters *ap)
{
AVStream *st;
@@ -46,6 +76,22 @@ static int modplug_read_header(AVFormatContext *s, AVFormatParameters *ap)
settings.mFrequency = 44100;
settings.mResamplingMode = MODPLUG_RESAMPLE_FIR; // best quality
settings.mLoopCount = 0; // prevents looping forever
+
+ if (modplug->noise_reduction) settings.mFlags |= MODPLUG_ENABLE_NOISE_REDUCTION;
+ SET_OPT_IF_REQUESTED(mReverbDepth, reverb_depth, MODPLUG_ENABLE_REVERB);
+ SET_OPT_IF_REQUESTED(mReverbDelay, reverb_delay, MODPLUG_ENABLE_REVERB);
+ SET_OPT_IF_REQUESTED(mBassAmount, bass_amount, MODPLUG_ENABLE_MEGABASS);
+ SET_OPT_IF_REQUESTED(mBassRange, bass_range, MODPLUG_ENABLE_MEGABASS);
+ SET_OPT_IF_REQUESTED(mSurroundDepth, surround_depth, MODPLUG_ENABLE_SURROUND);
+ SET_OPT_IF_REQUESTED(mSurroundDelay, surround_delay, MODPLUG_ENABLE_SURROUND);
+
+ if (modplug->reverb_depth) settings.mReverbDepth = modplug->reverb_depth;
+ if (modplug->reverb_delay) settings.mReverbDelay = modplug->reverb_delay;
+ if (modplug->bass_amount) settings.mBassAmount = modplug->bass_amount;
+ if (modplug->bass_range) settings.mBassRange = modplug->bass_range;
+ if (modplug->surround_depth) settings.mSurroundDepth = modplug->surround_depth;
+ if (modplug->surround_delay) settings.mSurroundDelay = modplug->surround_delay;
+
ModPlug_SetSettings(&settings);
modplug->f = ModPlug_Load(modplug->buf, sz);
@@ -93,6 +139,13 @@ static int modplug_read_seek(AVFormatContext *s, int stream_idx, int64_t ts, int
return 0;
}
+static const AVClass modplug_class = {
+ .class_name = "ModPlug demuxer",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
AVInputFormat ff_libmodplug_demuxer = {
.name = "libmodplug",
.long_name = NULL_IF_CONFIG_SMALL("ModPlug demuxer"),
@@ -103,4 +156,5 @@ AVInputFormat ff_libmodplug_demuxer = {
.read_seek = modplug_read_seek,
.extensions = "669,abc,amf,ams,dbm,dmf,dsm,far,it,mdl,med,mid,mod,mt2,mtm,okt,psm,ptm,s3m,stm,ult,umx,xm"
",itgz,itr,itz,mdgz,mdr,mdz,s3gz,s3r,s3z,xmgz,xmr,xmz", // compressed mods
+ .priv_class = &modplug_class,
};