HACKING 3.9 KB

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