r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / toolame-02l / common.c
blob7f0be873723b08e05b2fd21259675fa2dd4edae7
2 /***********************************************************************
4 * Global Include Files
6 ***********************************************************************/
7 #include <stdio.h>
8 #include <string.h> /* 1995-07-11 shn */
9 #include <ctype.h>
10 #include <stdlib.h>
11 #include "common.h"
12 #include "options.h"
13 #include "encode_new.h"
14 #include "tables.h"
16 /***********************************************************************
18 * Global Variable Definitions
20 ***********************************************************************/
22 char *mode_names[4] = { "stereo", "j-stereo", "dual-ch", "single-ch" };
23 char *version_names[2] = { "MPEG-2 LSF", "MPEG-1" };
25 /* 1: MPEG-1, 0: MPEG-2 LSF, 1995-07-11 shn */
26 double s_freq[2][4] = { {22.05, 24, 16, 0}, {44.1, 48, 32, 0} };
28 /* 1: MPEG-1, 0: MPEG-2 LSF, 1995-07-11 shn */
29 int bitrate[2][15] = {
30 {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160},
31 {0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384}
34 double multiple[64] = {
35 2.00000000000000, 1.58740105196820, 1.25992104989487,
36 1.00000000000000, 0.79370052598410, 0.62996052494744, 0.50000000000000,
37 0.39685026299205, 0.31498026247372, 0.25000000000000, 0.19842513149602,
38 0.15749013123686, 0.12500000000000, 0.09921256574801, 0.07874506561843,
39 0.06250000000000, 0.04960628287401, 0.03937253280921, 0.03125000000000,
40 0.02480314143700, 0.01968626640461, 0.01562500000000, 0.01240157071850,
41 0.00984313320230, 0.00781250000000, 0.00620078535925, 0.00492156660115,
42 0.00390625000000, 0.00310039267963, 0.00246078330058, 0.00195312500000,
43 0.00155019633981, 0.00123039165029, 0.00097656250000, 0.00077509816991,
44 0.00061519582514, 0.00048828125000, 0.00038754908495, 0.00030759791257,
45 0.00024414062500, 0.00019377454248, 0.00015379895629, 0.00012207031250,
46 0.00009688727124, 0.00007689947814, 0.00006103515625, 0.00004844363562,
47 0.00003844973907, 0.00003051757813, 0.00002422181781, 0.00001922486954,
48 0.00001525878906, 0.00001211090890, 0.00000961243477, 0.00000762939453,
49 0.00000605545445, 0.00000480621738, 0.00000381469727, 0.00000302772723,
50 0.00000240310869, 0.00000190734863, 0.00000151386361, 0.00000120155435,
51 1E-20
54 enum byte_order NativeByteOrder = order_unknown;
56 /***********************************************************************
58 * Global Function Definitions
60 ***********************************************************************/
64 int js_bound (int m_ext)
66 /* layer 2 only */
67 static int jsb_table[4] = { 4, 8, 12, 16 };
69 if (m_ext < 0 || m_ext > 3) {
70 fprintf (stderr, "js_bound bad modext (%d)\n", m_ext);
71 exit (1);
73 return (jsb_table[m_ext]);
76 void hdr_to_frps (frame_info * frame)
77 /* interpret data in hdr str to fields in frame */
79 frame_header *hdr = frame->header; /* (or pass in as arg?) */
81 frame->actual_mode = hdr->mode;
82 frame->nch = (hdr->mode == MPG_MD_MONO) ? 1 : 2;
84 frame->sblimit = pick_table (frame);
85 /* MFC FIX this up */
86 encode_init(frame);
88 if (hdr->mode == MPG_MD_JOINT_STEREO)
89 frame->jsbound = js_bound (hdr->mode_ext);
90 else
91 frame->jsbound = frame->sblimit;
92 /* alloc, tab_num set in pick_table */
95 int toolame_BitrateIndex (int bRate, /* legal rates from 32 to 448 */
96 int version /* MPEG-1 or MPEG-2 LSF */ )
97 /* convert bitrate in kbps to index */
99 int index = 0;
100 int found = 0;
102 while (!found && index < 15) {
103 if (bitrate[version][index] == bRate)
104 found = 1;
105 else
106 ++index;
108 if (found)
109 return (index);
110 else {
111 fprintf (stderr,
112 "toolame_BitrateIndex: %d is not a legal bitrate for version %i\n",
113 bRate, version);
114 exit (-1); /* Error! */
118 int toolame_SmpFrqIndex (long sRate, int *version)
119 /* convert samp frq in Hz to index */
120 /* legal rates 16000, 22050, 24000, 32000, 44100, 48000 */
122 if (sRate == 44100L) {
123 *version = MPEG_AUDIO_ID;
124 return (0);
125 } else if (sRate == 48000L) {
126 *version = MPEG_AUDIO_ID;
127 return (1);
128 } else if (sRate == 32000L) {
129 *version = MPEG_AUDIO_ID;
130 return (2);
131 } else if (sRate == 24000L) {
132 *version = MPEG_PHASE2_LSF;
133 return (1);
134 } else if (sRate == 22050L) {
135 *version = MPEG_PHASE2_LSF;
136 return (0);
137 } else if (sRate == 16000L) {
138 *version = MPEG_PHASE2_LSF;
139 return (2);
140 } else {
141 fprintf (stderr, "toolame_SmpFrqIndex: %ld is not a legal sample rate\n", sRate);
142 return (-1); /* Error! */
150 /********************************************************************
151 new_ext()
152 Puts a new extension name on a file name <filename>.
153 Removes the last extension name, if any.
154 1992-08-19, 1995-06-12 shn
155 ***********************************************************************/
156 void new_ext (char *filename, char *extname, char *newname)
158 int found, dotpos;
160 /* First, strip the extension */
161 dotpos = strlen (filename);
162 found = 0;
163 do {
164 switch (filename[dotpos]) {
165 case '.':
166 found = 1;
167 break;
168 case '\\':
169 case '/':
170 case ':':
171 found = -1;
172 break;
173 default:
174 dotpos--;
175 if (dotpos < 0)
176 found = -1;
177 break;
180 while (found == 0);
181 if (found == -1)
182 strcpy (newname, filename);
183 if (found == 1) {
184 strncpy (newname, filename, dotpos);
185 newname[dotpos] = '\0';
187 strcat (newname, extname);