vorbisenc.c 4.4 KB

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