Skip to content

Commit 7dfad88

Browse files
committed
Noise fill: Weight raw value, not output weight...
... and reduce floor-to-mask ratio, fix comment, new copyright date, apply ceiling to NoiseEnd
1 parent 58824fe commit 7dfad88

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

libulc/ulcEncoder_NoiseFill.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**************************************/
22
//! ulc-codec: Ultra-Low-Complexity Audio Codec
3-
//! Copyright (C) 2022, Ruben Nunez (Aikku; aik AT aol DOT com DOT au)
3+
//! Copyright (C) 2023, Ruben Nunez (Aikku; aik AT aol DOT com DOT au)
44
//! Refer to the project README file for license terms.
55
/**************************************/
66
#pragma once
@@ -33,7 +33,6 @@
3333
static inline void Block_Transform_CalculateNoiseLogSpectrumWithWeights(
3434
float *Dst,
3535
const float *Src,
36-
const float *Weights,
3736
int N
3837
) {
3938
//! Hopefully compilers apply loop peeling to the inner loops...
@@ -44,7 +43,6 @@ static inline void Block_Transform_CalculateNoiseLogSpectrumWithWeights(
4443
__m256 x = _mm256_load_ps(Src); Src += 8;
4544
__m256 y = _mm256_add_ps(_mm256_set1_ps(1.0f), _mm256_mul_ps(x, _mm256_set1_ps(0.5f / (1 << Log2M))));
4645
for(i=0;i<Log2M;i++) y = _mm256_mul_ps(y, y);
47-
y = _mm256_mul_ps(y, _mm256_add_ps(_mm256_set1_ps(0.1f), _mm256_load_ps(Weights))); Weights += 8;
4846
x = _mm256_mul_ps(x, y);
4947
__m256 l = _mm256_unpacklo_ps(y, x);
5048
__m256 h = _mm256_unpackhi_ps(y, x);
@@ -58,15 +56,14 @@ static inline void Block_Transform_CalculateNoiseLogSpectrumWithWeights(
5856
__m128 x = _mm_load_ps(Src); Src += 4;
5957
__m128 y = _mm_add_ps(_mm_set1_ps(1.0f), _mm_mul_ps(x, _mm_set1_ps(0.5f / (1 << Log2M))));
6058
for(i=0;i<Log2M;i++) y = _mm_mul_ps(y, y);
61-
y = _mm_mul_ps(y, _mm_add_ps(_mm_set1_ps(0.1f), _mm_load_ps(Weights))); Weights += 4;
6259
x = _mm_mul_ps(x, y);
6360
_mm_store_ps(Dst+0, _mm_unpacklo_ps(y, x));
6461
_mm_store_ps(Dst+4, _mm_unpackhi_ps(y, x)); Dst += 8;
6562
}
6663
#else
6764
for(n=0;n<N;n++) {
6865
//! Target:
69-
//! y = (E^x)^2 = E^(0.5*x)
66+
//! y = (E^x)^0.5 = E^(0.5*x)
7067
//! E^x = (1+x/m)^m | m->inf
7168
//! We use an approximation here, since this value is only
7269
//! used as a weight; hyper-exactness isn't important.
@@ -79,7 +76,6 @@ static inline void Block_Transform_CalculateNoiseLogSpectrumWithWeights(
7976
float x = *Src++;
8077
float y = 1.0f + x*(0.5f / (1 << Log2M));
8178
for(i=0;i<Log2M;i++) y *= y;
82-
y *= 0.1f + Weights[n];
8379
*Dst++ = y;
8480
*Dst++ = x * y;
8581
}
@@ -97,7 +93,7 @@ static inline void Block_Transform_CalculateNoiseLogSpectrum(float *Data, void *
9793
//! for tones in the masking band, but setting it too low will
9894
//! pick up too many artifacts and will require manipulation of
9995
//! the energy below 1kHz.
100-
static const int FloorToMaskRatio = 2;
96+
static const int FloorToMaskRatio = 1;
10197

10298
//! DCT+DST -> Pseudo-DFT
10399
N /= 2;
@@ -125,13 +121,15 @@ static inline void Block_Transform_CalculateNoiseLogSpectrum(float *Data, void *
125121
}
126122

127123
//! Normalize the energy and convert to fixed-point
124+
//! NOTE: Reduce amplitude at <=1kHz to reduce issues in
125+
//! this relatively important band.
128126
Norm = (Norm > 0x1.0p-96f) ? (0x1.FFFFFCp31f / Norm) : 0x1.FFFFFCp127f;
129127
float LogScale = 0x1.715476p27f / N;
130128
uint32_t *Weight = (uint32_t*)Data;
131129
uint32_t *EnergyNp = (uint32_t*)Temp;
132130
for(n=0;n<N;n++) {
133131
v = Data[n] * Norm;
134-
float ve = v;
132+
float ve = v * (1.0f - 0x1.6B5434p-2f*FreqWeightTable[n]); //! 0x1.6B5434p-2 = 10^(-9/20)
135133
float vw = 0x1.0p16f * sqrtf(ve);
136134
Weight [n] = (vw <= 1.0f) ? 1 : (uint32_t)vw;
137135
EnergyNp[n] = (ve <= 1.0f) ? 0 : (uint32_t)(logf(ve) * LogScale);
@@ -142,7 +140,7 @@ static inline void Block_Transform_CalculateNoiseLogSpectrum(float *Data, void *
142140
//! Extract the noise floor level in each line's noise bandwidth
143141
//! NOTE: We write to Data+N, because we then need to store 2*N
144142
//! data points at Data[] when we calculate the weights next.
145-
int NoiseBeg = 0, NoiseEnd = 0;
143+
int NoiseBeg = 0, NoiseEnd = (1<<RangeScaleFxp) - 1; //! <- Bias towards Ceiling
146144
uint64_t MaskSum = 0, MaskSumW = 0;
147145
uint32_t FloorSum = 0;
148146
float *LogNoiseFloor = Data + N;
@@ -192,7 +190,7 @@ static inline void Block_Transform_CalculateNoiseLogSpectrum(float *Data, void *
192190
//! Save the (approximate) exponent to use as a weight during noise calculations.
193191
//! This operation is factored out so that it can be efficiently vectorized.
194192
//! Note that this function also interleaves {Weight,Weight*Data} as output.
195-
Block_Transform_CalculateNoiseLogSpectrumWithWeights(Data, LogNoiseFloor, FreqWeightTable, N);
193+
Block_Transform_CalculateNoiseLogSpectrumWithWeights(Data, LogNoiseFloor, N);
196194
}
197195

198196
/**************************************/

0 commit comments

Comments
 (0)