Get rid of shmmap stuff
[platform/upstream/libvorbis.git] / lib / vorbisenc.c
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  ********************************************************************
12
13  function: simple programmatic interface for encoder mode setup
14  last mod: $Id: vorbisenc.c,v 1.18 2001/10/18 17:39:34 cwolf Exp $
15
16  ********************************************************************/
17
18 #include <stdlib.h>
19 #include <string.h>
20 #include <math.h>
21
22 #include "vorbis/codec.h"
23 #include "vorbis/vorbisenc.h"
24
25 #include "codec_internal.h"
26 #include "registry.h"
27 #include "modes/modes.h"
28
29 #include "os.h"
30 #include "misc.h"
31
32 /* deepcopy all but the codebooks; in this usage, they're static
33    (don't copy as they could be big) */
34 static void codec_setup_partialcopy(codec_setup_info *ci,
35                                  codec_setup_info *cs){
36   int i;
37
38   memcpy(ci,cs,sizeof(*ci)); /* to get the flat numbers */
39
40   /* codebooks */
41   for(i=0;i<ci->books;i++){
42     ci->book_param[i]=cs->book_param[i];
43   }
44
45   /* time backend settings */
46   for(i=0;i<ci->times;i++){
47     ci->time_param[i]=_time_P[ci->time_type[i]]->
48       copy_info(cs->time_param[i]);
49   }
50
51   /* floor backend settings */
52   for(i=0;i<ci->floors;i++){
53     ci->floor_param[i]=_floor_P[ci->floor_type[i]]->
54       copy_info(cs->floor_param[i]);
55   }
56
57   /* residue backend settings */
58   for(i=0;i<ci->residues;i++){
59     ci->residue_param[i]=_residue_P[ci->residue_type[i]]->
60       copy_info(cs->residue_param[i]);
61   }
62
63   /* map backend settings */
64   for(i=0;i<ci->maps;i++){
65     ci->map_param[i]=_mapping_P[ci->map_type[i]]->
66       copy_info(cs->map_param[i]);
67   }
68   
69   /* mode settings */
70   for(i=0;i<ci->modes;i++){
71     ci->mode_param[i]=_ogg_calloc(1,sizeof(*ci->mode_param[i]));
72     ci->mode_param[i]->blockflag=cs->mode_param[i]->blockflag;
73     ci->mode_param[i]->windowtype=cs->mode_param[i]->windowtype;
74     ci->mode_param[i]->transformtype=cs->mode_param[i]->transformtype;
75     ci->mode_param[i]->mapping=cs->mode_param[i]->mapping;
76   }
77
78   /* psy settings */
79   for(i=0;i<ci->psys;i++){
80     ci->psy_param[i]=_vi_psy_copy(cs->psy_param[i]);
81   }
82
83 }
84
85 /* encoders will need to use vorbis_info_init beforehand and call
86    vorbis_info clear when all done */
87
88 int vorbis_encode_init_vbr(vorbis_info *vi,
89                            long channels,
90                            long rate,
91                            
92                            float base_quality /* 0. to 1. */
93                            ){
94
95   switch(channels){
96   case 2:
97     return(OV_EIMPL);
98
99
100     break;
101   default:
102     return(OV_EIMPL);
103
104     break;
105   }
106 }
107
108
109 int vorbis_encode_init(vorbis_info *vi,
110                        long channels,
111                        long rate,
112
113                        long max_bitrate,
114                        long nominal_bitrate,
115                        long min_bitrate){
116
117   long bpch;
118   int i,j;
119   codec_setup_info *ci=vi->codec_setup;
120   codec_setup_info *mode=NULL;
121   if(!ci)return(OV_EFAULT);
122
123   vi->version=0;
124   vi->channels=channels;
125   vi->rate=rate;
126   
127   vi->bitrate_upper=max_bitrate;
128   vi->bitrate_nominal=nominal_bitrate;
129   vi->bitrate_lower=min_bitrate;
130   vi->bitrate_window=2;
131
132   /* copy a mode into our allocated storage */
133   bpch=nominal_bitrate/channels;
134
135 #if 0
136   switch(channels){
137   case 2:
138 /*      if(rate>40000){ */
139
140     if(bpch<35000){
141       mode=&info_44c_Z;
142     }else if(bpch<45000){
143       mode=&info_44c_Y;
144     }else if(bpch<55000){
145       mode=&info_44c_X;
146     }else if(bpch<75000){
147       mode=&info_44c_A;
148     }else if(bpch<90000){
149       mode=&info_44c_B;
150     }else if(bpch<110000){
151       mode=&info_44c_C;
152     }else if(bpch<160000){
153       mode=&info_44c_D;
154     }else{
155       mode=&info_44c_E;
156     }
157 /*      }       */
158
159     break;
160   default:
161
162     if(bpch<40000){
163       mode=&info_44_Z;
164     }else if(bpch<50000){
165       mode=&info_44_Y;
166     }else if(bpch<70000){
167       mode=&info_44_X;
168     }else if(bpch<90000){
169       mode=&info_44_A;
170     }else if(bpch<120000){
171       mode=&info_44_B;
172     }else{
173       mode=&info_44_C;
174     }
175     break;
176   }
177 #endif
178
179   mode=&info_44c_A;
180
181   /* now we have to deepcopy */
182   codec_setup_partialcopy(ci,mode);
183
184   /* adjust for sample rate */
185   /* we don't have any floor 0 modes anymore 
186   for(i=0;i<ci->floors;i++)
187     if(ci->floor_type[i]==0)
188     ((vorbis_info_floor0 *)(ci->floor_param[i]))->rate=rate; */
189
190   /* adjust for channels */
191   /* but all our mappings use submap zero now! */
192
193   return(0);
194 }
195
196 int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){
197   return(OV_EIMPL);
198 }
199