Skip to content

Commit 8863db1

Browse files
committed
[Fix] LAME: Apply <https://sourceforge.net/p/lame/svn/6444/> from LAME SVN trunk to fix <https://sourceforge.net/p/lame/bugs/500/>. [Fix] LAME: Apply <https://sourceforge.net/p/lame/svn/6445/> from LAME SVN trunk to fix <https://sourceforge.net/p/lame/bugs/501/>. git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@24983 56274372-70c3-4bfc-bfc3-4c3a0b034d27
1 parent a2626f6 commit 8863db1

File tree

4 files changed

+69
-24
lines changed

4 files changed

+69
-24
lines changed

include/lame/OpenMPT.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
lame library version 3.100.
22
The following changes have been made:
33
* Obviously, unnecessary folders and files have been removed.
4+
* <https://sourceforge.net/p/lame/svn/6438/> has been applied to fix
5+
<https://sourceforge.net/p/lame/bugs/496/>.
6+
* <https://sourceforge.net/p/lame/svn/6444/> has been applied to fix
7+
<https://sourceforge.net/p/lame/bugs/500/>.
8+
* <https://sourceforge.net/p/lame/svn/6445/> has been applied to fix
9+
<https://sourceforge.net/p/lame/bugs/501/>.
410
* negative-shift warning in VbrTag.c has been fixed.
511
* function prototype mismatch has been fixed for on_pe() and
612
L3psycho_anal_vbr().

include/lame/libmp3lame/lame.c

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Copyright (c) 1999-2000 Mark Taylor
66
* Copyright (c) 2000-2005 Takehiro Tominaga
7-
* Copyright (c) 2000-2017 Robert Hegemann
7+
* Copyright (c) 2000-2019 Robert Hegemann
88
* Copyright (c) 2000-2005 Gabriel Bouvigne
99
* Copyright (c) 2000-2004 Alexander Leidinger
1010
*
@@ -2082,6 +2082,29 @@ lame_init_bitstream(lame_global_flags * gfp)
20822082
return -3;
20832083
}
20842084

2085+
static int
2086+
calc_mp3buffer_size_remaining( int mp3buffer_size, int mp3count)
2087+
{
2088+
/* if user specifed buffer size = 0, dont check size */
2089+
if (mp3buffer_size == 0)
2090+
return INT_MAX;
2091+
else if (mp3buffer_size > 0 && mp3count >= 0 ) {
2092+
int const mp3buffer_size_remaining = mp3buffer_size - mp3count;
2093+
if (mp3buffer_size_remaining > 0) {
2094+
return mp3buffer_size_remaining;
2095+
}
2096+
assert(mp3buffer_size_remaining >= 0);
2097+
/* we reached the end of the output buffer, set to -1
2098+
because we have to distinguish this case from the case above,
2099+
where the caller did not specify any buffer size
2100+
*/
2101+
return -1;
2102+
}
2103+
else {
2104+
/* values are invalid, block writing into output buffer */
2105+
return -1;
2106+
}
2107+
}
20852108

