summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndree Buschmann <AndreeBuschmann@t-online.de>2011-09-10 20:35:04 +0000
committerAndree Buschmann <AndreeBuschmann@t-online.de>2011-09-10 20:35:04 +0000
commitf163b405c0a6fcf069e79d099ac7d7d64adc4471 (patch)
tree77479775fdc3e8be42efba6f3a03d381bcc47279
parentd4249affc41a0483ff9800b0b197e0fbeb5757fc (diff)
downloadrockbox-f163b405c0a6fcf069e79d099ac7d7d64adc4471.tar.gz
rockbox-f163b405c0a6fcf069e79d099ac7d7d64adc4471.zip
Fully remove floating point code from libmusepack. Introduce two small const arrays for precalculated scalefactors, correct the integer type of scalefactors to unsigned, migrate some metadata calculations to fixed point. No impact to decoder output.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30497 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/codecs/libmusepack/decoder.h2
-rw-r--r--apps/codecs/libmusepack/internal.h2
-rw-r--r--apps/codecs/libmusepack/mpc_decoder.c2
-rw-r--r--apps/codecs/libmusepack/requant.c70
-rw-r--r--apps/codecs/libmusepack/streaminfo.c10
-rw-r--r--apps/codecs/libmusepack/streaminfo.h4
6 files changed, 75 insertions, 15 deletions
diff --git a/apps/codecs/libmusepack/decoder.h b/apps/codecs/libmusepack/decoder.h
index 7e985407c5..1acacae8d9 100644
--- a/apps/codecs/libmusepack/decoder.h
+++ b/apps/codecs/libmusepack/decoder.h
@@ -91,7 +91,7 @@ struct mpc_decoder_t {
91 MPC_SAMPLE_FORMAT *V_R; 91 MPC_SAMPLE_FORMAT *V_R;
92 MPC_SAMPLE_FORMAT *Y_L; 92 MPC_SAMPLE_FORMAT *Y_L;
93 MPC_SAMPLE_FORMAT *Y_R; 93 MPC_SAMPLE_FORMAT *Y_R;
94 MPC_SAMPLE_FORMAT SCF[256]; ///< holds adapted scalefactors (for clipping prevention) 94 mpc_uint32_t SCF[256]; ///< holds adapted scalefactors (for clipping prevention)
95 //@} 95 //@}
96}; 96};
97 97
diff --git a/apps/codecs/libmusepack/internal.h b/apps/codecs/libmusepack/internal.h
index 3f8b29f9f5..897e6a7b17 100644
--- a/apps/codecs/libmusepack/internal.h
+++ b/apps/codecs/libmusepack/internal.h
@@ -99,7 +99,7 @@ static mpc_inline mpc_status mpc_check_key(char * key)
99 99
100/// helper functions used by multiple files 100/// helper functions used by multiple files
101mpc_uint32_t mpc_random_int(mpc_decoder *d); // in synth_filter.c 101mpc_uint32_t mpc_random_int(mpc_decoder *d); // in synth_filter.c
102void mpc_decoder_init_quant(mpc_decoder *d, double scale_factor); 102void mpc_decoder_init_quant(mpc_decoder *d, MPC_SAMPLE_FORMAT factor); // in requant.c
103void mpc_decoder_synthese_filter_float(mpc_decoder *d, MPC_SAMPLE_FORMAT* OutData, mpc_int_t channels); 103void mpc_decoder_synthese_filter_float(mpc_decoder *d, MPC_SAMPLE_FORMAT* OutData, mpc_int_t channels);
104unsigned long mpc_crc32(unsigned char *buf, int len); 104unsigned long mpc_crc32(unsigned char *buf, int len);
105 105
diff --git a/apps/codecs/libmusepack/mpc_decoder.c b/apps/codecs/libmusepack/mpc_decoder.c
index eb8916f343..3bfc4cc7fc 100644
--- a/apps/codecs/libmusepack/mpc_decoder.c
+++ b/apps/codecs/libmusepack/mpc_decoder.c
@@ -251,7 +251,7 @@ static void mpc_decoder_setup(mpc_decoder *d)
251 memset(d->Y_L, 0, sizeof(g_Y_L)); 251 memset(d->Y_L, 0, sizeof(g_Y_L));
252 memset(d->Y_R, 0, sizeof(g_Y_R)); 252 memset(d->Y_R, 0, sizeof(g_Y_R));
253 253
254 mpc_decoder_init_quant(d, 1.0f); 254 mpc_decoder_init_quant(d, MAKE_MPC_SAMPLE(1.0));
255} 255}
256 256
257static void mpc_decoder_set_streaminfo(mpc_decoder *d, mpc_streaminfo *si) 257static void mpc_decoder_set_streaminfo(mpc_decoder *d, mpc_streaminfo *si)
diff --git a/apps/codecs/libmusepack/requant.c b/apps/codecs/libmusepack/requant.c
index 5a113b0885..fc27dfd199 100644
--- a/apps/codecs/libmusepack/requant.c
+++ b/apps/codecs/libmusepack/requant.c
@@ -39,6 +39,7 @@
39#include "mpcdec_math.h" 39#include "mpcdec_math.h"
40#include "decoder.h" 40#include "decoder.h"
41#include "internal.h" 41#include "internal.h"
42#include <string.h>
42 43
43/* C O N S T A N T S */ 44/* C O N S T A N T S */
44// Bits per sample for chosen quantizer 45// Bits per sample for chosen quantizer
@@ -70,6 +71,64 @@ const mpc_int16_t __Dc [1 + 18] ICONST_ATTR = {
70 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767 71 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767
71}; 72};
72 73
74// Table'ized SCF calculated from mpc_decoder_scale_output(d, 1.0)
75static const mpc_uint32_t SCF[] = {
76 1289035711, 1073741824, 1788812356, 1490046106, 1241179595, 1033878604, 861200887, 717363687,
77 597550081, 497747664, 414614180, 345365595, 287682863, 239634262, 199610707, 166271859,
78 138501244, 115368858, 96100028, 80049465, 66679657, 55542865, 46266132, 38538793,
79 32102070, 26740403, 22274239, 18554010, 15455132, 12873826, 10723648, 8932591,
80 7440676, 6197939, 5162763, 4300482, 3582218, 2983918, 2485546, 2070412,
81 1724613, 1436569, 1196634, 996773, 830293, 691618, 576104, 479883,
82 399734, 332970, 277358, 231034, 192446, 160304, 133530, 111228,
83 92651, 77176, 64286, 53549, 44605, 37155, 30949, 25780,
84 21474, 17888, 14900, 12411, 10338, 8612, 7173, 5975,
85 4977, 4146, 3453, 2876, 2396, 1996, 1662, 1385,
86 1153, 961, 800, 666, 555, 462, 385, 321,
87 267, 222, 185, 154, 128, 107, 89, 74,
88 61, 51, 43, 35, 29, 24, 20, 17,
89 14, 11, 9, 8, 6, 5, 4, 3,
90 3, 2, 2, 1, 1, 1, 1, 0,
91 0, 0, 0, 0, 0, 0, 0, 0,
92 0, 2147483648, 2147483648, 2147483648, 2147483648, 2147483648, 2147483648, 2147483648,
93 2147483648, 2147483648, 2147483648, 2147483648, 1930697728, 1608233877, 1339627724, 1115883992,
94 1859019579, 1548527365, 1289893354, 1074456223, 1790002518, 1491037488, 1242005398, 2069132964,
95 1723547752, 1435681952, 1195895306, 1992315335, 1659560152, 1382381519, 1151497076, 1918349601,
96 1597948125, 1331059892, 1108747153, 1847129882, 1538623477, 1281643607, 2135168687, 1778554232,
97 1481501287, 1234061927, 2055899448, 1712524489, 1426499787, 1188246741, 1979573121, 1648946134,
98 1373540247, 1144132468, 1906080447, 1587728158, 1322546856, 1101655960, 1835316227, 1528782931,
99 1273446622, 2121512828, 1767179166, 1472026076, 1226169259, 2042750570, 1701571728, 1417376349,
100 1180647093, 1966912401, 1638400000, 1364755521, 1136814961, 1893889764, 1577573554, 1314088268,
101 1094610119, 1823578129, 1519005322, 1265302063, 2107944308, 1755876851, 1462611466, 1218327071,
102 2029685788, 1690689017, 1408311261, 1173096050, 1954332656, 1627921315, 1356026979, 1129544254,
103 1881777048, 1567483896, 1305683778, 1087609341, 1811915104, 1509290248, 1257209594, 2094462567,
104 1744646821, 1453257069, 1210535039, 2016704564, 1679875908, 1399304151, 1165593302, 1941833367,
105 1617509648, 1347354262, 1122320049, 1869741801, 1557458768, 1297333040, 1080653338, 1800326672,
106 1499637308, 1249168882, 2081067051, 1733488616, 1443962500, 1202792843, 2003806364, 1669131957,
107 1390354647, 1158138538, 1929414019, 1607164572, 1338737013, 1115142047, 1857783528, 1547497758
108};
109
110// Table'ized SCF_shift calculated from mpc_decoder_scale_output(d, 1.0)
111static const mpc_uint8_t SCF_shift[] = {
112 30, 30, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
113 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
114 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
115 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
116 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
117 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
118 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
119 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
120 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
121 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5,
122 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9,
123 9, 9, 10, 10, 10, 10, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13,
124 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 17, 17, 17, 17,
125 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 22,
126 22, 22, 22, 23, 23, 23, 23, 24, 24, 24, 24, 25, 25, 25, 25, 26,
127 26, 26, 27, 27, 27, 27, 28, 28, 28, 28, 29, 29, 29, 29, 30, 30
128};
129
130/* F U N C T I O N S */
131/* not used anymore, tables from above are used
73#ifdef MPC_FIXED_POINT 132#ifdef MPC_FIXED_POINT
74static mpc_uint32_t find_shift(double fval) 133static mpc_uint32_t find_shift(double fval)
75{ 134{
@@ -86,8 +145,6 @@ static mpc_uint32_t find_shift(double fval)
86} 145}
87#endif 146#endif
88 147
89/* F U N C T I O N S */
90
91#define SET_SCF(N,X) d->SCF[N] = MAKE_MPC_SAMPLE_EX(X,d->SCF_shift[N] = (mpc_uint8_t) find_shift(X)); 148#define SET_SCF(N,X) d->SCF[N] = MAKE_MPC_SAMPLE_EX(X,d->SCF_shift[N] = (mpc_uint8_t) find_shift(X));
92 149
93static void 150static void
@@ -116,9 +173,12 @@ mpc_decoder_scale_output(mpc_decoder *d, double factor)
116 f2 *= 1/0.83298066476582673961; 173 f2 *= 1/0.83298066476582673961;
117 } 174 }
118} 175}
119 176*/
120void 177void
121mpc_decoder_init_quant(mpc_decoder *d, double scale_factor) 178mpc_decoder_init_quant(mpc_decoder *d, MPC_SAMPLE_FORMAT factor)
122{ 179{
123 mpc_decoder_scale_output(d, scale_factor); 180 //mpc_decoder_scale_output(d, (double)factor / MPC_FIXED_POINT_SHIFT)
181 (void)factor;
182 memcpy(d->SCF, SCF, sizeof(d->SCF));
183 memcpy(d->SCF_shift, SCF_shift, sizeof(d->SCF_shift));
124} 184}
diff --git a/apps/codecs/libmusepack/streaminfo.c b/apps/codecs/libmusepack/streaminfo.c
index b31e5f605a..6b4d3df0c1 100644
--- a/apps/codecs/libmusepack/streaminfo.c
+++ b/apps/codecs/libmusepack/streaminfo.c
@@ -167,8 +167,8 @@ streaminfo_read_header_sv7(mpc_streaminfo* si, mpc_bits_reader * r)
167 else 167 else
168 si->samples -= MPC_DECODER_SYNTH_DELAY; 168 si->samples -= MPC_DECODER_SYNTH_DELAY;
169 169
170 si->average_bitrate = (si->tag_offset - si->header_position) * 8.0 170 si->average_bitrate = 8LL * (si->tag_offset - si->header_position)
171 * si->sample_freq / si->samples; 171 * si->sample_freq / si->samples;
172 172
173 return check_streaminfo(si); 173 return check_streaminfo(si);
174} 174}
@@ -216,8 +216,8 @@ streaminfo_read_header_sv8(mpc_streaminfo* si, const mpc_bits_reader * r_in,
216 si->bitrate = 0; 216 si->bitrate = 0;
217 217
218 if ((si->samples - si->beg_silence) != 0) 218 if ((si->samples - si->beg_silence) != 0)
219 si->average_bitrate = (si->tag_offset - si->header_position) * 8.0 219 si->average_bitrate = 8LL * (si->tag_offset - si->header_position)
220 * si->sample_freq / (si->samples - si->beg_silence); 220 * si->sample_freq / (si->samples - si->beg_silence);
221 221
222 return check_streaminfo(si); 222 return check_streaminfo(si);
223} 223}
@@ -227,7 +227,7 @@ void streaminfo_encoder_info(mpc_streaminfo* si, const mpc_bits_reader * r_in)
227{ 227{
228 mpc_bits_reader r = *r_in; 228 mpc_bits_reader r = *r_in;
229 229
230 si->profile = mpc_bits_read(&r, 7) / 8.; 230 si->profile = mpc_bits_read(&r, 7); // to be divided by 8
231/* rockbox: not used 231/* rockbox: not used
232 si->profile_name = mpc_get_version_string(si->profile); 232 si->profile_name = mpc_get_version_string(si->profile);
233*/ 233*/
diff --git a/apps/codecs/libmusepack/streaminfo.h b/apps/codecs/libmusepack/streaminfo.h
index 739d40acf3..52e97936a0 100644
--- a/apps/codecs/libmusepack/streaminfo.h
+++ b/apps/codecs/libmusepack/streaminfo.h
@@ -58,7 +58,7 @@ typedef struct mpc_streaminfo {
58 mpc_uint32_t channels; ///< Number of channels in stream 58 mpc_uint32_t channels; ///< Number of channels in stream
59 mpc_uint32_t stream_version; ///< Streamversion of stream 59 mpc_uint32_t stream_version; ///< Streamversion of stream
60 mpc_uint32_t bitrate; ///< Bitrate of stream file (in bps) 60 mpc_uint32_t bitrate; ///< Bitrate of stream file (in bps)
61 double average_bitrate; ///< Average bitrate of stream (in bits/sec) 61 mpc_uint32_t average_bitrate; ///< Average bitrate of stream (in bits/sec)
62 mpc_uint32_t max_band; ///< Maximum band-index used in stream (0...31) 62 mpc_uint32_t max_band; ///< Maximum band-index used in stream (0...31)
63 mpc_uint32_t ms; ///< Mid/side stereo (0: off, 1: on) 63 mpc_uint32_t ms; ///< Mid/side stereo (0: off, 1: on)
64 mpc_uint32_t fast_seek; ///< True if stream supports fast-seeking (sv7) 64 mpc_uint32_t fast_seek; ///< True if stream supports fast-seeking (sv7)
@@ -87,7 +87,7 @@ typedef struct mpc_streaminfo {
87 char encoder[256]; ///< Encoder name 87 char encoder[256]; ///< Encoder name
88*/ 88*/
89 mpc_bool_t pns; ///< pns used 89 mpc_bool_t pns; ///< pns used
90 float profile; ///< Quality profile of stream 90 mpc_uint32_t profile; ///< Quality profile of stream
91/* rockbox: not used 91/* rockbox: not used
92 const char* profile_name; ///< Name of profile used by stream 92 const char* profile_name; ///< Name of profile used by stream
93*/ 93*/