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
|
/*
** FAAD - Freeware Advanced Audio Decoder
** Copyright (C) 2002 M. Bakker
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** $Id: pns.c,v 1.1 2002/07/14 23:43:01 miguelfreitas Exp $
**/
#include "common.h"
#include "pns.h"
/* Needs some more work */
/* From the spec:
If the same scalefactor band and group is coded by perceptual noise
substitution in both channels of a channel pair, the correlation of
the noise signal can be controlled by means of the ms_used field: While
the default noise generation process works independently for each channel
(separate generation of random vectors), the same random vector is used
for both channels if ms_used[] is set for a particular scalefactor band
and group. In this case, no M/S stereo coding is carried out (because M/S
stereo coding and noise substitution coding are mutually exclusive).
If the same scalefactor band and group is coded by perceptual noise
substitution in only one channel of a channel pair the setting of ms_used[]
is not evaluated.
*/
static INLINE int32_t random2()
{
static int32_t state = 1;
state = (1664525L * state) + 1013904223L; /* Numerical recipes */
return state;
}
/* The function gen_rand_vector(addr, size) generates a vector of length
<size> with signed random values of average energy MEAN_NRG per random
value. A suitable random number generator can be realized using one
multiplication/accumulation per random value.
*/
static INLINE void gen_rand_vector(real_t *spec, uint16_t scale_factor, uint16_t size)
{
uint16_t i;
real_t scale;
for (i = 0; i < size; i++)
{
spec[i] = (real_t)random2();
}
/* 14496-3 says:
scale = 1.0f/(size * (real_t)sqrt(MEAN_NRG));
*/
scale = 1.0f/(real_t)sqrt(size * MEAN_NRG);
scale = MUL(scale, (real_t)exp(LN2 * 0.25 * scale_factor));
/* Scale random vector to desired target energy */
for (i = 0; i < size; i++)
spec[i] = MUL(spec[i], scale);
}
void pns_decode(ic_stream *ics, real_t *spec, uint16_t frame_len)
{
uint8_t g, sfb, b;
uint16_t size, offs;
uint8_t group = 0;
uint16_t nshort = frame_len/8;
for (g = 0; g < ics->num_window_groups; g++)
{
/* Do perceptual noise substitution decoding */
for (b = 0; b < ics->window_group_length[g]; b++)
{
for (sfb = 0; sfb < ics->max_sfb; sfb++)
{
if (is_noise(ics, g, sfb))
{
/* Simultaneous use of LTP and PNS is not prevented in the
syntax. If both LTP, and PNS are enabled on the same
scalefactor band, PNS takes precedence, and no prediction
is applied to this band.
*/
ics->ltp.long_used[sfb] = 0;
ics->ltp2.long_used[sfb] = 0;
/* For scalefactor bands coded using PNS the corresponding
predictors are switched to "off".
*/
ics->pred.prediction_used[sfb] = 0;
offs = ics->swb_offset[sfb];
size = ics->swb_offset[sfb+1] - offs;
/* Generate random vector */
gen_rand_vector(&spec[(group*nshort)+offs],
ics->scale_factors[g][sfb], size);
}
}
group++;
}
}
}
|