Newer
Older
monitord / lame-3.97 / .svn / text-base / HACKING.svn-base
  1. First, see the file STYLEGUIDE
  2.  
  3. ************************************************************************
  4. TESTING
  5. =======
  6. If you make changes, please test. There is a python
  7. script in the test/ directory which will compare two versions
  8. of lame using a bunch of CBR and ABR options. To run this
  9. script, copy your favorite (and short!) wav file to the
  10. lame/test directory, and run:
  11.  
  12. % cd lame/test
  13. % ./lametest.py [-w] CBRABR.op castanets.wav lame_orig lame_new
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20. ************************************************************************
  21. LAME API
  22.  
  23. For a general outline of the code, see the file API.
  24. Also, frontend/main.c is a simple front end to libmp3lame.a
  25.  
  26. The guts of the code are called from lame_encode_buffer().
  27.  
  28. lame_encode_buffer() handles buffering and resampling, and
  29. then calls lame_encode_frame() for each frame. lame_encode_frame()
  30. looks like this:
  31.  
  32. lame_encode_frame_mp3():
  33. l3psycho_anal() compute masking thresholds
  34. mdct_sub() compute MDCT coefficients
  35. iteration_loop() choose scalefactors (via iteration)
  36. which determine noise shapping, and
  37. choose best huffman tables for lossless compression
  38.  
  39. format_bitstream format the bitstream. when data+headers are complete,
  40. output to internal bit buffer.
  41. copy_buffer() copy internal bit buffer into user's mp3 buffer
  42.  
  43. ************************************************************************
  44. ADDING NEW OPTIONS
  45.  
  46. control variable goes in lame_global_flags sturct.
  47. Assume the variable is called 'new_variable'.
  48.  
  49. You also need to write (in get_set.c):
  50.  
  51. lame_set_new_variable()
  52. lame_get_new_variable()
  53.  
  54. And then document the variable in the file USAGE as well as the
  55. output of "lame --longhelp"
  56.  
  57. And add a "--option" style command line option to enable this variable
  58. in parse.m
  59.  
  60. Note: for experimental features that you need to call from the frontend
  61. but that should not be part of the official API, see the section at
  62. the end of get_set.c. These functions should *NOT* be prototyped in
  63. lame.h (since that would indicate to the world that they are part
  64. of the API).
  65.  
  66.  
  67. ************************************************************************
  68.  
  69. THREADSAFE:
  70.  
  71. Lame should now be thread safe and re-entrant.
  72. The only problem seems to be some OS's allocate small
  73. stacks (< 128K) to threads launched by applictions, and this
  74. is not enough for LAME. Fix is to increase the stack space,
  75. or move some of our automatic variables onto the heap with
  76. by using bug-prove malloc()'s and free().
  77.  
  78.  
  79.  
  80. ************************************************************************
  81. Global Variables:
  82.  
  83. There are two types of global variables. All data in
  84. both strucs is initialized to zero.
  85.  
  86. 1. lame_global_flags *gfp
  87.  
  88. These are input paramters which are set by the calling program,
  89. and some information which the calling program may be interested in.
  90.  
  91. This struct instantiated by the call to lame_init().
  92.  
  93.  
  94. 2. lame_internal_flags *gfc
  95.  
  96. Most global variables go here.
  97.  
  98. All internal data not set by the user. All 'static' data from
  99. old non-reentrant code should be moved here.
  100.  
  101. Defined in util.h. Data for which the size is known
  102. in advace should be explicitly declaired (for example,
  103. float xr[576]); Data which needs to be malloc'd is
  104. handled by:
  105.  
  106. 1. in lame_init_params(), malloc the data
  107. 2. be sure to free the data in freegfc()
  108.  
  109.  
  110. If the data to be malloc'd is large and only used in
  111. certain conditions (like resampling), use the following:
  112. this has the disadvantage that it is hard to catch and return error
  113. flags all the way back up the call stack.
  114.  
  115. 1. Add an initialization variable to the gfc struct: lame_init_resample
  116. 2. In the resample routine, there should be some code like this:
  117.  
  118. if (0==gfc->lame_init_resample) {
  119. gfc->lame_init_resample=1;
  120. /* initialization code: malloc() data, etc */
  121. }
  122.  
  123. 3. The data should be free'd in the routine freegfc().
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.