📄 lame.c
字号:
for (i = 0; i < SBMAX_s + 1; i++) gfc->scalefac_band.s[i] = sfBandIndex[j].s[i]; for (i = 0; i < PSFB12 + 1; i++){ int size = (gfc->scalefac_band.s[ 13 ] - gfc->scalefac_band.s[ 12 ])/PSFB12; int start = gfc->scalefac_band.s[ 12 ] + i*size; gfc->scalefac_band.psfb12[i] = start; } gfc->scalefac_band.psfb12[PSFB12] = 192; /* determine the mean bitrate for main data */ if (gfp->version == 1) /* MPEG 1 */ gfc->sideinfo_len = (gfc->channels_out == 1) ? 4 + 17 : 4 + 32; else /* MPEG 2 */ gfc->sideinfo_len = (gfc->channels_out == 1) ? 4 + 9 : 4 + 17; if (gfp->error_protection) gfc->sideinfo_len += 2; lame_init_bitstream(gfp); gfc->Class_ID = LAME_ID; /*if (gfp->exp_nspsytune & 1)*/ { int i; for (i = 0; i < 19; i++) gfc->nsPsy.pefirbuf[i] = 700*gfc->mode_gr*gfc->channels_out; if (gfp->ATHtype == -1) gfp->ATHtype = 4; if (gfp->exp_nspsytune2.pointer[0]) gfc->nsPsy.pass1fp = gfp->exp_nspsytune2.pointer[0]; else gfc->nsPsy.pass1fp = NULL; } assert( gfp->VBR_q <= 9 ); assert( gfp->VBR_q >= 0 ); gfc->PSY->tonalityPatch = 0; switch (gfp->VBR) { case vbr_mt: gfp->VBR = vbr_mtrh; case vbr_mtrh: { apply_preset(gfp, 500 - (gfp->VBR_q*10), 0); if (gfp->quality < 0) gfp->quality = LAME_DEFAULT_QUALITY; if (gfp->quality > 7) { gfp->quality = 7; /* needs psymodel */ ERRORF( gfc, "VBR needs a psymodel, switching to quality level 7\n"); } /* tonality */ if (gfp->cwlimit <= 0) gfp->cwlimit = 0.42 * gfp->out_samplerate; gfc->PSY->tonalityPatch = 1; gfc->PSY->mask_adjust = gfp->maskingadjust; gfc->PSY->mask_adjust_short = gfp->maskingadjust_short; /* sfb21 extra only with MPEG-1 at higher sampling rates */ if ( gfp->experimentalY ) gfc->sfb21_extra = 0; else gfc->sfb21_extra = (gfp->out_samplerate > 44000); break; } case vbr_rh: { apply_preset(gfp, 500 - (gfp->VBR_q*10), 0); gfc->PSY->mask_adjust = gfp->maskingadjust; gfc->PSY->mask_adjust_short = gfp->maskingadjust_short; if ( gfp->psymodel == PSY_GPSYCHO ) gfc->PSY->tonalityPatch = 1; /* sfb21 extra only with MPEG-1 at higher sampling rates */ if ( gfp->experimentalY ) gfc->sfb21_extra = 0; else gfc->sfb21_extra = (gfp->out_samplerate > 44000); /* VBR needs at least the output of GPSYCHO, * so we have to garantee that by setting a minimum * quality level, actually level 6 does it. * down to level 6 */ if (gfp->quality > 6) gfp->quality = 6; if (gfp->quality < 0) gfp->quality = LAME_DEFAULT_QUALITY; break; } default: /* cbr/abr */{ vbr_mode vbrmode; /* no sfb21 extra with CBR code */ gfc->sfb21_extra = 0; if (gfp->quality < 0) gfp->quality = LAME_DEFAULT_QUALITY; vbrmode = lame_get_VBR(gfp); if (vbrmode == vbr_off) lame_set_VBR_mean_bitrate_kbps(gfp, gfp->brate); /* second, set parameters depending on bitrate */ apply_preset(gfp, gfp->VBR_mean_bitrate_kbps, 0); lame_set_VBR(gfp, vbrmode); gfc->PSY->mask_adjust = gfp->maskingadjust; gfc->PSY->mask_adjust_short = gfp->maskingadjust_short; break; } } /*initialize default values common for all modes*/ if (lame_get_VBR(gfp) != vbr_off) { /* choose a min/max bitrate for VBR */ /* if the user didn't specify VBR_max_bitrate: */ gfc->VBR_min_bitrate = 1; /* default: allow 8 kbps (MPEG-2) or 32 kbps (MPEG-1) */ gfc->VBR_max_bitrate = 14; /* default: allow 160 kbps (MPEG-2) or 320 kbps (MPEG-1) */ if (gfp->VBR_min_bitrate_kbps) if ( (gfc->VBR_min_bitrate = BitrateIndex(gfp->VBR_min_bitrate_kbps, gfp->version, gfp->out_samplerate)) < 0) return -1; if (gfp->VBR_max_bitrate_kbps) if ( (gfc->VBR_max_bitrate = BitrateIndex(gfp->VBR_max_bitrate_kbps, gfp->version, gfp->out_samplerate)) < 0) return -1; gfp->VBR_min_bitrate_kbps = bitrate_table[gfp->version][gfc->VBR_min_bitrate]; gfp->VBR_max_bitrate_kbps = bitrate_table[gfp->version][gfc->VBR_max_bitrate]; gfp->VBR_mean_bitrate_kbps = Min(bitrate_table[gfp->version][gfc->VBR_max_bitrate], gfp->VBR_mean_bitrate_kbps); gfp->VBR_mean_bitrate_kbps = Max(bitrate_table[gfp->version][gfc->VBR_min_bitrate], gfp->VBR_mean_bitrate_kbps); } /* just another daily changing developer switch */ if ( gfp->tune ) gfc->PSY->mask_adjust = gfp->tune_value_a; /* initialize internal qval settings */ lame_init_qval(gfp); /* automatic ATH adjustment on */ if ( gfp->athaa_type < 0 ) gfc->ATH->use_adjust = 3; else gfc->ATH->use_adjust = gfp->athaa_type; /* initialize internal adaptive ATH settings -jd */ gfc->ATH->aa_sensitivity_p = pow( 10.0, gfp->athaa_sensitivity / -10.0 ); gfc->PSY->cwlimit = gfp->cwlimit <= 0 ? 8871.7f : gfp->cwlimit; if (gfp->short_blocks == short_block_not_set) { gfp->short_blocks = short_block_allowed; } /*Note Jan/2003: Many hardware decoders cannot handle short blocks in regular stereo mode unless they are coupled (same type in both channels) it is a rare event (1 frame per min. or so) that LAME would use uncoupled short blocks, so lets turn them off until we decide how to handle this. No other encoders allow uncoupled short blocks, even though it is in the standard. */ /* rh 20040217: coupling makes no sense for mono and dual-mono streams */ if (gfp->short_blocks == short_block_allowed && (gfp->mode == JOINT_STEREO || gfp->mode == STEREO) ) { gfp->short_blocks = short_block_coupled; } if (lame_get_quant_comp(gfp) < 0 ) lame_set_quant_comp(gfp, 1); if (lame_get_quant_comp_short(gfp) < 0 ) lame_set_quant_comp_short(gfp, 0); if (lame_get_msfix(gfp) < 0 ) lame_set_msfix(gfp, 0); /* select psychoacoustic model */ if ((lame_get_psy_model(gfp) < 0) || (lame_get_psy_model(gfp) == PSY_NSPSYTUNE)) { lame_set_psy_model(gfp, PSY_NSPSYTUNE); lame_set_exp_nspsytune(gfp, lame_get_exp_nspsytune(gfp) | 1); } else { lame_set_psy_model(gfp, PSY_GPSYCHO); lame_set_exp_nspsytune(gfp, (lame_get_exp_nspsytune(gfp) >> 1) << 1); } if (lame_get_short_threshold_lrm(gfp) < 0 ) lame_set_short_threshold_lrm(gfp, NSATTACKTHRE); if (lame_get_short_threshold_s(gfp) < 0 ) lame_set_short_threshold_s(gfp, NSATTACKTHRE_S); if ( gfp->scale < 0 ) gfp->scale = 1; if (gfp->ATHtype < 0) gfp->ATHtype = 4; if ( gfp->ATHcurve < 0 ) gfp->ATHcurve = 4; if ( gfp->athaa_loudapprox < 0 ) gfp->athaa_loudapprox = 2; if (gfp->interChRatio < 0 ) gfp->interChRatio = 0; if (gfp->useTemporal < 0 ) gfp->useTemporal = 1; /* on by default */ /* padding method as described in * "MPEG-Layer3 / Bitstream Syntax and Decoding" * by Martin Sieler, Ralph Sperschneider * * note: there is no padding for the very first frame * * Robert Hegemann 2000-06-22 */ gfc->slot_lag = gfc->frac_SpF = 0; if (gfp->VBR == vbr_off) gfc->slot_lag = gfc->frac_SpF = ((gfp->version+1)*72000L*gfp->brate) % gfp->out_samplerate; /* mid side sparsing */ gfc->sparsing = gfp->sparsing; gfc->sparseA = gfp->sparse_low; gfc->sparseB = gfp->sparse_low-gfp->sparse_high; if ( gfc->sparseA < 0 ) gfc->sparseA = 0; if ( gfc->sparseB < 0 ) gfc->sparseB = 0; if ( gfc->sparseB > gfc->sparseA ) gfc->sparseB = gfc->sparseA; iteration_init(gfp); psymodel_init(gfp); return 0;}/* * print_config * * Prints some selected information about the coding parameters via * the macro command MSGF(), which is currently mapped to lame_errorf * (reports via a error function?), which is a printf-like function * for <stderr>. */voidlame_print_config(const lame_global_flags * gfp){ lame_internal_flags *gfc = gfp->internal_flags; double out_samplerate = gfp->out_samplerate; double in_samplerate = gfp->out_samplerate * gfc->resample_ratio; MSGF(gfc, "LAME %s %s (%s)\n", get_lame_version(), get_lame_os_bitness(), get_lame_url()); if (LAME_ALPHA_VERSION) MSGF(gfc, "warning: alpha versions should be used for testing only\n"); if (gfc->CPU_features.MMX || gfc->CPU_features.AMD_3DNow || gfc->CPU_features.SSE || gfc->CPU_features.SSE2) { MSGF(gfc, "CPU features: "); if (gfc->CPU_features.MMX)#ifdef MMX_choose_table MSGF(gfc, "MMX (ASM used)");#else MSGF(gfc, "MMX");#endif if (gfc->CPU_features.AMD_3DNow)#ifdef HAVE_NASM MSGF(gfc, ", 3DNow! (ASM used)");#else MSGF(gfc, ", 3DNow!");#endif if (gfc->CPU_features.SSE)#ifdef HAVE_XMMINTRIN_H MSGF(gfc, ", SSE (ASM used)");#else MSGF(gfc, ", SSE");#endif if (gfc->CPU_features.SSE2) MSGF(gfc, ", SSE2"); MSGF(gfc, "\n"); } if (gfp->num_channels == 2 && gfc->channels_out == 1 /* mono */ ) { MSGF (gfc, "Autoconverting from stereo to mono. Setting encoding to mono mode.\n"); } if (gfc->resample_ratio != 1.) { MSGF(gfc, "Resampling: input %g kHz output %g kHz\n", 1.e-3 * in_samplerate, 1.e-3 * out_samplerate); } if (gfc->filter_type == 0) { if (gfc->highpass2 > 0.) MSGF (gfc, "Using polyphase highpass filter, transition band: %5.0f Hz - %5.0f Hz\n", 0.5 * gfc->highpass1 * out_samplerate, 0.5 * gfc->highpass2 * out_samplerate); if (0. < gfc->lowpass1 && gfc->lowpass1 < 1.) { MSGF (gfc, "Using polyphase lowpass filter, transition band: %5.0f Hz - %5.0f Hz\n", 0.5 * gfc->lowpass1 * out_samplerate, 0.5 * gfc->lowpass2 * out_samplerate); } else { MSGF(gfc, "polyphase lowpass filter disabled\n"); } } else { MSGF(gfc, "polyphase filters disabled\n"); } if (gfp->free_format) { MSGF(gfc, "Warning: many decoders cannot handle free format bitstreams\n"); if (gfp->brate > 320) { MSGF (gfc, "Warning: many decoders cannot handle free format bitrates >320 kbps (see documentation)\n"); } }}/** rh: * some pretty printing is very welcome at this point! * so, if someone is willing to do so, please do it! * add more, if you see more... */void lame_print_internals( const lame_global_flags * gfp ){ lame_internal_flags *gfc = gfp->internal_flags; const char * pc = ""; /* compiler/processor optimizations, operational, etc. */ MSGF( gfc, "\nmisc:\n\n" ); MSGF( gfc, "\tscaling: %g\n", gfp->scale ); MSGF( gfc, "\tch0 (left) scaling: %g\n", gfp->scale_left ); MSGF( gfc, "\tch1 (right) scaling: %g\n", gfp->scale_right ); MSGF( gfc, "\tfilter type: %d\n", gfc->filter_type ); pc = gfc->quantization ? "xr^3/4" : "ISO"; MSGF( gfc, "\tquantization: %s\n", pc ); switch( gfc->use_best_huffman ) { default: pc = "normal"; break; case 1: pc = "best (outside loop)"; break; case 2: pc = "best (inside loop, slow)"; break; } MSGF( gfc, "\thuffman search: %s\n", pc ); MSGF( gfc, "\texperimental Y=%d\n", gfp->experimentalY); MSGF( gfc, "\t...\n" ); /* everything controlling the stream format */ MSGF( gfc, "\nstream format:\n\n" ); switch ( gfp->version ) { case 0: pc = "2.5"; break; case 1: pc = "1"; break; case 2: pc = "2"; break; default: pc = "?"; break; } MSGF( gfc, "\tMPEG-%s Layer 3\n", pc ); switch ( gfp->mode ) { case JOINT_STEREO: pc = "joint stereo"; break; case STEREO : pc = "stereo"; break; case DUAL_CHANNEL: pc = "dual channel"; break; case MONO : pc = "mono"; break; case NOT_SET : pc = "not set (error)"; break; default : pc = "unknown (error)"; break; } MSGF( gfc, "\t%d channel - %s\n", gfc->channels_out, pc ); switch (gfp->VBR) { case vbr_off : pc = "off"; break; default : pc = "all"; break; } MSGF( gfc, "\tpadding: %s\n", pc ); if ( vbr_default == gfp->VBR ) pc = "(default)"; else if ( gfp->free_format ) pc = "(free format)"; else pc = ""; switch ( gfp->VBR ) { case vbr_off : MSGF( gfc, "\tconstant bitrate - CBR %s\n", pc ); break; case vbr_abr : MSGF( gfc, "\tvariable bitrate - ABR %s\n", pc ); break; case vbr_rh : MSGF( gfc, "\tvariable bitrate - VBR rh %s\n", pc ); break; case vbr_mt : MSGF( gfc, "\tvariable bitrate - VBR mt %s\n", pc ); break; case vbr_mtrh: MSGF( gfc, "\tvariable bitrate - VBR mtrh %s\n", pc ); break; default : MSGF( gfc, "\t ?? oops, some new one ?? \n" ); break; } if (gfp->bWriteVbrTag) MSGF( gfc, "\tusing LAME Tag\n" ); MSGF( gfc, "\t...\n" ); /* everything controlling psychoacoustic settings, like ATH, etc.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -