Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Stefan Strogin
flac
Commits
6e2b5659
Commit
6e2b5659
authored
Apr 28, 2006
by
Josh Coalson
Browse files
fix a calcuation bug in FLAC__lpc_compute_best_order()
parent
96d8cd23
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/libFLAC/include/private/lpc.h
View file @
6e2b5659
...
...
@@ -200,10 +200,11 @@ FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scal
* IN lpc_error[0,max_order-1] >= 0.0 error returned from calculating LP coefficients
* IN max_order > 0 max LP order
* IN total_samples > 0 # of samples in residual signal
* IN bits_per_signal_sample # of bits per sample in the original signal
* IN overhead_bits_per_order # of bits overhead for each increased LP order
* (includes warmup sample size and quantized LP coefficient)
* RETURN [1,max_order] best order
*/
unsigned
FLAC__lpc_compute_best_order
(
const
FLAC__double
lpc_error
[],
unsigned
max_order
,
unsigned
total_samples
,
unsigned
bits_per_signal_sample
);
unsigned
FLAC__lpc_compute_best_order
(
const
FLAC__double
lpc_error
[],
unsigned
max_order
,
unsigned
total_samples
,
unsigned
overhead_bits_per_order
);
#endif
/* !defined FLAC__INTEGER_ONLY_LIBRARY */
...
...
src/libFLAC/lpc.c
View file @
6e2b5659
...
...
@@ -62,6 +62,13 @@ void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_le
FLAC__ASSERT(lag > 0);
FLAC__ASSERT(lag <= data_len);
/*
* Technically we should subtract the mean first like so:
* for(i = 0; i < data_len; i++)
* data[i] -= mean;
* but it appears not to make enough of a difference to matter, and
* most signals are already closely centered around zero
*/
while(lag--) {
for(i = lag, d = 0.0; i < data_len; i++)
d += data[i] * data[i - lag];
...
...
@@ -410,28 +417,28 @@ FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scal
}
}
unsigned
FLAC__lpc_compute_best_order
(
const
FLAC__double
lpc_error
[],
unsigned
max_order
,
unsigned
total_samples
,
unsigned
bits_per_signal_sample
)
unsigned
FLAC__lpc_compute_best_order
(
const
FLAC__double
lpc_error
[],
unsigned
max_order
,
unsigned
total_samples
,
unsigned
overhead_bits_per_order
)
{
unsigned
order
,
best_order
;
FLAC__double
best_
bits
,
tmp
_bits
,
error_scale
;
unsigned
order
,
index
,
best_index
;
/* 'index' the index into lpc_error; index==order-1 since lpc_error[0] is for order==1, lpc_error[1] is for order==2, etc */
FLAC__double
bits
,
best
_bits
,
error_scale
;
FLAC__ASSERT
(
max_order
>
0
);
FLAC__ASSERT
(
total_samples
>
0
);
error_scale
=
0
.
5
*
M_LN2
*
M_LN2
/
(
FLAC__double
)
total_samples
;
best_
or
de
r
=
0
;
best_bits
=
FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale
(
lpc_error
[
0
],
error_scale
)
*
(
FLAC__double
)
total_samples
;
best_
in
de
x
=
0
;
best_bits
=
(
unsigned
)(
-
1
)
;
for
(
order
=
1
;
or
de
r
<
max_order
;
order
++
)
{
tmp_
bits
=
FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale
(
lpc_error
[
or
de
r
],
error_scale
)
*
(
FLAC__double
)(
total_samples
-
order
)
+
(
FLAC__double
)(
order
*
bits_per_signal_sample
);
if
(
tmp_
bits
<
best_bits
)
{
best_
or
de
r
=
or
de
r
;
best_bits
=
tmp_
bits
;
for
(
index
=
0
,
order
=
1
;
in
de
x
<
max_order
;
index
++
,
order
++
)
{
bits
=
FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale
(
lpc_error
[
in
de
x
],
error_scale
)
*
(
FLAC__double
)(
total_samples
-
order
)
+
(
FLAC__double
)(
order
*
overhead_bits_per_order
);
if
(
bits
<
best_bits
)
{
best_
in
de
x
=
in
de
x
;
best_bits
=
bits
;
}
}
return
best_
or
de
r
+
1
;
/* +1 since index of lpc_error[] is order-1 */
return
best_
in
de
x
+
1
;
/* +1 since index of lpc_error[] is order-1 */
}
#endif
/* !defined FLAC__INTEGER_ONLY_LIBRARY */
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment