Skip to content

Commit

Permalink
fix crush bug for small signal segment.
Browse files Browse the repository at this point in the history
  • Loading branch information
aikiriao committed Jan 23, 2025
1 parent 260cda5 commit 079a822
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion libs/srla_encoder/src/srla_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -875,11 +875,12 @@ static double SRLAEncoder_CalculateRGRMeanCodeLength(double mean_abs_error, uint
/* 幾何分布のエントロピーを計算 */
static double SRLAEncoder_CalculateGeometricDistributionEntropy(double mean_abs_error, uint32_t bps)
{
const double min_abs_error = 1e-16; /* 最小絶対値 */
const double intmean = mean_abs_error * (1 << (bps - 1)); /* 整数量子化した時の平均値 */
const double rho = 1.0 / (1.0 + intmean);
const double invrho = 1.0 - rho;

if (mean_abs_error < FLT_MIN) {
if (mean_abs_error < min_abs_error) {
return 0.0;
}

Expand Down
37 changes: 37 additions & 0 deletions test/srla_encode_decode/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ static void SRLAEncodeDecodeTest_GenerateNegativeConstant(double **data, uint32_
static void SRLAEncodeDecodeTest_GenerateNyquistOsc(double **data, uint32_t num_channels, uint32_t num_samples);
/* ガウス雑音の生成 */
static void SRLAEncodeDecodeTest_GenerateGaussNoise(double **data, uint32_t num_channels, uint32_t num_samples);
/* 先頭部分で微小なインパルスの生成 */
static void SRLAEncodeDecodeTest_GenerateMiniImpulse(double** data, uint32_t num_channels, uint32_t num_samples);

/* 無音の生成 */
static void SRLAEncodeDecodeTest_GenerateSilence(
Expand Down Expand Up @@ -189,6 +191,22 @@ static void SRLAEncodeDecodeTest_GenerateGaussNoise(
}
}

/* 先頭部分で微小なインパルスの生成 */
static void SRLAEncodeDecodeTest_GenerateMiniImpulse(
double** data, uint32_t num_channels, uint32_t num_samples)
{
uint32_t smpl, ch;

assert(data != NULL);

for (ch = 0; ch < num_channels; ch++) {
for (smpl = 0; smpl < num_samples; smpl++) {
data[ch][smpl] = 0.0f;
}
data[ch][1] = pow(2.0, -15.0);
}
}

/* double入力データの固定小数化 */
static void SRLAEncodeDecodeTest_InputDoubleToInputFixedFloat(
const struct SRLAEncodeParameter *param, uint32_t offset_lshift,
Expand Down Expand Up @@ -543,6 +561,25 @@ TEST(SRLAEncodeDecodeTest, EncodeDecodeCheckTest)
{ { 8, 8, 8000, 512, 1024, SRLA_NUM_PARAMETER_PRESETS - 1 }, 0, 8500, SRLAEncodeDecodeTest_GenerateGaussNoise },
{ { 8, 16, 8000, 512, 1024, SRLA_NUM_PARAMETER_PRESETS - 1 }, 0, 8500, SRLAEncodeDecodeTest_GenerateGaussNoise },
{ { 8, 24, 8000, 512, 1024, SRLA_NUM_PARAMETER_PRESETS - 1 }, 0, 8500, SRLAEncodeDecodeTest_GenerateGaussNoise },
/* 微小インパルスの部 */
{ { 1, 8, 8000, 512, 1024, 0 }, 0, 8500, SRLAEncodeDecodeTest_GenerateMiniImpulse },
{ { 1, 16, 8000, 512, 1024, 0 }, 0, 8500, SRLAEncodeDecodeTest_GenerateMiniImpulse },
{ { 1, 24, 8000, 512, 1024, 0 }, 0, 8500, SRLAEncodeDecodeTest_GenerateMiniImpulse },
{ { 2, 8, 8000, 512, 1024, 0 }, 0, 8500, SRLAEncodeDecodeTest_GenerateMiniImpulse },
{ { 2, 16, 8000, 512, 1024, 0 }, 0, 8500, SRLAEncodeDecodeTest_GenerateMiniImpulse },
{ { 2, 24, 8000, 512, 1024, 0 }, 0, 8500, SRLAEncodeDecodeTest_GenerateMiniImpulse },
{ { 8, 8, 8000, 512, 1024, 0 }, 0, 8500, SRLAEncodeDecodeTest_GenerateMiniImpulse },
{ { 8, 16, 8000, 512, 1024, 0 }, 0, 8500, SRLAEncodeDecodeTest_GenerateMiniImpulse },
{ { 8, 24, 8000, 512, 1024, 0 }, 0, 8500, SRLAEncodeDecodeTest_GenerateMiniImpulse },
{ { 1, 8, 8000, 512, 1024, SRLA_NUM_PARAMETER_PRESETS - 1 }, 0, 8500, SRLAEncodeDecodeTest_GenerateMiniImpulse },
{ { 1, 16, 8000, 512, 1024, SRLA_NUM_PARAMETER_PRESETS - 1 }, 0, 8500, SRLAEncodeDecodeTest_GenerateMiniImpulse },
{ { 1, 24, 8000, 512, 1024, SRLA_NUM_PARAMETER_PRESETS - 1 }, 0, 8500, SRLAEncodeDecodeTest_GenerateMiniImpulse },
{ { 2, 8, 8000, 512, 1024, SRLA_NUM_PARAMETER_PRESETS - 1 }, 0, 8500, SRLAEncodeDecodeTest_GenerateMiniImpulse },
{ { 2, 16, 8000, 512, 1024, SRLA_NUM_PARAMETER_PRESETS - 1 }, 0, 8500, SRLAEncodeDecodeTest_GenerateMiniImpulse },
{ { 2, 24, 8000, 512, 1024, SRLA_NUM_PARAMETER_PRESETS - 1 }, 0, 8500, SRLAEncodeDecodeTest_GenerateMiniImpulse },
{ { 8, 8, 8000, 512, 1024, SRLA_NUM_PARAMETER_PRESETS - 1 }, 0, 8500, SRLAEncodeDecodeTest_GenerateMiniImpulse },
{ { 8, 16, 8000, 512, 1024, SRLA_NUM_PARAMETER_PRESETS - 1 }, 0, 8500, SRLAEncodeDecodeTest_GenerateMiniImpulse },
{ { 8, 24, 8000, 512, 1024, SRLA_NUM_PARAMETER_PRESETS - 1 }, 0, 8500, SRLAEncodeDecodeTest_GenerateMiniImpulse },
};

/* テストケース数 */
Expand Down

0 comments on commit 079a822

Please sign in to comment.