vorbisenc.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /********************************************************************
  2. * *
  3. * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
  4. * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
  5. * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  6. * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
  7. * *
  8. * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
  9. * by the XIPHOPHORUS Company http://www.xiph.org/ *
  10. ********************************************************************
  11. function: simple programmatic interface for encoder mode setup
  12. last mod: $Id: vorbisenc.c,v 1.7.2.3 2001/08/13 00:20:11 xiphmont Exp $
  13. ********************************************************************/
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <math.h>
  17. #include "vorbis/codec.h"
  18. #include "vorbis/vorbisenc.h"
  19. #include "codec_internal.h"
  20. #include "registry.h"
  21. #include "modes/modes.h"
  22. #include "os.h"
  23. #include "misc.h"
  24. /* deepcopy all but the codebooks; in this usage, they're static
  25. (don't copy as they could be big) */
  26. static void codec_setup_partialcopy(codec_setup_info *ci,
  27. codec_setup_info *cs){
  28. int i;
  29. memcpy(ci,cs,sizeof(codec_setup_info)); /* to get the flat numbers */
  30. /* codebooks */
  31. for(i=0;i<ci->books;i++){
  32. ci->book_param[i]=cs->book_param[i];
  33. }
  34. /* time backend settings */
  35. for(i=0;i<ci->times;i++){
  36. ci->time_param[i]=_time_P[ci->time_type[i]]->
  37. copy_info(cs->time_param[i]);
  38. }
  39. /* floor backend settings */
  40. for(i=0;i<ci->floors;i++){
  41. ci->floor_param[i]=_floor_P[ci->floor_type[i]]->
  42. copy_info(cs->floor_param[i]);
  43. }
  44. /* residue backend settings */
  45. for(i=0;i<ci->residues;i++){
  46. ci->residue_param[i]=_residue_P[ci->residue_type[i]]->
  47. copy_info(cs->residue_param[i]);
  48. }
  49. /* map backend settings */
  50. for(i=0;i<ci->maps;i++){
  51. ci->map_param[i]=_mapping_P[ci->map_type[i]]->
  52. copy_info(cs->map_param[i]);
  53. }
  54. /* mode settings */
  55. for(i=0;i<ci->modes;i++){
  56. ci->mode_param[i]=_ogg_calloc(1,sizeof(vorbis_info_mode));
  57. ci->mode_param[i]->blockflag=cs->mode_param[i]->blockflag;
  58. ci->mode_param[i]->windowtype=cs->mode_param[i]->windowtype;
  59. ci->mode_param[i]->transformtype=cs->mode_param[i]->transformtype;
  60. ci->mode_param[i]->mapping=cs->mode_param[i]->mapping;
  61. }
  62. /* psy settings */
  63. for(i=0;i<ci->psys;i++){
  64. ci->psy_param[i]=_vi_psy_copy(cs->psy_param[i]);
  65. }
  66. }
  67. /* encoders will need to use vorbis_info_init beforehand and call
  68. vorbis_info clear when all done */
  69. int vorbis_encode_init_vbr(vorbis_info *vi,
  70. long channels,
  71. long rate,
  72. float base_quality /* 0. to 1. */
  73. ){
  74. }
  75. int vorbis_encode_init(vorbis_info *vi,
  76. long channels,
  77. long rate,
  78. long max_bitrate,
  79. long nominal_bitrate,
  80. long min_bitrate){
  81. long bpch;
  82. int i,j;
  83. codec_setup_info *ci=vi->codec_setup;
  84. codec_setup_info *mode=NULL;
  85. if(!ci)return(OV_EFAULT);
  86. vi->version=0;
  87. vi->channels=channels;
  88. vi->rate=rate;
  89. vi->bitrate_upper=max_bitrate;
  90. vi->bitrate_nominal=nominal_bitrate;
  91. vi->bitrate_lower=min_bitrate;
  92. vi->bitrate_window=2;
  93. /* copy a mode into our allocated storage */
  94. bpch=nominal_bitrate/channels;
  95. mode=&info_44c_Z;
  96. #if 0
  97. if(bpch<60000){
  98. /* mode AA */
  99. mode=&info_AA;
  100. }else if(bpch<75000){
  101. /* mode A */
  102. mode=&info_A;
  103. }else if(bpch<90000){
  104. /* mode B */
  105. mode=&info_B;
  106. }else if(bpch<110000){
  107. /* mode C */
  108. mode=&info_C;
  109. }else if(bpch<160000){
  110. /* mode D */
  111. mode=&info_D;
  112. }else{
  113. /* mode E */
  114. mode=&info_E;
  115. }
  116. #endif
  117. /* now we have to deepcopy */
  118. codec_setup_partialcopy(ci,mode);
  119. /* adjust for sample rate */
  120. for(i=0;i<ci->floors;i++)
  121. if(ci->floor_type[i]==0)
  122. ((vorbis_info_floor0 *)(ci->floor_param[i]))->rate=rate;
  123. /* adjust for channels; all our mappings use submap zero now */
  124. /* yeah, OK, _ogg_calloc did this for us. But it's a reminder/placeholder */
  125. for(i=0;i<ci->maps;i++)
  126. for(j=0;j<channels;j++)
  127. ((vorbis_info_mapping0 *)ci->map_param[i])->chmuxlist[j]=0;
  128. return(0);
  129. }
  130. int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){
  131. return(OV_EIMPL);
  132. }