1159b3361Sopenharmony_ciFirst, see the file STYLEGUIDE 2159b3361Sopenharmony_ci 3159b3361Sopenharmony_ci************************************************************************ 4159b3361Sopenharmony_ciTESTING 5159b3361Sopenharmony_ci======= 6159b3361Sopenharmony_ci 7159b3361Sopenharmony_ciIf you make changes, please test. There is a python script in the test/ 8159b3361Sopenharmony_cidirectory which will compare two versions of lame using a bunch of CBR 9159b3361Sopenharmony_ciand ABR options. To run this script, copy your favorite (and short!) wav 10159b3361Sopenharmony_cifile to the lame/test directory, and run: 11159b3361Sopenharmony_ci 12159b3361Sopenharmony_ci% cd lame/test 13159b3361Sopenharmony_ci% ./lametest.py [-w] CBRABR.op castanets.wav lame_orig lame_new 14159b3361Sopenharmony_ci 15159b3361Sopenharmony_ci 16159b3361Sopenharmony_ci 17159b3361Sopenharmony_ci************************************************************************ 18159b3361Sopenharmony_ciLAME API 19159b3361Sopenharmony_ci======== 20159b3361Sopenharmony_ci 21159b3361Sopenharmony_ciFor a general outline of the code, see the file API. 22159b3361Sopenharmony_ciAlso, frontend/main.c is a simple front end to libmp3lame.a 23159b3361Sopenharmony_ci 24159b3361Sopenharmony_ciThe guts of the code are called from lame_encode_buffer(). 25159b3361Sopenharmony_ci 26159b3361Sopenharmony_cilame_encode_buffer() handles buffering and resampling, and 27159b3361Sopenharmony_cithen calls lame_encode_frame() for each frame. lame_encode_frame() 28159b3361Sopenharmony_cilooks like this: 29159b3361Sopenharmony_ci 30159b3361Sopenharmony_cilame_encode_frame_mp3(): 31159b3361Sopenharmony_ci l3psycho_anal() compute masking thresholds 32159b3361Sopenharmony_ci mdct_sub() compute MDCT coefficients 33159b3361Sopenharmony_ci iteration_loop() choose scalefactors (via iteration) 34159b3361Sopenharmony_ci which determine noise shapping, and 35159b3361Sopenharmony_ci choose best huffman tables for lossless compression 36159b3361Sopenharmony_ci format_bitstream format the bitstream. when data+headers are complete, 37159b3361Sopenharmony_ci output to internal bit buffer. 38159b3361Sopenharmony_ci copy_buffer() copy internal bit buffer into user's mp3 buffer 39159b3361Sopenharmony_ci 40159b3361Sopenharmony_ci************************************************************************ 41159b3361Sopenharmony_ciADDING NEW OPTIONS 42159b3361Sopenharmony_ci================== 43159b3361Sopenharmony_ci 44159b3361Sopenharmony_cicontrol variable goes in lame_global_flags struct. 45159b3361Sopenharmony_ciAssume the variable is called 'new_variable'. 46159b3361Sopenharmony_ci 47159b3361Sopenharmony_ciYou also need to write (in set_get.c): 48159b3361Sopenharmony_ci 49159b3361Sopenharmony_cilame_set_new_variable() 50159b3361Sopenharmony_cilame_get_new_variable() 51159b3361Sopenharmony_ci 52159b3361Sopenharmony_ciAnd then document the variable in the file USAGE as well as the 53159b3361Sopenharmony_cioutput of "lame --longhelp" 54159b3361Sopenharmony_ci 55159b3361Sopenharmony_ciAnd add a "--option" style command line option to enable this variable 56159b3361Sopenharmony_ciin parse.c 57159b3361Sopenharmony_ci 58159b3361Sopenharmony_ciNote: for experimental features that you need to call from the frontend 59159b3361Sopenharmony_cibut that should not be part of the official API, see the section at 60159b3361Sopenharmony_cithe end of set_get.c. These functions should *NOT* be prototyped in 61159b3361Sopenharmony_cilame.h (since that would indicate to the world that they are part 62159b3361Sopenharmony_ciof the API). 63159b3361Sopenharmony_ci 64159b3361Sopenharmony_ci 65159b3361Sopenharmony_ci************************************************************************ 66159b3361Sopenharmony_ciTHREADSAFE: 67159b3361Sopenharmony_ci=========== 68159b3361Sopenharmony_ci 69159b3361Sopenharmony_ciLame should now be thread safe and re-entrant. The only problem seems to 70159b3361Sopenharmony_cibe some OS's allocate small stacks (< 128K) to threads launched by 71159b3361Sopenharmony_ciapplications, and this is not enough for LAME. Fix is to increase the 72159b3361Sopenharmony_cistack space, or move some of our automatic variables onto the heap with 73159b3361Sopenharmony_ciby using bug-proof malloc()'s and free(). 74159b3361Sopenharmony_ci 75159b3361Sopenharmony_ci 76159b3361Sopenharmony_ci************************************************************************ 77159b3361Sopenharmony_ciGlobal Variables: 78159b3361Sopenharmony_ci================= 79159b3361Sopenharmony_ci 80159b3361Sopenharmony_ciThere are two types of global variables. All data in both structs is 81159b3361Sopenharmony_ciinitialized to zero. 82159b3361Sopenharmony_ci 83159b3361Sopenharmony_ci1. lame_global_flags *gfp 84159b3361Sopenharmony_ci 85159b3361Sopenharmony_ciThese are input parameters which are set by the calling program, and some 86159b3361Sopenharmony_ciinformation which the calling program may be interested in. 87159b3361Sopenharmony_ci 88159b3361Sopenharmony_ciThis struct instantiated by the call to lame_init(). 89159b3361Sopenharmony_ci 90159b3361Sopenharmony_ci 91159b3361Sopenharmony_ci2. lame_internal_flags *gfc 92159b3361Sopenharmony_ci 93159b3361Sopenharmony_ciMost global variables go here. 94159b3361Sopenharmony_ci 95159b3361Sopenharmony_ciAll internal data not set by the user. All 'static' data from 96159b3361Sopenharmony_ciold non-reentrant code should be moved here. 97159b3361Sopenharmony_ci 98159b3361Sopenharmony_ciDefined in util.h. Data for which the size is known 99159b3361Sopenharmony_ciin advance should be explicitly declaired (for example, 100159b3361Sopenharmony_cifloat xr[576]); Data which needs to be malloc'd is 101159b3361Sopenharmony_cihandled by: 102159b3361Sopenharmony_ci 103159b3361Sopenharmony_ci1. in lame_init_params(), malloc the data 104159b3361Sopenharmony_ci2. be sure to free the data in freegfc() 105159b3361Sopenharmony_ci 106159b3361Sopenharmony_ci 107159b3361Sopenharmony_ciIf the data to be malloc'd is large and only used in 108159b3361Sopenharmony_cicertain conditions (like resampling), use the following: 109159b3361Sopenharmony_cithis has the disadvantage that it is hard to catch and return error 110159b3361Sopenharmony_ciflags all the way back up the call stack. 111159b3361Sopenharmony_ci 112159b3361Sopenharmony_ci1. Add an initialization variable to the gfc struct: lame_init_resample 113159b3361Sopenharmony_ci2. In the resample routine, there should be some code like this: 114159b3361Sopenharmony_ci 115159b3361Sopenharmony_ci if (0==gfc->lame_init_resample) { 116159b3361Sopenharmony_ci gfc->lame_init_resample=1; 117159b3361Sopenharmony_ci /* initialization code: malloc() data, etc */ 118159b3361Sopenharmony_ci } 119159b3361Sopenharmony_ci 120159b3361Sopenharmony_ci3. The data should be free'd in the routine freegfc(). 121159b3361Sopenharmony_ci 122