20862109
/*****************************************************************/
20872110
/* flush internal PCM sample buffers, then mp3 buffers */
@@ -2149,20 +2172,17 @@ lame_encode_flush(lame_global_flags * gfp, unsigned char *mp3buffer, int mp3buff
21492172
if (bunch > 1152) bunch = 1152;
21502173
if (bunch < 1) bunch = 1;
21512174

2152-
mp3buffer_size_remaining = mp3buffer_size - mp3count;
2153-
2154-
/* if user specifed buffer size = 0, dont check size */
2155-
if (mp3buffer_size == 0)
2156-
mp3buffer_size_remaining = 0;
2175+
mp3buffer_size_remaining = calc_mp3buffer_size_remaining(mp3buffer_size, mp3count);
21572176

21582177
/* send in a frame of 0 padding until all internal sample buffers
21592178
* are flushed
21602179
*/
21612180
imp3 = lame_encode_buffer(gfp, buffer[0], buffer[1], bunch,
21622181
mp3buffer, mp3buffer_size_remaining);
2163-
2164-
mp3buffer += imp3;
2165-
mp3count += imp3;
2182+
if (imp3 > 0) {
2183+
mp3buffer += imp3;
2184+
mp3count += imp3;
2185+
}
21662186
{ /* even a single pcm sample can produce several frames!
21672187
* for example: 1 Hz input file resampled to 8 kHz mpeg2.5
21682188
*/
@@ -2181,10 +2201,7 @@ lame_encode_flush(lame_global_flags * gfp, unsigned char *mp3buffer, int mp3buff
21812201
return imp3;
21822202
}
21832203

2184-
mp3buffer_size_remaining = mp3buffer_size - mp3count;
2185-
/* if user specifed buffer size = 0, dont check size */
2186-
if (mp3buffer_size == 0)
2187-
mp3buffer_size_remaining = INT_MAX;
2204+
mp3buffer_size_remaining = calc_mp3buffer_size_remaining(mp3buffer_size, mp3count);
21882205

21892206
/* mp3 related stuff. bit buffer might still contain some mp3 data */
21902207
flush_bitstream(gfc);

include/lame/libmp3lame/quantize.c

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 1999-2000 Mark Taylor
55
* Copyright (c) 1999-2003 Takehiro Tominaga
6-
* Copyright (c) 2000-2011 Robert Hegemann
6+
* Copyright (c) 2000-2019 Robert Hegemann
77
* Copyright (c) 2001-2005 Gabriel Bouvigne
88
*
99
* This library is free software; you can redistribute it and/or
@@ -1768,21 +1768,23 @@ static void
17681768
calc_target_bits(lame_internal_flags * gfc,
17691769
const FLOAT pe[2][2],
17701770
FLOAT const ms_ener_ratio[2],
1771-
int targ_bits[2][2], int *analog_silence_bits, int *max_frame_bits)
1771+
int targ_bits_out[2][2], int *analog_silence_bits_out,
1772+
int *max_frame_bits_out)
17721773
{
17731774
SessionConfig_t const *const cfg = &gfc->cfg;
17741775
EncResult_t *const eov = &gfc->ov_enc;
17751776
III_side_info_t const *const l3_side = &gfc->l3_side;
17761777
FLOAT res_factor;
17771778
int gr, ch, totbits, mean_bits;
17781779
int framesize = 576 * cfg->mode_gr;
1780+
int max_frame_bits=0, analog_silence_bits=0, targ_bits[2][2]={0};
17791781

17801782
eov->bitrate_index = cfg->vbr_max_bitrate_index;
1781-
*max_frame_bits = ResvFrameBegin(gfc, &mean_bits);
1783+
max_frame_bits = ResvFrameBegin(gfc, &mean_bits);
17821784

17831785
eov->bitrate_index = 1;
17841786
mean_bits = getframebits(gfc) - cfg->sideinfo_len * 8;
1785-
*analog_silence_bits = mean_bits / (cfg->mode_gr * cfg->channels_out);
1787+
analog_silence_bits = mean_bits / (cfg->mode_gr * cfg->channels_out);
17861788

17871789
mean_bits = cfg->vbr_avg_bitrate_kbps * framesize * 1000;
17881790
if (gfc->sv_qnt.substep_shaping & 1)
@@ -1872,14 +1874,31 @@ calc_target_bits(lame_internal_flags * gfc,
18721874

18731875
/* repartion target bits if needed
18741876
*/
1875-
if (totbits > *max_frame_bits && totbits > 0) {
1877+
if (totbits > max_frame_bits && max_frame_bits > 0) {
1878+
int const act_totbits = totbits;
1879+
totbits = 0;
18761880
for (gr = 0; gr < cfg->mode_gr; gr++) {
18771881
for (ch = 0; ch < cfg->channels_out; ch++) {
1878-
targ_bits[gr][ch] *= *max_frame_bits;
1879-
targ_bits[gr][ch] /= totbits;
1882+
targ_bits[gr][ch] *= max_frame_bits;
1883+
targ_bits[gr][ch] /= act_totbits;
1884+
totbits += targ_bits[gr][ch];
18801885
}
18811886
}
18821887
}
1888+
assert( totbits <= max_frame_bits );
1889+
1890+
/* set output arguments
1891+
*/
1892+
for (gr = 0; gr < cfg->mode_gr; gr++) {
1893+
for (ch = 0; ch < cfg->channels_out; ch++) {
1894+
int const gr_ch_bits = targ_bits[gr][ch];
1895+
targ_bits_out[gr][ch] = gr_ch_bits;
1896+
if (analog_silence_bits > gr_ch_bits)
1897+
analog_silence_bits = gr_ch_bits;
1898+
}
1899+
}
1900+
*analog_silence_bits_out = analog_silence_bits;
1901+
*max_frame_bits_out = max_frame_bits;
18831902
}
18841903

18851904

@@ -1955,6 +1974,8 @@ ABR_iteration_loop(lame_internal_flags * gfc, const FLOAT pe[2][2],
19551974
(void) outer_loop(gfc, cod_info, l3_xmin, xrpow, ch, targ_bits[gr][ch]);
19561975
}
19571976
iteration_finish_one(gfc, gr, ch);
1977+
assert(cod_info->part2_3_length <= MAX_BITS_PER_CHANNEL);
1978+
assert(cod_info->part2_3_length <= targ_bits[gr][ch]);
19581979
} /* ch */
19591980
} /* gr */
19601981

include/lame/libmp3lame/vector/xmm_quantize_sub.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@ static const FLOAT costab[TRI_SIZE * 2] = {
6060

6161

6262
SSE_FUNCTION void
63-
init_xrpow_core_sse(gr_info * const cod_info, FLOAT xrpow[576], int upper, FLOAT * sum)
63+
init_xrpow_core_sse(gr_info * const cod_info, FLOAT xrpow[576], int max_nz, FLOAT * sum)
6464
{
6565
int i;
6666
float tmp_max = 0;
6767
float tmp_sum = 0;
68+
int upper = max_nz + 1;
6869
int upper4 = (upper / 4) * 4;
6970
int rest = upper-upper4;
7071

@@ -74,8 +75,8 @@ init_xrpow_core_sse(gr_info * const cod_info, FLOAT xrpow[576], int upper, FLOAT
7475
vecfloat_union vec_sum;
7576
vecfloat_union vec_tmp;
7677

77-
_mm_prefetch((char *) cod_info->xr, _MM_HINT_T0);
78-
_mm_prefetch((char *) xrpow, _MM_HINT_T0);
78+
_mm_prefetch((char const *) cod_info->xr, _MM_HINT_T0);
79+
_mm_prefetch((char const *) xrpow, _MM_HINT_T0);
7980

8081
vec_xrpow_max._m128 = _mm_set_ps1(0);
8182
vec_sum._m128 = _mm_set_ps1(0);
@@ -206,7 +207,7 @@ fht_SSE2(FLOAT * fz, int n)
206207
__m128 p, q, r;
207208

208209
q = _mm_setr_ps(fi[k1], fi[k3], gi[k1], gi[k3]); /* Q := {fi_k1,fi_k3,gi_k1,gi_k3}*/
209-
p = _mm_mul_ps(_mm_set_ps1(s2), q); /* P := s2 * Q */
210+
p = _mm_mul_ps(v_s2, q); /* P := s2 * Q */
210211
q = _mm_mul_ps(v_c2, q); /* Q := c2 * Q */
211212
q = _mm_shuffle_ps(q, q, _MM_SHUFFLE(1,0,3,2)); /* Q := {-c2*gi_k1,-c2*gi_k3,c2*fi_k1,c2*fi_k3} */
212213
p = _mm_add_ps(p, q);

0 commit comments

Comments
 (0)