1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
diff --git a/apps/plugins/mp3_encoder.c b/apps/plugins/mp3_encoder.c
index fe417ce..910437a 100644
--- a/apps/plugins/mp3_encoder.c
+++ b/apps/plugins/mp3_encoder.c
@@ -29,11 +29,11 @@ enum e_byte_order { order_unknown, order_bigEndian, order_littleEndian };
 typedef struct {
     int   type; /* 0=(MPEG2 - 22.05,24,16kHz) 1=(MPEG1 - 44.1,48,32kHz) */
     int   mode; /* 0=stereo, 1=jstereo, 2=dual, 3=mono  */
-    int   bitrate;
     int   padding;
-    int   num_bands;
     long  bitr_id;
     int   smpl_id;
+    uint16_t bitrate;
+    uint8_t num_bands;
 } mpeg_t;

 /* Side information */
@@ -42,13 +42,13 @@ typedef struct {
     int    count1;          /* number of 0-1-quadruples  */
     uint32_t global_gain;
     uint32_t table_select[4];
-    uint32_t region_0_1;
     uint32_t address1;
     uint32_t address2;
     uint32_t address3;
     long     quantStep;
     long     additStep;
     uint32_t max_val;
+    uint8_t  region_0_1;
 } side_info_t;

 typedef struct {
@@ -64,7 +64,7 @@ typedef struct {
     int               channels;
     int               granules;
     int               resample;
-    long              samplerate;
+    uint16_t          samplerate;
 } config_t;

 typedef struct {
@@ -97,14 +97,14 @@ static int       sb_data     [2][2][18][SBLIMIT] IBSS_ATTR; /* 13824 Bytes */
 static int       mdct_freq   [SAMPL2]            IBSS_ATTR; /*  2304 Bytes */
 static char      mdct_sign   [SAMPL2]            IBSS_ATTR; /*   576 Bytes */
 static short     enc_data    [SAMPL2]            IBSS_ATTR; /*  1152 Bytes */
-static uint32_t  scalefac    [23]                IBSS_ATTR; /*    92 Bytes */
+static uint16_t  scalefac    [23]                IBSS_ATTR; /*    46 Bytes */
 static BF_Data   CodedData                       IBSS_ATTR; /*  1056 Bytes */
-static int       ca          [8]                 IBSS_ATTR; /*    32 Bytes */
-static int       cs          [8]                 IBSS_ATTR; /*    32 Bytes */
-static int       cx          [9]                 IBSS_ATTR; /*    36 Bytes */
-static int       win         [18][4]             IBSS_ATTR; /*   288 Bytes */
-static short     enwindow    [15*27+24]          IBSS_ATTR; /*   862 Bytes */
-static short     int2idx     [4096]              IBSS_ATTR; /*  8192 Bytes */
+static int16_t   ca          [8]                 IBSS_ATTR; /*    16 Bytes */
+static uint16_t  cs          [8]                 IBSS_ATTR; /*    16 Bytes */
+static int16_t   cx          [9]                 IBSS_ATTR; /*    18 Bytes */
+static int16_t   win         [18][4]             IBSS_ATTR; /*   144 Bytes */
+static int16_t   enwindow    [15*27+24]          IBSS_ATTR; /*   862 Bytes */
+static uint16_t  int2idx     [4096]              IBSS_ATTR; /*  8192 Bytes */
 static uint8_t   ht_count    [2][2][16]          IBSS_ATTR; /*    64 Bytes */
 static uint32_t  tab01       [ 16]               IBSS_ATTR; /*    64 Bytes */
 static uint32_t  tab23       [  9]               IBSS_ATTR; /*    36 Bytes */
@@ -453,8 +453,8 @@ static const struct huffcodebig ht_big[HTN] =

 static const struct
 {
-  uint32_t region0_cnt;
-  uint32_t region1_cnt;
+  uint8_t region0_cnt;
+  uint8_t region1_cnt;
 } subdv_table[23] =
 { {0, 0}, /*  0 bands */
   {0, 0}, /*  1 bands */
@@ -481,7 +481,7 @@ static const struct
   {6, 7}, /* 22 bands */
 };

-static const uint32_t sfBand[6][23] =
+static const uint16_t sfBand[6][23] =
 {
 /* Table B.2.b: 22.05 kHz */
 {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},
@@ -497,7 +497,7 @@ static const uint32_t sfBand[6][23] =
 {0,4, 8,12,16,20,24,30,36,44,54,66, 82,102,126,156,194,240,296,364,448,550,576} };


-static const short int2idx_const[4096] = /*  int2idx[i] = sqrt(i*sqrt(i)); */
+static const uint16_t int2idx_const[4096] = /*  int2idx[i] = sqrt(i*sqrt(i)); */
 {
   0,  1,  2,  2,  3,  3,  4,  4,  5,  5,  6,  6,  6,  7,  7,  8,  8,  8,  9,  9,
   9, 10, 10, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 16,
@@ -705,33 +705,33 @@ static const short int2idx_const[4096] = /*  int2idx[i] = sqrt(i*sqrt(i)); */
 509,509,509,509,509,509,509,509,509,509,510,510,510,510,510,510,510,510,510,510,
 510,511,511,511,511,511,511,511,511,511,511,512,512,512,512,512 };

-static const int order[32] = 
+static const uint8_t order[32] =
 { 0, 1, 16, 17, 8, 9, 24, 25, 4, 5, 20, 21, 12, 13, 28, 29,
   2, 3, 18, 19,10,11, 26, 27, 6, 7, 22, 23, 14, 15, 30, 31 };

-static const long sampr_index[2][3] = 
+static const uint16_t sampr_index[2][3] =
 { { 22050, 24000, 16000 },      /* MPEG 2 */
   { 44100, 48000, 32000 } };    /* MPEG 1 */

-static const long bitr_index[2][15] =
+static const uint16_t bitr_index[2][15] =
 { {0, 8,16,24,32,40,48,56, 64, 80, 96,112,128,144,160},    /* MPEG 2 */
   {0,32,40,48,56,64,80,96,112,128,160,192,224,256,320} };  /* MPEG 1 */

-static const int num_bands[3][15]  =
+static const uint8_t num_bands[3][15]  =
 { {0,10,10,10,10,12,14,16, 20, 22, 24, 26, 28, 30, 32},
   {0,10,10,10,10,10,12,14, 18, 24, 26, 28, 30, 32, 32},
   {0,10,12,14,18,24,26,28, 30, 32, 32, 32, 32, 32, 32} };

-static const int cx_const[9] =
+static const int16_t cx_const[9] =
 { 16135, 10531,  5604, 15396, -2845,-12551, 14189,  8192, 16384 };

-static const int ca_const[8] =
+static const int16_t ca_const[8] =
 {-16859,-15458,-10269, -5961, -3099, -1342,  -465,  -121 };

-static const int cs_const[8] =
+static const uint16_t cs_const[8] =
 { 28098, 28893, 31117, 32221, 32621, 32740, 32765, 32768 };

-static const short enwindow_const[15*27+24] = 
+static const int16_t enwindow_const[15*27+24] =
 { 0,   65,  593,  1766, 22228, 2115, 611, 62,
   8,  119, 1419, 10564,-11659,-1635,-154, -9,
  -8, -119,-1419,-10564, 11659, 1635, 154,  9, 464,  100,  91,
@@ -782,7 +782,7 @@ static const short enwindow_const[15*27+24] =
  21226,-21226,10604,-10604,1860,-1860,1458,-1458,576,-576,130,-130,60,-60,8,-8
 };

-static const int win_const[18][4] = {
+static const int16_t win_const[18][4] = {
   { -3072, -134, -146, 3352 },
   { -2747, -362, -471, 3579 },
   { -2387, -529, -831, 3747 },
@@ -2011,7 +2011,7 @@ void mdct_long(int *out, int *in)
   out[16] = ct - st;
 }

-static int find_bitrate_index(int type, int bitrate)
+static int find_bitrate_index(int type, uint16_t bitrate)
 {
   int i;

@@ -2022,7 +2022,7 @@ static int find_bitrate_index(int type, int bitrate)
   return i;
 }

-static int find_samplerate_index(long freq, int *mp3_type)
+static int find_samplerate_index(uint16_t freq, int *mp3_type)
 {
   int    mpg, rate;

@@ -2037,7 +2037,7 @@ static int find_samplerate_index(long freq, int *mp3_type)
   return 0;
 }

-void init_mp3_encoder_engine(bool stereo, int bitrate, int sample_rate)
+void init_mp3_encoder_engine(bool stereo, int bitrate, uint16_t sample_rate)
 {
   uint32_t  avg_byte_per_frame;