⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 presets.c

📁 音频编码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * presets.c -- Apply presets * *	Copyright (c) 2002-2005 Gabriel Bouvigne * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */#include "set_get.h"#ifdef HAVE_CONFIG_H# include <config.h>#endif#include "util.h"#define SET_OPTION(opt, val, def) if (enforce) \    lame_set_##opt(gfp, val); \    else if (lame_get_##opt(gfp) == def) \    lame_set_##opt(gfp, val);int apply_abr_preset(lame_global_flags*  gfp, int preset, int enforce){    int k;     typedef struct {        int    abr_kbps;        int    quant_comp;        int    quant_comp_s;        int    safejoint;        FLOAT  nsmsfix;        FLOAT  st_lrm; /*short threshold*/        FLOAT  st_s;        FLOAT  nsbass;        FLOAT  scale;        FLOAT  masking_adj;        FLOAT  ath_lower;        FLOAT  ath_curve;        FLOAT  interch;        int sfscale;    } abr_presets_t;    /* Switch mappings for ABR mode */    const abr_presets_t abr_switch_map [] = {        /* kbps  quant q_s safejoint nsmsfix st_lrm  st_s  ns-bass scale   msk ath_lwr ath_curve  interch , sfscale */        {   8,   9,    9,  0,        0   ,    6.60, 145  ,  0,      0.95,    0, -30.0,        11,  0.0012 ,       1}, /*   8, impossible to use in stereo */        {  16,   9,    9,  0,        0   ,    6.60, 145  ,  0,      0.95,    0, -25.0,        11,  0.0010 ,       1}, /*  16 */        {  24,   9,    9,  0,        0   ,    6.60, 145  ,  0,      0.95,    0, -20.0,        11,  0.0010 ,       1}, /*  24 */        {  32,   9,    9,  0,        0   ,    6.60, 145  ,  0,      0.95,    0, -15.0,        11,  0.0010 ,       1}, /*  32 */        {  40,   9,    9,  0,        0   ,    6.60, 145  ,  0,      0.95,    0, -10.0,        11,  0.0009 ,       1}, /*  40 */        {  48,   9,    9,  0,        0   ,    6.60, 145  ,  0,      0.95,    0, -10.0,        11,  0.0009 ,       1}, /*  48 */        {  56,   9,    9,  0,        0   ,    6.60, 145  ,  0,      0.95,    0,  -6.0,        11,  0.0008 ,       1}, /*  56 */        {  64,   9,    9,  0,        0   ,    6.60, 145  ,  0,      0.95,    0,  -2.0,        11,  0.0008 ,       1}, /*  64 */        {  80,   9,    9,  0,        0   ,    6.60, 145  ,  0,      0.95,    0,    .0,         8,  0.0007 ,       1}, /*  80 */        {  96,   9,    9,  0,        2.50,    6.60, 145  ,  0,      0.95,    0,   1.0,       5.5,  0.0006 ,       1}, /*  96 */        { 112,   9,    9,  0,        2.25,    6.60, 145  ,  0,      0.95,    0,   2.0,       4.5,  0.0005 ,       1}, /* 112 */        { 128,   9,    9,  0,        1.95,    6.40, 140  ,  0,      0.95,    0,   3.0,         4,  0.0002 ,       1}, /* 128 */        { 160,   9,    9,  1,        1.79,    6.00, 135  ,  0,      0.95,   -2,   5.0,       3.5,  0      ,       1}, /* 160 */        { 192,   9,    9,  1,        1.49,    5.60, 125  ,  0,      0.97,   -4,   7.0,         3,  0      ,       0}, /* 192 */        { 224,   9,    9,  1,        1.25,    5.20, 125  ,  0,      0.98,   -6,   9.0,         2,  0      ,       0}, /* 224 */        { 256,   9,    9,  1,        0.97,    5.20, 125  ,  0,      1.00,   -8,  10.0,         1,  0      ,       0}, /* 256 */        { 320,   9,    9,  1,        0.90,    5.20, 125  ,  0,      1.00,  -10,  12.0,         0,  0      ,       0}  /* 320 */                                       };        /* Variables for the ABR stuff */    int r;    int actual_bitrate = preset;    r= nearestBitrateFullIndex(preset);    lame_set_VBR(gfp, vbr_abr);     lame_set_VBR_mean_bitrate_kbps(gfp, (actual_bitrate));    lame_set_VBR_mean_bitrate_kbps(gfp, Min(lame_get_VBR_mean_bitrate_kbps(gfp), 320));     lame_set_VBR_mean_bitrate_kbps(gfp, Max(lame_get_VBR_mean_bitrate_kbps(gfp), 8));     lame_set_brate(gfp, lame_get_VBR_mean_bitrate_kbps(gfp));    SET_OPTION(psy_model, PSY_NSPSYTUNE, -1);    /* parameters for which there is no proper set/get interface */    if (abr_switch_map[r].safejoint > 0)        lame_set_exp_nspsytune(gfp, lame_get_exp_nspsytune(gfp) | 2); /* safejoint */    if (abr_switch_map[r].sfscale > 0)        lame_set_sfscale(gfp, 1);    /* ns-bass tweaks */    if (abr_switch_map[r].nsbass != 0) {        k = (int)(abr_switch_map[r].nsbass * 4);        if (k < 0) k += 64;        lame_set_exp_nspsytune(gfp, lame_get_exp_nspsytune(gfp) | (k << 2));    }    SET_OPTION(quant_comp, abr_switch_map[r].quant_comp, -1);    SET_OPTION(quant_comp_short, abr_switch_map[r].quant_comp_s, -1);    SET_OPTION(msfix, abr_switch_map[r].nsmsfix, -1);    SET_OPTION(short_threshold_lrm, abr_switch_map[r].st_lrm, -1);    SET_OPTION(short_threshold_s, abr_switch_map[r].st_s, -1);    /* ABR seems to have big problems with clipping, especially at low bitrates */    /* so we compensate for that here by using a scale value depending on bitrate */    SET_OPTION(scale, abr_switch_map[r].scale, -1);    SET_OPTION(maskingadjust, abr_switch_map[r].masking_adj , 0);    if (abr_switch_map[r].masking_adj > 0) {        SET_OPTION(maskingadjust_short, abr_switch_map[r].masking_adj * .9 , 0);    } else {        SET_OPTION(maskingadjust_short, abr_switch_map[r].masking_adj * 1.1 , 0);    }    SET_OPTION(ATHlower, abr_switch_map[r].ath_lower, 0);    SET_OPTION(ATHcurve, abr_switch_map[r].ath_curve, -1);    SET_OPTION(interChRatio, abr_switch_map[r].interch, -1);    return preset;}int apply_preset(lame_global_flags*  gfp, int preset, int enforce){    /*translate legacy presets*/    switch (preset) {    case R3MIX: {        preset = V3;        lame_set_VBR(gfp, vbr_mtrh);        break;    }    case MEDIUM: {        preset = V4;        lame_set_VBR(gfp, vbr_rh);        break;    }    case MEDIUM_FAST: {        preset = V4;        lame_set_VBR(gfp, vbr_mtrh);        break;    }    case STANDARD: {        preset = V2;        lame_set_VBR(gfp, vbr_rh);        break;    }    case STANDARD_FAST: {        preset = V2;        lame_set_VBR(gfp, vbr_mtrh);        break;    }    case EXTREME: {        preset = V0;        lame_set_VBR(gfp, vbr_rh);        break;    }    case EXTREME_FAST: {        preset = V0;        lame_set_VBR(gfp, vbr_mtrh);        break;    }    case INSANE: {        preset = 320;        break;    }    }            gfp->preset = preset;    switch (preset) {    case V9: {        lame_set_VBR_q(gfp, 9);        switch (lame_get_VBR(gfp)) {        case vbr_rh: {            SET_OPTION(short_threshold_lrm, 6.60f, -1);            SET_OPTION(short_threshold_s, 145.0f, -1);            SET_OPTION(quant_comp, 9, -1);            SET_OPTION(quant_comp_short, 9, -1);            SET_OPTION(psy_model, PSY_NSPSYTUNE, -1);            SET_OPTION(maskingadjust, 1.6, 0);            SET_OPTION(maskingadjust_short, 1.6, 0);            SET_OPTION(interChRatio, 0.0008, -1);            SET_OPTION(ATHlower, -36, 0);            SET_OPTION(ATHcurve, 11, -1);            SET_OPTION(athaa_sensitivity, -25, 0);            lame_set_experimentalY(gfp, 1);            return preset;        }        default: {            SET_OPTION(short_threshold_lrm, 6.60f, -1);            SET_OPTION(short_threshold_s, 145.0f, -1);            SET_OPTION(quant_comp, 0, -1);            SET_OPTION(quant_comp_short, 0, -1);            SET_OPTION(psy_model, PSY_NSPSYTUNE, -1);            SET_OPTION(maskingadjust, 1.75, 0);            SET_OPTION(maskingadjust_short, 1.75, 0);            SET_OPTION(interChRatio, 0.0008, -1);            SET_OPTION(ATHlower, -39.5, 0);            SET_OPTION(ATHcurve, 11, -1);            SET_OPTION(athaa_sensitivity, -25, 0);            lame_set_experimentalY(gfp, 1);            return preset;        }        }    }    case V8: {        lame_set_VBR_q(gfp, 8);        switch (lame_get_VBR(gfp)) {        case vbr_rh: {            SET_OPTION(short_threshold_lrm, 6.60f, -1);            SET_OPTION(short_threshold_s, 145.0f, -1);            SET_OPTION(quant_comp, 9, -1);            SET_OPTION(quant_comp_short, 9, -1);            SET_OPTION(psy_model, PSY_NSPSYTUNE, -1);            SET_OPTION(maskingadjust, 1.2, 0);            SET_OPTION(maskingadjust_short, 1.15, 0);            SET_OPTION(interChRatio, 0.0007, -1);            SET_OPTION(ATHlower, -27.5, 0);            SET_OPTION(ATHcurve, 10, -1);            SET_OPTION(athaa_sensitivity, -23, 0);            lame_set_experimentalY(gfp, 1);            return preset;        }        default: {            SET_OPTION(short_threshold_lrm, 6.60f, -1);            SET_OPTION(short_threshold_s, 145.0f, -1);            SET_OPTION(quant_comp, 0, -1);            SET_OPTION(quant_comp_short, 0, -1);            SET_OPTION(psy_model, PSY_NSPSYTUNE, -1);            SET_OPTION(maskingadjust, 1.2, 0);            SET_OPTION(maskingadjust_short, 1.15, 0);            SET_OPTION(interChRatio, 0.0007, -1);            SET_OPTION(ATHlower, -30, 0);            SET_OPTION(ATHcurve, 10, -1);            SET_OPTION(athaa_sensitivity, -23, 0);            lame_set_experimentalY(gfp, 1);            return preset;        }        }    }    case V7: {        lame_set_VBR_q(gfp, 7);        switch (lame_get_VBR(gfp)) {        case vbr_rh: {            SET_OPTION(short_threshold_lrm, 6.60f, -1);            SET_OPTION(short_threshold_s, 145.0f, -1);            SET_OPTION(quant_comp, 9, -1);            SET_OPTION(quant_comp_short, 9, -1);            SET_OPTION(psy_model, PSY_NSPSYTUNE, -1);            SET_OPTION(msfix, 2.70, -1);            SET_OPTION(maskingadjust, .8, 0);            SET_OPTION(maskingadjust_short, .75, 0);            SET_OPTION(interChRatio, 0.0006, -1);            SET_OPTION(ATHlower, -19.7, 0);            SET_OPTION(ATHcurve, 8, -1);            SET_OPTION(athaa_sensitivity, -22, 0);            lame_set_experimentalY(gfp, 1);            return preset;        }        default: {            SET_OPTION(short_threshold_lrm, 6.60f, -1);            SET_OPTION(short_threshold_s, 145.0f, -1);            SET_OPTION(quant_comp, 0, -1);            SET_OPTION(quant_comp_short, 0, -1);            SET_OPTION(psy_model, PSY_NSPSYTUNE, -1);            SET_OPTION(msfix, 2.70, -1);            SET_OPTION(maskingadjust, 0.8, 0);            SET_OPTION(maskingadjust_short, 0.78, 0);            SET_OPTION(interChRatio, 0.0006, -1);            SET_OPTION(ATHlower, -22, 0);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -