static av_cold float ath(float f, float add)
{
f /= 1000.0f;
- return 3.64 * pow(f, -0.8)
+ return 3.64 * pow(f, -0.8)
- 6.8 * exp(-0.6 * (f - 3.4) * (f - 3.4))
+ 6.0 * exp(-0.15 * (f - 8.7) * (f - 8.7))
+ (0.6 + 0.04 * add) * 0.001 * f * f * f * f;
start = 0;
for (g = 0; g < ctx->num_bands[j]; g++) {
minscale = ath(ctx->avctx->sample_rate * start / 1024.0, ATH_ADD);
- for (i = 1; i < ctx->bands[j][g]; i++) {
- minscale = fminf(minscale, ath(ctx->avctx->sample_rate * (start + i) / 1024.0 / 2.0, ATH_ADD));
- }
+ for (i = 1; i < ctx->bands[j][g]; i++)
+ minscale = FFMIN(minscale, ath(ctx->avctx->sample_rate * (start + i) / 1024.0 / 2.0, ATH_ADD));
coeffs->ath[g] = minscale - minath;
start += ctx->bands[j][g];
}
int channel, int prev_type)
{
int i, j;
- int br = ctx->avctx->bit_rate / ctx->avctx->channels;
- int attack_ratio = br <= 16000 ? 18 : 10;
+ int br = ctx->avctx->bit_rate / ctx->avctx->channels;
+ int attack_ratio = br <= 16000 ? 18 : 10;
Psy3gppContext *pctx = (Psy3gppContext*) ctx->model_priv_data;
- Psy3gppChannel *pch = &pctx->ch[channel];
- uint8_t grouping = 0;
+ Psy3gppChannel *pch = &pctx->ch[channel];
+ uint8_t grouping = 0;
FFPsyWindowInfo wi;
memset(&wi, 0, sizeof(wi));
v = iir_filter(audio[(i*128+j)*ctx->avctx->channels], pch->iir_state);
sum += v*v;
}
- s[i] = sum;
+ s[i] = sum;
sum2 += sum;
}
for (i = 0; i < 8; i++) {
if (s[i] > pch->win_energy * attack_ratio) {
- attack_n = i + 1;
+ attack_n = i + 1;
switch_to_eight = 1;
break;
}
/**
* Calculate band thresholds as suggested in 3GPP TS26.403
*/
-static void psy_3gpp_analyze(FFPsyContext *ctx, int channel, const float *coefs,
- FFPsyWindowInfo *wi)
+static void psy_3gpp_analyze(FFPsyContext *ctx, int channel,
+ const float *coefs, FFPsyWindowInfo *wi)
{
Psy3gppContext *pctx = (Psy3gppContext*) ctx->model_priv_data;
- Psy3gppChannel *pch = &pctx->ch[channel];
+ Psy3gppChannel *pch = &pctx->ch[channel];
int start = 0;
int i, w, g;
- const int num_bands = ctx->num_bands[wi->num_windows == 8];
+ const int num_bands = ctx->num_bands[wi->num_windows == 8];
const uint8_t* band_sizes = ctx->bands[wi->num_windows == 8];
- Psy3gppCoeffs *coeffs = &pctx->psy_coef[wi->num_windows == 8];
+ Psy3gppCoeffs *coeffs = &pctx->psy_coef[wi->num_windows == 8];
//calculate energies, initial thresholds and related values - 5.4.2 "Threshold Calculation"
for (w = 0; w < wi->num_windows*16; w += 16) {
for (i = 0; i < band_sizes[g]; i++)
band->energy += coefs[start+i] * coefs[start+i];
band->energy *= 1.0f / (512*512);
- band->thr = band->energy * 0.001258925f;
- start += band_sizes[g];
+ band->thr = band->energy * 0.001258925f;
+ start += band_sizes[g];
ctx->psy_bands[channel*PSY_MAX_BANDS+w+g].energy = band->energy;
}
//modify thresholds - spread, threshold in quiet - 5.4.3 "Spreaded Energy Calculation"
for (w = 0; w < wi->num_windows*16; w += 16) {
Psy3gppBand *band = &pch->band[w];
- for (g = 1; g < num_bands; g++) {
+ for (g = 1; g < num_bands; g++)
band[g].thr = FFMAX(band[g].thr, band[g-1].thr * coeffs->spread_low[g-1]);
- }
- for (g = num_bands - 2; g >= 0; g--) {
+ for (g = num_bands - 2; g >= 0; g--)
band[g].thr = FFMAX(band[g].thr, band[g+1].thr * coeffs->spread_hi [g]);
- }
for (g = 0; g < num_bands; g++) {
band[g].thr_quiet = FFMAX(band[g].thr, coeffs->ath[g]);
- if (wi->num_windows != 8 && wi->window_type[1] != EIGHT_SHORT_SEQUENCE) {
- band[g].thr_quiet = fmaxf(PSY_3GPP_RPEMIN*band[g].thr_quiet,
- fminf(band[g].thr_quiet,
+ if (wi->num_windows != 8 && wi->window_type[1] != EIGHT_SHORT_SEQUENCE)
+ band[g].thr_quiet = FFMAX(PSY_3GPP_RPEMIN*band[g].thr_quiet,
+ FFMIN(band[g].thr_quiet,
PSY_3GPP_RPELEV*pch->prev_band[w+g].thr_quiet));
- }
band[g].thr = FFMAX(band[g].thr, band[g].thr_quiet * 0.25);
ctx->psy_bands[channel*PSY_MAX_BANDS+w+g].threshold = band[g].thr;