1 /********************************************************************
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. *
8 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
9 * by the XIPHOPHORUS Company http://www.xiph.org/ *
11 ********************************************************************
13 function: simple programmatic interface for encoder mode setup
14 last mod: $Id: vorbisenc.c,v 1.16 2001/09/13 21:38:45 cwolf Exp $
16 ********************************************************************/
22 #include "vorbis/codec.h"
23 #include "vorbis/vorbisenc.h"
25 #include "codec_internal.h"
27 #include "modes/modes.h"
33 * If this module gets built into a separate shared library
34 * on win32 (DLL), then the backend mappings from registry.c
35 * need to be referenced from a file-mapped shared memory segment.
37 #if defined(_MSC_VER) && defined(STANDALONE_VORBISENC_DLL)
40 SHARED_MAP *g_shared_map;
42 # define _time_P g_shared_map->p_time_P
43 # define _floor_P g_shared_map->p_floor_P
44 # define _residue_P g_shared_map->p_residue_P
45 # define _mapping_P g_shared_map->p_mapping_P
48 /* deepcopy all but the codebooks; in this usage, they're static
49 (don't copy as they could be big) */
50 static void codec_setup_partialcopy(codec_setup_info *ci,
51 codec_setup_info *cs){
54 #if defined(_MSC_VER) && defined(STANDALONE_VORBISENC_DLL)
57 if ((g_shared_map = table_map2mem(&maplen)) == (SHARED_MAP*)0)
58 ; /* some error handling for memory exhaustion */
61 memcpy(ci,cs,sizeof(codec_setup_info)); /* to get the flat numbers */
64 for(i=0;i<ci->books;i++){
65 ci->book_param[i]=cs->book_param[i];
68 /* time backend settings */
69 for(i=0;i<ci->times;i++){
70 ci->time_param[i]=_time_P[ci->time_type[i]]->
71 copy_info(cs->time_param[i]);
74 /* floor backend settings */
75 for(i=0;i<ci->floors;i++){
76 ci->floor_param[i]=_floor_P[ci->floor_type[i]]->
77 copy_info(cs->floor_param[i]);
80 /* residue backend settings */
81 for(i=0;i<ci->residues;i++){
82 ci->residue_param[i]=_residue_P[ci->residue_type[i]]->
83 copy_info(cs->residue_param[i]);
86 /* map backend settings */
87 for(i=0;i<ci->maps;i++){
88 ci->map_param[i]=_mapping_P[ci->map_type[i]]->
89 copy_info(cs->map_param[i]);
93 for(i=0;i<ci->modes;i++){
94 ci->mode_param[i]=_ogg_calloc(1,sizeof(vorbis_info_mode));
95 ci->mode_param[i]->blockflag=cs->mode_param[i]->blockflag;
96 ci->mode_param[i]->windowtype=cs->mode_param[i]->windowtype;
97 ci->mode_param[i]->transformtype=cs->mode_param[i]->transformtype;
98 ci->mode_param[i]->mapping=cs->mode_param[i]->mapping;
102 for(i=0;i<ci->psys;i++){
103 ci->psy_param[i]=_vi_psy_copy(cs->psy_param[i]);
108 /* encoders will need to use vorbis_info_init beforehand and call
109 vorbis_info clear when all done */
111 int vorbis_encode_init_vbr(vorbis_info *vi,
115 float base_quality /* 0. to 1. */
132 int vorbis_encode_init(vorbis_info *vi,
137 long nominal_bitrate,
142 codec_setup_info *ci=vi->codec_setup;
143 codec_setup_info *mode=NULL;
144 if(!ci)return(OV_EFAULT);
147 vi->channels=channels;
150 vi->bitrate_upper=max_bitrate;
151 vi->bitrate_nominal=nominal_bitrate;
152 vi->bitrate_lower=min_bitrate;
153 vi->bitrate_window=2;
155 /* copy a mode into our allocated storage */
156 bpch=nominal_bitrate/channels;
161 /* if(rate>40000){ */
165 }else if(bpch<45000){
167 }else if(bpch<55000){
169 }else if(bpch<75000){
171 }else if(bpch<90000){
173 }else if(bpch<110000){
175 }else if(bpch<160000){
187 }else if(bpch<50000){
189 }else if(bpch<70000){
191 }else if(bpch<90000){
193 }else if(bpch<120000){
204 /* now we have to deepcopy */
205 codec_setup_partialcopy(ci,mode);
207 /* adjust for sample rate */
208 /* we don't have any floor 0 modes anymore
209 for(i=0;i<ci->floors;i++)
210 if(ci->floor_type[i]==0)
211 ((vorbis_info_floor0 *)(ci->floor_param[i]))->rate=rate; */
213 /* adjust for channels */
214 /* but all our mappings use submap zero now! */
219 int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){