codec: Make ir77_ambe_decode return an error if less than 50% are valid

Thanks to schneider <schneider@blinkenlichts.net> for the original
patch.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
This commit is contained in:
Sylvain Munaut 2017-12-02 19:23:42 +01:00
parent 39141a86bb
commit 982cba9029
2 changed files with 17 additions and 6 deletions

View File

@ -97,12 +97,12 @@ ir77_ambe_decode_speech(struct ir77_ambe_decoder *dec,
return 0;
}
/*! \brief Decodes an AMBE superframe to audio
/*! \brief Decodes an AMBE superframe (=2 frames) to audio
* \param[in] dec Decoder object
* \param[out] audio Output audio buffers
* \param[in] N number of audio samples to produce (== 720 for now)
* \param[in] superframe SuperFrame data (39 bytes = 312 bits)
* \returns 0 for success. Negative error code otherwise.
* \returns Number of successfully decoded frames. Negative error code otherwise.
*/
int
ir77_ambe_decode_superframe(struct ir77_ambe_decoder *dec,
@ -111,7 +111,7 @@ ir77_ambe_decode_superframe(struct ir77_ambe_decoder *dec,
{
ubit_t superframe_bits[312];
ubit_t frame_bits[156];
int i;
int frames = 0, i;
/* Unpack to ubits */
osmo_pbit2ubit_ext(superframe_bits, 0, superframe, 0, 312, 1);
@ -146,6 +146,8 @@ ir77_ambe_decode_superframe(struct ir77_ambe_decoder *dec,
continue;
}
frames++;
/* De-prioritize */
ir77_ambe_prioritize(frame_lin, frame, 1);
@ -170,7 +172,7 @@ ir77_ambe_decode_superframe(struct ir77_ambe_decoder *dec,
}
}
return 0;
return frames;
}
/*! @} */

View File

@ -73,6 +73,8 @@ int main(int argc, char *argv[])
struct ir77_ambe_decoder *dec = NULL;
FILE *fin, *fout;
int is_wave = 0, l, rv;
int frames_ok = 0, frames_total = 0;
float error_ratio = 1.0f;
/* Arguments */
if (argc > 3) {
@ -139,11 +141,14 @@ int main(int argc, char *argv[])
/* Decompress */
rv = ir77_ambe_decode_superframe(dec, audio, 2*360, superframe);
if (rv) {
if (rv < 0) {
fprintf(stderr, "[!] codec error\n");
break;
}
frames_ok += rv;
frames_total += 2;
/* Write audio output */
for (i=0; i<2*360; i++)
audio[i] = le16(audio[i]);
@ -158,6 +163,10 @@ int main(int argc, char *argv[])
l += 2*360;
}
/* Report the frame error ratio */
error_ratio = 1.0f - (1.0f * frames_ok) / frames_total;
fprintf(stderr, "Error ratio: %.2f\n", error_ratio);
/* Release decoder */
ir77_ambe_decode_release(dec);
@ -195,5 +204,5 @@ exit:
fclose(fin);
/* All done ! */
return 0;
return error_ratio < 0.5f ? 0 : 1;
}