📄 set_get.c
字号:
/* -*- mode: C; mode: fold -*- *//* * set/get functions for lame_global_flags * * Copyright (c) 2001-2005 Alexander Leidinger * * 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. *//* $Id: set_get.c,v 1.71.2.2 2005/11/26 18:37:34 bouvigne Exp $ */#ifdef HAVE_CONFIG_H# include <config.h>#endif#include <assert.h>#include "util.h"#include "bitstream.h" /* because of compute_flushbits */#ifdef WITH_DMALLOC#include <dmalloc.h>#endif#include "set_get.h"/* * input stream description *//* number of samples *//* it's unlikely for this function to return an error */intlame_set_num_samples( lame_global_flags* gfp, unsigned long num_samples){ /* default = 2^32-1 */ gfp->num_samples = num_samples; return 0;}unsigned longlame_get_num_samples( const lame_global_flags* gfp ){ return gfp->num_samples;}/* input samplerate */intlame_set_in_samplerate( lame_global_flags* gfp, int in_samplerate ){ /* input sample rate in Hz, default = 44100 Hz */ gfp->in_samplerate = in_samplerate; return 0;}intlame_get_in_samplerate( const lame_global_flags* gfp ){ return gfp->in_samplerate;}/* number of channels in input stream */intlame_set_num_channels( lame_global_flags* gfp, int num_channels ){ /* default = 2 */ if ( 2 < num_channels || 0 == num_channels ) return -1; /* we don't support more than 2 channels */ gfp->num_channels = num_channels; return 0;}intlame_get_num_channels( const lame_global_flags* gfp ){ return gfp->num_channels;}/* scale the input by this amount before encoding (not used for decoding) */intlame_set_scale( lame_global_flags* gfp, float scale ){ /* default = 0 */ gfp->scale = scale; return 0;}floatlame_get_scale( const lame_global_flags* gfp ){ return gfp->scale;}/* scale the channel 0 (left) input by this amount before encoding (not used for decoding) */intlame_set_scale_left( lame_global_flags* gfp, float scale ){ /* default = 0 */ gfp->scale_left = scale; return 0;}floatlame_get_scale_left( const lame_global_flags* gfp ){ return gfp->scale_left;}/* scale the channel 1 (right) input by this amount before encoding (not used for decoding) */intlame_set_scale_right( lame_global_flags* gfp, float scale ){ /* default = 0 */ gfp->scale_right = scale; return 0;}floatlame_get_scale_right( const lame_global_flags* gfp ){ return gfp->scale_right;}/* output sample rate in Hz */intlame_set_out_samplerate( lame_global_flags* gfp, int out_samplerate ){ /* * default = 0: LAME picks best value based on the amount * of compression * MPEG only allows: * MPEG1 32, 44.1, 48khz * MPEG2 16, 22.05, 24 * MPEG2.5 8, 11.025, 12 * * (not used by decoding routines) */ gfp->out_samplerate = out_samplerate; return 0;}intlame_get_out_samplerate( const lame_global_flags* gfp ){ return gfp->out_samplerate;}/* * general control parameters *//* collect data for an MP3 frame analzyer */intlame_set_analysis( lame_global_flags* gfp, int analysis ){ /* default = 0 */ /* enforce disable/enable meaning, if we need more than two values we need to switch to an enum to have an apropriate representation of the possible meanings of the value */ if ( 0 > analysis || 1 < analysis ) return -1; gfp->analysis = analysis; return 0;}intlame_get_analysis( const lame_global_flags* gfp ){ assert( 0 <= gfp->analysis && 1 >= gfp->analysis ); return gfp->analysis;}/* write a Xing VBR header frame */intlame_set_bWriteVbrTag( lame_global_flags* gfp, int bWriteVbrTag ){ /* default = 1 (on) for VBR/ABR modes, 0 (off) for CBR mode */ /* enforce disable/enable meaning, if we need more than two values we need to switch to an enum to have an apropriate representation of the possible meanings of the value */ if ( 0 > bWriteVbrTag || 1 < bWriteVbrTag ) return -1; gfp->bWriteVbrTag = bWriteVbrTag; return 0;}intlame_get_bWriteVbrTag( const lame_global_flags* gfp ){ assert( 0 <= gfp->bWriteVbrTag && 1 >= gfp->bWriteVbrTag ); return gfp->bWriteVbrTag;}/* decode only, use lame/mpglib to convert mp3 to wav */intlame_set_decode_only( lame_global_flags* gfp, int decode_only ){ /* default = 0 (disabled) */ /* enforce disable/enable meaning, if we need more than two values we need to switch to an enum to have an apropriate representation of the possible meanings of the value */ if ( 0 > decode_only || 1 < decode_only ) return -1; gfp->decode_only = decode_only; return 0;}intlame_get_decode_only( const lame_global_flags* gfp ){ assert( 0 <= gfp->decode_only && 1 >= gfp->decode_only ); return gfp->decode_only;}/* encode a Vorbis .ogg file *//* DEPRECATED */intlame_set_ogg( lame_global_flags* gfp, int ogg ){ return -1;}intlame_get_ogg( const lame_global_flags* gfp ){ return 0;}/* * Internal algorithm selection. * True quality is determined by the bitrate but this variable will effect * quality by selecting expensive or cheap algorithms. * quality=0..9. 0=best (very slow). 9=worst. * recommended: 3 near-best quality, not too slow * 5 good quality, fast * 7 ok quality, really fast */intlame_set_quality( lame_global_flags* gfp, int quality ){ gfp->quality = quality; return 0;}intlame_get_quality( const lame_global_flags* gfp ){ return gfp->quality;}/* mode = STEREO, JOINT_STEREO, DUAL_CHANNEL (not supported), MONO */intlame_set_mode( lame_global_flags* gfp, MPEG_mode mode ){ /* default: lame chooses based on compression ratio and input channels */ if( 0 > mode || MAX_INDICATOR <= mode ) return -1; /* Unknown MPEG mode! */ gfp->mode = mode; return 0;}MPEG_modelame_get_mode( const lame_global_flags* gfp ){ assert( 0 <= gfp->mode && MAX_INDICATOR > gfp->mode ); return gfp->mode;}/* Us a M/S mode with a switching threshold based on compression ratio *//* DEPRECATED */intlame_set_mode_automs( lame_global_flags* gfp, int mode_automs ){ /* default = 0 (disabled) */ /* enforce disable/enable meaning, if we need more than two values we need to switch to an enum to have an apropriate representation of the possible meanings of the value */ if ( 0 > mode_automs || 1 < mode_automs ) return -1; lame_set_mode( gfp, JOINT_STEREO ); return 0;}intlame_get_mode_automs( const lame_global_flags* gfp ){ return 1;}/* * Force M/S for all frames. For testing only. * Requires mode = 1. */intlame_set_force_ms( lame_global_flags* gfp, int force_ms ){ /* default = 0 (disabled) */ /* enforce disable/enable meaning, if we need more than two values we need to switch to an enum to have an apropriate representation of the possible meanings of the value */ if ( 0 > force_ms || 1 < force_ms ) return -1; gfp->force_ms = force_ms; return 0;}intlame_get_force_ms( const lame_global_flags* gfp ){ assert( 0 <= gfp->force_ms && 1 >= gfp->force_ms ); return gfp->force_ms;}/* Use free_format. */intlame_set_free_format( lame_global_flags* gfp, int free_format ){ /* default = 0 (disabled) */ /* enforce disable/enable meaning, if we need more than two values we need to switch to an enum to have an apropriate representation of the possible meanings of the value */ if ( 0 > free_format || 1 < free_format ) return -1; gfp->free_format = free_format; return 0;}intlame_get_free_format( const lame_global_flags* gfp ){ assert( 0 <= gfp->free_format && 1 >= gfp->free_format ); return gfp->free_format;}/* Perform ReplayGain analysis */intlame_set_findReplayGain( lame_global_flags* gfp, int findReplayGain ){ /* default = 0 (disabled) */ /* enforce disable/enable meaning, if we need more than two values we need to switch to an enum to have an apropriate representation of the possible meanings of the value */ if ( 0 > findReplayGain || 1 < findReplayGain ) return -1; gfp->findReplayGain = findReplayGain; return 0;}intlame_get_findReplayGain( const lame_global_flags* gfp ){ assert( 0 <= gfp->findReplayGain && 1 >= gfp->findReplayGain); return gfp->findReplayGain;}/* Decode on the fly. Find the peak sample. If ReplayGain analysis is enabled then perform it on the decoded data. */intlame_set_decode_on_the_fly( lame_global_flags* gfp, int decode_on_the_fly ){#ifndef DECODE_ON_THE_FLY return -1;#else /* default = 0 (disabled) */ /* enforce disable/enable meaning, if we need more than two values we need to switch to an enum to have an apropriate representation of the possible meanings of the value */ if ( 0 > decode_on_the_fly || 1 < decode_on_the_fly ) return -1; gfp->decode_on_the_fly = decode_on_the_fly; return 0;#endif}intlame_get_decode_on_the_fly( const lame_global_flags* gfp ){ assert( 0 <= gfp->decode_on_the_fly && 1 >= gfp->decode_on_the_fly ); return gfp->decode_on_the_fly;}/* DEPRECATED. same as lame_set_decode_on_the_fly() */intlame_set_findPeakSample( lame_global_flags* gfp, int arg ){ return lame_set_decode_on_the_fly(gfp, arg);}intlame_get_findPeakSample( const lame_global_flags* gfp ){ return lame_get_decode_on_the_fly(gfp);}/* DEPRECATED. same as lame_set_findReplayGain() */intlame_set_ReplayGain_input( lame_global_flags* gfp, int arg ){ return lame_set_findReplayGain(gfp, arg);}intlame_get_ReplayGain_input( const lame_global_flags* gfp ){ return lame_get_findReplayGain(gfp);}/* DEPRECATED. same as lame_set_decode_on_the_fly() && lame_set_findReplayGain() */intlame_set_ReplayGain_decode( lame_global_flags* gfp, int arg ){ if( lame_set_decode_on_the_fly(gfp, arg) < 0 || lame_set_findReplayGain(gfp, arg) < 0) return -1; else return 0;}intlame_get_ReplayGain_decode( const lame_global_flags* gfp ){ if (lame_get_decode_on_the_fly(gfp) > 0 && lame_get_findReplayGain(gfp) > 0) return 1; else return 0;}/* set and get some gapless encoding flags */intlame_set_nogap_total( lame_global_flags* gfp, int the_nogap_total ){ lame_internal_flags *gfc = gfp->internal_flags; gfc->nogap_total = the_nogap_total; return 0;}intlame_get_nogap_total( const lame_global_flags* gfp ){ return gfp->internal_flags->nogap_total;}intlame_set_nogap_currentindex( lame_global_flags* gfp, int the_nogap_index ){ lame_internal_flags *gfc = gfp->internal_flags; gfc->nogap_current = the_nogap_index; return 0;}intlame_get_nogap_currentindex( const lame_global_flags* gfp ){ return gfp->internal_flags->nogap_current;} /* message handlers */intlame_set_errorf( lame_global_flags* gfp, void (*func)( const char*, va_list ) ){ gfp->report.errorf = func; return 0;}intlame_set_debugf( lame_global_flags* gfp, void (*func)( const char*, va_list ) ){ gfp->report.debugf = func; return 0;}intlame_set_msgf( lame_global_flags* gfp, void (*func)( const char *, va_list ) ){ gfp->report.msgf = func; return 0;}/* * Set one of * - brate * - compression ratio. * * Default is compression ratio of 11. */intlame_set_brate( lame_global_flags* gfp, int brate ){ gfp->brate = brate; if (brate > 320) { gfp->disable_reservoir = 1; } return 0;}intlame_get_brate( const lame_global_flags* gfp ){ return gfp->brate;}intlame_set_compression_ratio( lame_global_flags* gfp, float compression_ratio ){ gfp->compression_ratio = compression_ratio; return 0;}floatlame_get_compression_ratio( const lame_global_flags* gfp ){ return gfp->compression_ratio;}/*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -