25 #define MODPLUG_STATIC
26 #include <libmodplug/modplug.h>
67 "speed",
"tempo",
"order",
"pattern",
"row",
79 #define FF_MODPLUG_MAX_FILE_SIZE (100 * 1<<20) // 100M
80 #define FF_MODPLUG_DEF_FILE_SIZE ( 5 * 1<<20) // 5M
82 #define OFFSET(x) offsetof(ModPlugContext, x)
83 #define D AV_OPT_FLAG_DECODING_PARAM
85 {
"noise_reduction",
"Enable noise reduction 0(off)-1(on)",
OFFSET(noise_reduction),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1,
D},
86 {
"reverb_depth",
"Reverb level 0(quiet)-100(loud)",
OFFSET(reverb_depth),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 100,
D},
87 {
"reverb_delay",
"Reverb delay in ms, usually 40-200ms",
OFFSET(reverb_delay),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX,
D},
88 {
"bass_amount",
"XBass level 0(quiet)-100(loud)",
OFFSET(bass_amount),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 100,
D},
90 {
"surround_depth",
"Surround level 0(quiet)-100(heavy)",
OFFSET(surround_depth),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 100,
D},
91 {
"surround_delay",
"Surround delay in ms, usually 5-40ms",
OFFSET(surround_delay),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX,
D},
92 {
"max_size",
"Max file size supported (in bytes). Default is 5MB. Set to 0 for no limit (not recommended)",
96 {
"video_stream_w",
"Video stream width in char (one char = 8x8px)",
OFFSET(w),
AV_OPT_TYPE_INT, {.i64 = 30}, 20, 512,
D},
97 {
"video_stream_h",
"Video stream height in char (one char = 8x8px)",
OFFSET(h),
AV_OPT_TYPE_INT, {.i64 = 30}, 20, 512,
D},
98 {
"video_stream_ptxt",
"Print speed, tempo, order, ... in video stream",
OFFSET(print_textinfo),
AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1,
D},
102 #define SET_OPT_IF_REQUESTED(libopt, opt, flag) do { \
103 if (modplug->opt) { \
104 settings.libopt = modplug->opt; \
105 settings.mFlags |= flag; \
109 #define ADD_META_MULTIPLE_ENTRIES(entry_name, fname) do { \
110 if (n_## entry_name ##s) { \
113 for (i = 0; i < n_## entry_name ##s; i++) { \
114 char item_name[64] = {0}; \
115 fname(f, i, item_name); \
119 av_dict_set(&s->metadata, #entry_name, "\n", AV_DICT_APPEND); \
120 av_dict_set(&s->metadata, #entry_name, item_name, AV_DICT_APPEND); \
124 extra = av_asprintf(", %u/%u " #entry_name "%s", \
125 n, n_## entry_name ##s, n > 1 ? "s" : ""); \
127 return AVERROR(ENOMEM); \
128 av_dict_set(&s->metadata, "extra info", extra, AV_DICT_APPEND); \
136 ModPlugFile *f = modplug->
f;
138 const char *
name = ModPlug_GetName(f);
139 const char *msg = ModPlug_GetMessage(f);
141 unsigned n_instruments = ModPlug_NumInstruments(f);
142 unsigned n_samples = ModPlug_NumSamples(f);
143 unsigned n_patterns = ModPlug_NumPatterns(f);
144 unsigned n_channels = ModPlug_NumChannels(f);
150 n_patterns, n_patterns > 1 ?
"s" :
"",
151 n_channels, n_channels > 1 ?
"s" :
"");
162 #define AUDIO_PKT_SIZE 512
168 ModPlug_Settings settings;
178 "but demuxing is likely to fail due to incomplete buffer\n",
184 NULL, NULL, NULL, NULL, 0, s);
194 ModPlug_GetSettings(&settings);
195 settings.mChannels = 2;
197 settings.mFrequency = 44100;
198 settings.mResamplingMode = MODPLUG_RESAMPLE_FIR;
199 settings.mLoopCount = 0;
201 if (modplug->
noise_reduction) settings.mFlags |= MODPLUG_ENABLE_NOISE_REDUCTION;
216 ModPlug_SetSettings(&settings);
218 modplug->
f = ModPlug_Load(modplug->
buf, sz);
226 st->
duration = ModPlug_GetLength(modplug->
f);
255 dst += y*linesize + x*3;
256 for (i = 0; s[i]; i++, dst += 3) {
263 #define PRINT_INFO(line, name, idvalue) do { \
264 snprintf(intbuf, sizeof(intbuf), "%.0f", var_values[idvalue]); \
265 write_text(pkt->data, name ":", modplug->linesize, 0+1, line+1); \
266 write_text(pkt->data, intbuf, modplug->linesize, 10+1, line+1); \
278 var_values[
VAR_W ] = modplug->
w;
279 var_values[
VAR_H ] = modplug->
h;
281 var_values[
VAR_SPEED ] = ModPlug_GetCurrentSpeed (modplug->
f);
282 var_values[
VAR_TEMPO ] = ModPlug_GetCurrentTempo (modplug->
f);
283 var_values[
VAR_ORDER ] = ModPlug_GetCurrentOrder (modplug->
f);
284 var_values[
VAR_PATTERN] = ModPlug_GetCurrentPattern(modplug->
f);
285 var_values[
VAR_ROW ] = ModPlug_GetCurrentRow (modplug->
f);
304 for (y = 0; y < modplug->
h; y++) {
305 for (x = 0; x < modplug->
w; x++) {
307 var_values[
VAR_X] = x;
310 pkt->
data[y*modplug->
linesize + x*3 + 2] |= av_clip((
int)color, 0, 0xf)<<4;
327 if (pkt->
size <= 0) {
337 ModPlug_Unload(modplug->
f);
345 ModPlug_Seek(modplug->
f, (
int)ts);
351 static const char modplug_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";
372 .
name =
"libmodplug",
381 .priv_class = &modplug_class,